... | ... |
@@ -27,7 +27,7 @@ plotUMAP <- function(inSCE, colorBy = NULL, shape = NULL, |
27 | 27 |
reducedDimName = reducedDimName) |
28 | 28 |
} else { |
29 | 29 |
stop(reducedDimName, |
30 |
- " dimension not found. Run runUMAP() or set runUMAP to TRUE.") |
|
30 |
+ " dimension not found. Run `runUMAP()` or set `runUMAP` to `TRUE`.") |
|
31 | 31 |
} |
32 | 32 |
} |
33 | 33 |
UMAPDf <- data.frame(SingleCellExperiment::reducedDim(inSCE, |
... | ... |
@@ -16,18 +16,18 @@ |
16 | 16 |
#' @examples |
17 | 17 |
#' data(scExample, package = "singleCellTK") |
18 | 18 |
#' sce <- subsetSCECols(sce, colData = "type != 'EmptyDroplet'") |
19 |
-#' sce <- getUMAP(inSCE = sce, useAssay = "counts", reducedDimName = "UMAP") |
|
19 |
+#' sce <- runQuickUMAP(sce) |
|
20 | 20 |
#' plotUMAP(sce) |
21 | 21 |
plotUMAP <- function(inSCE, colorBy = NULL, shape = NULL, |
22 | 22 |
reducedDimName = "UMAP", runUMAP = FALSE, |
23 |
- useAssay = "logcounts"){ |
|
23 |
+ useAssay = "counts"){ |
|
24 | 24 |
if(!(reducedDimName %in% names(SingleCellExperiment::reducedDims(inSCE)))){ |
25 | 25 |
if (runUMAP){ |
26 |
- inSCE <- getUMAP(inSCE, useAssay = useAssay, |
|
27 |
- reducedDimName = reducedDimName) |
|
26 |
+ inSCE <- runQuickUMAP(inSCE, useAssay = useAssay, |
|
27 |
+ reducedDimName = reducedDimName) |
|
28 | 28 |
} else { |
29 | 29 |
stop(reducedDimName, |
30 |
- " dimension not found. Run getUMAP() or set runUMAP to TRUE.") |
|
30 |
+ " dimension not found. Run runUMAP() or set runUMAP to TRUE.") |
|
31 | 31 |
} |
32 | 32 |
} |
33 | 33 |
UMAPDf <- data.frame(SingleCellExperiment::reducedDim(inSCE, |
... | ... |
@@ -17,9 +17,7 @@ |
17 | 17 |
#' data(scExample, package = "singleCellTK") |
18 | 18 |
#' sce <- subsetSCECols(sce, colData = "type != 'EmptyDroplet'") |
19 | 19 |
#' sce <- getUMAP(inSCE = sce, useAssay = "counts", reducedDimName = "UMAP") |
20 |
-#' plotUMAP(sce, shape = "No Shape", reducedDimName = "UMAP", |
|
21 |
-#' runUMAP = TRUE, useAssay = "counts") |
|
22 |
-#' |
|
20 |
+#' plotUMAP(sce) |
|
23 | 21 |
plotUMAP <- function(inSCE, colorBy = NULL, shape = NULL, |
24 | 22 |
reducedDimName = "UMAP", runUMAP = FALSE, |
25 | 23 |
useAssay = "logcounts"){ |
... | ... |
@@ -20,7 +20,7 @@ |
20 | 20 |
#' plotUMAP(sce, shape = "No Shape", reducedDimName = "UMAP", |
21 | 21 |
#' runUMAP = TRUE, useAssay = "counts") |
22 | 22 |
#' |
23 |
-plotUMAP <- function(inSCE, colorBy = "No Color", shape = "No Shape", |
|
23 |
+plotUMAP <- function(inSCE, colorBy = NULL, shape = NULL, |
|
24 | 24 |
reducedDimName = "UMAP", runUMAP = FALSE, |
25 | 25 |
useAssay = "logcounts"){ |
26 | 26 |
if(!(reducedDimName %in% names(SingleCellExperiment::reducedDims(inSCE)))){ |
... | ... |
@@ -41,12 +41,7 @@ plotUMAP <- function(inSCE, colorBy = "No Color", shape = "No Shape", |
41 | 41 |
colnames(UMAPDf)[2] <- "UMAP2" |
42 | 42 |
xdim <- colnames(UMAPDf)[1] |
43 | 43 |
ydim <- colnames(UMAPDf)[2] |
44 |
- if (colorBy == "No Color"){ |
|
45 |
- colorBy <- NULL |
|
46 |
- } |
|
47 |
- if (shape == "No Shape"){ |
|
48 |
- shape <- NULL |
|
49 |
- } |
|
44 |
+ |
|
50 | 45 |
if (!is.null(colorBy)){ |
51 | 46 |
UMAPDf$color <- SingleCellExperiment::colData(inSCE)[, colorBy] |
52 | 47 |
} |
... | ... |
@@ -15,7 +15,7 @@ |
15 | 15 |
#' |
16 | 16 |
#' @examples |
17 | 17 |
#' data(scExample, package = "singleCellTK") |
18 |
-#' sce <- sce[, colData(sce)$type != 'EmptyDroplet'] |
|
18 |
+#' sce <- subsetSCECols(sce, colData = "type != 'EmptyDroplet'") |
|
19 | 19 |
#' sce <- getUMAP(inSCE = sce, useAssay = "counts", reducedDimName = "UMAP") |
20 | 20 |
#' plotUMAP(sce, shape = "No Shape", reducedDimName = "UMAP", |
21 | 21 |
#' runUMAP = TRUE, useAssay = "counts") |
... | ... |
@@ -1,10 +1,11 @@ |
1 | 1 |
#' Plot UMAP results either on already run results or run first and then plot. |
2 | 2 |
#' |
3 |
-#' @param inSCE Input SCtkExperiment object with saved dimension reduction components |
|
4 |
-#' or a variable with saved results. Required |
|
3 |
+#' @param inSCE Input \linkS4class{SingleCellExperiment} object with saved |
|
4 |
+#' dimension reduction components. Required |
|
5 | 5 |
#' @param colorBy color by a condition(any column of the annotation data). |
6 | 6 |
#' @param shape add shapes to each condition. |
7 |
-#' @param reducedDimName saved dimension reduction name in the SCtkExperiment object. Required. |
|
7 |
+#' @param reducedDimName saved dimension reduction name in the |
|
8 |
+#' \linkS4class{SingleCellExperiment} object. Required. |
|
8 | 9 |
#' @param runUMAP If the dimension reduction components are already available |
9 | 10 |
#' set this to FALSE, otherwise set to TRUE. Default is False. |
10 | 11 |
#' @param useAssay Indicate which assay to use. The default is "logcounts" |
... | ... |
@@ -13,7 +13,10 @@ |
13 | 13 |
#' @export |
14 | 14 |
#' |
15 | 15 |
#' @examples |
16 |
-#' plotUMAP(mouseBrainSubsetSCE, shape = "No Shape", reducedDimName = "UMAP", |
|
16 |
+#' data(scExample, package = "singleCellTK") |
|
17 |
+#' sce <- sce[, colData(sce)$type != 'EmptyDroplet'] |
|
18 |
+#' sce <- getUMAP(inSCE = sce, useAssay = "counts", reducedDimName = "UMAP") |
|
19 |
+#' plotUMAP(sce, shape = "No Shape", reducedDimName = "UMAP", |
|
17 | 20 |
#' runUMAP = TRUE, useAssay = "counts") |
18 | 21 |
#' |
19 | 22 |
plotUMAP <- function(inSCE, colorBy = "No Color", shape = "No Shape", |
... | ... |
@@ -19,7 +19,7 @@ |
19 | 19 |
plotUMAP <- function(inSCE, colorBy = "No Color", shape = "No Shape", |
20 | 20 |
reducedDimName = "UMAP", runUMAP = FALSE, |
21 | 21 |
useAssay = "logcounts"){ |
22 |
- if (is.null(SingleCellExperiment::reducedDim(inSCE, reducedDimName))){ |
|
22 |
+ if(!(reducedDimName %in% names(SingleCellExperiment::reducedDims(inSCE)))){ |
|
23 | 23 |
if (runUMAP){ |
24 | 24 |
inSCE <- getUMAP(inSCE, useAssay = useAssay, |
25 | 25 |
reducedDimName = reducedDimName) |
... | ... |
@@ -33,6 +33,8 @@ plotUMAP <- function(inSCE, colorBy = "No Color", shape = "No Shape", |
33 | 33 |
if (ncol(UMAPDf) > 2){ |
34 | 34 |
warning("More than two UMAP dimensions. Using the first two.") |
35 | 35 |
} |
36 |
+ colnames(UMAPDf)[1] <- "UMAP1" |
|
37 |
+ colnames(UMAPDf)[2] <- "UMAP2" |
|
36 | 38 |
xdim <- colnames(UMAPDf)[1] |
37 | 39 |
ydim <- colnames(UMAPDf)[2] |
38 | 40 |
if (colorBy == "No Color"){ |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,63 @@ |
1 |
+#' Plot UMAP results either on already run results or run first and then plot. |
|
2 |
+#' |
|
3 |
+#' @param inSCE Input SCtkExperiment object with saved dimension reduction components |
|
4 |
+#' or a variable with saved results. Required |
|
5 |
+#' @param colorBy color by a condition(any column of the annotation data). |
|
6 |
+#' @param shape add shapes to each condition. |
|
7 |
+#' @param reducedDimName saved dimension reduction name in the SCtkExperiment object. Required. |
|
8 |
+#' @param runUMAP If the dimension reduction components are already available |
|
9 |
+#' set this to FALSE, otherwise set to TRUE. Default is False. |
|
10 |
+#' @param useAssay Indicate which assay to use. The default is "logcounts" |
|
11 |
+#' |
|
12 |
+#' @return a UMAP plot of the reduced dimensions. |
|
13 |
+#' @export |
|
14 |
+#' |
|
15 |
+#' @examples |
|
16 |
+#' plotUMAP(mouseBrainSubsetSCE, shape = "No Shape", reducedDimName = "UMAP", |
|
17 |
+#' runUMAP = TRUE, useAssay = "counts") |
|
18 |
+#' |
|
19 |
+plotUMAP <- function(inSCE, colorBy = "No Color", shape = "No Shape", |
|
20 |
+ reducedDimName = "UMAP", runUMAP = FALSE, |
|
21 |
+ useAssay = "logcounts"){ |
|
22 |
+ if (is.null(SingleCellExperiment::reducedDim(inSCE, reducedDimName))){ |
|
23 |
+ if (runUMAP){ |
|
24 |
+ inSCE <- getUMAP(inSCE, useAssay = useAssay, |
|
25 |
+ reducedDimName = reducedDimName) |
|
26 |
+ } else { |
|
27 |
+ stop(reducedDimName, |
|
28 |
+ " dimension not found. Run getUMAP() or set runUMAP to TRUE.") |
|
29 |
+ } |
|
30 |
+ } |
|
31 |
+ UMAPDf <- data.frame(SingleCellExperiment::reducedDim(inSCE, |
|
32 |
+ reducedDimName)) |
|
33 |
+ if (ncol(UMAPDf) > 2){ |
|
34 |
+ warning("More than two UMAP dimensions. Using the first two.") |
|
35 |
+ } |
|
36 |
+ xdim <- colnames(UMAPDf)[1] |
|
37 |
+ ydim <- colnames(UMAPDf)[2] |
|
38 |
+ if (colorBy == "No Color"){ |
|
39 |
+ colorBy <- NULL |
|
40 |
+ } |
|
41 |
+ if (shape == "No Shape"){ |
|
42 |
+ shape <- NULL |
|
43 |
+ } |
|
44 |
+ if (!is.null(colorBy)){ |
|
45 |
+ UMAPDf$color <- SingleCellExperiment::colData(inSCE)[, colorBy] |
|
46 |
+ } |
|
47 |
+ if (!is.null(shape)){ |
|
48 |
+ UMAPDf$shape <- factor(SingleCellExperiment::colData(inSCE)[, shape]) |
|
49 |
+ } |
|
50 |
+ UMAPDf$Sample <- colnames(inSCE) |
|
51 |
+ g <- ggplot2::ggplot(UMAPDf, ggplot2::aes_string(xdim, ydim, |
|
52 |
+ label = "Sample")) + |
|
53 |
+ ggplot2::geom_point() |
|
54 |
+ if (!is.null(colorBy)){ |
|
55 |
+ g <- g + ggplot2::aes_string(color = "color") + |
|
56 |
+ ggplot2::labs(color = colorBy) |
|
57 |
+ } |
|
58 |
+ if (!is.null(shape)){ |
|
59 |
+ g <- g + ggplot2::aes_string(shape = "shape") + |
|
60 |
+ ggplot2::labs(shape = shape) |
|
61 |
+ } |
|
62 |
+ return(g) |
|
63 |
+} |