ventolab / CellphoneDB

CellPhoneDB can be used to search for a particular ligand/receptor, or interrogate your own HUMAN single-cell transcriptomics data.
https://www.cellphonedb.org/
MIT License
305 stars 52 forks source link

Error when no interactions are found using cpdb_statistical_analysis_method #109

Closed ldiao closed 7 months ago

ldiao commented 1 year ago

When no interactions are found in an analysis, an error is thrown instead of a null output + warning message. The latter may be preferable to prevent errors when running many samples. Full error output:

NoInteractionsFound Traceback (most recent call last) Cell In[6], line 21 18 if not os.path.exists(out_path): 19 os.mkdir(out_path) ---> 21 deconvoluted, means, pvalues, significant_means = cpdb_statistical_analysis_method.call( 22 cpdb_file_path = cpdb_file_path, # mandatory: CellPhoneDB database zip file. 23 meta_file_path = meta_file_path, # mandatory: tsv file defining barcodes to cell label. 24 counts_file_path = counts_file_path, # mandatory: normalized count matrix. 25 counts_data = 'hgnc_symbol', # defines the gene annotation in counts matrix. 26 microenvs_file_path = microenvs_file_path, # optional (default: None): defines cells per microenvironment. 27 iterations = 1000, # denotes the number of shufflings performed in the analysis. 28 threshold = 0.01, # defines the min % of cells expressing a gene for this to be employed in the analysis. 29 threads = 12, # number of threads to use in the analysis. 30 debug_seed = 42, # debug randome seed. To disable >=0. 31 result_precision = 3, # Sets the rounding for the mean values in significan_means. 32 pvalue = 0.05, # P-value threshold to employ for significance. 33 subsampling = False, # To enable subsampling the data (geometri sketching). 34 subsampling_log = False, # (mandatory) enable subsampling log1p for non log-transformed data inputs. 35 subsampling_num_pc = 100, # Number of componets to subsample via geometric skectching (dafault: 100). 36 subsampling_num_cells = 1000, # Number of cells to subsample (integer) (default: 1/3 of the dataset). 37 separator = '|', # Sets the string to employ to separate cells in the results dataframes "cellA|CellB". 38 debug = False, # Saves all intermediate tables employed during the analysis in pkl format. 39 output_path = out_path, # Path to save results. 40 output_suffix = '0.01_thresh', # Replaces the timestamp in the output files by a user defined string in the (default: None). 41 )

File ~/venvs/cpdb/lib/python3.8/site-packages/cellphonedb/src/core/methods/cpdb_statistical_analysis_method.py:108, in call(cpdb_file_path, meta_file_path, counts_file_path, counts_data, output_path, microenvs_file_path, iterations, threshold, threads, debug_seed, result_precision, pvalue, subsampling, subsampling_log, subsampling_num_pc, subsampling_num_cells, separator, debug, output_suffix) 104 ss = subsampler.Subsampler(log=subsampling_log, num_pc=subsampling_num_pc, num_cells=subsampling_num_cells, verbose=False, debug_seed=None) 105 counts = ss.subsample(counts) 107 pvalues, means, significant_means, deconvoluted = \ --> 108 cpdb_statistical_analysis_complex_method.call(meta.copy(), 109 counts.copy(), 110 counts_data, 111 interactions, 112 genes, 113 complex_expanded, 114 complex_composition, 115 microenvs, 116 pvalue, 117 separator, 118 iterations, 119 threshold, 120 threads, 121 debug_seed, 122 result_precision, 123 debug, 124 output_path 125 ) 128 max_rank = significant_means['rank'].max() 129 significant_means['rank'] = significant_means['rank'].apply(lambda rank: rank if rank != 0 else (1 + max_rank))

File ~/venvs/cpdb/lib/python3.8/site-packages/cellphonedb/src/core/methods/cpdb_statistical_analysis_complex_method.py:57, in call(meta, counts, counts_data, interactions, genes, complexes, complex_compositions, microenvs, pvalue, separator, iterations, threshold, threads, debug_seed, result_precision, debug, output_path) 50 interactions_filtered, counts_filtered, complex_composition_filtered = \ 51 cpdb_statistical_analysis_helper.prefilters(interactions_reduced, 52 counts, 53 complexes, 54 complex_compositions) 56 if interactions_filtered.empty: ---> 57 raise NoInteractionsFound() 59 meta = meta.loc[counts.columns] 61 complex_to_protein_row_ids = complex_helper.map_complex_to_protein_row_ids(complex_composition_filtered, counts_filtered)

NoInteractionsFound: No CellPhoneDB interacions found in this input.

datasome commented 1 year ago

Hi Idiao,

Thank you for using CellphoneDB and your feedback. You are right - it is not an exception to find no interactions. I've just fixed it in master branch. You can get the latest code via: pip install --force-reinstall "git+https://github.com/ventolab/CellphoneDB.git"

Best regards,

Robert.