saeyslab / multinichenetr

MultiNicheNet: a flexible framework for differential cell-cell communication analysis from multi-sample multi-condition single-cell transcriptomics data
GNU General Public License v3.0
112 stars 14 forks source link

Error: not enough samples when there are #17

Closed lo2811 closed 1 year ago

lo2811 commented 1 year ago

Hello, Thank you for a great tool and detailed vignettes. I have a question related to the error: "not enough samples per group with sufficient cells of this cell type". I ran into this error with a cell type (CAFs) when I know for sure that there are enough cells, see below: Screenshot 2023-08-03 at 3 32 38 PM

Screenshot 2023-08-03 at 3 33 21 PM

Do you know why this error showed up?

Thank you!

browaeysrobin commented 1 year ago

Hi @lo2811

If I see it correctly: you have 3 groups with, after filtering out samples with insufficient CAFs (=L42572), 2 or more remaining samples per group. In theory, this should work, so let's try to find out the problem.

Can you give me more details about how you ran the analysis? Which vignette did you follow? Which function gives the error? What is the exact error message? What value of min_cells did you use? Did you assign batches or not? etc. The more information you provide, the more likely it is I will be able to help you.

lo2811 commented 1 year ago

Yes, I have 3 groups and only L42572 doesn't have enough cells. I followed the MultiNicheNet analysis: MIS-C threewise comparison - wrapper function vignette and ran into the error at multi_nichenet_analysis. Here are my parameters:

`logFC_threshold = 0.25 p_val_threshold = 0.05 fraction_cutoff = 0.05 p_val_adj = FALSE empirical_pval = FALSE top_n_target = 250 cores_system = 8 prioritizing_weights_DE = c("de_ligand" = 1, "de_receptor" = 1) prioritizing_weights_activity = c("activity_scaled" = 2)

prioritizing_weights_expression_specificity = c("exprs_ligand" = 2, "exprs_receptor" = 2)

prioritizing_weights_expression_sufficiency = c("frac_exprs_ligand_receptor" = 1)

prioritizing_weights_relative_abundance = c( "abund_sender" = 0, "abund_receiver" = 0) prioritizing_weights = c(prioritizing_weights_DE, prioritizing_weights_activity, prioritizing_weights_expression_specificity, prioritizing_weights_expression_sufficiency, prioritizing_weights_relative_abundance)`

min_cells were 10, and no batches, but I used sequencing flowcell as covariates.

Contrast set up: contrasts_oi = c("'LAMN-(LGMA+MHNA)/2','LGMA-(LAMN+MHNA)/2','MHNA-(LGMA+LAMN)/2'")

This is the exact error message: `perform_muscat_de_analysis errored for celltype: CAFs Here's the original error message: subscript out of bounds <subscriptOutOfBoundsError in x[[1]]: subscript out of bounds> perform_muscat_de_analysis errored for celltype: CAFs

[1] "In case: Error in x[[1]]: subscript out of bounds: this likely means that there are not enough samples per group with sufficient cells of this cell type. This cell type will thus be ignored for further analyses, other cell types will still be considered."`

Thank you and I hope we can figure out what was wrong.

lo2811 commented 1 year ago

I reran the exact analysis without covariates and the error went away. So it has to do with using flowcell as a covariate, does multi_nichenet_analysis treat covariate and batch the same, i.e. each sample per batch/covariate should meet the min_cells parameter?

browaeysrobin commented 1 year ago

I reran the exact analysis without covariates and the error went away. So it has to do with using flowcell as a covariate, does multi_nichenet_analysis treat covariate and batch the same, i.e. each sample per batch/covariate should meet the min_cells parameter?

Thanks for the information. Can you provide a table of sample_id vs flowcell so I can have insight in how your covariate is spread across the samples?

browaeysrobin commented 1 year ago

In any case, if your covariate is categorical, it will be considered the same as batch during the DE analysis, meaning that each leavel of the covariate should occur in at least one sample per group/condition. I improved the error message thrown in this function to make that clear.

If this is the issue for your data, you can close this issue.