1111# ' @param inSCE Input \linkS4class{SingleCellExperiment} object
1212# ' @param method Specify which method to use for variable gene extraction
1313# ' from Seurat \code{"vst"}, \code{"mean.var.plot"}, \code{"dispersion"} or
14- # ' Scran \code{"modelGeneVar"}. Default \code{"vst"}
14+ # ' Scran \code{"modelGeneVar"} or Scanpy \code{"seurat"}, \code{"cell_ranger"},
15+ # ' \code{"seurat_v3"}. Default \code{"vst"}
1516# ' @param hvgNumber Specify the number of top variable genes to extract.
1617# ' @param useFeatureSubset Get the feature names in the HVG list set by
1718# ' \code{setTopHVG}. Will ignore \code{method} and \code{hvgNumber} if not
5253# ' @importFrom S4Vectors metadata
5354getTopHVG <- function (inSCE ,
5455 method = c(" vst" , " dispersion" ,
55- " mean.var.plot" , " modelGeneVar" ),
56+ " mean.var.plot" , " modelGeneVar" , " seurat" ,
57+ " seurat_v3" , " cell_ranger" ),
5658 hvgNumber = 2000 ,
5759 useFeatureSubset = NULL ,
5860 featureDisplay = metadata(inSCE )$ featureDisplay ) {
@@ -64,7 +66,12 @@ getTopHVG <- function(inSCE,
6466 } else {
6567 metrics <- .dfFromHVGMetric(inSCE , method )
6668 metrics <- metrics [order(- metrics $ v_rank ),]
67- metrics <- metrics [metrics $ v_rank > 0 , ]
69+ if (method == " seurat" ){
70+ metrics <- metrics [metrics $ v_plot > 0 , ]
71+ }
72+ else {
73+ metrics <- metrics [metrics $ v_rank > 0 , ]
74+ }
6875 if (method == " mean.var.plot" ) {
6976 means.use <- (metrics $ mean > 0.1 ) & (metrics $ mean < 8 )
7077 dispersions.use <- (metrics $ v_plot > 1 ) & (metrics $ v_plot < Inf )
@@ -87,7 +94,8 @@ getTopHVG <- function(inSCE,
8794# ' @importFrom S4Vectors metadata<-
8895setTopHVG <- function (inSCE ,
8996 method = c(" vst" , " dispersion" ,
90- " mean.var.plot" , " modelGeneVar" ),
97+ " mean.var.plot" , " modelGeneVar" , " seurat" ,
98+ " seurat_v3" , " cell_ranger" ),
9199 hvgNumber = 2000 ,
92100 featureSubsetName = NULL ,
93101 genes = NULL , genesBy = NULL ,
@@ -138,13 +146,15 @@ setTopHVG <- function(inSCE,
138146# ' @param inSCE Input \linkS4class{SingleCellExperiment} object
139147# ' @param method Specify which method to use for variable gene extraction
140148# ' from Seurat \code{"vst"}, \code{"mean.var.plot"}, \code{"dispersion"} or
141- # ' Scran \code{"modelGeneVar"}. Default \code{"vst"}
149+ # ' Scran \code{"modelGeneVar"} or Scanpy \code{"seurat"}, \code{"cell_ranger"},
150+ # ' \code{"seurat_v3"}. Default \code{"vst"}
142151# ' @return data.frame object of HVG metrics calculated by \code{method},
143152# ' containing columns of \code{"mean"}, \code{"v_rank"}, \code{"v_plot"}
144153# ' @noRd
145154.dfFromHVGMetric <- function (inSCE ,
146155 method = c(" vst" , " mean.var.plot" , " dispersion" ,
147- " modelGeneVar" )) {
156+ " modelGeneVar" , " seurat" ,
157+ " seurat_v3" , " cell_ranger" )) {
148158 method <- match.arg(method )
149159 df <- data.frame (featureNames = rownames(inSCE ))
150160 if (method == " vst" ) {
@@ -167,6 +177,39 @@ setTopHVG <- function(inSCE,
167177 " Run `runSeuratFindHVG()` with 'dispersion' method " ,
168178 " before using this function!" )
169179 }
180+ }else if (method == " seurat_v3" ) {
181+ m <- " means"
182+ v_rank <- " variances"
183+ v_plot <- " variances_norm"
184+ if (is.null(rowData(inSCE )[[v_rank ]]) ||
185+ is.null(rowData(inSCE )[[m ]]) ||
186+ is.null(rowData(inSCE )[[v_plot ]])) {
187+ stop(" Scanpy variance metric not found in inSCE. " ,
188+ " Run `runScanpyFindHVG()` with 'seurat_v3' method " ,
189+ " before using this function!" )
190+ }
191+ }else if (method == " cell_ranger" ) {
192+ m <- " means"
193+ v_rank <- " dispersions"
194+ v_plot <- " dispersions_norm"
195+ if (is.null(rowData(inSCE )[[v_rank ]]) ||
196+ is.null(rowData(inSCE )[[m ]]) ||
197+ is.null(rowData(inSCE )[[v_plot ]])) {
198+ stop(" Scanpy dispersion metric not found in inSCE. " ,
199+ " Run `runScanpyFindHVG()` with 'cell_ranger' method " ,
200+ " before using this function!" )
201+ }
202+ }else if (method == " seurat" ) {
203+ m <- " means"
204+ v_rank <- " dispersions"
205+ v_plot <- " dispersions_norm"
206+ if (is.null(rowData(inSCE )[[v_rank ]]) ||
207+ is.null(rowData(inSCE )[[m ]]) ||
208+ is.null(rowData(inSCE )[[v_plot ]])) {
209+ stop(" Scanpy dispersion metric not found in inSCE. " ,
210+ " Run `runScanpyFindHVG()` with 'dispersion' method " ,
211+ " before using this function!" )
212+ }
170213 } else if (method == " modelGeneVar" ) {
171214 m <- " scran_modelGeneVar_mean"
172215 v_rank <- " scran_modelGeneVar_bio"
0 commit comments