Skip to content

Commit

Permalink
Merge pull request #46 from YosefLab/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
deto authored Feb 7, 2019
2 parents da73af0 + da8fc41 commit b5e280c
Show file tree
Hide file tree
Showing 142 changed files with 326 additions and 231 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: VISION
Title: Functional interpretation of single cell RNA-seq latent manifolds
Version: 1.0.0
Version: 1.0.1
Authors@R: c(person("Matt", "Jones", email = "[email protected]", role = c("aut", "cre")),
person("David", "Detomaso", email = "[email protected]", role = c("aut", "cre")),
person("Tal", "Ashuach", email = "[email protected]", role = c("aut")),
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# VISION 1.0.1

* Bugfixes related to caching in the output report
* Change default `cellsPerPartition` value to 10
* Change default `filterThreshold` parameter value to 5% in applyMicroClustering (for consistency with Vision constructor)

# VISION 1.0.0

* Added Layout Options to the output report
Expand Down
31 changes: 28 additions & 3 deletions R/AnalysisFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,41 @@ filterData <- function(object,
object@projection_genes <- projection_genes
object@threshold <- threshold

message("Determining projection genes...")

if (length(object@projection_genes) == 1){
message("Determining projection genes...")

exprData <- matLog2(object@exprData)
object@projection_genes <- applyFilters(
projection_genes <- applyFilters(
exprData,
object@threshold,
object@projection_genes)

if (length(projection_genes) == 0){
stop(
sprintf("Filtering with (projection_genes=\"%s\", threshold=%i) results in 0 genes\n Set a lower threshold and re-run",
object@projection_genes, object@threshold)
)
}
} else {
projection_genes <- intersect(
object@projection_genes, rownames(object@exprData))

if (length(projection_genes) == 0){
stop("Supplied list of genes in `projection_genes` does not match any rows of expression data")
} else {
message(
sprintf(" Using supplied list of genes: Found %i/%i matches",
length(projection_genes), length(object@projection_genes)
)
)
}
}

message()

object@projection_genes <- projection_genes


return(object)
}
Expand Down Expand Up @@ -228,7 +253,7 @@ computeLatentSpace <- function(object, projection_genes = NULL,
perm_wPCA <- object@perm_wPCA

if (!is.null(projection_genes)) {
exprData <- expr[projection_genes, ]
exprData <- expr[projection_genes, , drop = FALSE]
} else {
exprData <- expr
}
Expand Down
6 changes: 3 additions & 3 deletions R/Filters.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ filterGenesNovar <- function(data) {
#' @return character vector of gene names passing filter
filterGenesThreshold <- function(data, threshold) {
message(
sprintf(" Applying Threshold filter...removing genes detected in less than %i cells", 2343)
sprintf(" Applying Threshold filter...removing genes detected in less than %i cells", threshold)
)

if ( is(data, "sparseMatrix") ){
valid_rows <- rowSums(data > 0) > threshold
valid_rows <- rowSums(data > 0) >= threshold
} else {
valid_rows <- matrixStats::rowCounts(data > 0) > threshold
valid_rows <- matrixStats::rowCounts(data > 0) >= threshold
}

genes_passing <- rownames(data)[valid_rows]
Expand Down
37 changes: 28 additions & 9 deletions R/Microclusters.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#'
#'
#' @param exprData the expression data matrix
#' @param cellsPerPartition control over the minimum number of cells to put into each supercell
#' @param cellsPerPartition control over the target number of cells to put into each supercell
#' @param filterInput name of filtering method ('threshold' or 'fano') or list of
#' genes to use when computing projections.
#' @param filterThreshold Threshold to apply when using the 'threshold' projection genes filter.
#' @param filterThreshold Threshold to apply when using the 'threshold' or 'fano' projection genes filter.
#' If greater than 1, this specifies the number of cells in which a gene must be detected
#' for it to be used when computing PCA. If less than 1, this instead specifies the proportion of cells needed
#' @param latentSpace (Optional) Latent space to be used instead of PCA numeric matrix cells x components
Expand All @@ -23,27 +23,46 @@
#' @return pooled cells - named list of vectors - cells in each supercell
#' @export
applyMicroClustering <- function(
exprData, cellsPerPartition=100,
exprData, cellsPerPartition=10,
filterInput = "fano",
filterThreshold = round(ncol(exprData) * 0.2),
filterThreshold = round(ncol(exprData) * 0.05),
latentSpace = NULL) {

if (is.data.frame(exprData)){
exprData <- data.matrix(exprData)
}

if (is.null(latentSpace) || all(dim(latentSpace) == c(1, 1))) {
exprData <- matLog2(exprData)


if (length(filterInput > 1)){
gene_passes <- filterInput
message(" Computing a latent space for microclustering using PCA...")
if (length(filterInput) > 1){
gene_passes <- intersect(filterInput, rownames(exprData))
if (length(gene_passes) == 0){
stop("Supplied list of genes in `filterInput` does not match any rows of `exprData`")
} else {
message(
sprintf(" Using supplied list of genes: Found %i/%i matches", length(gene_passes), length(filterInput))
)
}
} else {
message(" Determining lateng space genes...")
gene_passes <- applyFilters(exprData, filterThreshold, filterInput)

if (length(gene_passes) == 0){
stop(
sprintf("Filtering with (filterInput=\"%s\", filterThreshold=%i) results in 0 genes\n Set a lower threshold and re-run", filterInput, filterThreshold)
)
}
}

fexpr <- exprData[gene_passes, ]
fexpr <- exprData[gene_passes, , drop = FALSE]

message(" Computing a latent space for microclustering using PCA...")
# Compute wcov using matrix operations to avoid
# creating a large dense matrix

message(" Performing PCA...")
N <- ncol(fexpr)
wcov <- tcrossprod(fexpr) / N

Expand Down Expand Up @@ -82,7 +101,7 @@ applyMicroClustering <- function(
pools <- readjust_clusters(cl, res, cellsPerPartition = cellsPerPartition)

# Rename clusters
cn <- paste0("microcluster ", 1:length(pools))
cn <- paste0("microcluster_", 1:length(pools))
names(pools) <- cn

message(
Expand Down
2 changes: 1 addition & 1 deletion R/Projections.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ generateProjectionsInner <- function(expr, latentSpace, projection_genes=NULL, p
if (method == "ICA" || method == "RBFPCA") {

if (!is.null(projection_genes)) {
exprData <- expr[projection_genes, ]
exprData <- expr[projection_genes, , drop = FALSE]
} else {
exprData <- expr
}
Expand Down
7 changes: 3 additions & 4 deletions R/Server.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ServerSigProjMatrix <- function(zscores, pvals, proj_labels, sig_labels) {
#' @return JSON formatted Signature object.
signatureToJSON <- function(sig) {

# Pass in a Signature object from a FastProject Object to be converted into a JSON object
# Pass in a Signature object from an R Object to be converted into a JSON object
sig@sigDict <- as.list(sig@sigDict)

json <- toJSON(sig, force=TRUE, pretty=TRUE, auto_unbox=TRUE)
Expand Down Expand Up @@ -100,7 +100,7 @@ coordinatesToJSON <- function(p) {
return(json)
}

#' Converts a sigProjMatrix from a FastProject Object to a JSON object
#' Converts a sigProjMatrix from an R Object to a JSON object
#' @importFrom jsonlite toJSON
#' @param sigzscores Matrix of signature z-scores
#' @param sigpvals Matrix of signature p-values
Expand Down Expand Up @@ -156,8 +156,7 @@ compressJSONResponse <- function(json, res, req){
#' Lanch the server
#' @importFrom jsonlite fromJSON
#' @importFrom utils browseURL URLdecode stack
#' @param object FastProject object or path to a file containing such an
#' object (saved using saveAndViewResults, or directly using saveRDS)
#' @param object Vision object
#' @param port The port on which to serve the output viewer. If omitted, a
#' random port between 8000 and 9999 is chosen.
#' @param host The host used to serve the output viewer. If omitted, "127.0.0.1"
Expand Down
4 changes: 2 additions & 2 deletions R/SigScoreMethods.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#' Different ways to evalutate the signature score
#'
#' EAch method should have the same signature so they can be swapped
#' Each method should have the same signature so they can be swapped
#'
#' Right now, each takes in a wrapped data object and signature object
#'
#' Specified by FastProject argument (sig_score_method), default = naiveEvalSignature
#' Specified by Vision argument (sig_score_method), default = "naive"

#' Evaluate signature scores efficiently in batches
#'
Expand Down
13 changes: 9 additions & 4 deletions R/Utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ batchify <- function(items, per_batch, n_workers = 1) {
}


#' Check's the version of the FastProject object and displays error if necessary
#' Checks the version of the Vision object and displays error if necessary
#'
#' @param object FastProject object
#' @param object Vision object
#' @return NULL
versionCheck <- function(object) {

templateStr <- paste0(
"This FastProject object was created with an older version of the library.",
" To view, either install an older version (commit #COMMIT) from GitHub (www.github.com/YosefLab/FastProjectR) or",
"This Vision object was created with an older version of the library.",
" To view, either install an older version (commit #COMMIT) from GitHub (www.github.com/YosefLab/Vision) or",
" recreate the object and re-run analyze"
)

Expand All @@ -57,6 +57,11 @@ versionCheck <- function(object) {
stop(msg, call. = FALSE)
}

if(object@version < 1.1) {
msg <- gsub("#COMMIT", "2db4552", templateStr)
stop(msg, call. = FALSE)
}

# Add new commit hashes here as version increases and breaks backward compatibility

return()
Expand Down
8 changes: 4 additions & 4 deletions R/methods-Vision.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#' supplied expression matrix are removed.
#' @param weights Precomputed weights for each coordinate. Normally computed
#' from the FNR curve.
#' @param threshold Threshold to apply when using the 'threshold' projection genes filter.
#' @param threshold Threshold to apply when using the 'threshold' or 'fano' projection genes filter.
#' If greater than 1, this specifies the number of cells in which a gene must be detected
#' for it to be used when computing PCA. If less than 1, this instead specifies the proportion of cells needed
#' @param perm_wPCA If TRUE, apply permutation procedure to calculate significant
Expand All @@ -34,10 +34,10 @@
#' or "rank_norm_columns"
#' @param sig_score_method Method to apply when calculating signature scores.
#' Either "naive" (default) or "weighted_avg"
#' @param pool indicates whether or not to create supercells. Acceptable values
#' @param pool indicates whether or not to pool cells into supercells. Acceptable values
#' are TRUE, FALSE, or 'auto', the last of which is the default and enables
#' pooling if there are more than 15000 cells.
#' @param cellsPerPartition the minimum number of cells to put into a cluster
#' @param cellsPerPartition the target number of cells to put into a supercell when pooling
#' @param latentSpace latent space for expression data. Numeric matrix or dataframe
#' with dimensions CELLS x COMPONENTS
#' @param latentTrajectory trajectory to model cell progression. Wrapped result
Expand Down Expand Up @@ -78,7 +78,7 @@ setMethod("Vision", signature(data = "matrixORSparse"),
"znorm_rows_then_columns",
"rank_norm_columns"),
sig_score_method=c("naive", "weighted_avg"),
pool="auto", cellsPerPartition=100, name=NULL,
pool="auto", cellsPerPartition=10, name=NULL,
latentSpace = NULL, latentTrajectory = NULL, pools=list()) {

.Object <- new("Vision")
Expand Down
2 changes: 1 addition & 1 deletion docs/LICENSE-text.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/articles/VISION-vignette.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions docs/articles/micropooling.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/trajectories.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/web_only/10xData.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/web_only/Seurat.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/web_only/SignatureAutocorrelation.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/web_only/Signatures.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b5e280c

Please sign in to comment.