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
107 stars 14 forks source link

Condition-specific cell types error at get_DE_info() #79

Closed chloebazin closed 3 days ago

chloebazin commented 1 month ago

Hello,

I am trying to run the DE analysis with 3 conditions. One conditions has a condition-specific cell type (adipocyte). In the corresponding vignette for condition-specific cell types, you mention that "Logically, DE analysis cannot be performed for the condition-specific cell types. This results here in an error for the "L_T_TIM3._CD38._HLADR." cell type.". Similarly, I am getting the following error:

perform_muscat_de_analysis errored for celltype: adipocyte
Here is the original error message:
Error in x[[1]]: subscript out of bounds
"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.")

Due to this error, I cannot continue the analysis because the get_DE_info() function stops running at the condition-specific cell type. Any help would be very much appreciated!

Here are my parameters:

browaeysrobin commented 1 month ago

Hi @chloebazin

Are you sure you can't continue the analysis? If you have at least one other cell type that is present across all conditions, your DE_info will exist.

chloebazin commented 1 month ago

Hi @browaeysrobin,

I just checked again and I can't continue the analysis, which is strange. I have 11 other cell types present in all 3 conditions, and this is the only cell type that is specific to one condition, but my DE_info does not exist. This is the full error I'm getting. Let me know if I can send you more info to help solve this error.

perform_muscat_de_analysis errored for celltype: adipocyte

Here's the original error message:

Error in x[[1]]: subscript out of bounds
Traceback:

1. get_DE_info(sce = sce, sample_id = sample_id, group_id = group_id, 
 .     celltype_id = celltype_id, batches = batches, covariates = covariates, 
 .     contrasts_oi = contrasts_oi, min_cells = min_cells, expressed_df = frq_list$expressed_df)
2. celltypes %>% lapply(function(celltype_oi, sce) {
 .     sce_oi = sce[, SummarizedExperiment::colData(sce)[, celltype_id] == 
 .         celltype_oi]
 .     DE_result = tryCatch({
 .         perform_muscat_de_analysis(sce = sce_oi, sample_id = sample_id, 
 .             celltype_id = celltype_id, group_id = group_id, batches = batches, 
 .             covariates = covariates, contrasts = contrasts_oi, 
 .             expressed_df = expressed_df, assay_oi_pb = assay_oi_pb, 
 .             fun_oi_pb = fun_oi_pb, de_method_oi = de_method_oi, 
 .             min_cells = min_cells)
 .     }, error = function(cond) {
 .         message(paste0("perform_muscat_de_analysis errored for celltype: ", 
 .             celltype_oi))
 .         message("Here's the original error message:")
 .         message(cond)
 .         message("")
 .         print(cond)
 .         message(paste0("perform_muscat_de_analysis errored for celltype: ", 
 .             celltype_oi))
 .         message("")
 .         print("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.")
 .         return(NA)
 .     })
 . }, sce)
3. lapply(., function(celltype_oi, sce) {
 .     sce_oi = sce[, SummarizedExperiment::colData(sce)[, celltype_id] == 
 .         celltype_oi]
 .     DE_result = tryCatch({
 .         perform_muscat_de_analysis(sce = sce_oi, sample_id = sample_id, 
 .             celltype_id = celltype_id, group_id = group_id, batches = batches, 
 .             covariates = covariates, contrasts = contrasts_oi, 
 .             expressed_df = expressed_df, assay_oi_pb = assay_oi_pb, 
 .             fun_oi_pb = fun_oi_pb, de_method_oi = de_method_oi, 
 .             min_cells = min_cells)
 .     }, error = function(cond) {
 .         message(paste0("perform_muscat_de_analysis errored for celltype: ", 
 .             celltype_oi))
 .         message("Here's the original error message:")
 .         message(cond)
 .         message("")
 .         print(cond)
 .         message(paste0("perform_muscat_de_analysis errored for celltype: ", 
 .             celltype_oi))
 .         message("")
 .         print("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.")
 .         return(NA)
 .     })
 . }, sce)
4. FUN(X[[i]], ...)
5. tryCatch({
 .     perform_muscat_de_analysis(sce = sce_oi, sample_id = sample_id, 
 .         celltype_id = celltype_id, group_id = group_id, batches = batches, 
 .         covariates = covariates, contrasts = contrasts_oi, expressed_df = expressed_df, 
 .         assay_oi_pb = assay_oi_pb, fun_oi_pb = fun_oi_pb, de_method_oi = de_method_oi, 
 .         min_cells = min_cells)
 . }, error = function(cond) {
 .     message(paste0("perform_muscat_de_analysis errored for celltype: ", 
 .         celltype_oi))
 .     message("Here's the original error message:")
 .     message(cond)
 .     message("")
 .     print(cond)
 .     message(paste0("perform_muscat_de_analysis errored for celltype: ", 
 .         celltype_oi))
 .     message("")
 .     print("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.")
 .     return(NA)
 . })
6. tryCatchList(expr, classes, parentenv, handlers)
7. tryCatchOne(expr, names, parentenv, handlers[[1L]])
8. value[[3L]](cond)
9. message(cond)
10. withRestarts({
  .     signalCondition(cond)
  .     defaultHandler(cond)
  . }, muffleMessage = function() NULL)
11. withOneRestart(expr, restarts[[1L]])
12. doWithOneRestart(return(expr), restart)
browaeysrobin commented 1 month ago

Hi @chloebazin 1) Can you print the output of DE_info$celltype_de$de_output_tidy %>% head()? 2) Do you encounter the same problem with the vignette tutorial data?

chloebazin commented 1 month ago

Hi Robin,

  1. The output of that command is: Error in eval(expr, envir, enclos): object 'DE_info' not found. Traceback:
  2. When running with the vignette tutorial data and I get the same error as I had with my data, namely that the DE_info function does not run due to this error. The error is also followed by the same Traceback as with the one I had with my data in the previous message.
perform_muscat_de_analysis errored for celltype: L_T_TIM3._CD38._HLADR.

Here's the original error message:

Error in perform_muscat_de_analysis(sce = sce_oi, sample_id = sample_id, : conditions written in contrasts should be in the condition-indicating column! This is not the case, which can lead to errors downstream.

Then when running DE_info$celltype_de$de_output_tidy %>% head(), I get:

Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'head':
object 'DE_info' not found

Thank you for your help!

browaeysrobin commented 4 days ago

Hi @chloebazin

It is normal that there is an error message, but the function get_DE_info performs error handling through tryCatch in those cases, so you still obtain an output object in the end. Because this is not the case for you, I suspect something is different in your system settings/way you run R/Rmd files with respect to error handling.