Browse code

Updates to scanpy

Irzam Sarfraz authored on 04/10/2022 14:16:00
Showing 11 changed files

... ...
@@ -182,7 +182,12 @@ export(runQuickUMAP)
182 182
 export(runSCANORAMA)
183 183
 export(runSCMerge)
184 184
 export(runScDblFinder)
185
+export(runScanpyFindHVG)
185 186
 export(runScanpyNormalizeData)
187
+export(runScanpyPCA)
188
+export(runScanpyScaleData)
189
+export(runScanpyTSNE)
190
+export(runScanpyUMAP)
186 191
 export(runScranSNN)
187 192
 export(runScrublet)
188 193
 export(runSeuratFindClusters)
... ...
@@ -9328,10 +9328,11 @@ shinyServer(function(input, output, session) {
9328 9328
     {
9329 9329
       req(vals$counts)
9330 9330
       message(paste0(date(), " ... Finding High Variable Genes"))
9331
-        # vals$counts <- runSeuratFindHVG(inSCE = vals$counts,
9332
-        #                                 useAssay = metadata(vals$counts)$sctk$seuratUseAssay,
9333
-        #                                 method = input$hvg_method,
9334
-        #                                 hvgNumber = as.numeric(input$hvg_no_features))
9331
+        vals$counts <- runScanpyFindHVG(inSCE = vals$counts,
9332
+                                        #useAssay = metadata(vals$counts)$sctk$seuratUseAssay,
9333
+                                        useAssay = "counts",
9334
+                                        method = "cell_ranger")
9335
+                                        #hvgNumber = as.numeric(input$hvg_no_features))
9335 9336
 
9336 9337
       # vals$counts <- singleCellTK:::.seuratInvalidate(inSCE = vals$counts, varFeatures = FALSE)
9337 9338
       # message(paste0(date(), " ... Plotting HVG"))
... ...
@@ -9367,12 +9368,12 @@ shinyServer(function(input, output, session) {
9367 9368
       # # incompatible with Seurat's "_"-to-"-" change. But in `runSeuratPCA/ICA`,
9368 9369
       # # we automatically detect seurat HVG from the object when `useFeatureSubset
9369 9370
       # # = NULL`, so no need to specify this now.
9370
-      # vals$counts <- runSeuratPCA(inSCE = vals$counts,
9371
-      #                             useAssay = "seuratNormData",
9372
-      #                             reducedDimName = "seuratPCA",
9373
-      #                             #useFeatureSubset = getSeuratVariableFeatures(vals$counts),
9374
-      #                             nPCs = input$pca_no_components,
9375
-      #                             seed = input$seed_PCA)
9371
+      vals$counts <- runScanpyPCA(inSCE = vals$counts,
9372
+                                  algorithm = "auto")
9373
+                                  #useAssay = "seuratNormData",
9374
+                                  #reducedDimName = "seuratPCA",
9375
+                                  #nPCs = input$pca_no_components,
9376
+                                  #seed = input$seed_PCA)
9376 9377
       # 
9377 9378
       # vals$counts@metadata$seurat$count_pc <- dim(convertSCEToSeurat(vals$counts)[["pca"]])[2]
9378 9379
       # vals$counts <- singleCellTK:::.seuratInvalidate(inSCE = vals$counts, scaleData = FALSE, varFeatures = FALSE, PCA = FALSE, ICA = FALSE)
... ...
@@ -25,11 +25,6 @@ shinyPanelScanpy <- fluidPage(
25 25
         )
26 26
     ),
27 27
     bsCollapse(id = "ScanpyUI", open = "scanpy QC & Filtering", # ScanPy
28
-            bsCollapsePanel("QC & Filtering",
29
-                fluidRow(
30
-                        ),
31
-                            style = "primary"
32
-                            ),
33 28
             bsCollapsePanel("Normalize Data",
34 29
                                                                    fluidRow(
35 30
                                                                      column(4,
... ...
@@ -7,7 +7,8 @@
7 7
 \usage{
8 8
 getTopHVG(
9 9
   inSCE,
10
-  method = c("vst", "dispersion", "mean.var.plot", "modelGeneVar"),
10
+  method = c("vst", "dispersion", "mean.var.plot", "modelGeneVar", "seurat",
11
+    "seurat_v3", "cell_ranger"),
11 12
   hvgNumber = 2000,
12 13
   useFeatureSubset = NULL,
13 14
   featureDisplay = metadata(inSCE)$featureDisplay
14 15
new file mode 100644
... ...
@@ -0,0 +1,41 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/scanpyFunctions.R
3
+\name{runScanpyFindHVG}
4
+\alias{runScanpyFindHVG}
5
+\title{runScanpyFindHVG
6
+Find highly variable genes and store in the input sce object}
7
+\usage{
8
+runScanpyFindHVG(
9
+  inSCE,
10
+  useAssay = "counts",
11
+  method = c("seurat", "cell_ranger", "seurat_v3"),
12
+  hvgNumber = 2000
13
+)
14
+}
15
+\arguments{
16
+\item{inSCE}{(sce) object to compute highly variable genes from and to store
17
+back to it}
18
+
19
+\item{useAssay}{Specify the name of the assay to use for computation
20
+of variable genes. It is recommended to use a raw counts assay with the}
21
+
22
+\item{method}{selected method to use for computation of highly variable
23
+genes. One of \code{'seurat'}, \code{'cell_ranger'}, or \code{'seurat_v3'}.
24
+Default \code{"seurat"}.}
25
+
26
+\item{hvgNumber}{numeric value of how many genes to select as highly
27
+variable. Default \code{2000}}
28
+}
29
+\value{
30
+Updated \code{SingleCellExperiment} object with highly variable genes
31
+computation stored
32
+\code{\link{getTopHVG}}, \code{\link{plotTopHVG}}
33
+}
34
+\description{
35
+runScanpyFindHVG
36
+Find highly variable genes and store in the input sce object
37
+}
38
+\examples{
39
+data(scExample, package = "singleCellTK")
40
+sce <- runScanpyFindHVG(sce)
41
+}
... ...
@@ -4,7 +4,7 @@
4 4
 \alias{runScanpyNormalizeData}
5 5
 \title{runScanpyNormalizeData
6 6
 Wrapper for NormalizeData() function from scanpy library
7
-Normalizes the sce object according to the input parameters provided.}
7
+Normalizes the sce object according to the input parameters}
8 8
 \usage{
9 9
 runScanpyNormalizeData(
10 10
   inSCE,
... ...
@@ -30,7 +30,7 @@ Normalized \code{SingleCellExperiment} object
30 30
 \description{
31 31
 runScanpyNormalizeData
32 32
 Wrapper for NormalizeData() function from scanpy library
33
-Normalizes the sce object according to the input parameters provided.
33
+Normalizes the sce object according to the input parameters
34 34
 }
35 35
 \examples{
36 36
 data(scExample, package = "singleCellTK")
37 37
new file mode 100644
... ...
@@ -0,0 +1,52 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/scanpyFunctions.R
3
+\name{runScanpyPCA}
4
+\alias{runScanpyPCA}
5
+\title{runScanpyPCA
6
+Computes PCA on the input sce object and stores the calculated principal
7
+components within the sce object}
8
+\usage{
9
+runScanpyPCA(
10
+  inSCE,
11
+  useAssay = "scanpyScaledData",
12
+  reducedDimName = "scanpyPCA",
13
+  nPCs = 50L,
14
+  algorithm = c("arpack", "randomized", "auto", "lobpcg"),
15
+  use_highly_variable = TRUE
16
+)
17
+}
18
+\arguments{
19
+\item{inSCE}{(sce) object on which to compute PCA}
20
+
21
+\item{useAssay}{Assay containing scaled counts to use in PCA. Default
22
+\code{"scanpyScaledData"}.}
23
+
24
+\item{reducedDimName}{Name of new reducedDims object containing Scanpy PCA.
25
+Default \code{scanpyPCA}.}
26
+
27
+\item{nPCs}{numeric value of how many components to compute. Default
28
+\code{20}.}
29
+
30
+\item{algorithm}{selected method to use for computation of pca. One of \code{'arpack'}, \code{'randomized'}, \code{'auto'} or \code{'lobpcg'}.
31
+Default \code{"arpack"}.}
32
+
33
+\item{use_highly_variable}{boolean value of whether to use highly variable genes only. By default uses them if they have been determined beforehand.}
34
+}
35
+\value{
36
+Updated \code{SingleCellExperiment} object which now contains the
37
+computed principal components
38
+}
39
+\description{
40
+runScanpyPCA
41
+Computes PCA on the input sce object and stores the calculated principal
42
+components within the sce object
43
+}
44
+\examples{
45
+data(scExample, package = "singleCellTK")
46
+\dontrun{
47
+sce <- runScanpyNormalizeData(sce, useAssay = "counts")
48
+sce <- runScanpyFindHVG(sce, useAssay = "counts")
49
+sce <- runScanpyScaleData(sce, useAssay = "counts")
50
+sce <- runScanpyPCA(sce, useAssay = "counts")
51
+}
52
+}
0 53
new file mode 100644
... ...
@@ -0,0 +1,36 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/scanpyFunctions.R
3
+\name{runScanpyScaleData}
4
+\alias{runScanpyScaleData}
5
+\title{runScanpyScaleData
6
+Scales the input sce object according to the input parameters}
7
+\usage{
8
+runScanpyScaleData(
9
+  inSCE,
10
+  useAssay = "scanpyNormData",
11
+  scaledAssayName = "scanpyScaledData"
12
+)
13
+}
14
+\arguments{
15
+\item{inSCE}{(sce) object to scale}
16
+
17
+\item{useAssay}{Assay containing normalized counts to scale.}
18
+
19
+\item{scaledAssayName}{Name of new assay containing scaled data. Default
20
+\code{scanpyScaledData}.}
21
+}
22
+\value{
23
+Scaled \code{SingleCellExperiment} object
24
+}
25
+\description{
26
+runScanpyScaleData
27
+Scales the input sce object according to the input parameters
28
+}
29
+\examples{
30
+data(scExample, package = "singleCellTK")
31
+\dontrun{
32
+sce <- runScanpyNormalizeData(sce, useAssay = "counts")
33
+sce <- runScanpyFindHVG(sce, useAssay = "counts")
34
+sce <- runScanpyScaleData(sce, useAssay = "counts")
35
+}
36
+}
0 37
new file mode 100644
... ...
@@ -0,0 +1,43 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/scanpyFunctions.R
3
+\name{runScanpyTSNE}
4
+\alias{runScanpyTSNE}
5
+\title{runScanpyTSNE
6
+Computes tSNE from the given sce object and stores the tSNE computations back
7
+into the sce object}
8
+\usage{
9
+runScanpyTSNE(
10
+  inSCE,
11
+  useReduction = "scanpyPCA",
12
+  reducedDimName = "scanpyTSNE",
13
+  dims = 10L,
14
+  perplexity = 15L,
15
+  externalReduction = NULL
16
+)
17
+}
18
+\arguments{
19
+\item{inSCE}{(sce) object on which to compute the tSNE}
20
+
21
+\item{useReduction}{selected reduction algorithm to use for computing tSNE.
22
+Default \code{"pca"}.}
23
+
24
+\item{reducedDimName}{Name of new reducedDims object containing Scanpy tSNE
25
+Default \code{scanpyTSNE}.}
26
+
27
+\item{dims}{Number of reduction components to use for tSNE computation.
28
+Default \code{10}.}
29
+
30
+\item{perplexity}{Adjust the perplexity tuneable parameter for the underlying
31
+tSNE call. Default \code{15}.}
32
+
33
+\item{externalReduction}{Pass DimReduc object if PCA computed through
34
+other libraries. Default \code{NULL}.}
35
+}
36
+\value{
37
+Updated sce object with tSNE computations stored
38
+}
39
+\description{
40
+runScanpyTSNE
41
+Computes tSNE from the given sce object and stores the tSNE computations back
42
+into the sce object
43
+}
0 44
new file mode 100644
... ...
@@ -0,0 +1,67 @@
1
+% Generated by roxygen2: do not edit by hand
2
+% Please edit documentation in R/scanpyFunctions.R
3
+\name{runScanpyUMAP}
4
+\alias{runScanpyUMAP}
5
+\title{runScanpyUMAP
6
+Computes UMAP from the given sce object and stores the UMAP computations back
7
+into the sce object}
8
+\usage{
9
+runScanpyUMAP(
10
+  inSCE,
11
+  useReduction = "scanpyPCA",
12
+  reducedDimName = "scanpyUMAP",
13
+  dims = 10L,
14
+  minDist = 0.5,
15
+  nNeighbors = 15L,
16
+  spread = 1,
17
+  alpha = 1,
18
+  gamma = 1,
19
+  externalReduction = NULL
20
+)
21
+}
22
+\arguments{
23
+\item{inSCE}{(sce) object on which to compute the UMAP}
24
+
25
+\item{useReduction}{Reduction to use for computing UMAP. Default is \code{"pca"}.}
26
+
27
+\item{reducedDimName}{Name of new reducedDims object containing Scanpy UMAP
28
+Default \code{scanpyUMAP}.}
29
+
30
+\item{dims}{Numerical value of how many reduction components to use for UMAP
31
+computation. Default \code{10}.}
32
+
33
+\item{minDist}{Sets the \code{"min_dist"} parameter to the underlying UMAP
34
+call. Default \code{0.5}.}
35
+
36
+\item{nNeighbors}{Sets the \code{"n_neighbors"} parameter to the underlying
37
+UMAP call. Default \code{15L}.}
38
+
39
+\item{spread}{Sets the \code{"spread"} parameter to the underlying UMAP call.
40
+Default \code{1}.
41
+#' @param alpha Sets the \code{"alpha"} parameter to the underlying UMAP call.
42
+Default \code{1}.
43
+#' @param gamma Sets the \code{"gamma"} parameter to the underlying UMAP call.
44
+Default \code{1}.}
45
+
46
+\item{externalReduction}{Pass DimReduce object if PCA computed through
47
+other libraries. Default \code{NULL}.}
48
+}
49
+\value{
50
+Updated sce object with UMAP computations stored
51
+}
52
+\description{
53
+runScanpyUMAP
54
+Computes UMAP from the given sce object and stores the UMAP computations back
55
+into the sce object
56
+}
57
+\examples{
58
+data(scExample, package = "singleCellTK")
59
+\dontrun{
60
+sce <- runScanpyNormalizeData(sce, useAssay = "counts")
61
+sce <- runScanpyFindHVG(sce, useAssay = "counts")
62
+sce <- runScanpyScaleData(sce, useAssay = "counts")
63
+sce <- runScanpyPCA(sce, useAssay = "counts")
64
+sce <- runScanpyFindClusters(sce, useAssay = "counts")
65
+sce <- runScanpyUMAP(sce, useReduction = "scanpyPCA")
66
+}
67
+}
... ...
@@ -1,11 +1,23 @@
1 1
 % Generated by roxygen2: do not edit by hand
2
-% Please edit documentation in R/seuratFunctions.R
2
+% Please edit documentation in R/scanpyFunctions.R, R/seuratFunctions.R
3 3
 \name{runSeuratFindClusters}
4 4
 \alias{runSeuratFindClusters}
5
-\title{runSeuratFindClusters
5
+\title{runScanpyFindClusters
6 6
 Computes the clusters from the input sce object and stores them back in sce
7 7
 object}
8 8
 \usage{
9
+runSeuratFindClusters(
10
+  inSCE,
11
+  useAssay = "seuratScaledData",
12
+  useReduction = c("pca", "ica"),
13
+  dims = 10,
14
+  algorithm = c("louvain", "multilevel", "SLM"),
15
+  groupSingletons = TRUE,
16
+  resolution = 0.8,
17
+  externalReduction = NULL,
18
+  verbose = TRUE
19
+)
20
+
9 21
 runSeuratFindClusters(
10 22
   inSCE,
11 23
   useAssay = "seuratScaledData",
... ...
@@ -46,11 +58,38 @@ other libraries. Default \code{NULL}.}
46 58
 
47 59
 \item{verbose}{Logical value indicating if informative messages should
48 60
 be displayed. Default is \code{TRUE}.}
61
+
62
+\item{nNeighbors}{The size of local neighborhood (in terms of number of 
63
+neighboring data points) used for manifold approximation. Larger values 
64
+result in more global views of the manifold, while smaller values result in 
65
+more local data being preserved. Default \code{15L}.}
66
+
67
+\item{colDataName}{colName to store the result in annData object}
68
+
69
+\item{niterations}{How many iterations of the Leiden clustering algorithm to 
70
+perform. Positive values above 2 define the total number of iterations to 
71
+perform, -1 has the algorithm run until it reaches its optimal clustering.}
72
+
73
+\item{flavor}{Choose between to packages for computing the clustering.}
74
+
75
+\item{use_weights}{Boolean. Use weights from knn graph.}
76
+
77
+\item{cor_method}{correlation method to use. Options are ‘pearson’, 
78
+‘kendall’, and ‘spearman’. Default 'pearson'.}
79
+
80
+\item{inplace}{If True, adds dendrogram information to annData object, 
81
+else this function returns the information.}
49 82
 }
50 83
 \value{
84
+Updated sce object which now contains the computed clusters
85
+
51 86
 Updated sce object which now contains the computed clusters
52 87
 }
53 88
 \description{
89
+runScanpyFindClusters
90
+Computes the clusters from the input sce object and stores them back in sce
91
+object
92
+
54 93
 runSeuratFindClusters
55 94
 Computes the clusters from the input sce object and stores them back in sce
56 95
 object
... ...
@@ -58,6 +97,14 @@ object
58 97
 \examples{
59 98
 data(scExample, package = "singleCellTK")
60 99
 \dontrun{
100
+sce <- runScanpyNormalizeData(sce, useAssay = "counts")
101
+sce <- runScanpyFindHVG(sce, useAssay = "counts")
102
+sce <- runScanpyScaleData(sce, useAssay = "counts")
103
+sce <- runScanpyPCA(sce, useAssay = "counts")
104
+sce <- runScanpyFindClusters(sce, useAssay = "counts")
105
+}
106
+data(scExample, package = "singleCellTK")
107
+\dontrun{
61 108
 sce <- runSeuratNormalizeData(sce, useAssay = "counts")
62 109
 sce <- runSeuratFindHVG(sce, useAssay = "counts")
63 110
 sce <- runSeuratScaleData(sce, useAssay = "counts")