cell2cell
  • Home
  • API Documentation

cell2cell Tutorials

  • Cell-cell communication from bulk dataset
  • Cell-cell communication from single-cell dataset
    • Data
      • RNA-seq data
      • Protein-Protein Interactions or Ligand-Receptor Pairs
      • Metadata
    • Cell-cell Interactions and Communication Analysis
      • Using an Interaction Pipeline
      • Compute communication scores for each PPI or LR pair
      • Compute CCI scores for each pair of cells
      • Perform permutation analysis
    • Visualizations
      • Visualize communication scores for each LR pair and each cell pair
      • Circos plot
      • Dot plot for significance
      • Visualize CCI scores
      • Dot plot for significance
      • Project samples/cells with PCoA into a Euclidean space

Tensor-cell2cell Tutorials

  • Obtaining patterns of cell-cell communication with Tensor-cell2cell
  • Downstream analysis 1: Factor-specific analyses
  • Downstream analysis 2: Gene Set Enrichment Analysis
  • Inspecting CCC patterns from spatial transcriptomics
  • Running Tensor-cell2cell on your own GPU or on Google Colab's GPU
cell2cell
  • »
  • cell2cell Tutorials »
  • Cell-cell communication from single-cell dataset
  • Edit on GitHub

Cell-cell communication from single-cell dataset¶

In [1]:
Copied!
import cell2cell as c2c
import scanpy as sc
import pandas as pd

%matplotlib inline
import cell2cell as c2c import scanpy as sc import pandas as pd %matplotlib inline
In [2]:
Copied!
import warnings
warnings.filterwarnings('ignore')
import warnings warnings.filterwarnings('ignore')

Data¶

RNA-seq data¶

We begin by loading the single-cell transcriptomics data. For this tutorial, we will use a lung dataset of 63k immune and epithelial cells across three control, three moderate, and six severe COVID-19 patients21. We use a convenient function to download the data and store it in the AnnData format, on which the scanpy package is built.

In [3]:
Copied!
rnaseq = c2c.datasets.balf_covid()
rnaseq = c2c.datasets.balf_covid()
In [4]:
Copied!
rnaseq
rnaseq
Out[4]:
AnnData object with n_obs × n_vars = 63103 × 33538
    obs: 'sample', 'sample_new', 'group', 'disease', 'hasnCoV', 'cluster', 'celltype', 'condition'
In [5]:
Copied!
rnaseq.obs.head()
rnaseq.obs.head()
Out[5]:
sample sample_new group disease hasnCoV cluster celltype condition
AAACCCACAGCTACAT_3 C100 HC3 HC N N 27.0 B Control
AAACCCATCCACGGGT_3 C100 HC3 HC N N 23.0 Macrophages Control
AAACCCATCCCATTCG_3 C100 HC3 HC N N 6.0 T Control
AAACGAACAAACAGGC_3 C100 HC3 HC N N 10.0 Macrophages Control
AAACGAAGTCGCACAC_3 C100 HC3 HC N N 10.0 Macrophages Control

For the purpose of this example, we will inspect only a patient with Severe COVID-19

In [6]:
Copied!
rnaseq = rnaseq[rnaseq.obs.sample_new == 'S1']
rnaseq = rnaseq[rnaseq.obs.sample_new == 'S1']
In [7]:
Copied!
rnaseq
rnaseq
Out[7]:
View of AnnData object with n_obs × n_vars = 11762 × 33538
    obs: 'sample', 'sample_new', 'group', 'disease', 'hasnCoV', 'cluster', 'celltype', 'condition'

Then we do simple preprocessing of the data. For more standard data processing, refer to these best practices.

In [8]:
Copied!
sc.pp.filter_cells(rnaseq, min_genes=200)
sc.pp.filter_genes(rnaseq, min_cells=3)
sc.pp.filter_cells(rnaseq, min_genes=200) sc.pp.filter_genes(rnaseq, min_cells=3)

Protein-Protein Interactions or Ligand-Receptor Pairs¶

In this case, we use a list of LR pairs published with CellChat (Jin et al. 2021, Nature Communications).

In [9]:
Copied!
lr_pairs = pd.read_csv('https://raw.githubusercontent.com/LewisLabUCSD/Ligand-Receptor-Pairs/master/Human/Human-2020-Jin-LR-pairs.csv')
lr_pairs = lr_pairs.astype(str)
lr_pairs = pd.read_csv('https://raw.githubusercontent.com/LewisLabUCSD/Ligand-Receptor-Pairs/master/Human/Human-2020-Jin-LR-pairs.csv') lr_pairs = lr_pairs.astype(str)
In [10]:
Copied!
lr_pairs.head()
lr_pairs.head()
Out[10]:
interaction_name pathway_name ligand receptor agonist antagonist co_A_receptor co_I_receptor evidence annotation interaction_name_2 ligand_symbol receptor_symbol ligand_ensembl receptor_ensembl interaction_symbol interaction_ensembl
0 TGFB1_TGFBR1_TGFBR2 TGFb TGFB1 TGFbR1_R2 TGFb agonist TGFb antagonist nan TGFb inhibition receptor KEGG: hsa04350 Secreted Signaling TGFB1 - (TGFBR1+TGFBR2) TGFB1 TGFBR1&TGFBR2 ENSG00000105329 ENSG00000106799&ENSG00000163513 TGFB1^TGFBR1&TGFBR2 ENSG00000105329^ENSG00000106799&ENSG00000163513
1 TGFB2_TGFBR1_TGFBR2 TGFb TGFB2 TGFbR1_R2 TGFb agonist TGFb antagonist nan TGFb inhibition receptor KEGG: hsa04350 Secreted Signaling TGFB2 - (TGFBR1+TGFBR2) TGFB2 TGFBR1&TGFBR2 ENSG00000092969 ENSG00000106799&ENSG00000163513 TGFB2^TGFBR1&TGFBR2 ENSG00000092969^ENSG00000106799&ENSG00000163513
2 TGFB3_TGFBR1_TGFBR2 TGFb TGFB3 TGFbR1_R2 TGFb agonist TGFb antagonist nan TGFb inhibition receptor KEGG: hsa04350 Secreted Signaling TGFB3 - (TGFBR1+TGFBR2) TGFB3 TGFBR1&TGFBR2 ENSG00000119699 ENSG00000106799&ENSG00000163513 TGFB3^TGFBR1&TGFBR2 ENSG00000119699^ENSG00000106799&ENSG00000163513
3 TGFB1_ACVR1B_TGFBR2 TGFb TGFB1 ACVR1B_TGFbR2 TGFb agonist TGFb antagonist nan TGFb inhibition receptor PMID: 27449815 Secreted Signaling TGFB1 - (ACVR1B+TGFBR2) TGFB1 ACVR1B&TGFBR2 ENSG00000105329 ENSG00000135503&ENSG00000163513 TGFB1^ACVR1B&TGFBR2 ENSG00000105329^ENSG00000135503&ENSG00000163513
4 TGFB1_ACVR1C_TGFBR2 TGFb TGFB1 ACVR1C_TGFbR2 TGFb agonist TGFb antagonist nan TGFb inhibition receptor PMID: 27449815 Secreted Signaling TGFB1 - (ACVR1C+TGFBR2) TGFB1 ACVR1C&TGFBR2 ENSG00000105329 ENSG00000123612&ENSG00000163513 TGFB1^ACVR1C&TGFBR2 ENSG00000105329^ENSG00000123612&ENSG00000163513

 Metadata¶

Metadata for the single cells

In [11]:
Copied!
meta = rnaseq.obs.copy()
meta = rnaseq.obs.copy()
In [12]:
Copied!
meta.head()
meta.head()
Out[12]:
sample sample_new group disease hasnCoV cluster celltype condition n_genes
AAACCTGAGCCCGAAA_9 C145 S1 S Y N 15.0 Neutrophil Severe COVID-19 691
AAACCTGAGCTACCGC_9 C145 S1 S Y N 0.0 Macrophages Severe COVID-19 744
AAACCTGAGGAGTAGA_9 C145 S1 S Y N 4.0 Macrophages Severe COVID-19 2003
AAACCTGAGGCCCGTT_9 C145 S1 S Y N 2.0 Macrophages Severe COVID-19 1702
AAACCTGCAAATCCGT_9 C145 S1 S Y N 3.0 Macrophages Severe COVID-19 1254

Cell-cell Interactions and Communication Analysis¶

Using an Interaction Pipeline¶

The pipeline integrates the RNA-seq and PPI datasets by using the analysis setups. It generates an interaction space containing an instance for each sample/cell type, containing the values assigned to each protein in the PPI list given the setups for computing the CCI and CCC scores.

In this case is single cell data.

In [13]:
Copied!
interactions = c2c.analysis.SingleCellInteractions(rnaseq_data=rnaseq.to_df().T,
                                                   ppi_data=lr_pairs,
                                                   metadata=meta,
                                                   interaction_columns=('ligand_symbol', 'receptor_symbol'),
                                                   communication_score='expression_thresholding',
                                                   expression_threshold=0.1, # values after aggregation
                                                   cci_score='bray_curtis',
                                                   cci_type='undirected',
                                                   aggregation_method='nn_cell_fraction',
                                                   barcode_col='index',
                                                   celltype_col='celltype',
                                                   complex_sep='&',
                                                   verbose=False)
interactions = c2c.analysis.SingleCellInteractions(rnaseq_data=rnaseq.to_df().T, ppi_data=lr_pairs, metadata=meta, interaction_columns=('ligand_symbol', 'receptor_symbol'), communication_score='expression_thresholding', expression_threshold=0.1, # values after aggregation cci_score='bray_curtis', cci_type='undirected', aggregation_method='nn_cell_fraction', barcode_col='index', celltype_col='celltype', complex_sep='&', verbose=False)

Compute communication scores for each PPI or LR pair¶

In [14]:
Copied!
interactions.compute_pairwise_communication_scores()
interactions.compute_pairwise_communication_scores()
Computing pairwise communication
Computing communication score between Epithelial and Epithelial
Computing communication score between T and T
Computing communication score between pDC and B
Computing communication score between NK and B
Computing communication score between Macrophages and B
Computing communication score between Epithelial and T
Computing communication score between Epithelial and pDC
Computing communication score between Mast and T
Computing communication score between NK and Epithelial
Computing communication score between Neutrophil and Neutrophil
Computing communication score between B and pDC
Computing communication score between mDC and pDC
Computing communication score between Macrophages and Epithelial
Computing communication score between B and mDC
Computing communication score between mDC and mDC
Computing communication score between pDC and T
Computing communication score between Plasma and NK
Computing communication score between NK and T
Computing communication score between Mast and Mast
Computing communication score between Macrophages and pDC
Computing communication score between Neutrophil and NK
Computing communication score between Macrophages and mDC
Computing communication score between pDC and Mast
Computing communication score between Neutrophil and Macrophages
Computing communication score between B and B
Computing communication score between mDC and B
Computing communication score between Plasma and pDC
Computing communication score between B and Epithelial
Computing communication score between mDC and Epithelial
Computing communication score between Plasma and mDC
Computing communication score between Mast and Neutrophil
Computing communication score between Neutrophil and pDC
Computing communication score between Neutrophil and mDC
Computing communication score between B and T
Computing communication score between T and Plasma
Computing communication score between mDC and T
Computing communication score between T and Mast
Computing communication score between pDC and Neutrophil
Computing communication score between Epithelial and Plasma
Computing communication score between Mast and NK
Computing communication score between Mast and Plasma
Computing communication score between Epithelial and Mast
Computing communication score between Macrophages and T
Computing communication score between Plasma and B
Computing communication score between Mast and Macrophages
Computing communication score between pDC and Plasma
Computing communication score between NK and Plasma
Computing communication score between NK and Mast
Computing communication score between Neutrophil and B
Computing communication score between Plasma and Epithelial
Computing communication score between pDC and Macrophages
Computing communication score between Macrophages and Mast
Computing communication score between T and Neutrophil
Computing communication score between Neutrophil and Epithelial
Computing communication score between Plasma and T
Computing communication score between Epithelial and Neutrophil
Computing communication score between Mast and mDC
Computing communication score between Neutrophil and T
Computing communication score between B and Neutrophil
Computing communication score between T and NK
Computing communication score between Plasma and Mast
Computing communication score between NK and Neutrophil
Computing communication score between T and Macrophages
Computing communication score between Epithelial and NK
Computing communication score between Macrophages and Neutrophil
Computing communication score between B and Plasma
Computing communication score between mDC and Plasma
Computing communication score between Epithelial and Macrophages
Computing communication score between B and Mast
Computing communication score between mDC and Mast
Computing communication score between Mast and B
Computing communication score between pDC and NK
Computing communication score between NK and NK
Computing communication score between B and Macrophages
Computing communication score between mDC and Macrophages
Computing communication score between Macrophages and NK
Computing communication score between Macrophages and Plasma
Computing communication score between Mast and Epithelial
Computing communication score between T and pDC
Computing communication score between NK and Macrophages
Computing communication score between Plasma and Neutrophil
Computing communication score between T and mDC
Computing communication score between Macrophages and Macrophages
Computing communication score between pDC and Epithelial
Computing communication score between Mast and pDC
Computing communication score between Epithelial and mDC
Computing communication score between mDC and Neutrophil
Computing communication score between pDC and pDC
Computing communication score between NK and pDC
Computing communication score between Plasma and Plasma
Computing communication score between pDC and mDC
Computing communication score between NK and mDC
Computing communication score between Plasma and Macrophages
Computing communication score between Neutrophil and Plasma
Computing communication score between T and B
Computing communication score between Neutrophil and Mast
Computing communication score between B and NK
Computing communication score between mDC and NK
Computing communication score between Epithelial and B
Computing communication score between T and Epithelial

Compute CCI scores for each pair of cells¶

It is computed according to the analysis setups. We computed an undirected Bray-Curtis-like score for each pair, meaning that score(C1, C2) = score(C2, C1). Notice that our score is undirected, so for C1 and C2 was not necessary to compute C2 and C1 as happened for the communication scores

In [15]:
Copied!
interactions.compute_pairwise_cci_scores()
interactions.compute_pairwise_cci_scores()
Computing pairwise interactions
Computing interaction score between B and B
Computing interaction score between Macrophages and Mast
Computing interaction score between Macrophages and Plasma
Computing interaction score between T and pDC
Computing interaction score between Epithelial and Epithelial
Computing interaction score between T and T
Computing interaction score between T and mDC
Computing interaction score between Plasma and pDC
Computing interaction score between Plasma and T
Computing interaction score between Macrophages and Macrophages
Computing interaction score between B and Epithelial
Computing interaction score between Plasma and mDC
Computing interaction score between Epithelial and T
Computing interaction score between Mast and Neutrophil
Computing interaction score between Mast and pDC
Computing interaction score between Epithelial and Neutrophil
Computing interaction score between Epithelial and pDC
Computing interaction score between Mast and T
Computing interaction score between Mast and mDC
Computing interaction score between Neutrophil and pDC
Computing interaction score between Epithelial and mDC
Computing interaction score between Neutrophil and T
Computing interaction score between Neutrophil and Neutrophil
Computing interaction score between B and Neutrophil
Computing interaction score between B and pDC
Computing interaction score between Neutrophil and mDC
Computing interaction score between B and T
Computing interaction score between mDC and pDC
Computing interaction score between B and mDC
Computing interaction score between pDC and pDC
Computing interaction score between mDC and mDC
Computing interaction score between NK and pDC
Computing interaction score between Plasma and Plasma
Computing interaction score between NK and T
Computing interaction score between NK and Neutrophil
Computing interaction score between NK and mDC
Computing interaction score between Epithelial and Plasma
Computing interaction score between Mast and NK
Computing interaction score between Epithelial and NK
Computing interaction score between Mast and Plasma
Computing interaction score between Mast and Mast
Computing interaction score between Epithelial and Mast
Computing interaction score between Macrophages and Neutrophil
Computing interaction score between Macrophages and pDC
Computing interaction score between Neutrophil and Plasma
Computing interaction score between Macrophages and T
Computing interaction score between B and Plasma
Computing interaction score between Macrophages and mDC
Computing interaction score between B and NK
Computing interaction score between Epithelial and Macrophages
Computing interaction score between B and Mast
Computing interaction score between NK and Plasma
Computing interaction score between NK and NK
Computing interaction score between B and Macrophages
Computing interaction score between Macrophages and NK

Perform permutation analysis¶

Just for demonstration, we are performing only 10 permutations here. We recommend using at least 100, ideally 1000. In addition, enable fdr correction with fdr_correction=True.

In [16]:
Copied!
cci_pvals = interactions.permute_cell_labels(evaluation='interactions', 
                                             permutations=10, 
                                             fdr_correction=False,
                                             verbose=True)
cci_pvals = interactions.permute_cell_labels(evaluation='interactions', permutations=10, fdr_correction=False, verbose=True)
100%|███████████████████████████████████████████████████████████████| 10/10 [00:24<00:00,  2.45s/it]
In [17]:
Copied!
cci_pvals
cci_pvals
Out[17]:
B Epithelial Macrophages Mast NK Neutrophil Plasma T mDC pDC
B 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818
Epithelial 0.181818 0.363636 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818
Macrophages 0.181818 0.181818 0.090909 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818
Mast 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818
NK 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818
Neutrophil 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818
Plasma 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818
T 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818
mDC 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818
pDC 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.181818 0.363636
In [18]:
Copied!
ccc_pvals = interactions.permute_cell_labels(evaluation='communication',
                                             permutations=10, 
                                             fdr_correction=False,
                                             verbose=True)
ccc_pvals = interactions.permute_cell_labels(evaluation='communication', permutations=10, fdr_correction=False, verbose=True)
100%|███████████████████████████████████████████████████████████████| 10/10 [00:25<00:00,  2.52s/it]
In [19]:
Copied!
ccc_pvals
ccc_pvals
Out[19]:
Epithelial;Epithelial T;T pDC;B NK;B Macrophages;B Epithelial;T Epithelial;pDC Mast;T NK;Epithelial Neutrophil;Neutrophil ... pDC;mDC NK;mDC Plasma;Macrophages Neutrophil;Plasma T;B Neutrophil;Mast B;NK mDC;NK Epithelial;B T;Epithelial
(TGFB1, TGFBR1&TGFBR2) 1.000000 0.909091 0.181818 0.181818 0.181818 0.909091 0.909091 0.909091 1.000000 0.909091 ... 0.090909 0.090909 0.909091 0.909091 0.181818 0.181818 0.909091 0.909091 0.181818 1.000000
(TGFB2, TGFBR1&TGFBR2) 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 ... 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091
(TGFB3, TGFBR1&TGFBR2) 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 ... 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091
(TGFB1, ACVR1B&TGFBR2) 0.090909 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.090909 0.909091 ... 0.909091 0.909091 0.909091 0.909091 0.909091 0.363636 0.909091 0.909091 0.909091 0.090909
(TGFB1, ACVR1C&TGFBR2) 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 ... 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
(SIGLEC1, SPN) 0.909091 0.909091 0.909091 0.909091 0.909091 0.090909 0.090909 0.909091 0.909091 0.909091 ... 0.090909 0.909091 0.909091 0.909091 0.909091 0.727273 0.909091 0.090909 0.909091 0.909091
(ITGA4&ITGB1, VCAM1) 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 ... 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091
(ITGA9&ITGB1, VCAM1) 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 ... 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091
(ITGA4&ITGB7, VCAM1) 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 ... 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091
(VSIR, IGSF11) 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 ... 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091 0.909091

1006 rows × 100 columns

Visualizations¶

If we want to save the figure as a vector figure, we can pass a filename input to each plot function to save the figure. E.g. filename='/Users/cell2cell/CommScores.svg'

Generate a metadata for the cell types

In [20]:
Copied!
meta.celltype.unique()
meta.celltype.unique()
Out[20]:
['Neutrophil', 'Macrophages', 'T', 'NK', 'Mast', 'pDC', 'mDC', 'Epithelial', 'Plasma', 'B']
Categories (10, object): ['B', 'Epithelial', 'Macrophages', 'Mast', ..., 'Plasma', 'T', 'mDC', 'pDC']
In [21]:
Copied!
group_meta = pd.DataFrame(columns=['Celltype', 'Group'])
group_meta['Celltype'] = meta.celltype.unique().tolist()
group_meta['Group'] = ['Myeloid', 'Myeloid', 'Lymphoid', 'Lymphoid', 'Myeloid', 'Myeloid', 'Myeloid', 'Epithelial',
                       'Lymphoid', 'Lymphoid']
group_meta = pd.DataFrame(columns=['Celltype', 'Group']) group_meta['Celltype'] = meta.celltype.unique().tolist() group_meta['Group'] = ['Myeloid', 'Myeloid', 'Lymphoid', 'Lymphoid', 'Myeloid', 'Myeloid', 'Myeloid', 'Epithelial', 'Lymphoid', 'Lymphoid']
In [22]:
Copied!
group_meta
group_meta
Out[22]:
Celltype Group
0 Neutrophil Myeloid
1 Macrophages Myeloid
2 T Lymphoid
3 NK Lymphoid
4 Mast Myeloid
5 pDC Myeloid
6 mDC Myeloid
7 Epithelial Epithelial
8 Plasma Lymphoid
9 B Lymphoid

Generate colors for the groups in the metadata

It returns a dictionary with the colors.

In [23]:
Copied!
colors = c2c.plotting.get_colors_from_labels(labels=group_meta['Group'].unique().tolist(),
                                             cmap='tab10'
                                            )
colors = c2c.plotting.get_colors_from_labels(labels=group_meta['Group'].unique().tolist(), cmap='tab10' )

Visualize communication scores for each LR pair and each cell pair¶

In [24]:
Copied!
interaction_clustermap = c2c.plotting.clustermap_ccc(interactions,
                                                     metric='jaccard',
                                                     method='complete',
                                                     metadata=group_meta,
                                                     sample_col='Celltype',
                                                     group_col='Group',
                                                     colors=colors,
                                                     row_fontsize=14,
                                                     title='Active ligand-receptor pairs for interacting cells',
                                                     filename=None,
                                                     cell_labels=('SENDER-CELLS', 'RECEIVER-CELLS'),
                                                     **{'figsize' : (10,9),
                                                       }
                                                     )

# Add a legend to know the groups of the sender and receiver cells:
l1 = c2c.plotting.generate_legend(color_dict=colors,
                                  loc='center left',
                                  bbox_to_anchor=(20, -2), # Indicated where to include it
                                  ncol=1, fancybox=True,
                                  shadow=True,
                                  title='Groups',
                                  fontsize=14,
                                 )
interaction_clustermap = c2c.plotting.clustermap_ccc(interactions, metric='jaccard', method='complete', metadata=group_meta, sample_col='Celltype', group_col='Group', colors=colors, row_fontsize=14, title='Active ligand-receptor pairs for interacting cells', filename=None, cell_labels=('SENDER-CELLS', 'RECEIVER-CELLS'), **{'figsize' : (10,9), } ) # Add a legend to know the groups of the sender and receiver cells: l1 = c2c.plotting.generate_legend(color_dict=colors, loc='center left', bbox_to_anchor=(20, -2), # Indicated where to include it ncol=1, fancybox=True, shadow=True, title='Groups', fontsize=14, )
Interaction space detected as an InteractionSpace class

 Circos plot¶

It generates a circos plot, showing the cells producing ligands (sender_cells), according to a list of specific ligands (ligands) to the cells producing receptors (receiver_cells), according to a list of specific receptors (receptors). The order of these lists is preserved in the visualization. Elements that are not used are omitted and therefore not plotted (in this case those with a communication score of 0, specified in 'excluded_score').

In [25]:
Copied!
sender_cells = ['Epithelial', 'pDC', 'mDC']
receiver_cells = ['Neutrophil', 'NK', 'T', 'B', 'Macrophages']
ligands = ['CCL5',
           'MIF',
           'LAMB2'
          ]
receptors = ['NCL',
             'CD74&CD44',
             'CCR1',
            ]
sender_cells = ['Epithelial', 'pDC', 'mDC'] receiver_cells = ['Neutrophil', 'NK', 'T', 'B', 'Macrophages'] ligands = ['CCL5', 'MIF', 'LAMB2' ] receptors = ['NCL', 'CD74&CD44', 'CCR1', ]
In [26]:
Copied!
c2c.plotting.circos_plot(interaction_space=interactions,
                         sender_cells=sender_cells,
                         receiver_cells=receiver_cells,
                         ligands=ligands,
                         receptors=receptors,
                         excluded_score=0,
                         metadata=group_meta,
                         sample_col='Celltype',
                         group_col='Group',
                         colors=colors,
                         fontsize=15,
                        )
c2c.plotting.circos_plot(interaction_space=interactions, sender_cells=sender_cells, receiver_cells=receiver_cells, ligands=ligands, receptors=receptors, excluded_score=0, metadata=group_meta, sample_col='Celltype', group_col='Group', colors=colors, fontsize=15, )
Out[26]:
<Axes: >

If we do not pass metadata info, the samples/cell types are only plotted.

We can also change the label colors of ligands and receptors

In [27]:
Copied!
c2c.plotting.circos_plot(interaction_space=interactions,
                         sender_cells=sender_cells,
                         receiver_cells=receiver_cells,
                         ligands=ligands,
                         receptors=receptors,
                         excluded_score=0,
                         fontsize=20,
                         ligand_label_color='orange',
                         receptor_label_color='brown',
                        )
c2c.plotting.circos_plot(interaction_space=interactions, sender_cells=sender_cells, receiver_cells=receiver_cells, ligands=ligands, receptors=receptors, excluded_score=0, fontsize=20, ligand_label_color='orange', receptor_label_color='brown', )
Out[27]:
<Axes: >

Dot plot for significance¶

In [28]:
Copied!
fig = c2c.plotting.dot_plot(interactions,
                            evaluation='communication',
                            significance = 0.2,
                            figsize=(9, 16),
                            cmap='PuOr',
                            senders=sender_cells,
                            receivers=receiver_cells,
                            tick_size=8
                            )
fig = c2c.plotting.dot_plot(interactions, evaluation='communication', significance = 0.2, figsize=(9, 16), cmap='PuOr', senders=sender_cells, receivers=receiver_cells, tick_size=8 )

Visualize CCI scores¶

Since this case is undirected, a triangular heatmap is plotted instead of the complete one.

In [29]:
Copied!
cm = c2c.plotting.clustermap_cci(interactions,
                                 method='complete',
                                 metadata=group_meta,
                                 sample_col="Celltype",
                                 group_col="Group",
                                 colors=colors,
                                 title='CCI scores for cell-types',
                                 cmap='Blues'
                                 )

# Add a legend to know the groups of the sender and receiver cells:
l1 = c2c.plotting.generate_legend(color_dict=colors,
                                  loc='center left',
                                  bbox_to_anchor=(20, -2), # Indicated where to include it
                                  ncol=1, fancybox=True,
                                  shadow=True,
                                  title='Groups',
                                  fontsize=14,
                                 )
cm = c2c.plotting.clustermap_cci(interactions, method='complete', metadata=group_meta, sample_col="Celltype", group_col="Group", colors=colors, title='CCI scores for cell-types', cmap='Blues' ) # Add a legend to know the groups of the sender and receiver cells: l1 = c2c.plotting.generate_legend(color_dict=colors, loc='center left', bbox_to_anchor=(20, -2), # Indicated where to include it ncol=1, fancybox=True, shadow=True, title='Groups', fontsize=14, )
Interaction space detected as a Interactions class

Dot plot for significance¶

In [30]:
Copied!
fig = c2c.plotting.dot_plot(interactions,
                            evaluation='interactions',
                            significance = 0.2,
                            figsize=(16, 9),
                            cmap='Blues',
                            )
fig = c2c.plotting.dot_plot(interactions, evaluation='interactions', significance = 0.2, figsize=(16, 9), cmap='Blues', )

Project samples/cells with PCoA into a Euclidean space¶

We can project the samples/cells given their CCI scores with other cells and see how close they are given their potential of interaction.

THIS ONLY WORKS WITH UNDIRECTED CCI SCORES

In [31]:
Copied!
if interactions.analysis_setup['cci_type'] == 'undirected':
        
    pcoa = c2c.plotting.pcoa_3dplot(interactions,
                                    metadata=group_meta,
                                    sample_col="Celltype",
                                    group_col="Group",
                                    title='PCoA based on potential CCIs',
                                    colors=colors,
                                    )
if interactions.analysis_setup['cci_type'] == 'undirected': pcoa = c2c.plotting.pcoa_3dplot(interactions, metadata=group_meta, sample_col="Celltype", group_col="Group", title='PCoA based on potential CCIs', colors=colors, )
Interaction space detected as a Interactions class

Without metadata

In [32]:
Copied!
if interactions.analysis_setup['cci_type'] == 'undirected':
    celltype_colors = c2c.plotting.get_colors_from_labels(labels=meta['celltype'].unique().tolist(),
                                                          cmap='tab10'
                                                         )    
    pcoa = c2c.plotting.pcoa_3dplot(interactions,
                                    title='PCoA based on potential CCIs',
                                    colors=celltype_colors,
                                    )
if interactions.analysis_setup['cci_type'] == 'undirected': celltype_colors = c2c.plotting.get_colors_from_labels(labels=meta['celltype'].unique().tolist(), cmap='tab10' ) pcoa = c2c.plotting.pcoa_3dplot(interactions, title='PCoA based on potential CCIs', colors=celltype_colors, )
Interaction space detected as a Interactions class
In [ ]:
Copied!

Previous Next

Built with MkDocs using a theme provided by Read the Docs.
GitHub « Previous Next »