Bug Description
When running cpdb_statistical_analysis_method.call() with score_interactions=True, a KeyError is raised because some interaction pairs in interaction_scores['interacting_pair'] are not found in the interacting_pair2score dictionary.
Error Location
File: cellphonedb/utils/scoring_utils.py, line 293:
interaction_scores[ct_pair] = [interacting_pair2score[id] for id in interaction_scores['interacting_pair']]
Error Message
KeyError: 'BMP8A_ACVR_1A2B_receptor'
Steps to Reproduce
- Load a human spatial transcriptomics dataset (e.g., 10x Visium human lymph node)
- Run CellPhoneDB v5 statistical analysis with
score_interactions=True
from cellphonedb.src.core.methods import cpdb_statistical_analysis_method
result = cpdb_statistical_analysis_method.call(
cpdb_file_path=db_path,
meta_file_path=meta_file,
counts_file_path=counts_file,
counts_data='hgnc_symbol',
threshold=0.1,
iterations=100,
output_path=output_dir,
score_interactions=True, # This causes the error
)
Expected Behavior
The scoring should handle missing interactions gracefully, either by:
- Skipping interactions not found in the scoring matrix
- Assigning a default score (e.g., 0 or NaN)
Workaround
Setting score_interactions=False avoids the error, but disables the interaction scoring feature.
Environment
- CellPhoneDB version: 5.0.0
- Python version: 3.10
- OS: macOS
Additional Context
This bug was discovered while integrating CellPhoneDB into ChatSpatial, an MCP server for spatial transcriptomics analysis.
Bug Description
When running
cpdb_statistical_analysis_method.call()withscore_interactions=True, aKeyErroris raised because some interaction pairs ininteraction_scores['interacting_pair']are not found in theinteracting_pair2scoredictionary.Error Location
File:
cellphonedb/utils/scoring_utils.py, line 293:Error Message
Steps to Reproduce
score_interactions=TrueExpected Behavior
The scoring should handle missing interactions gracefully, either by:
Workaround
Setting
score_interactions=Falseavoids the error, but disables the interaction scoring feature.Environment
Additional Context
This bug was discovered while integrating CellPhoneDB into ChatSpatial, an MCP server for spatial transcriptomics analysis.