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
86 stars 24 forks source link

Error when simulating batch effects and library size #19

Closed lazappi closed 1 year ago

lazappi commented 1 year ago

I am trying to create a simulation including both batch effects and library size based on the tutorials. Each one individually works fine but I get an error when I try to include both. Example code (reference data is the PBMC data from the batch effects tutorial):

reference <- readRDS((url("https://figshare.com/ndownloader/files/40581965")))
sim <- scDesign3::scdesign3(
    sce = reference, 
    celltype = "cell_type",
    pseudotime = NULL,
    spatial = NULL,
    other_covariates = c("batch", "nCount_RNA"), 
    mu_formula = "cell_type + batch + offset(log(nCount_RNA))",
    corr_formula = "1"
)
#> Input Data Construction Start
#> Input Data Construction End
#> Start Marginal Fitting
#> Marginal Fitting End
#> Start Copula Fitting
#> Convert Residuals to Multivariate Gaussian
#> Error in `colnames<-`(`*tmp*`, value = rownames(sce)) : 
#>  attempt to set 'colnames' on an object with less than two dimensions
#> In addition: Warning message:
#> In mclapply(seq_len(n), do_one, mc.preschedule = mc.preschedule,  :
#>   all scheduled cores encountered errors in user code

Should this work or am I doing something wrong here? There is also a warning about parallelization so maybe that is involved somehow? Thanks!

SONGDONGYUAN1994 commented 1 year ago

Hi Luke, Thank you for your message! I found it was caused by a bug in construct_data and I have fixed it now. Please update the package, thanks! In addition, please make sure that the variable types are correct in your input sce (e.g., nCount_RNA is not numeric in this example data so you need to convert it to numeric first.)

If you have any other suggestions for improving the package, please don't hesitate to let me know. It would be constructive since you are the pioneer in simulating sc data. Thanks!

Best, Dongyuan

lazappi commented 1 year ago

Thanks for replying so quickly! I have tried with the new version and it seems to be working now. I have run into another problem but I don't think it's related so I will open a new issue for that.