single-cell-cellphonedb-communication-mapping
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSingle-cell CellPhoneDB communication mapping
单细胞CellPhoneDB通讯图谱绘制
Overview
概述
Apply this skill when a user wants to quantify ligand–receptor communication between annotated single-cell populations and display the networks with . It distils the workflow from , which analyses EVT trophoblast data.
CellChatVizt_cellphonedb.ipynb当用户想要量化带注释的单细胞群体之间的配体-受体通讯,并使用展示网络时,可应用此技能。它提炼自中的工作流,该教程分析了EVT滋养层细胞数据。
CellChatVizt_cellphonedb.ipynbInstructions
操作步骤
- Prepare the environment
- Use an environment with ,
omicverse>=0.2,scanpy,anndata,pandas, andmatplotlibresources. The tutorial assumes the pre-built CellPhoneDB v5 SQLite bundle downloaded ascellphonedbin the working directory.cellphonedb.zip - Activate omicverse plotting defaults via so that downstream figures follow the project palette.
ov.plot_set()
- Use an environment with
- Load and subset the annotated AnnData object
- Read the normalised counts with .
adata = ov.read('data/cpdb/normalised_log_counts.h5ad') - Filter to the cell populations of interest using (e.g., EVT, dNK, VCT). Ensure
adata.obs['cell_labels']is categorical and free of missing values so CellPhoneDB groups cells correctly.adata.obs['cell_labels'] - Confirm values are log-normalised (should be <10 and non-integer); raw counts inflate CellPhoneDB permutations.
adata.X.max()
- Read the normalised counts with
- Run CellPhoneDB via omicverse
- Execute with the curated AnnData and metadata column:
ov.single.run_cellphonedb_v5pythoncpdb_results, adata_cpdb = ov.single.run_cellphonedb_v5( adata, cpdb_file_path='./cellphonedb.zip', celltype_key='cell_labels', min_cell_fraction=0.005, min_genes=200, min_cells=3, iterations=1000, threshold=0.1, pvalue=0.05, threads=10, output_dir='./cpdb_results', cleanup_temp=True, ) - Persist the outputs for reuse (,
ov.utils.save(cpdb_results, ...)). Saving avoids recomputing permutations.adata_cpdb.write(...)
- Execute
- Initialise CellChat-style visualisation
- Create a colour dictionary that maps ordered categories to
cell_labelsfrom previous plots.adata.uns['cell_labels_colors'] - Instantiate the viewer: . Inspect
viz = ov.pl.CellChatViz(adata_cpdb, palette=color_dict)to ensure communication slots (adata_cpdb/uns) were populated.obsm
- Create a colour dictionary that maps ordered
- Summarise global communication
- Derive aggregated counts/weights with .
viz.compute_aggregated_network(pvalue_threshold=0.05, use_means=True) - Plot overall interaction strength and counts using with matching figure sizes and colormaps.
viz.netVisual_circle(...) - Generate outgoing/incoming per-celltype circles using and
viz.netVisual_individual_circleto highlight senders versus receivers.viz.netVisual_individual_circle_incoming
- Derive aggregated counts/weights with
- Interrogate specific pathways
- Compute pathway summaries: .
pathway_comm = viz.compute_pathway_communication(method='mean', min_lr_pairs=2, min_expression=0.1) - Identify significant signalling routes with , then plot selected pathways using
viz.get_significant_pathways_v2(...),viz.netVisual_aggregate(..., layout='circle'), orviz.netVisual_chord_cell(...).viz.netVisual_heatmap_marsilea(...) - For ligand–receptor focus, call or
viz.netVisual_chord_LR(...)to surface dominant pairs.viz.netAnalysis_contribution(pathway)
- Compute pathway summaries:
- System-level visualisations
- Compose bubble summaries for multiple pathways with , optionally restricting
viz.netVisual_bubble_marsilea(...)/sources_use.targets_use - Display gene-level chords via to inspect signalling directionality.
viz.netVisual_chord_gene(...) - Evaluate signalling roles using ,
viz.netAnalysis_computeCentrality(),viz.netAnalysis_signalingRole_network_marsilea(...), andviz.netAnalysis_signalingRole_scatter(...)for incoming/outgoing programmes.viz.netAnalysis_signalingRole_heatmap(...)
- Compose bubble summaries for multiple pathways with
- Troubleshooting tips
- Metadata alignment: CellPhoneDB requires a categorical . If the column contains spaces, mixed casing, or
celltype_key, clean it (NaN).adata.obs['cell_labels'] = adata.obs['cell_labels'].astype('category').cat.remove_unused_categories() - Database bundle: must point to a full CellPhoneDB v5 SQLite zip. If omicverse raises
cpdb_file_pathor missing receptor tables, re-download the bundle from the official release and ensure the zip is not corrupted.FileNotFoundError - Permutation failures: Low cell counts per group (<) cause early termination. Increase
min_cellsthresholds or merge sparse clusters before rerunning.min_cell_fraction - Palette mismatches: When colours render incorrectly, rebuild from
color_dictafter sorting categories to keep nodes and legends consistent.adata.uns['cell_labels_colors']
- Metadata alignment: CellPhoneDB requires a categorical
- 准备环境
- 使用包含、
omicverse>=0.2、scanpy、anndata、pandas以及matplotlib资源的环境。本教程假设预构建的CellPhoneDB v5 SQLite包已下载到工作目录,命名为cellphonedb。cellphonedb.zip - 通过激活omicverse的绘图默认设置,以便后续图表遵循项目配色方案。
ov.plot_set()
- 使用包含
- 加载并筛选带注释的AnnData对象
- 使用读取归一化后的计数数据。
adata = ov.read('data/cpdb/normalised_log_counts.h5ad') - 利用筛选出感兴趣的细胞群体(例如EVT、dNK、VCT)。确保
adata.obs['cell_labels']为分类类型且无缺失值,以便CellPhoneDB正确分组细胞。adata.obs['cell_labels'] - 确认数据为对数归一化(应小于10且为非整数);原始计数会导致CellPhoneDB的置换分析结果失真。
adata.X.max()
- 使用
- 通过omicverse运行CellPhoneDB
- 使用整理好的AnnData和元数据列执行:
ov.single.run_cellphonedb_v5pythoncpdb_results, adata_cpdb = ov.single.run_cellphonedb_v5( adata, cpdb_file_path='./cellphonedb.zip', celltype_key='cell_labels', min_cell_fraction=0.005, min_genes=200, min_cells=3, iterations=1000, threshold=0.1, pvalue=0.05, threads=10, output_dir='./cpdb_results', cleanup_temp=True, ) - 保存输出结果以便复用(、
ov.utils.save(cpdb_results, ...))。保存操作可避免重复计算置换分析。adata_cpdb.write(...)
- 使用整理好的AnnData和元数据列执行
- 初始化CellChat风格的可视化
- 创建一个颜色字典,将排序后的分类映射到之前绘图中
cell_labels的颜色值。adata.uns['cell_labels_colors'] - 实例化查看器:。检查
viz = ov.pl.CellChatViz(adata_cpdb, palette=color_dict)以确保通讯相关的存储槽(adata_cpdb/uns)已填充数据。obsm
- 创建一个颜色字典,将排序后的
- 汇总全局通讯情况
- 使用生成汇总计数/权重。
viz.compute_aggregated_network(pvalue_threshold=0.05, use_means=True) - 使用绘制整体相互作用强度和计数,匹配合适的图幅大小和颜色映射。
viz.netVisual_circle(...) - 使用和
viz.netVisual_individual_circle生成每个细胞类型的 outgoing/incoming 环形图,以突出发送方和接收方。viz.netVisual_individual_circle_incoming
- 使用
- 探究特定通路
- 计算通路汇总信息:。
pathway_comm = viz.compute_pathway_communication(method='mean', min_lr_pairs=2, min_expression=0.1) - 使用识别显著的信号通路,然后使用
viz.get_significant_pathways_v2(...)、viz.netVisual_aggregate(..., layout='circle')或viz.netVisual_chord_cell(...)绘制选定通路。viz.netVisual_heatmap_marsilea(...) - 若聚焦配体-受体对,可调用或
viz.netVisual_chord_LR(...)来找出主导配对。viz.netAnalysis_contribution(pathway)
- 计算通路汇总信息:
- 系统级可视化
- 使用生成多个通路的气泡汇总图,可选择性限制
viz.netVisual_bubble_marsilea(...)/sources_use。targets_use - 通过展示基因层面的弦图,以检查信号传导方向。
viz.netVisual_chord_gene(...) - 使用、
viz.netAnalysis_computeCentrality()、viz.netAnalysis_signalingRole_network_marsilea(...)和viz.netAnalysis_signalingRole_scatter(...)评估信号传导角色,分析 outgoing/incoming 程序。viz.netAnalysis_signalingRole_heatmap(...)
- 使用
- 故障排除提示
- 元数据对齐:CellPhoneDB要求为分类类型。若该列包含空格、大小写混合或
celltype_key,请清理数据(NaN)。adata.obs['cell_labels'] = adata.obs['cell_labels'].astype('category').cat.remove_unused_categories() - 数据库包:必须指向完整的CellPhoneDB v5 SQLite压缩包。若omicverse抛出
cpdb_file_path或提示缺失受体表,请从官方发布渠道重新下载压缩包并确保其未损坏。FileNotFoundError - 置换分析失败:每组细胞数量过少(小于)会导致提前终止。可提高
min_cells阈值,或在重新运行前合并稀疏集群。min_cell_fraction - 配色不匹配:若颜色渲染错误,请在排序分类后重新从构建
adata.uns['cell_labels_colors'],以保持节点和图例的一致性。color_dict
- 元数据对齐:CellPhoneDB要求
Examples
示例
- "Run CellPhoneDB on our trophoblast dataset and export both the cpdb results pickle and processed AnnData."
- "Highlight significant 'Signaling by Fibroblast growth factor' interactions with chord and bubble plots."
- "Generate outgoing versus incoming communication circles to compare dNK subsets."
- "在我们的滋养层数据集上运行CellPhoneDB,并导出cpdb结果的pickle文件和处理后的AnnData。"
- "用弦图和气泡图突出显示显著的‘成纤维细胞生长因子信号传导’相互作用。"
- "生成 outgoing 与 incoming 通讯环形图,以比较dNK亚群。"
References
参考资料
- Tutorial notebook:
t_cellphonedb.ipynb - Example data:
omicverse_guide/docs/Tutorials-single/data/cpdb/ - Quick copy/paste commands:
reference.md
- 教程笔记本:
t_cellphonedb.ipynb - 示例数据:
omicverse_guide/docs/Tutorials-single/data/cpdb/ - 快速复制命令:
reference.md