Skip to content

Commit

Permalink
move modelGeneVar to internal function, switch scran to suggest
Browse files Browse the repository at this point in the history
  • Loading branch information
shazanfar committed Jul 16, 2024
1 parent 423567a commit 54bbfb4
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 17 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ Imports:
Matrix,
MASS,
abind,
scran,
SummarizedExperiment,
methods,
MatrixGenerics,
BiocGenerics,
BiocSingular,
BiocParallel
Suggests:
scran,
scater,
knitr,
UpSetR,
gridExtra,
Expand Down
37 changes: 22 additions & 15 deletions R/stabMap.R
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,13 @@ stabMap <- function(assay_list,
" variance ranking"
)
}
genevars <- scran::modelGeneVar(
assay_list[[reference_dataset]][features, ]
)
genevars_sorted <- genevars[order(genevars$bio, decreasing = TRUE), ]
features <- rownames(genevars_sorted)[seq_len(maxFeatures)]
# genevars <- scran::modelGeneVar(
# assay_list[[reference_dataset]][features, ]
# )
# genevars_sorted <- genevars[order(genevars$bio, decreasing = TRUE), ]
# features <- rownames(genevars_sorted)[seq_len(maxFeatures)]
# replacement below
features = selectFeatures(assay_list[[reference_dataset]], features, maxFeatures)
}

labels_train <- labels_list[[reference_dataset]]
Expand Down Expand Up @@ -476,16 +478,21 @@ stabMap <- function(assay_list,
)
}

genevars <- scran::modelGeneVar(
assay_list[[path_current[1]]][features_current, ],
min.mean = 0
)
genevars_sorted <- genevars[
order(genevars$bio, decreasing = TRUE),
]
features_current <- rownames(
genevars_sorted
)[seq_len(maxFeatures)]
# genevars <- scran::modelGeneVar(
# assay_list[[path_current[1]]][features_current, ],
# min.mean = 0
# )
# genevars_sorted <- genevars[
# order(genevars$bio, decreasing = TRUE),
# ]
# features_current <- rownames(
# genevars_sorted
# )[seq_len(maxFeatures)]
# replacement below

features_current = selectFeatures(assay_list[[path_current[1]]],
features_current,
maxFeatures)
}

coef <- stats::lm.fit(
Expand Down
31 changes: 31 additions & 0 deletions R/stabMap_utils.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#' selectFeatures
#'
#' For a given assay and set of features, perform variance ranking and select
#' a subset of features
#'
#' @param assay An assay matrix rows are features, columns are cells
#' @param features Character vector of the current features that are selected
#' @param maxFeatures Integer of the number of maxFeatures to select
#'
#' @return A character vector of the selected features according to variance
#' ranking.
#'
#' @keywords internal
selectFeatures = function(assay, features, maxFeatures) {

if (!requireNamespace("scran", quietly = TRUE)) {
stop("Install 'scran' select features when maxFeatures is selected")
}

genevars <- scran::modelGeneVar(
assay[features, ],
min.mean = 0
)
genevars_sorted <- genevars[
order(genevars$bio, decreasing = TRUE),
]
features_selected <- rownames(
genevars_sorted
)[seq_len(maxFeatures)]
return(features_selected)
}
24 changes: 24 additions & 0 deletions man/selectFeatures.Rd

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

3 changes: 2 additions & 1 deletion vignettes/stabMap_PBMC_Multiome.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ knitr::opts_chunk$set(

```{r setup, message=FALSE, warning=FALSE}
library(StabMap)
library(scran)
library(magrittr)
library(scater)
library(scran)
library(SingleCellMultiModal)
library(gridExtra)
```
Expand Down

0 comments on commit 54bbfb4

Please sign in to comment.