... | ... |
@@ -44,7 +44,7 @@ setMethod("celdaHeatmap", signature(sce = "SingleCellExperiment"), |
44 | 44 |
model <- celdaModel(sce, altExpName = altExpName) |
45 | 45 |
|
46 | 46 |
if (model == "celda_C") { |
47 |
- z <- celdaClusters(sce, altExpName = altExpName) |
|
47 |
+ z <- as.integer(celdaClusters(sce, altExpName = altExpName)) |
|
48 | 48 |
g <- .celdaHeatmapCelda_C( |
49 | 49 |
counts = counts, |
50 | 50 |
z = z, |
... | ... |
@@ -53,8 +53,8 @@ setMethod("celdaHeatmap", signature(sce = "SingleCellExperiment"), |
53 | 53 |
} else if (model == "celda_CG") { |
54 | 54 |
fm <- factorizeMatrix(x = sce, useAssay = useAssay, |
55 | 55 |
altExpName = altExpName, type = "proportion") |
56 |
- z <- celdaClusters(sce, altExpName = altExpName) |
|
57 |
- y <- celdaModules(sce, altExpName = altExpName) |
|
56 |
+ z <- as.integer(celdaClusters(sce, altExpName = altExpName)) |
|
57 |
+ y <- as.integer(celdaModules(sce, altExpName = altExpName)) |
|
58 | 58 |
g <- .celdaHeatmapCelda_CG( |
59 | 59 |
counts = counts, |
60 | 60 |
fm = fm, |
... | ... |
@@ -65,7 +65,7 @@ setMethod("celdaHeatmap", signature(sce = "SingleCellExperiment"), |
65 | 65 |
} else if (model == "celda_G") { |
66 | 66 |
fm <- factorizeMatrix(x = sce, useAssay = useAssay, |
67 | 67 |
altExpName = altExpName, type = "proportion") |
68 |
- y <- celdaModules(sce, altExpName = altExpName) |
|
68 |
+ y <- as.integer(celdaModules(sce, altExpName = altExpName)) |
|
69 | 69 |
g <- .celdaHeatmapCelda_G(counts, |
70 | 70 |
fm, |
71 | 71 |
y, |
... | ... |
@@ -19,7 +19,13 @@ |
19 | 19 |
#' @return list A list containing dendrogram information and the heatmap grob |
20 | 20 |
#' @export |
21 | 21 |
setGeneric("celdaHeatmap", |
22 |
- function(sce, ...) { |
|
22 |
+ function(sce, |
|
23 |
+ useAssay = "counts", |
|
24 |
+ altExpName = "featureSubset", |
|
25 |
+ featureIx = NULL, |
|
26 |
+ nfeatures = 25, |
|
27 |
+ ...) { |
|
28 |
+ |
|
23 | 29 |
standardGeneric("celdaHeatmap") |
24 | 30 |
}) |
25 | 31 |
|
... | ... |
@@ -33,60 +33,72 @@ setMethod("celdaHeatmap", signature(sce = "SingleCellExperiment"), |
33 | 33 |
function(sce, useAssay = "counts", altExpName = "featureSubset", |
34 | 34 |
featureIx = NULL, nfeatures = 25, ...) { |
35 | 35 |
|
36 |
- if (celdaModel(sce, altExpName = altExpName) == "celda_C") { |
|
37 |
- g <- .celdaHeatmapCelda_C(sce = sce, |
|
38 |
- useAssay = useAssay, |
|
39 |
- altExpName = altExpName, |
|
36 |
+ counts <- SummarizedExperiment::assay(sce, i = useAssay) |
|
37 |
+ counts <- .processCounts(counts) |
|
38 |
+ model <- celdaModel(sce, altExpName = altExpName) |
|
39 |
+ |
|
40 |
+ if (model == "celda_C") { |
|
41 |
+ z <- celdaClusters(sce, altExpName = altExpName) |
|
42 |
+ g <- .celdaHeatmapCelda_C( |
|
43 |
+ counts = counts, |
|
44 |
+ z = z, |
|
40 | 45 |
featureIx = featureIx, |
41 | 46 |
...) |
42 |
- return(g) |
|
43 |
- } else if (celdaModel(sce, altExpName = altExpName) == "celda_CG") { |
|
44 |
- g <- .celdaHeatmapCelda_CG(sce = sce, |
|
45 |
- useAssay = useAssay, |
|
46 |
- altExpName = altExpName, |
|
47 |
+ } else if (model == "celda_CG") { |
|
48 |
+ fm <- factorizeMatrix(x = sce, useAssay = useAssay, |
|
49 |
+ altExpName = altExpName, type = "proportion") |
|
50 |
+ z <- celdaClusters(sce, altExpName = altExpName) |
|
51 |
+ y <- celdaModules(sce, altExpName = altExpName) |
|
52 |
+ g <- .celdaHeatmapCelda_CG( |
|
53 |
+ counts = counts, |
|
54 |
+ fm = fm, |
|
55 |
+ z = z, |
|
56 |
+ y = y, |
|
47 | 57 |
nfeatures = nfeatures, |
48 | 58 |
...) |
49 |
- return(g) |
|
50 |
- } else if (celdaModel(sce, altExpName = altExpName) == "celda_G") { |
|
51 |
- g <- .celdaHeatmapCelda_G(sce = sce, |
|
52 |
- useAssay = useAssay, |
|
53 |
- altExpName = altExpName, |
|
59 |
+ } else if (model == "celda_G") { |
|
60 |
+ fm <- factorizeMatrix(x = sce, useAssay = useAssay, |
|
61 |
+ altExpName = altExpName, type = "proportion") |
|
62 |
+ y <- celdaModules(sce, altExpName = altExpName) |
|
63 |
+ g <- .celdaHeatmapCelda_G(counts, |
|
64 |
+ fm, |
|
65 |
+ y, |
|
54 | 66 |
nfeatures = nfeatures, |
55 | 67 |
...) |
56 |
- return(g) |
|
57 | 68 |
} else { |
58 | 69 |
stop("S4Vectors::metadata(altExp(sce, altExpName))$", |
59 | 70 |
"celda_parameters$model must be", |
60 | 71 |
" one of 'celda_C', 'celda_G', or 'celda_CG'") |
61 | 72 |
} |
73 |
+ return(g) |
|
62 | 74 |
} |
63 | 75 |
) |
64 | 76 |
|
65 | 77 |
|
66 |
-.celdaHeatmapCelda_C <- function(sce, |
|
67 |
- useAssay, altExpName, featureIx, ...) { |
|
78 |
+.celdaHeatmapCelda_C <- function( |
|
79 |
+ counts, |
|
80 |
+ z, |
|
81 |
+ featureIx, ...) { |
|
68 | 82 |
|
69 |
- counts <- SummarizedExperiment::assay(sce, i = useAssay) |
|
70 |
- counts <- .processCounts(counts) |
|
71 | 83 |
norm <- normalizeCounts(counts, |
72 | 84 |
normalize = "proportion", |
73 | 85 |
transformationFun = sqrt) |
74 | 86 |
|
75 | 87 |
if (is.null(featureIx)) { |
76 |
- return(plotHeatmap(norm, |
|
77 |
- z = celdaClusters(sce, altExpName = altExpName), ...)) |
|
88 |
+ return(plotHeatmap(norm, z, ...)) |
|
78 | 89 |
} |
79 |
- |
|
80 |
- return(plotHeatmap(norm[featureIx, ], |
|
81 |
- z = celdaClusters(sce, altExpName = altExpName), ...)) |
|
90 |
+ return(plotHeatmap(norm[featureIx, ], z = z, ...)) |
|
82 | 91 |
} |
83 | 92 |
|
84 | 93 |
|
85 |
-.celdaHeatmapCelda_CG <- function(sce, useAssay, altExpName, nfeatures, ...) { |
|
86 |
- counts <- SummarizedExperiment::assay(sce, i = useAssay) |
|
87 |
- counts <- .processCounts(counts) |
|
88 |
- fm <- factorizeMatrix(x = sce, useAssay = useAssay, |
|
89 |
- altExpName = altExpName, type = "proportion") |
|
94 |
+.celdaHeatmapCelda_CG <- function( |
|
95 |
+ counts = counts, |
|
96 |
+ fm = fm, |
|
97 |
+ z = z, |
|
98 |
+ y = y, |
|
99 |
+ nfeatures, |
|
100 |
+ ...) { |
|
101 |
+ |
|
90 | 102 |
top <- topRank(fm$proportions$module, n = nfeatures) |
91 | 103 |
ix <- unlist(top$index) |
92 | 104 |
rn <- unlist(top$names) |
... | ... |
@@ -94,25 +106,20 @@ setMethod("celdaHeatmap", signature(sce = "SingleCellExperiment"), |
94 | 106 |
normalize = "proportion", |
95 | 107 |
transformationFun = sqrt) |
96 | 108 |
plt <- plotHeatmap(norm[rn, ], |
97 |
- z = celdaClusters(sce, altExpName = altExpName), |
|
98 |
- y = celdaModules(sce, altExpName = altExpName)[ix], |
|
109 |
+ z = z, |
|
110 |
+ y = y[ix], |
|
99 | 111 |
...) |
100 | 112 |
return(plt) |
101 | 113 |
} |
102 | 114 |
|
103 | 115 |
|
104 |
-.celdaHeatmapCelda_G <- function(sce, useAssay, altExpName, nfeatures, ...) { |
|
105 |
- counts <- SummarizedExperiment::assay(sce, i = useAssay) |
|
106 |
- counts <- .processCounts(counts) |
|
107 |
- fm <- factorizeMatrix(x = sce, useAssay = useAssay, |
|
108 |
- altExpName = altExpName, type = "proportion") |
|
116 |
+.celdaHeatmapCelda_G <- function(counts, fm, y, nfeatures, ...) { |
|
109 | 117 |
top <- topRank(fm$proportions$module, n = nfeatures) |
110 | 118 |
ix <- unlist(top$index) |
111 | 119 |
rn <- unlist(top$names) |
112 | 120 |
norm <- normalizeCounts(counts, |
113 | 121 |
normalize = "proportion", |
114 | 122 |
transformationFun = sqrt) |
115 |
- plt <- plotHeatmap(norm[rn, ], y = celdaModules(sce, |
|
116 |
- altExpName = altExpName)[ix], ...) |
|
123 |
+ plt <- plotHeatmap(norm[rn, ], y = y[ix], ...) |
|
117 | 124 |
return(plt) |
118 | 125 |
} |
... | ... |
@@ -3,9 +3,9 @@ |
3 | 3 |
#' clustering results. |
4 | 4 |
#' @param sce A \link[SingleCellExperiment]{SingleCellExperiment} object |
5 | 5 |
#' returned by \link{celda_C}, \link{celda_G}, or \link{celda_CG}. |
6 |
-#' @param useAssay A string specifying which \link[SummarizedExperiment]{assay} |
|
6 |
+#' @param useAssay A string specifying which \link{assay} |
|
7 | 7 |
#' slot to use. Default "counts". |
8 |
-#' @param altExpName The name for the \link[SingleCellExperiment]{altExp} slot |
|
8 |
+#' @param altExpName The name for the \link{altExp} slot |
|
9 | 9 |
#' to use. Default "featureSubset". |
10 | 10 |
#' @param featureIx Integer vector. Select features for display in heatmap. If |
11 | 11 |
#' NULL, no subsetting will be performed. Default NULL. \strong{Only used for |
... | ... |
@@ -97,7 +97,7 @@ setMethod("celdaHeatmap", signature(sce = "SingleCellExperiment"), |
97 | 97 |
z = celdaClusters(sce, altExpName = altExpName), |
98 | 98 |
y = celdaModules(sce, altExpName = altExpName)[ix], |
99 | 99 |
...) |
100 |
- invisible(plt) |
|
100 |
+ return(plt) |
|
101 | 101 |
} |
102 | 102 |
|
103 | 103 |
|
... | ... |
@@ -114,5 +114,5 @@ setMethod("celdaHeatmap", signature(sce = "SingleCellExperiment"), |
114 | 114 |
transformationFun = sqrt) |
115 | 115 |
plt <- plotHeatmap(norm[rn, ], y = celdaModules(sce, |
116 | 116 |
altExpName = altExpName)[ix], ...) |
117 |
- invisible(plt) |
|
117 |
+ return(plt) |
|
118 | 118 |
} |
... | ... |
@@ -33,21 +33,21 @@ setMethod("celdaHeatmap", signature(sce = "SingleCellExperiment"), |
33 | 33 |
function(sce, useAssay = "counts", altExpName = "featureSubset", |
34 | 34 |
featureIx = NULL, nfeatures = 25, ...) { |
35 | 35 |
|
36 |
- if (celdaModel(sce) == "celda_C") { |
|
36 |
+ if (celdaModel(sce, altExpName = altExpName) == "celda_C") { |
|
37 | 37 |
g <- .celdaHeatmapCelda_C(sce = sce, |
38 | 38 |
useAssay = useAssay, |
39 | 39 |
altExpName = altExpName, |
40 | 40 |
featureIx = featureIx, |
41 | 41 |
...) |
42 | 42 |
return(g) |
43 |
- } else if (celdaModel(sce) == "celda_CG") { |
|
43 |
+ } else if (celdaModel(sce, altExpName = altExpName) == "celda_CG") { |
|
44 | 44 |
g <- .celdaHeatmapCelda_CG(sce = sce, |
45 | 45 |
useAssay = useAssay, |
46 | 46 |
altExpName = altExpName, |
47 | 47 |
nfeatures = nfeatures, |
48 | 48 |
...) |
49 | 49 |
return(g) |
50 |
- } else if (celdaModel(sce) == "celda_G") { |
|
50 |
+ } else if (celdaModel(sce, altExpName = altExpName) == "celda_G") { |
|
51 | 51 |
g <- .celdaHeatmapCelda_G(sce = sce, |
52 | 52 |
useAssay = useAssay, |
53 | 53 |
altExpName = altExpName, |
... | ... |
@@ -33,8 +33,6 @@ setMethod("celdaHeatmap", signature(sce = "SingleCellExperiment"), |
33 | 33 |
function(sce, useAssay = "counts", altExpName = "featureSubset", |
34 | 34 |
featureIx = NULL, nfeatures = 25, ...) { |
35 | 35 |
|
36 |
- aleExp <- SingleCellExperiment::altExp(sce, altExpName) |
|
37 |
- |
|
38 | 36 |
if (celdaModel(sce) == "celda_C") { |
39 | 37 |
g <- .celdaHeatmapCelda_C(sce = sce, |
40 | 38 |
useAssay = useAssay, |
... | ... |
@@ -97,7 +95,7 @@ setMethod("celdaHeatmap", signature(sce = "SingleCellExperiment"), |
97 | 95 |
transformationFun = sqrt) |
98 | 96 |
plt <- plotHeatmap(norm[rn, ], |
99 | 97 |
z = celdaClusters(sce, altExpName = altExpName), |
100 |
- y = celdaModules(sce)[ix], |
|
98 |
+ y = celdaModules(sce, altExpName = altExpName)[ix], |
|
101 | 99 |
...) |
102 | 100 |
invisible(plt) |
103 | 101 |
} |
... | ... |
@@ -114,6 +112,7 @@ setMethod("celdaHeatmap", signature(sce = "SingleCellExperiment"), |
114 | 112 |
norm <- normalizeCounts(counts, |
115 | 113 |
normalize = "proportion", |
116 | 114 |
transformationFun = sqrt) |
117 |
- plt <- plotHeatmap(norm[rn, ], y = celdaModules(sce)[ix], ...) |
|
115 |
+ plt <- plotHeatmap(norm[rn, ], y = celdaModules(sce, |
|
116 |
+ altExpName = altExpName)[ix], ...) |
|
118 | 117 |
invisible(plt) |
119 | 118 |
} |
... | ... |
@@ -35,21 +35,21 @@ setMethod("celdaHeatmap", signature(sce = "SingleCellExperiment"), |
35 | 35 |
|
36 | 36 |
aleExp <- SingleCellExperiment::altExp(sce, altExpName) |
37 | 37 |
|
38 |
- if (celdaModel(aleExp) == "celda_C") { |
|
38 |
+ if (celdaModel(sce) == "celda_C") { |
|
39 | 39 |
g <- .celdaHeatmapCelda_C(sce = sce, |
40 | 40 |
useAssay = useAssay, |
41 | 41 |
altExpName = altExpName, |
42 | 42 |
featureIx = featureIx, |
43 | 43 |
...) |
44 | 44 |
return(g) |
45 |
- } else if (celdaModel(aleExp) == "celda_CG") { |
|
45 |
+ } else if (celdaModel(sce) == "celda_CG") { |
|
46 | 46 |
g <- .celdaHeatmapCelda_CG(sce = sce, |
47 | 47 |
useAssay = useAssay, |
48 | 48 |
altExpName = altExpName, |
49 | 49 |
nfeatures = nfeatures, |
50 | 50 |
...) |
51 | 51 |
return(g) |
52 |
- } else if (celdaModel(aleExp) == "celda_G") { |
|
52 |
+ } else if (celdaModel(sce) == "celda_G") { |
|
53 | 53 |
g <- .celdaHeatmapCelda_G(sce = sce, |
54 | 54 |
useAssay = useAssay, |
55 | 55 |
altExpName = altExpName, |
... | ... |
@@ -5,6 +5,8 @@ |
5 | 5 |
#' returned by \link{celda_C}, \link{celda_G}, or \link{celda_CG}. |
6 | 6 |
#' @param useAssay A string specifying which \link[SummarizedExperiment]{assay} |
7 | 7 |
#' slot to use. Default "counts". |
8 |
+#' @param altExpName The name for the \link[SingleCellExperiment]{altExp} slot |
|
9 |
+#' to use. Default "featureSubset". |
|
8 | 10 |
#' @param featureIx Integer vector. Select features for display in heatmap. If |
9 | 11 |
#' NULL, no subsetting will be performed. Default NULL. \strong{Only used for |
10 | 12 |
#' \code{sce} containing celda_C model result returned by \link{celda_C}.} |
... | ... |
@@ -28,27 +30,35 @@ setGeneric("celdaHeatmap", |
28 | 30 |
#' celdaHeatmap(sceCeldaCG) |
29 | 31 |
#' @export |
30 | 32 |
setMethod("celdaHeatmap", signature(sce = "SingleCellExperiment"), |
31 |
- function(sce, useAssay = "counts", featureIx = NULL, nfeatures = 25, ...) { |
|
32 |
- if (celdaModel(sce) == "celda_C") { |
|
33 |
+ function(sce, useAssay = "counts", altExpName = "featureSubset", |
|
34 |
+ featureIx = NULL, nfeatures = 25, ...) { |
|
35 |
+ |
|
36 |
+ aleExp <- SingleCellExperiment::altExp(sce, altExpName) |
|
37 |
+ |
|
38 |
+ if (celdaModel(aleExp) == "celda_C") { |
|
33 | 39 |
g <- .celdaHeatmapCelda_C(sce = sce, |
34 | 40 |
useAssay = useAssay, |
41 |
+ altExpName = altExpName, |
|
35 | 42 |
featureIx = featureIx, |
36 | 43 |
...) |
37 | 44 |
return(g) |
38 |
- } else if (celdaModel(sce) == "celda_CG") { |
|
45 |
+ } else if (celdaModel(aleExp) == "celda_CG") { |
|
39 | 46 |
g <- .celdaHeatmapCelda_CG(sce = sce, |
40 | 47 |
useAssay = useAssay, |
48 |
+ altExpName = altExpName, |
|
41 | 49 |
nfeatures = nfeatures, |
42 | 50 |
...) |
43 | 51 |
return(g) |
44 |
- } else if (celdaModel(sce) == "celda_G") { |
|
52 |
+ } else if (celdaModel(aleExp) == "celda_G") { |
|
45 | 53 |
g <- .celdaHeatmapCelda_G(sce = sce, |
46 | 54 |
useAssay = useAssay, |
55 |
+ altExpName = altExpName, |
|
47 | 56 |
nfeatures = nfeatures, |
48 | 57 |
...) |
49 | 58 |
return(g) |
50 | 59 |
} else { |
51 |
- stop("S4Vectors::metadata(sce)$celda_parameters$model must be", |
|
60 |
+ stop("S4Vectors::metadata(altExp(sce, altExpName))$", |
|
61 |
+ "celda_parameters$model must be", |
|
52 | 62 |
" one of 'celda_C', 'celda_G', or 'celda_CG'") |
53 | 63 |
} |
54 | 64 |
} |
... | ... |
@@ -56,7 +66,7 @@ setMethod("celdaHeatmap", signature(sce = "SingleCellExperiment"), |
56 | 66 |
|
57 | 67 |
|
58 | 68 |
.celdaHeatmapCelda_C <- function(sce, |
59 |
- useAssay, featureIx, ...) { |
|
69 |
+ useAssay, altExpName, featureIx, ...) { |
|
60 | 70 |
|
61 | 71 |
counts <- SummarizedExperiment::assay(sce, i = useAssay) |
62 | 72 |
counts <- .processCounts(counts) |
... | ... |
@@ -66,42 +76,44 @@ setMethod("celdaHeatmap", signature(sce = "SingleCellExperiment"), |
66 | 76 |
|
67 | 77 |
if (is.null(featureIx)) { |
68 | 78 |
return(plotHeatmap(norm, |
69 |
- z = celdaClusters(sce), ...)) |
|
79 |
+ z = celdaClusters(sce, altExpName = altExpName), ...)) |
|
70 | 80 |
} |
71 | 81 |
|
72 | 82 |
return(plotHeatmap(norm[featureIx, ], |
73 |
- z = celdaClusters(sce), ...)) |
|
83 |
+ z = celdaClusters(sce, altExpName = altExpName), ...)) |
|
74 | 84 |
} |
75 | 85 |
|
76 | 86 |
|
77 |
-.celdaHeatmapCelda_CG <- function(sce, useAssay, nfeatures, ...) { |
|
87 |
+.celdaHeatmapCelda_CG <- function(sce, useAssay, altExpName, nfeatures, ...) { |
|
78 | 88 |
counts <- SummarizedExperiment::assay(sce, i = useAssay) |
79 | 89 |
counts <- .processCounts(counts) |
80 |
- fm <- factorizeMatrix(x = sce, useAssay = useAssay, type = "proportion") |
|
90 |
+ fm <- factorizeMatrix(x = sce, useAssay = useAssay, |
|
91 |
+ altExpName = altExpName, type = "proportion") |
|
81 | 92 |
top <- topRank(fm$proportions$module, n = nfeatures) |
82 | 93 |
ix <- unlist(top$index) |
94 |
+ rn <- unlist(top$names) |
|
83 | 95 |
norm <- normalizeCounts(counts, |
84 | 96 |
normalize = "proportion", |
85 | 97 |
transformationFun = sqrt) |
86 |
- plt <- plotHeatmap(norm[ix, ], |
|
87 |
- z = celdaClusters(sce), |
|
98 |
+ plt <- plotHeatmap(norm[rn, ], |
|
99 |
+ z = celdaClusters(sce, altExpName = altExpName), |
|
88 | 100 |
y = celdaModules(sce)[ix], |
89 |
- ... |
|
90 |
- ) |
|
101 |
+ ...) |
|
91 | 102 |
invisible(plt) |
92 | 103 |
} |
93 | 104 |
|
94 | 105 |
|
95 |
-.celdaHeatmapCelda_G <- function(sce, useAssay, nfeatures, ...) { |
|
106 |
+.celdaHeatmapCelda_G <- function(sce, useAssay, altExpName, nfeatures, ...) { |
|
96 | 107 |
counts <- SummarizedExperiment::assay(sce, i = useAssay) |
97 | 108 |
counts <- .processCounts(counts) |
98 |
- fm <- factorizeMatrix(x = sce, useAssay = useAssay, type = "proportion") |
|
99 |
- top <- celda::topRank(fm$proportions$module, n = nfeatures) |
|
109 |
+ fm <- factorizeMatrix(x = sce, useAssay = useAssay, |
|
110 |
+ altExpName = altExpName, type = "proportion") |
|
111 |
+ top <- topRank(fm$proportions$module, n = nfeatures) |
|
100 | 112 |
ix <- unlist(top$index) |
113 |
+ rn <- unlist(top$names) |
|
101 | 114 |
norm <- normalizeCounts(counts, |
102 | 115 |
normalize = "proportion", |
103 |
- transformationFun = sqrt |
|
104 |
- ) |
|
105 |
- plt <- plotHeatmap(norm[ix, ], y = celdaModules(sce)[ix], ...) |
|
116 |
+ transformationFun = sqrt) |
|
117 |
+ plt <- plotHeatmap(norm[rn, ], y = celdaModules(sce)[ix], ...) |
|
106 | 118 |
invisible(plt) |
107 | 119 |
} |
... | ... |
@@ -59,6 +59,7 @@ setMethod("celdaHeatmap", signature(sce = "SingleCellExperiment"), |
59 | 59 |
useAssay, featureIx, ...) { |
60 | 60 |
|
61 | 61 |
counts <- SummarizedExperiment::assay(sce, i = useAssay) |
62 |
+ counts <- .processCounts(counts) |
|
62 | 63 |
norm <- normalizeCounts(counts, |
63 | 64 |
normalize = "proportion", |
64 | 65 |
transformationFun = sqrt) |
... | ... |
@@ -75,6 +76,7 @@ setMethod("celdaHeatmap", signature(sce = "SingleCellExperiment"), |
75 | 76 |
|
76 | 77 |
.celdaHeatmapCelda_CG <- function(sce, useAssay, nfeatures, ...) { |
77 | 78 |
counts <- SummarizedExperiment::assay(sce, i = useAssay) |
79 |
+ counts <- .processCounts(counts) |
|
78 | 80 |
fm <- factorizeMatrix(x = sce, useAssay = useAssay, type = "proportion") |
79 | 81 |
top <- topRank(fm$proportions$module, n = nfeatures) |
80 | 82 |
ix <- unlist(top$index) |
... | ... |
@@ -92,6 +94,7 @@ setMethod("celdaHeatmap", signature(sce = "SingleCellExperiment"), |
92 | 94 |
|
93 | 95 |
.celdaHeatmapCelda_G <- function(sce, useAssay, nfeatures, ...) { |
94 | 96 |
counts <- SummarizedExperiment::assay(sce, i = useAssay) |
97 |
+ counts <- .processCounts(counts) |
|
95 | 98 |
fm <- factorizeMatrix(x = sce, useAssay = useAssay, type = "proportion") |
96 | 99 |
top <- celda::topRank(fm$proportions$module, n = nfeatures) |
97 | 100 |
ix <- unlist(top$index) |
... | ... |
@@ -14,9 +14,6 @@ |
14 | 14 |
#' \link{celda_G}.} |
15 | 15 |
#' @param ... Additional parameters passed to \link{plotHeatmap}. |
16 | 16 |
#' @seealso `celdaTsne()` for generating 2-dimensional tSNE coordinates |
17 |
-#' @examples |
|
18 |
-#' data(sceCeldaCG) |
|
19 |
-#' celdaHeatmap(sceCeldaCG) |
|
20 | 17 |
#' @return list A list containing dendrogram information and the heatmap grob |
21 | 18 |
#' @export |
22 | 19 |
setGeneric("celdaHeatmap", |
... | ... |
@@ -26,6 +23,9 @@ setGeneric("celdaHeatmap", |
26 | 23 |
|
27 | 24 |
|
28 | 25 |
#' @rdname celdaHeatmap |
26 |
+#' @examples |
|
27 |
+#' data(sceCeldaCG) |
|
28 |
+#' celdaHeatmap(sceCeldaCG) |
|
29 | 29 |
#' @export |
30 | 30 |
setMethod("celdaHeatmap", signature(sce = "SingleCellExperiment"), |
31 | 31 |
function(sce, useAssay = "counts", featureIx = NULL, nfeatures = 25, ...) { |
... | ... |
@@ -1,326 +1,104 @@ |
1 |
-#' @title Plots heatmap based on Celda model |
|
2 |
-#' @description Renders a heatmap based on a matrix of counts where rows are |
|
3 |
-#' features and columns are cells. |
|
4 |
-#' @param counts Numeric matrix. Normalized counts matrix where rows represent |
|
5 |
-#' features and columns represent cells. . |
|
6 |
-#' @param z Numeric vector. Denotes cell population labels. |
|
7 |
-#' @param y Numeric vector. Denotes feature module labels. |
|
1 |
+#' @title Plot celda Heatmap |
|
2 |
+#' @description Render a stylable heatmap of count data based on celda |
|
3 |
+#' clustering results. |
|
4 |
+#' @param sce A \link[SingleCellExperiment]{SingleCellExperiment} object |
|
5 |
+#' returned by \link{celda_C}, \link{celda_G}, or \link{celda_CG}. |
|
6 |
+#' @param useAssay A string specifying which \link[SummarizedExperiment]{assay} |
|
7 |
+#' slot to use. Default "counts". |
|
8 | 8 |
#' @param featureIx Integer vector. Select features for display in heatmap. If |
9 |
-#' NULL, no subsetting will be performed. Default NULL. |
|
10 |
-#' @param cellIx Integer vector. Select cells for display in heatmap. If NULL, |
|
11 |
-#' no subsetting will be performed. Default NULL. |
|
12 |
-#' @param scaleRow Function. A function to scale each individual row. Set to |
|
13 |
-#' NULL to disable. Occurs after normalization and log transformation. Defualt |
|
14 |
-#' is 'scale' and thus will Z-score transform each row. |
|
15 |
-#' @param trim Numeric vector. Vector of length two that specifies the lower |
|
16 |
-#' and upper bounds for the data. This threshold is applied after row scaling. |
|
17 |
-#' Set to NULL to disable. Default c(-2,2). |
|
18 |
-#' @param clusterFeature Logical. Determines whether rows should be clustered. |
|
19 |
-#' Default TRUE. |
|
20 |
-#' @param clusterCell Logical. Determines whether columns should be clustered. |
|
21 |
-#' Default TRUE. |
|
22 |
-#' @param annotationCell Data frame. Additional annotations for each cell will |
|
23 |
-#' be shown in the column color bars. The format of the data frame should be |
|
24 |
-#' one row for each cell and one column for each annotation. Numeric variables |
|
25 |
-#' will be displayed as continuous color bars and factors will be displayed as |
|
26 |
-#' discrete color bars. Default NULL. |
|
27 |
-#' @param annotationFeature A data frame for the feature annotations (rows). |
|
28 |
-#' @param annotationColor List. Contains color scheme for all annotations. See |
|
29 |
-#' `?pheatmap` for more details. |
|
30 |
-#' @param colorScheme Character. One of "divergent" or "sequential". A |
|
31 |
-#' "divergent" scheme is best for highlighting relative data (denoted by |
|
32 |
-#' 'colorSchemeCenter') such as gene expression data that has been normalized |
|
33 |
-#' and centered. A "sequential" scheme is best for highlighting data that |
|
34 |
-#' are ordered low to high such as raw counts or probabilities. Default |
|
35 |
-#' "divergent". |
|
36 |
-#' @param colorSchemeSymmetric Logical. When the colorScheme is "divergent" |
|
37 |
-#' and the data contains both positive and negative numbers, TRUE indicates |
|
38 |
-#' that the color scheme should be symmetric from |
|
39 |
-#' \code{[-max(abs(data)), max(abs(data))]}. For example, if the data ranges |
|
40 |
-#' goes from -1.5 to 2, then setting this to TRUE will force the color scheme |
|
41 |
-#' to range from -2 to 2. Default TRUE. |
|
42 |
-#' @param colorSchemeCenter Numeric. Indicates the center of a "divergent" |
|
43 |
-#' colorScheme. Default 0. |
|
44 |
-#' @param col Color for the heatmap. |
|
45 |
-#' @param breaks Numeric vector. A sequence of numbers that covers the range |
|
46 |
-#' of values in the normalized `counts`. Values in the normalized `matrix` are |
|
47 |
-#' assigned to each bin in `breaks`. Each break is assigned to a unique color |
|
48 |
-#' from `col`. If NULL, then breaks are calculated automatically. Default NULL. |
|
49 |
-#' @param legend Logical. Determines whether legend should be drawn. Default |
|
50 |
-#' TRUE. |
|
51 |
-#' @param annotationLegend Logical. Whether legend for all annotations should |
|
52 |
-#' be drawn. Default TRUE. |
|
53 |
-#' @param annotationNamesFeature Logical. Whether the names for features should |
|
54 |
-#' be shown. Default TRUE. |
|
55 |
-#' @param annotationNamesCell Logical. Whether the names for cells should be |
|
56 |
-#' shown. Default TRUE. |
|
57 |
-#' @param showNamesFeature Logical. Specifies if feature names should be shown. |
|
58 |
-#' Default TRUE. |
|
59 |
-#' @param showNamesCell Logical. Specifies if cell names should be shown. |
|
60 |
-#' Default FALSE. |
|
61 |
-#' @param rowGroupOrder Vector. Specifies the order of feature clusters when |
|
62 |
-#' semisupervised clustering is performed on the \code{y} labels. |
|
63 |
-#' @param colGroupOrder Vector. Specifies the order of cell clusters when |
|
64 |
-#' semisupervised clustering is performed on the \code{z} labels. |
|
65 |
-#' @param hclustMethod Character. Specifies the method to use for the 'hclust' |
|
66 |
-#' function. See `?hclust` for possible values. Default "ward.D2". |
|
67 |
-#' @param treeheightFeature Numeric. Width of the feature dendrogram. Set to 0 |
|
68 |
-#' to disable plotting of this dendrogram. Default: if clusterFeature == TRUE, |
|
69 |
-#' then treeheightFeature = 50, else treeheightFeature = 0. |
|
70 |
-#' @param treeheightCell Numeric. Height of the cell dendrogram. Set to 0 to |
|
71 |
-#' disable plotting of this dendrogram. Default: if clusterCell == TRUE, then |
|
72 |
-#' treeheightCell = 50, else treeheightCell = 0. |
|
73 |
-#' @param silent Logical. Whether to plot the heatmap. |
|
74 |
-#' @param ... Other arguments to be passed to underlying pheatmap function. |
|
9 |
+#' NULL, no subsetting will be performed. Default NULL. \strong{Only used for |
|
10 |
+#' \code{sce} containing celda_C model result returned by \link{celda_C}.} |
|
11 |
+#' @param nfeatures Integer. Maximum number of features to select for each |
|
12 |
+#' gene module. Default 25. \strong{Only used for \code{sce} containing |
|
13 |
+#' celda_CG or celda_G model results returned by \link{celda_CG} or |
|
14 |
+#' \link{celda_G}.} |
|
15 |
+#' @param ... Additional parameters passed to \link{plotHeatmap}. |
|
16 |
+#' @seealso `celdaTsne()` for generating 2-dimensional tSNE coordinates |
|
75 | 17 |
#' @examples |
76 |
-#' data(celdaCGSim, celdaCGMod) |
|
77 |
-#' plotHeatmap(celdaCGSim$counts, |
|
78 |
-#' z = celdaCGMod@celdaClusters$z, y = celdaCGMod@celdaClusters$y |
|
79 |
-#' ) |
|
18 |
+#' data(sceCeldaCG) |
|
19 |
+#' celdaHeatmap(sceCeldaCG) |
|
80 | 20 |
#' @return list A list containing dendrogram information and the heatmap grob |
81 |
-#' @import graphics |
|
82 |
-#' @import grid |
|
83 | 21 |
#' @export |
84 |
-plotHeatmap <- function(counts, |
|
85 |
- z = NULL, |
|
86 |
- y = NULL, |
|
87 |
- scaleRow = scale, |
|
88 |
- trim = c(-2, 2), |
|
89 |
- featureIx = NULL, |
|
90 |
- cellIx = NULL, |
|
91 |
- clusterFeature = TRUE, |
|
92 |
- clusterCell = TRUE, |
|
93 |
- colorScheme = c("divergent", "sequential"), |
|
94 |
- colorSchemeSymmetric = TRUE, |
|
95 |
- colorSchemeCenter = 0, |
|
96 |
- col = NULL, |
|
97 |
- annotationCell = NULL, |
|
98 |
- annotationFeature = NULL, |
|
99 |
- annotationColor = NULL, |
|
100 |
- breaks = NULL, |
|
101 |
- legend = TRUE, |
|
102 |
- annotationLegend = TRUE, |
|
103 |
- annotationNamesFeature = TRUE, |
|
104 |
- annotationNamesCell = TRUE, |
|
105 |
- showNamesFeature = FALSE, |
|
106 |
- showNamesCell = FALSE, |
|
107 |
- rowGroupOrder = NULL, |
|
108 |
- colGroupOrder = NULL, |
|
109 |
- hclustMethod = "ward.D2", |
|
110 |
- treeheightFeature = ifelse(clusterFeature, 50, 0), |
|
111 |
- treeheightCell = ifelse(clusterCell, 50, 0), |
|
112 |
- silent = FALSE, |
|
113 |
- ...) { |
|
114 |
- # Check for same lengths for z and y group variables |
|
115 |
- if (!is.null(z) & length(z) != ncol(counts)) { |
|
116 |
- stop("Length of z must match number of columns in counts matrix") |
|
117 |
- } |
|
22 |
+setGeneric("celdaHeatmap", |
|
23 |
+ function(sce, ...) { |
|
24 |
+ standardGeneric("celdaHeatmap") |
|
25 |
+ }) |
|
118 | 26 |
|
119 |
- if (!is.null(y) & length(y) != nrow(counts)) { |
|
120 |
- stop("Length of y must match number of rows in counts matrix") |
|
121 |
- } |
|
122 | 27 |
|
123 |
- colorScheme <- match.arg(colorScheme) |
|
28 |
+#' @rdname celdaHeatmap |
|
29 |
+#' @export |
|
30 |
+setMethod("celdaHeatmap", signature(sce = "SingleCellExperiment"), |
|
31 |
+ function(sce, useAssay = "counts", featureIx = NULL, nfeatures = 25, ...) { |
|
32 |
+ if (celdaModel(sce) == "celda_C") { |
|
33 |
+ g <- .celdaHeatmapCelda_C(sce = sce, |
|
34 |
+ useAssay = useAssay, |
|
35 |
+ featureIx = featureIx, |
|
36 |
+ ...) |
|
37 |
+ return(g) |
|
38 |
+ } else if (celdaModel(sce) == "celda_CG") { |
|
39 |
+ g <- .celdaHeatmapCelda_CG(sce = sce, |
|
40 |
+ useAssay = useAssay, |
|
41 |
+ nfeatures = nfeatures, |
|
42 |
+ ...) |
|
43 |
+ return(g) |
|
44 |
+ } else if (celdaModel(sce) == "celda_G") { |
|
45 |
+ g <- .celdaHeatmapCelda_G(sce = sce, |
|
46 |
+ useAssay = useAssay, |
|
47 |
+ nfeatures = nfeatures, |
|
48 |
+ ...) |
|
49 |
+ return(g) |
|
50 |
+ } else { |
|
51 |
+ stop("S4Vectors::metadata(sce)$celda_parameters$model must be", |
|
52 |
+ " one of 'celda_C', 'celda_G', or 'celda_CG'") |
|
53 |
+ } |
|
54 |
+ } |
|
55 |
+) |
|
56 |
+ |
|
57 |
+ |
|
58 |
+.celdaHeatmapCelda_C <- function(sce, |
|
59 |
+ useAssay, featureIx, ...) { |
|
60 |
+ |
|
61 |
+ counts <- SummarizedExperiment::assay(sce, i = useAssay) |
|
62 |
+ norm <- normalizeCounts(counts, |
|
63 |
+ normalize = "proportion", |
|
64 |
+ transformationFun = sqrt) |
|
65 |
+ |
|
66 |
+ if (is.null(featureIx)) { |
|
67 |
+ return(plotHeatmap(norm, |
|
68 |
+ z = celdaClusters(sce), ...)) |
|
69 |
+ } |
|
70 |
+ |
|
71 |
+ return(plotHeatmap(norm[featureIx, ], |
|
72 |
+ z = celdaClusters(sce), ...)) |
|
73 |
+} |
|
124 | 74 |
|
125 |
- ## Create cell annotation |
|
126 |
- if (!is.null(annotationCell) & !is.null(z)) { |
|
127 |
- if (is.null(rownames(annotationCell))) { |
|
128 |
- rownames(annotationCell) <- colnames(counts) |
|
129 |
- } else { |
|
130 |
- if (any(rownames(annotationCell) != colnames(counts))) { |
|
131 |
- stop("Row names of 'annotationCell' are different than the |
|
132 |
- column names of 'counts'") |
|
133 |
- } |
|
134 |
- } |
|
135 |
- annotationCell <- |
|
136 |
- data.frame(cell = as.factor(z), annotationCell) |
|
137 |
- } else if (is.null(annotationCell) & !is.null(z)) { |
|
138 |
- annotationCell <- data.frame(cell = as.factor(z)) |
|
139 |
- rownames(annotationCell) <- colnames(counts) |
|
140 |
- } else { |
|
141 |
- annotationCell <- NA |
|
142 |
- } |
|
143 | 75 |
|
144 |
- # Set feature annotation |
|
145 |
- if (!is.null(annotationFeature) & !is.null(y)) { |
|
146 |
- if (is.null(rownames(annotationFeature))) { |
|
147 |
- rownames(annotationFeature) <- rownames(counts) |
|
148 |
- } else { |
|
149 |
- if (any(rownames(annotationFeature) != rownames(counts))) { |
|
150 |
- stop("Row names of 'annotationFeature' are different than the |
|
151 |
- row names of 'counts'") |
|
152 |
- } |
|
153 |
- } |
|
154 |
- annotationFeature <- data.frame( |
|
155 |
- module = as.factor(y), |
|
156 |
- annotationFeature |
|
76 |
+.celdaHeatmapCelda_CG <- function(sce, useAssay, nfeatures, ...) { |
|
77 |
+ counts <- SummarizedExperiment::assay(sce, i = useAssay) |
|
78 |
+ fm <- factorizeMatrix(x = sce, useAssay = useAssay, type = "proportion") |
|
79 |
+ top <- topRank(fm$proportions$module, n = nfeatures) |
|
80 |
+ ix <- unlist(top$index) |
|
81 |
+ norm <- normalizeCounts(counts, |
|
82 |
+ normalize = "proportion", |
|
83 |
+ transformationFun = sqrt) |
|
84 |
+ plt <- plotHeatmap(norm[ix, ], |
|
85 |
+ z = celdaClusters(sce), |
|
86 |
+ y = celdaModules(sce)[ix], |
|
87 |
+ ... |
|
157 | 88 |
) |
158 |
- } else if (is.null(annotationFeature) & !is.null(y)) { |
|
159 |
- annotationFeature <- data.frame(module = as.factor(y)) |
|
160 |
- rownames(annotationFeature) <- rownames(counts) |
|
161 |
- } else { |
|
162 |
- annotationFeature <- NA |
|
163 |
- } |
|
164 |
- |
|
165 |
- ## Select subsets of features/cells |
|
166 |
- if (!is.null(featureIx)) { |
|
167 |
- counts <- counts[featureIx, , drop = FALSE] |
|
168 |
- if (!is.null(annotationFeature) && |
|
169 |
- !is.null(ncol(annotationFeature))) { |
|
170 |
- annotationFeature <- annotationFeature[featureIx, , drop = FALSE] |
|
171 |
- } |
|
172 |
- if (!is.null(y)) { |
|
173 |
- y <- y[featureIx] |
|
174 |
- } |
|
175 |
- } |
|
176 |
- |
|
177 |
- if (!is.null(cellIx)) { |
|
178 |
- counts <- counts[, cellIx, drop = FALSE] |
|
179 |
- if (!is.null(annotationCell) && |
|
180 |
- !is.null(ncol(annotationCell))) { |
|
181 |
- annotationCell <- annotationCell[cellIx, , drop = FALSE] |
|
182 |
- } |
|
183 |
- if (!is.null(z)) { |
|
184 |
- z <- z[cellIx] |
|
185 |
- } |
|
186 |
- } |
|
187 |
- |
|
188 |
- ## Set annotation colors |
|
189 |
- if (!is.null(z)) { |
|
190 |
- if (is.factor(z)) { |
|
191 |
- K <- levels(z) |
|
192 |
- } else { |
|
193 |
- K <- unique(z) |
|
194 |
- } |
|
195 |
- K <- stringr::str_sort(K, numeric = TRUE) |
|
196 |
- kCol <- distinctColors(length(K)) |
|
197 |
- names(kCol) <- K |
|
198 |
- |
|
199 |
- |
|
200 |
- if (!is.null(annotationColor)) { |
|
201 |
- if (!("cell" %in% names(annotationColor))) { |
|
202 |
- annotationColor <- c(list(cell = kCol), annotationColor) |
|
203 |
- } |
|
204 |
- } else { |
|
205 |
- annotationColor <- list(cell = kCol) |
|
206 |
- } |
|
207 |
- } |
|
208 |
- |
|
209 |
- if (!is.null(y)) { |
|
210 |
- if (is.factor(y)) { |
|
211 |
- L <- levels(y) |
|
212 |
- } else { |
|
213 |
- L <- unique(y) |
|
214 |
- } |
|
215 |
- L <- stringr::str_sort(L, numeric = TRUE) |
|
216 |
- lCol <- distinctColors(length(L)) |
|
217 |
- names(lCol) <- L |
|
218 |
- |
|
219 |
- if (!is.null(annotationColor)) { |
|
220 |
- if (!("module" %in% names(annotationColor))) { |
|
221 |
- annotationColor <- c(list(module = lCol), annotationColor) |
|
222 |
- } |
|
223 |
- } else { |
|
224 |
- annotationColor <- list(module = lCol) |
|
225 |
- } |
|
226 |
- } |
|
227 |
- |
|
228 |
- # scale indivisual rows by scaleRow |
|
229 |
- if (!is.null(scaleRow)) { |
|
230 |
- if (is.function(scaleRow)) { |
|
231 |
- cn <- colnames(counts) |
|
232 |
- counts <- t(base::apply(counts, 1, scaleRow)) |
|
233 |
- colnames(counts) <- cn |
|
234 |
- } else { |
|
235 |
- stop("'scaleRow' needs to be of class 'function'") |
|
236 |
- } |
|
237 |
- } |
|
238 |
- |
|
239 |
- if (!is.null(trim)) { |
|
240 |
- if (length(trim) != 2) { |
|
241 |
- stop( |
|
242 |
- "'trim' should be a 2 element vector specifying the lower", |
|
243 |
- " and upper boundaries" |
|
244 |
- ) |
|
245 |
- } |
|
246 |
- trim <- sort(trim) |
|
247 |
- counts[counts < trim[1]] <- trim[1] |
|
248 |
- counts[counts > trim[2]] <- trim[2] |
|
249 |
- } |
|
250 |
- |
|
251 |
- ## Set color scheme and breaks |
|
252 |
- uBoundRange <- max(counts, na.rm = TRUE) |
|
253 |
- lboundRange <- min(counts, na.rm = TRUE) |
|
254 |
- |
|
255 |
- if (colorScheme == "divergent") { |
|
256 |
- if (colorSchemeSymmetric == TRUE) { |
|
257 |
- uBoundRange <- max(abs(uBoundRange), abs(lboundRange)) |
|
258 |
- lboundRange <- -uBoundRange |
|
259 |
- } |
|
260 |
- if (is.null(col)) { |
|
261 |
- col <- colorRampPalette(c("#1E90FF", "#FFFFFF", "#CD2626"), |
|
262 |
- space = "Lab" |
|
263 |
- )(100) |
|
264 |
- } |
|
265 |
- colLen <- length(col) |
|
266 |
- if (is.null(breaks)) { |
|
267 |
- breaks <- c( |
|
268 |
- seq( |
|
269 |
- lboundRange, |
|
270 |
- colorSchemeCenter, |
|
271 |
- length.out = round(colLen / 2) + 1 |
|
272 |
- ), |
|
273 |
- seq( |
|
274 |
- colorSchemeCenter + 1e-6, |
|
275 |
- uBoundRange, |
|
276 |
- length.out = colLen - round(colLen / 2) |
|
277 |
- ) |
|
278 |
- ) |
|
279 |
- } |
|
280 |
- } else { |
|
281 |
- # Sequential color scheme |
|
282 |
- if (is.null(col)) { |
|
283 |
- col <- colorRampPalette(c("#FFFFFF", brewer.pal( |
|
284 |
- n = 9, |
|
285 |
- name = "Blues" |
|
286 |
- )))(100) |
|
287 |
- } |
|
288 |
- colLen <- length(col) |
|
289 |
- if (is.null(breaks)) { |
|
290 |
- breaks <- seq(lboundRange, uBoundRange, length.out = colLen) |
|
291 |
- } |
|
292 |
- } |
|
293 |
- |
|
294 |
- sp <- semiPheatmap( |
|
295 |
- mat = counts, |
|
296 |
- color = col, |
|
297 |
- breaks = breaks, |
|
298 |
- clusterCols = clusterCell, |
|
299 |
- clusterRows = clusterFeature, |
|
300 |
- annotationRow = annotationFeature, |
|
301 |
- annotationCol = annotationCell, |
|
302 |
- annotationColors = annotationColor, |
|
303 |
- legend = legend, |
|
304 |
- annotationLegend = annotationLegend, |
|
305 |
- annotationNamesRow = annotationNamesFeature, |
|
306 |
- annotationNamesCol = annotationNamesCell, |
|
307 |
- showRownames = showNamesFeature, |
|
308 |
- showColnames = showNamesCell, |
|
309 |
- clusteringMethod = hclustMethod, |
|
310 |
- treeHeightRow = treeheightFeature, |
|
311 |
- treeHeightCol = treeheightCell, |
|
312 |
- rowLabel = y, |
|
313 |
- colLabel = z, |
|
314 |
- rowGroupOrder = rowGroupOrder, |
|
315 |
- colGroupOrder = colGroupOrder, |
|
316 |
- silent = TRUE, |
|
317 |
- ... |
|
318 |
- ) |
|
89 |
+ invisible(plt) |
|
90 |
+} |
|
319 | 91 |
|
320 |
- if (!isTRUE(silent)) { |
|
321 |
- grid::grid.newpage() |
|
322 |
- grid::grid.draw(sp$gtable) |
|
323 |
- } |
|
324 | 92 |
|
325 |
- invisible(sp) |
|
93 |
+.celdaHeatmapCelda_G <- function(sce, useAssay, nfeatures, ...) { |
|
94 |
+ counts <- SummarizedExperiment::assay(sce, i = useAssay) |
|
95 |
+ fm <- factorizeMatrix(x = sce, useAssay = useAssay, type = "proportion") |
|
96 |
+ top <- celda::topRank(fm$proportions$module, n = nfeatures) |
|
97 |
+ ix <- unlist(top$index) |
|
98 |
+ norm <- normalizeCounts(counts, |
|
99 |
+ normalize = "proportion", |
|
100 |
+ transformationFun = sqrt |
|
101 |
+ ) |
|
102 |
+ plt <- plotHeatmap(norm[ix, ], y = celdaModules(sce)[ix], ...) |
|
103 |
+ invisible(plt) |
|
326 | 104 |
} |
... | ... |
@@ -75,7 +75,7 @@ |
75 | 75 |
#' @examples |
76 | 76 |
#' data(celdaCGSim, celdaCGMod) |
77 | 77 |
#' plotHeatmap(celdaCGSim$counts, |
78 |
-#' z = celdaCGMod@clusters$z, y = celdaCGMod@clusters$y |
|
78 |
+#' z = celdaCGMod@celdaClusters$z, y = celdaCGMod@celdaClusters$y |
|
79 | 79 |
#' ) |
80 | 80 |
#' @return list A list containing dendrogram information and the heatmap grob |
81 | 81 |
#' @import graphics |
... | ... |
@@ -75,7 +75,7 @@ |
75 | 75 |
#' @examples |
76 | 76 |
#' data(celdaCGSim, celdaCGMod) |
77 | 77 |
#' plotHeatmap(celdaCGSim$counts, |
78 |
-#' z = clusters(celdaCGMod)$z, y = clusters(celdaCGMod)$y |
|
78 |
+#' z = celdaCGMod@clusters$z, y = celdaCGMod@clusters$y |
|
79 | 79 |
#' ) |
80 | 80 |
#' @return list A list containing dendrogram information and the heatmap grob |
81 | 81 |
#' @import graphics |
... | ... |
@@ -27,18 +27,18 @@ |
27 | 27 |
#' @param annotationFeature A data frame for the feature annotations (rows). |
28 | 28 |
#' @param annotationColor List. Contains color scheme for all annotations. See |
29 | 29 |
#' `?pheatmap` for more details. |
30 |
-#' @param colorScheme "Character. One of ""divergent"" or ""sequential"". A |
|
31 |
-#' ""divergent"" scheme is best for highlighting relative data (denoted by |
|
30 |
+#' @param colorScheme Character. One of "divergent" or "sequential". A |
|
31 |
+#' "divergent" scheme is best fo |