SONGDONGYUAN1994 / scDesign3

scDesign3 generates realistic in silico data for multimodal single-cell and spatial omics
https://songdongyuan1994.github.io/scDesign3/docs/index.html
MIT License
81 stars 23 forks source link

Error when setting `ncell` with a continuous convariate #20

Closed lazappi closed 9 months ago

lazappi commented 1 year ago

I get the following error if I set the ncell argument when there is a continuous covariate in the model.

reference <- readRDS((url("https://figshare.com/ndownloader/files/40581965")))
sim <- scDesign3::scdesign3(
    sce = reference, 
    assay_use = "counts", 
    celltype = "cell_type",
    pseudotime = NULL, 
    spatial = NULL, 
    other_covariates = "nCount_RNA", 
    mu_formula = "cell_type + offset(log(nCount_RNA))", 
    sigma_formula = "1", 
    family_use = "nb", 
    n_cores = 2, 
    usebam = FALSE, 
    corr_formula = "1", 
    copula = "gaussian", 
    DT = TRUE, 
    pseudo_obs = FALSE, 
    return_model = FALSE,
    ncell = 100
)
#> Input Data Construction Start
#> Error in dimnames(x) <- dn : 
#>   length of 'dimnames' [1] not equal to array extent
#> In addition: Warning message:
#> In mclapply(seq_len(n), do_one, mc.preschedule = mc.preschedule,  :
#>   all scheduled cores encountered errors in user code

(P.S. I thought I submitted this last week but apparently not, sorry for the delay)

qw130 commented 1 year ago

Hi Luke,

Thanks for trying out scDesign3, and I'm sorry for the late reply. I just updated the code to fix this bug, the newest code should run with no issue using your provided code. The reason for the bug is that when ncell is small and there are some cell types in the inputted data that have very few cells (For example, in this dataset, the number of Megakaryocytes is only 0.287% of all cells), the generated values for the 100 synthetic cells'cell_type may not include those cell types, and this will cause errors when generating the new values for nCount_RNA.

Please let me know if you have any further questions.

Best, Qingyang