... | ... |
@@ -16,13 +16,12 @@ |
16 | 16 |
#' * `counts`: `matrix` with generated gene counts. |
17 | 17 |
#' |
18 | 18 |
#' @examples |
19 |
-#' spe <- mockSVG(10, tot_genes = 200, de_genes = 20, return_SPE = TRUE) |
|
19 |
+#' spe <- mockSVG(size = 20, tot_genes = 3, de_genes = 1, return_SPE = TRUE) |
|
20 | 20 |
#' spe |
21 | 21 |
#' |
22 | 22 |
#' @export |
23 | 23 |
#' @importFrom stats rnbinom runif |
24 |
-mockSVG <- function(size = 10, tot_genes = 1000, de_genes = 100, |
|
25 |
- return_SPE = FALSE) { |
|
24 |
+mockSVG <- function(size, tot_genes, de_genes, return_SPE = FALSE) { |
|
26 | 25 |
n_cells <- size * size |
27 | 26 |
coordinates <- data.frame( |
28 | 27 |
x = rep(seq.int(size), size), |
... | ... |
@@ -49,8 +49,7 @@ mockSVG <- function(size = 10, tot_genes = 1000, de_genes = 100, |
49 | 49 |
if (return_SPE) { |
50 | 50 |
out <- SpatialExperiment::SpatialExperiment( |
51 | 51 |
assays = list(counts = counts), |
52 |
- spatialData = S4Vectors::DataFrame(coordinates), |
|
53 |
- spatialCoordsNames = c("x", "y") |
|
52 |
+ spatialCoords = as.matrix(coordinates) |
|
54 | 53 |
) |
55 | 54 |
} |
56 | 55 |
out |
... | ... |
@@ -49,7 +49,7 @@ mockSVG <- function(size = 10, tot_genes = 1000, de_genes = 100, |
49 | 49 |
if (return_SPE) { |
50 | 50 |
out <- SpatialExperiment::SpatialExperiment( |
51 | 51 |
assays = list(counts = counts), |
52 |
- spatialData = coordinates, |
|
52 |
+ spatialData = S4Vectors::DataFrame(coordinates), |
|
53 | 53 |
spatialCoordsNames = c("x", "y") |
54 | 54 |
) |
55 | 55 |
} |
... | ... |
@@ -1,9 +1,11 @@ |
1 | 1 |
#' Generate count matrix for spatially variable genes. |
2 | 2 |
#' |
3 |
-#' @param size `int` genes will be spatially arranged on a size x size grid |
|
4 |
-#' @param tot_genes `int` total number of genes |
|
5 |
-#' @param de_genes `int` number of spatially variable genes |
|
6 |
-#' @param return_SPE `logical`, whether to return result as a |
|
3 |
+#' @param size An `integer` scalar. Cells will be spatially arranged on a `size |
|
4 |
+#' x size` grid. Default: 10, corresponding to 100 cells. |
|
5 |
+#' @param tot_genes An `integer` scalar. Total number of genes. Default: 1000. |
|
6 |
+#' @param de_genes An `integer` scaler. The number of spatially variable genes. |
|
7 |
+#' Default: 100. |
|
8 |
+#' @param return_SPE A `logical`, whether to return result as a |
|
7 | 9 |
#' \linkS4class{SpatialExperiment}. Default: `FALSE`. |
8 | 10 |
#' |
9 | 11 |
#' @return |
... | ... |
@@ -19,7 +21,8 @@ |
19 | 21 |
#' |
20 | 22 |
#' @export |
21 | 23 |
#' @importFrom stats rnbinom runif |
22 |
-mockSVG <- function(size, tot_genes, de_genes, return_SPE = FALSE) { |
|
24 |
+mockSVG <- function(size = 10, tot_genes = 1000, de_genes = 100, |
|
25 |
+ return_SPE = FALSE) { |
|
23 | 26 |
n_cells <- size * size |
24 | 27 |
coordinates <- data.frame( |
25 | 28 |
x = rep(seq.int(size), size), |
... | ... |
@@ -3,13 +3,24 @@ |
3 | 3 |
#' @param size `int` genes will be spatially arranged on a size x size grid |
4 | 4 |
#' @param tot_genes `int` total number of genes |
5 | 5 |
#' @param de_genes `int` number of spatially variable genes |
6 |
+#' @param return_SPE `logical`, whether to return result as a |
|
7 |
+#' \linkS4class{SpatialExperiment}. Default: `FALSE`. |
|
6 | 8 |
#' |
7 |
-#' @return `list` containing: |
|
9 |
+#' @return |
|
10 |
+#' If `return_SPE = TRUE`, returns a \linkS4class{SpatialExperiment} object. |
|
11 |
+#' |
|
12 |
+#' If not, a `list` containing: |
|
8 | 13 |
#' * `coordinates`: `data.frame` with `x` and `y` columns; |
9 | 14 |
#' * `counts`: `matrix` with generated gene counts. |
15 |
+#' |
|
16 |
+#' @examples |
|
17 |
+#' spe <- mockSVG(10, tot_genes = 200, de_genes = 20, return_SPE = TRUE) |
|
18 |
+#' spe |
|
19 |
+#' |
|
10 | 20 |
#' @export |
11 | 21 |
#' @importFrom stats rnbinom runif |
12 |
-mockSVG <- function(size, tot_genes, de_genes) { |
|
22 |
+mockSVG <- function(size, tot_genes, de_genes, return_SPE = FALSE) { |
|
23 |
+ n_cells <- size * size |
|
13 | 24 |
coordinates <- data.frame( |
14 | 25 |
x = rep(seq.int(size), size), |
15 | 26 |
y = rep(seq.int(size), each = size) |
... | ... |
@@ -17,12 +28,27 @@ mockSVG <- function(size, tot_genes, de_genes) { |
17 | 28 |
|
18 | 29 |
mu <- 2^runif(tot_genes, -1, 5) |
19 | 30 |
counts <- matrix( |
20 |
- rnbinom(tot_genes * size * size, mu = mu, size = 10), |
|
31 |
+ rnbinom(tot_genes * n_cells, mu = mu, size = 10), |
|
21 | 32 |
nrow = tot_genes |
22 | 33 |
) |
23 | 34 |
m <- (size / 2) + 1 |
24 | 35 |
mask <- coordinates$x < m & coordinates$y < m |
25 | 36 |
counts[seq.int(de_genes), mask] <- counts[seq.int(de_genes), mask] + 20 |
26 | 37 |
|
27 |
- list(coordinates = coordinates, counts = counts) |
|
38 |
+ ## Set dimnames |
|
39 |
+ gene_names <- sprintf("Gene_%s", formatC(seq_len(tot_genes), width = 4, flag = 0)) |
|
40 |
+ cell_names <- sprintf("Cell_%s", formatC(seq_len(n_cells), width = 3, flag = 0)) |
|
41 |
+ rownames(coordinates) <- cell_names |
|
42 |
+ dimnames(counts) <- list(gene_names, cell_names) |
|
43 |
+ |
|
44 |
+ out <- list(coordinates = coordinates, counts = counts) |
|
45 |
+ |
|
46 |
+ if (return_SPE) { |
|
47 |
+ out <- SpatialExperiment::SpatialExperiment( |
|
48 |
+ assays = list(counts = counts), |
|
49 |
+ spatialData = coordinates, |
|
50 |
+ spatialCoordsNames = c("x", "y") |
|
51 |
+ ) |
|
52 |
+ } |
|
53 |
+ out |
|
28 | 54 |
} |
... | ... |
@@ -10,16 +10,19 @@ |
10 | 10 |
#' @export |
11 | 11 |
#' @importFrom stats rnbinom runif |
12 | 12 |
mockSVG <- function(size, tot_genes, de_genes) { |
13 |
- coordinates <- data.frame( |
|
14 |
- x = rep(seq.int(size), size), |
|
15 |
- y = rep(seq.int(size), each=size) |
|
16 |
- ) |
|
17 |
- |
|
18 |
- mu <- 2^runif(tot_genes, -1, 5) |
|
19 |
- counts <- matrix(rnbinom(tot_genes*size*size, mu=mu, size=10), nrow=tot_genes) |
|
20 |
- m <- (size/2)+1 |
|
21 |
- mask <- coordinates$x < m & coordinates$y < m |
|
22 |
- counts[seq.int(de_genes), mask] <- counts[seq.int(de_genes), mask] + 20 |
|
23 |
- |
|
24 |
- list(coordinates=coordinates, counts=counts) |
|
13 |
+ coordinates <- data.frame( |
|
14 |
+ x = rep(seq.int(size), size), |
|
15 |
+ y = rep(seq.int(size), each = size) |
|
16 |
+ ) |
|
17 |
+ |
|
18 |
+ mu <- 2^runif(tot_genes, -1, 5) |
|
19 |
+ counts <- matrix( |
|
20 |
+ rnbinom(tot_genes * size * size, mu = mu, size = 10), |
|
21 |
+ nrow = tot_genes |
|
22 |
+ ) |
|
23 |
+ m <- (size / 2) + 1 |
|
24 |
+ mask <- coordinates$x < m & coordinates$y < m |
|
25 |
+ counts[seq.int(de_genes), mask] <- counts[seq.int(de_genes), mask] + 20 |
|
26 |
+ |
|
27 |
+ list(coordinates = coordinates, counts = counts) |
|
25 | 28 |
} |
... | ... |
@@ -8,6 +8,7 @@ |
8 | 8 |
#' * `coordinates`: `data.frame` with `x` and `y` columns; |
9 | 9 |
#' * `counts`: `matrix` with generated gene counts. |
10 | 10 |
#' @export |
11 |
+#' @importFrom stats rnbinom runif |
|
11 | 12 |
mockSVG <- function(size, tot_genes, de_genes) { |
12 | 13 |
coordinates <- data.frame( |
13 | 14 |
x = rep(seq.int(size), size), |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,24 @@ |
1 |
+#' Generate count matrix for spatially variable genes. |
|
2 |
+#' |
|
3 |
+#' @param size `int` genes will be spatially arranged on a size x size grid |
|
4 |
+#' @param tot_genes `int` total number of genes |
|
5 |
+#' @param de_genes `int` number of spatially variable genes |
|
6 |
+#' |
|
7 |
+#' @return `list` containing: |
|
8 |
+#' * `coordinates`: `data.frame` with `x` and `y` columns; |
|
9 |
+#' * `counts`: `matrix` with generated gene counts. |
|
10 |
+#' @export |
|
11 |
+mockSVG <- function(size, tot_genes, de_genes) { |
|
12 |
+ coordinates <- data.frame( |
|
13 |
+ x = rep(seq.int(size), size), |
|
14 |
+ y = rep(seq.int(size), each=size) |
|
15 |
+ ) |
|
16 |
+ |
|
17 |
+ mu <- 2^runif(tot_genes, -1, 5) |
|
18 |
+ counts <- matrix(rnbinom(tot_genes*size*size, mu=mu, size=10), nrow=tot_genes) |
|
19 |
+ m <- (size/2)+1 |
|
20 |
+ mask <- coordinates$x < m & coordinates$y < m |
|
21 |
+ counts[seq.int(de_genes), mask] <- counts[seq.int(de_genes), mask] + 20 |
|
22 |
+ |
|
23 |
+ list(coordinates=coordinates, counts=counts) |
|
24 |
+} |