Skip to content

Commit b5e280c

Browse files
authored
Merge pull request #46 from YosefLab/staging
Staging
2 parents da73af0 + da8fc41 commit b5e280c

File tree

142 files changed

+326
-231
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+326
-231
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: VISION
22
Title: Functional interpretation of single cell RNA-seq latent manifolds
3-
Version: 1.0.0
3+
Version: 1.0.1
44
Authors@R: c(person("Matt", "Jones", email = "mattjones315@gmail.com", role = c("aut", "cre")),
55
person("David", "Detomaso", email = "david.detomaso@berkeley.edu", role = c("aut", "cre")),
66
person("Tal", "Ashuach", email = "tal_ashuach@berkeley.edu", role = c("aut")),

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# VISION 1.0.1
2+
3+
* Bugfixes related to caching in the output report
4+
* Change default `cellsPerPartition` value to 10
5+
* Change default `filterThreshold` parameter value to 5% in applyMicroClustering (for consistency with Vision constructor)
6+
17
# VISION 1.0.0
28

39
* Added Layout Options to the output report

R/AnalysisFunctions.R

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,41 @@ filterData <- function(object,
121121
object@projection_genes <- projection_genes
122122
object@threshold <- threshold
123123

124+
message("Determining projection genes...")
125+
124126
if (length(object@projection_genes) == 1){
125-
message("Determining projection genes...")
126127

127128
exprData <- matLog2(object@exprData)
128-
object@projection_genes <- applyFilters(
129+
projection_genes <- applyFilters(
129130
exprData,
130131
object@threshold,
131132
object@projection_genes)
133+
134+
if (length(projection_genes) == 0){
135+
stop(
136+
sprintf("Filtering with (projection_genes=\"%s\", threshold=%i) results in 0 genes\n Set a lower threshold and re-run",
137+
object@projection_genes, object@threshold)
138+
)
139+
}
140+
} else {
141+
projection_genes <- intersect(
142+
object@projection_genes, rownames(object@exprData))
143+
144+
if (length(projection_genes) == 0){
145+
stop("Supplied list of genes in `projection_genes` does not match any rows of expression data")
146+
} else {
147+
message(
148+
sprintf(" Using supplied list of genes: Found %i/%i matches",
149+
length(projection_genes), length(object@projection_genes)
150+
)
151+
)
152+
}
132153
}
133154

155+
message()
156+
157+
object@projection_genes <- projection_genes
158+
134159

135160
return(object)
136161
}
@@ -228,7 +253,7 @@ computeLatentSpace <- function(object, projection_genes = NULL,
228253
perm_wPCA <- object@perm_wPCA
229254

230255
if (!is.null(projection_genes)) {
231-
exprData <- expr[projection_genes, ]
256+
exprData <- expr[projection_genes, , drop = FALSE]
232257
} else {
233258
exprData <- expr
234259
}

R/Filters.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ filterGenesNovar <- function(data) {
5050
#' @return character vector of gene names passing filter
5151
filterGenesThreshold <- function(data, threshold) {
5252
message(
53-
sprintf(" Applying Threshold filter...removing genes detected in less than %i cells", 2343)
53+
sprintf(" Applying Threshold filter...removing genes detected in less than %i cells", threshold)
5454
)
5555

5656
if ( is(data, "sparseMatrix") ){
57-
valid_rows <- rowSums(data > 0) > threshold
57+
valid_rows <- rowSums(data > 0) >= threshold
5858
} else {
59-
valid_rows <- matrixStats::rowCounts(data > 0) > threshold
59+
valid_rows <- matrixStats::rowCounts(data > 0) >= threshold
6060
}
6161

6262
genes_passing <- rownames(data)[valid_rows]

R/Microclusters.R

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
#'
1212
#'
1313
#' @param exprData the expression data matrix
14-
#' @param cellsPerPartition control over the minimum number of cells to put into each supercell
14+
#' @param cellsPerPartition control over the target number of cells to put into each supercell
1515
#' @param filterInput name of filtering method ('threshold' or 'fano') or list of
1616
#' genes to use when computing projections.
17-
#' @param filterThreshold Threshold to apply when using the 'threshold' projection genes filter.
17+
#' @param filterThreshold Threshold to apply when using the 'threshold' or 'fano' projection genes filter.
1818
#' If greater than 1, this specifies the number of cells in which a gene must be detected
1919
#' for it to be used when computing PCA. If less than 1, this instead specifies the proportion of cells needed
2020
#' @param latentSpace (Optional) Latent space to be used instead of PCA numeric matrix cells x components
@@ -23,27 +23,46 @@
2323
#' @return pooled cells - named list of vectors - cells in each supercell
2424
#' @export
2525
applyMicroClustering <- function(
26-
exprData, cellsPerPartition=100,
26+
exprData, cellsPerPartition=10,
2727
filterInput = "fano",
28-
filterThreshold = round(ncol(exprData) * 0.2),
28+
filterThreshold = round(ncol(exprData) * 0.05),
2929
latentSpace = NULL) {
3030

31+
if (is.data.frame(exprData)){
32+
exprData <- data.matrix(exprData)
33+
}
34+
3135
if (is.null(latentSpace) || all(dim(latentSpace) == c(1, 1))) {
3236
exprData <- matLog2(exprData)
3337

3438

35-
if (length(filterInput > 1)){
36-
gene_passes <- filterInput
39+
message(" Computing a latent space for microclustering using PCA...")
40+
if (length(filterInput) > 1){
41+
gene_passes <- intersect(filterInput, rownames(exprData))
42+
if (length(gene_passes) == 0){
43+
stop("Supplied list of genes in `filterInput` does not match any rows of `exprData`")
44+
} else {
45+
message(
46+
sprintf(" Using supplied list of genes: Found %i/%i matches", length(gene_passes), length(filterInput))
47+
)
48+
}
3749
} else {
50+
message(" Determining lateng space genes...")
3851
gene_passes <- applyFilters(exprData, filterThreshold, filterInput)
52+
53+
if (length(gene_passes) == 0){
54+
stop(
55+
sprintf("Filtering with (filterInput=\"%s\", filterThreshold=%i) results in 0 genes\n Set a lower threshold and re-run", filterInput, filterThreshold)
56+
)
57+
}
3958
}
4059

41-
fexpr <- exprData[gene_passes, ]
60+
fexpr <- exprData[gene_passes, , drop = FALSE]
4261

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

65+
message(" Performing PCA...")
4766
N <- ncol(fexpr)
4867
wcov <- tcrossprod(fexpr) / N
4968

@@ -82,7 +101,7 @@ applyMicroClustering <- function(
82101
pools <- readjust_clusters(cl, res, cellsPerPartition = cellsPerPartition)
83102

84103
# Rename clusters
85-
cn <- paste0("microcluster ", 1:length(pools))
104+
cn <- paste0("microcluster_", 1:length(pools))
86105
names(pools) <- cn
87106

88107
message(

R/Projections.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ generateProjectionsInner <- function(expr, latentSpace, projection_genes=NULL, p
4545
if (method == "ICA" || method == "RBFPCA") {
4646

4747
if (!is.null(projection_genes)) {
48-
exprData <- expr[projection_genes, ]
48+
exprData <- expr[projection_genes, , drop = FALSE]
4949
} else {
5050
exprData <- expr
5151
}

R/Server.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ ServerSigProjMatrix <- function(zscores, pvals, proj_labels, sig_labels) {
3131
#' @return JSON formatted Signature object.
3232
signatureToJSON <- function(sig) {
3333

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

3737
json <- toJSON(sig, force=TRUE, pretty=TRUE, auto_unbox=TRUE)
@@ -100,7 +100,7 @@ coordinatesToJSON <- function(p) {
100100
return(json)
101101
}
102102

103-
#' Converts a sigProjMatrix from a FastProject Object to a JSON object
103+
#' Converts a sigProjMatrix from an R Object to a JSON object
104104
#' @importFrom jsonlite toJSON
105105
#' @param sigzscores Matrix of signature z-scores
106106
#' @param sigpvals Matrix of signature p-values
@@ -156,8 +156,7 @@ compressJSONResponse <- function(json, res, req){
156156
#' Lanch the server
157157
#' @importFrom jsonlite fromJSON
158158
#' @importFrom utils browseURL URLdecode stack
159-
#' @param object FastProject object or path to a file containing such an
160-
#' object (saved using saveAndViewResults, or directly using saveRDS)
159+
#' @param object Vision object
161160
#' @param port The port on which to serve the output viewer. If omitted, a
162161
#' random port between 8000 and 9999 is chosen.
163162
#' @param host The host used to serve the output viewer. If omitted, "127.0.0.1"

R/SigScoreMethods.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#' Different ways to evalutate the signature score
22
#'
3-
#' EAch method should have the same signature so they can be swapped
3+
#' Each method should have the same signature so they can be swapped
44
#'
55
#' Right now, each takes in a wrapped data object and signature object
66
#'
7-
#' Specified by FastProject argument (sig_score_method), default = naiveEvalSignature
7+
#' Specified by Vision argument (sig_score_method), default = "naive"
88

99
#' Evaluate signature scores efficiently in batches
1010
#'

R/Utilities.R

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ batchify <- function(items, per_batch, n_workers = 1) {
3535
}
3636

3737

38-
#' Check's the version of the FastProject object and displays error if necessary
38+
#' Checks the version of the Vision object and displays error if necessary
3939
#'
40-
#' @param object FastProject object
40+
#' @param object Vision object
4141
#' @return NULL
4242
versionCheck <- function(object) {
4343

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

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

60+
if(object@version < 1.1) {
61+
msg <- gsub("#COMMIT", "2db4552", templateStr)
62+
stop(msg, call. = FALSE)
63+
}
64+
6065
# Add new commit hashes here as version increases and breaks backward compatibility
6166

6267
return()

R/methods-Vision.R

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

8484
.Object <- new("Vision")

0 commit comments

Comments
 (0)