scDesign3_simulation: Simulate Datasets by scDesign3

View source: R/13-scDesign3.R

scDesign3_simulationR Documentation

Simulate Datasets by scDesign3

Description

This function is used to simulate datasets by simu_new function in scDesign3 package.

Usage

scDesign3_simulation(
  parameters,
  other_prior = NULL,
  return_format,
  verbose = FALSE,
  seed
)

Arguments

parameters

A object generated by scDesign3::fit_marginal() and scDesign3::fit_copula()

other_prior

A list with names of certain parameters. Some methods need extra parameters to execute the estimation step, so you must input them. In simulation step, the number of cells, genes, groups, batches, the percent of DEGs are usually customed, so before simulating a dataset you must point it out. See Details below for more information.

return_format

A character. Alternatives choices: list, SingleCellExperiment, Seurat, h5ad. If you select h5ad, you will get a path where the .h5ad file saves to.

verbose

Logical. Whether to return messages or not.

seed

A random seed.

Details

In addtion to simulate datasets with default parameters, users want to simulate other kinds of datasets, e.g. a counts matrix with 2 or more cell groups. In scDesign3, you can set extra parameters to simulate datasets.

The customed parameters you can set are below:

  1. nCells. In scDesign3, you can set nCells directly other_prior = list(nCells = 1000) to simulate 1000 cells.

  2. nGroups. You can not directly set other_prior = list(nGroups = 3) to simulate 3 groups. Instead, you should specify the group labels for cells in the estimation step in scDesign3_estimation function.

  3. nBatches You can not directly set other_prior = list(nBatches = 3) to simulate 3 groups. Instead, you should specify the batch labels for cells in the estimation step in scDesign3_estimation function. Note that, if you customed another simulated cell number which is not equal to the one of real data, the batch information for simulated cells is not returned.

For more customed parameters in scDesign3, please check scDesign3::simu_new().

References

Song, D., Wang, Q., Yan, G. et al. scDesign3 generates realistic in silico data for multimodal single-cell and spatial omics. Nat Biotechnol (2023). https://doi.org/10.1038/s41587-023-01772-1

Github URL: https://github.com/SONGDONGYUAN1994/scDesign3/tree/main

Examples

## Not run: 
ref_data <- simmethods::data

## Simulate datasets with default parameters
simulate_result <- scDesign3_simulation(ref_data = ref_data,
                                       return_format = "list",
                                       verbose = TRUE,
                                       seed = 111)
counts <- simulate_result[["simulate_result"]][["count_data"]]
dim(counts)


## Simulate two groups with 20% proportion of DEGs and 2 fold change. Note that
## scDesign3 does not provide fold changes for genes so users would better set
## fc.group parameter in simulation function.
simulate_result <- scDesign3_simulation(ref_data = ref_data,
                                       other_prior = list(nCells = 1000,
                                                          nGroups = 2,
                                                          de.prob = 0.2,
                                                          fc.group = 2),
                                       return_format = "list",
                                       verbose = TRUE,
                                       seed = 111)
counts <- simulate_result[["simulate_result"]][["count_data"]]
dim(counts)
## cell information
col_data <- simulate_result[["simulate_result"]][["col_meta"]]
table(col_data$group)
## gene information
row_data <- simulate_result[["simulate_result"]][["row_meta"]]
table(row_data$de_gene)/4000
table(row_data$up_down)


## Simulate three groups with 20% proportion of DEGs and 4 fold change. 20%, 40%
## and 40% of cells belong to Group1, Group2 and Group3, respectively.
simulate_result <- scDesign3_simulation(ref_data = ref_data,
                                       other_prior = list(nCells = 1000,
                                                          nGroups = 3,
                                                          prob.group = c(0.2, 0.4, 0.4),
                                                          de.prob = 0.2,
                                                          fc.group = 4),
                                       return_format = "list",
                                       verbose = TRUE,
                                       seed = 111)
counts <- simulate_result[["simulate_result"]][["count_data"]]
dim(counts)
## cell information
col_data <- simulate_result[["simulate_result"]][["col_meta"]]
table(col_data$group)

## End(Not run)


duohongrui/simmethods documentation built on June 17, 2024, 10:49 a.m.