... | ... |
@@ -1,25 +1,21 @@ |
1 |
-#' Compute Z-Score |
|
2 |
-#' |
|
3 |
-#' Computes Z-Score from an input count matrix using the formula ((x-mean(x))/sd(x)) |
|
4 |
-#' for each gene across all cells. The input count matrix can either be a base matrix, |
|
5 |
-#' dgCMatrix or a DelayedMatrix. Computations are performed using DelayedMatrixStats |
|
6 |
-#' package to efficiently compute the Z-Score matrix. |
|
7 |
-#' |
|
8 |
-#' @param counts matrix (base matrix, dgCMatrix or DelayedMatrix) |
|
9 |
-#' |
|
10 |
-#' @return z-score computed counts matrix (DelayedMatrix) |
|
11 |
-#' @export |
|
12 |
-#' |
|
13 |
-#' @examples |
|
14 |
-#' |
|
15 |
-#' data(sce_chcl, package = "scds") |
|
16 |
-#' assay(sce_chcl, "countsZScore") <- computeZScore(assay(sce_chcl, "counts")) |
|
17 |
-#' |
|
18 |
-computeZScore <- function(counts) { |
|
19 |
- if (!methods::is(counts, "DelayedArray")) { |
|
20 |
- counts <- DelayedArray::DelayedArray(counts) |
|
21 |
- } |
|
22 |
- counts <- (counts - DelayedMatrixStats::rowMeans2(counts)) / DelayedMatrixStats::rowSds(counts) |
|
23 |
- counts[base::is.nan(counts)] <- 0 |
|
24 |
- return(counts) |
|
25 |
-} |
|
1 |
+#' Compute Z-Score |
|
2 |
+#' |
|
3 |
+#' Computes Z-Score from an input count matrix using the formula |
|
4 |
+#' ((x-mean(x))/sd(x)) for each gene across all cells. The input count matrix |
|
5 |
+#' can either be a base matrix, dgCMatrix or a DelayedMatrix. Computations are |
|
6 |
+#' performed using DelayedMatrixStats package to efficiently compute the |
|
7 |
+#' Z-Score matrix. |
|
8 |
+#' @param counts matrix (base matrix, dgCMatrix or DelayedMatrix) |
|
9 |
+#' @return z-score computed counts matrix (DelayedMatrix) |
|
10 |
+#' @export |
|
11 |
+#' @examples |
|
12 |
+#' data(sce_chcl, package = "scds") |
|
13 |
+#' assay(sce_chcl, "countsZScore") <- computeZScore(assay(sce_chcl, "counts")) |
|
14 |
+computeZScore <- function(counts) { |
|
15 |
+ if (!methods::is(counts, "DelayedArray")) { |
|
16 |
+ counts <- DelayedArray::DelayedArray(counts) |
|
17 |
+ } |
|
18 |
+ counts <- (counts - DelayedMatrixStats::rowMeans2(counts)) / DelayedMatrixStats::rowSds(counts) |
|
19 |
+ counts[base::is.nan(counts)] <- 0 |
|
20 |
+ return(counts) |
|
21 |
+} |
... | ... |
@@ -16,12 +16,10 @@ |
16 | 16 |
#' assay(sce_chcl, "countsZScore") <- computeZScore(assay(sce_chcl, "counts")) |
17 | 17 |
#' |
18 | 18 |
computeZScore <- function(counts) { |
19 |
- #inputClass <- class(counts)[1] |
|
20 | 19 |
if (!methods::is(counts, "DelayedArray")) { |
21 | 20 |
counts <- DelayedArray::DelayedArray(counts) |
22 | 21 |
} |
23 | 22 |
counts <- (counts - DelayedMatrixStats::rowMeans2(counts)) / DelayedMatrixStats::rowSds(counts) |
24 | 23 |
counts[base::is.nan(counts)] <- 0 |
25 |
- #counts <- as(counts, inputClass) |
|
26 | 24 |
return(counts) |
27 | 25 |
} |
... | ... |
@@ -5,7 +5,7 @@ |
5 | 5 |
#' dgCMatrix or a DelayedMatrix. Computations are performed using DelayedMatrixStats |
6 | 6 |
#' package to efficiently compute the Z-Score matrix. |
7 | 7 |
#' |
8 |
-#' @param counts matrix (base matrix, dgCMatrix or DelaymedMatrix) |
|
8 |
+#' @param counts matrix (base matrix, dgCMatrix or DelayedMatrix) |
|
9 | 9 |
#' |
10 | 10 |
#' @return z-score computed counts matrix (DelayedMatrix) |
11 | 11 |
#' @export |
... | ... |
@@ -16,10 +16,12 @@ |
16 | 16 |
#' assay(sce_chcl, "countsZScore") <- computeZScore(assay(sce_chcl, "counts")) |
17 | 17 |
#' |
18 | 18 |
computeZScore <- function(counts) { |
19 |
+ #inputClass <- class(counts)[1] |
|
19 | 20 |
if (!methods::is(counts, "DelayedArray")) { |
20 | 21 |
counts <- DelayedArray::DelayedArray(counts) |
21 | 22 |
} |
22 | 23 |
counts <- (counts - DelayedMatrixStats::rowMeans2(counts)) / DelayedMatrixStats::rowSds(counts) |
23 | 24 |
counts[base::is.nan(counts)] <- 0 |
25 |
+ #counts <- as(counts, inputClass) |
|
24 | 26 |
return(counts) |
25 | 27 |
} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,25 @@ |
1 |
+#' Compute Z-Score |
|
2 |
+#' |
|
3 |
+#' Computes Z-Score from an input count matrix using the formula ((x-mean(x))/sd(x)) |
|
4 |
+#' for each gene across all cells. The input count matrix can either be a base matrix, |
|
5 |
+#' dgCMatrix or a DelayedMatrix. Computations are performed using DelayedMatrixStats |
|
6 |
+#' package to efficiently compute the Z-Score matrix. |
|
7 |
+#' |
|
8 |
+#' @param counts matrix (base matrix, dgCMatrix or DelaymedMatrix) |
|
9 |
+#' |
|
10 |
+#' @return z-score computed counts matrix (DelayedMatrix) |
|
11 |
+#' @export |
|
12 |
+#' |
|
13 |
+#' @examples |
|
14 |
+#' |
|
15 |
+#' data(sce_chcl, package = "scds") |
|
16 |
+#' assay(sce_chcl, "countsZScore") <- computeZScore(assay(sce_chcl, "counts")) |
|
17 |
+#' |
|
18 |
+computeZScore <- function(counts) { |
|
19 |
+ if (!methods::is(counts, "DelayedArray")) { |
|
20 |
+ counts <- DelayedArray::DelayedArray(counts) |
|
21 |
+ } |
|
22 |
+ counts <- (counts - DelayedMatrixStats::rowMeans2(counts)) / DelayedMatrixStats::rowSds(counts) |
|
23 |
+ counts[base::is.nan(counts)] <- 0 |
|
24 |
+ return(counts) |
|
25 |
+} |
1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,25 +0,0 @@ |
1 |
-#' Compute Z-Score |
|
2 |
-#' |
|
3 |
-#' Computes Z-Score from an input count matrix using the formula ((x-mean(x))/sd(x)) |
|
4 |
-#' for each gene across all cells. The input count matrix can either be a base matrix, |
|
5 |
-#' dgCMatrix or a DelayedMatrix. Computations are performed using DelayedMatrixStats |
|
6 |
-#' package to efficiently compute the Z-Score matrix. |
|
7 |
-#' |
|
8 |
-#' @param counts matrix (base matrix, dgCMatrix or DelaymedMatrix) |
|
9 |
-#' |
|
10 |
-#' @return z-score computed counts matrix (DelayedMatrix) |
|
11 |
-#' @export |
|
12 |
-#' |
|
13 |
-#' @examples |
|
14 |
-#' |
|
15 |
-#' data(sce_chcl, package = "scds") |
|
16 |
-#' assay(sce_chcl, "countsZScore") <- computeZScore(assay(sce_chcl, "counts")) |
|
17 |
-#' |
|
18 |
-computeZScore <- function(counts) { |
|
19 |
- if (!methods::is(counts, "DelayedArray")) { |
|
20 |
- counts <- DelayedArray::DelayedArray(counts) |
|
21 |
- } |
|
22 |
- counts <- (counts - DelayedMatrixStats::rowMeans2(counts)) / DelayedMatrixStats::rowSds(counts) |
|
23 |
- counts[base::is.nan(counts)] <- 0 |
|
24 |
- return(counts) |
|
25 |
-} |
... | ... |
@@ -1,25 +1,25 @@ |
1 |
-#' Compute Z-Score |
|
2 |
-#' |
|
3 |
-#' Computes Z-Score from an input count matrix using the formula ((x-mean(x))/sd(x)) |
|
4 |
-#' for each gene across all cells. The input count matrix can either be a base matrix, |
|
5 |
-#' dgCMatrix or a DelayedMatrix. Computations are performed using DelayedMatrixStats |
|
6 |
-#' package to efficiently compute the Z-Score matrix. |
|
7 |
-#' |
|
8 |
-#' @param counts matrix (base matrix, dgCMatrix or DelaymedMatrix) |
|
9 |
-#' |
|
10 |
-#' @return z-score computed counts matrix (DelayedMatrix) |
|
11 |
-#' @export |
|
12 |
-#' |
|
13 |
-#' @examples |
|
14 |
-#' |
|
15 |
-#' data(sce_chcl, package = "scds") |
|
16 |
-#' assay(sce_chcl, "countsZScore") <- computeZScore(assay(sce_chcl, "counts")) |
|
17 |
-#' |
|
18 |
-computeZScore <- function(counts) { |
|
19 |
- if (!methods::is(counts, "DelayedArray")) { |
|
20 |
- counts <- DelayedArray(counts) |
|
21 |
- } |
|
22 |
- counts <- (counts - DelayedMatrixStats::rowMeans2(counts)) / DelayedMatrixStats::rowSds(counts) |
|
23 |
- counts[base::is.nan(counts)] <- 0 |
|
24 |
- return(counts) |
|
25 |
-} |
|
1 |
+#' Compute Z-Score |
|
2 |
+#' |
|
3 |
+#' Computes Z-Score from an input count matrix using the formula ((x-mean(x))/sd(x)) |
|
4 |
+#' for each gene across all cells. The input count matrix can either be a base matrix, |
|
5 |
+#' dgCMatrix or a DelayedMatrix. Computations are performed using DelayedMatrixStats |
|
6 |
+#' package to efficiently compute the Z-Score matrix. |
|
7 |
+#' |
|
8 |
+#' @param counts matrix (base matrix, dgCMatrix or DelaymedMatrix) |
|
9 |
+#' |
|
10 |
+#' @return z-score computed counts matrix (DelayedMatrix) |
|
11 |
+#' @export |
|
12 |
+#' |
|
13 |
+#' @examples |
|
14 |
+#' |
|
15 |
+#' data(sce_chcl, package = "scds") |
|
16 |
+#' assay(sce_chcl, "countsZScore") <- computeZScore(assay(sce_chcl, "counts")) |
|
17 |
+#' |
|
18 |
+computeZScore <- function(counts) { |
|
19 |
+ if (!methods::is(counts, "DelayedArray")) { |
|
20 |
+ counts <- DelayedArray::DelayedArray(counts) |
|
21 |
+ } |
|
22 |
+ counts <- (counts - DelayedMatrixStats::rowMeans2(counts)) / DelayedMatrixStats::rowSds(counts) |
|
23 |
+ counts[base::is.nan(counts)] <- 0 |
|
24 |
+ return(counts) |
|
25 |
+} |
... | ... |
@@ -12,12 +12,9 @@ |
12 | 12 |
#' |
13 | 13 |
#' @examples |
14 | 14 |
#' |
15 |
-#' library(TENxPBMCData) |
|
16 |
-#' sce <- TENxPBMCData("pbmc3k") |
|
17 |
-#' rownames(sce) <- rowData(sce)$Symbol_TENx |
|
18 |
-#' colnames(sce) <- colData(sce)$Barcode |
|
19 |
-#' assay(sce, "countsZScore") <- computeZScore(assay(sce, "counts")) |
|
20 |
-#' |
|
15 |
+#' data(sce_chcl, package = "scds") |
|
16 |
+#' assay(sce_chcl, "countsZScore") <- computeZScore(assay(sce_chcl, "counts")) |
|
17 |
+#' |
|
21 | 18 |
computeZScore <- function(counts) { |
22 | 19 |
if (!methods::is(counts, "DelayedArray")) { |
23 | 20 |
counts <- DelayedArray(counts) |
... | ... |
@@ -19,10 +19,10 @@ |
19 | 19 |
#' assay(sce, "countsZScore") <- computeZScore(assay(sce, "counts")) |
20 | 20 |
#' |
21 | 21 |
computeZScore <- function(counts) { |
22 |
- if (!is(counts, "DelayedArray")) { |
|
22 |
+ if (!methods::is(counts, "DelayedArray")) { |
|
23 | 23 |
counts <- DelayedArray(counts) |
24 | 24 |
} |
25 | 25 |
counts <- (counts - DelayedMatrixStats::rowMeans2(counts)) / DelayedMatrixStats::rowSds(counts) |
26 |
- counts[is.nan(counts)] <- 0 |
|
26 |
+ counts[base::is.nan(counts)] <- 0 |
|
27 | 27 |
return(counts) |
28 | 28 |
} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,28 @@ |
1 |
+#' Compute Z-Score |
|
2 |
+#' |
|
3 |
+#' Computes Z-Score from an input count matrix using the formula ((x-mean(x))/sd(x)) |
|
4 |
+#' for each gene across all cells. The input count matrix can either be a base matrix, |
|
5 |
+#' dgCMatrix or a DelayedMatrix. Computations are performed using DelayedMatrixStats |
|
6 |
+#' package to efficiently compute the Z-Score matrix. |
|
7 |
+#' |
|
8 |
+#' @param counts matrix (base matrix, dgCMatrix or DelaymedMatrix) |
|
9 |
+#' |
|
10 |
+#' @return z-score computed counts matrix (DelayedMatrix) |
|
11 |
+#' @export |
|
12 |
+#' |
|
13 |
+#' @examples |
|
14 |
+#' |
|
15 |
+#' library(TENxPBMCData) |
|
16 |
+#' sce <- TENxPBMCData("pbmc3k") |
|
17 |
+#' rownames(sce) <- rowData(sce)$Symbol_TENx |
|
18 |
+#' colnames(sce) <- colData(sce)$Barcode |
|
19 |
+#' assay(sce, "countsZScore") <- computeZScore(assay(sce, "counts")) |
|
20 |
+#' |
|
21 |
+computeZScore <- function(counts) { |
|
22 |
+ if (!is(counts, "DelayedArray")) { |
|
23 |
+ counts <- DelayedArray(counts) |
|
24 |
+ } |
|
25 |
+ counts <- (counts - DelayedMatrixStats::rowMeans2(counts)) / DelayedMatrixStats::rowSds(counts) |
|
26 |
+ counts[is.nan(counts)] <- 0 |
|
27 |
+ return(counts) |
|
28 |
+} |