multinichenetr icon indicating copy to clipboard operation
multinichenetr copied to clipboard

Condition-specific cell types error at get_DE_info()

Open chloebazin opened this issue 1 year ago • 5 comments

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:

  • min_cells = 5
  • min_sample_prop = 0.5
  • fraction_cutoff = 0.05
  • logFC_threshold = 0.5
  • p_val_threshold = 0.05
  • p_val_adj = FALSE
  • empirical_pval = FALSE
  • top_n_target = 250
  • cores_system = 12
  • [1] "condition-specific celltypes:" [1] "adipocyte"
  • [1] "absent celltypes:" character(0)
  • analyse_condition_specific_celltypes = TRUE

chloebazin avatar Jul 13 '24 18:07 chloebazin

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.

browaeysrobin avatar Jul 16 '24 15:07 browaeysrobin

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)

chloebazin avatar Jul 16 '24 15:07 chloebazin

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?

browaeysrobin avatar Jul 17 '24 07:07 browaeysrobin

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!

chloebazin avatar Jul 18 '24 14:07 chloebazin

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.

browaeysrobin avatar Aug 19 '24 14:08 browaeysrobin

Hi, I seem to have run into this issue as well, I wrote a wrapper function for most of the code and the get_DE_info() internal tryCatch seems to work fine, but if I run this for multiple comparisons in a lapply, this step seems to fail. Any ideas or tips on this?

Edit: interestingly, switching from lapply to a for loop seemed to fix the tryCatch and allow the get_DE_info() step to proceed normally.

FerrenaAlexander avatar Aug 09 '25 00:08 FerrenaAlexander

Hi @FerrenaAlexander Thanks for the info. Can you reinstall multinichenetr and try it again?

browaeysrobin avatar Aug 12 '25 08:08 browaeysrobin

Hi, reinstalled and ran wrapped in lapply (instead of a for loop), it does work now. Thanks for all of your hard work!

FerrenaAlexander avatar Aug 20 '25 14:08 FerrenaAlexander