{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Comparative Cell-Cell Communication with LIANA+ and CrossTalkeR" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Background\n", "\n", "[CrossTalkeR](https://academic.oup.com/bioinformatics/article/37/22/4263/6275746) ([Nagai et al., 2021](https://academic.oup.com/bioinformatics/article/37/22/4263/6275746)) represents cell-cell communication as a directed graph: nodes are cell types and edges are the ligand-receptor signals sent between them. By scoring each node's importance in this graph (e.g. via PageRank) and **comparing those scores between two conditions**, it highlights the cell types whose communication patterns change the most — i.e. the candidate condition-driving cell types and their ligand-receptor interactions.\n", "\n", "`pyCrossTalkeR` is the Python implementation of CrossTalkeR. In addition to the graph rankings, it tests which interactions differ significantly between conditions using two complementary features: the **number** of interactions (proportion / Fisher test) and their **strength** (expression / Mann-Whitney test).\n", "\n", "In this notebook we take ligand-receptor scores inferred per condition with `liana`, hand them to `pyCrossTalkeR`, and walk through the comparative graph, ranking, and statistical views to read out how IFN-β stimulation reshapes PBMC communication." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Load Packages" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Install required packages via pip with the following command:\n", "\n", "```python\n", "pip install pycrosstalker\n", "```" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2026-10-31T12:37:21.544087Z", "iopub.status.busy": "2026-10-31T12:37:21.541931Z", "iopub.status.idle": "2026-10-31T12:37:26.194527Z", "shell.execute_reply": "2026-10-31T12:37:26.193896Z" } }, "outputs": [], "source": [ "import pandas as pd\n", "import scanpy as sc\n", "import plotnine as p9\n", "import liana as li\n", "import warnings\n", "warnings.filterwarnings('ignore')\n", "from collections import defaultdict\n", "from pycrosstalker import tools as cttl\n", "from pycrosstalker import plots as ctpl\n", "%matplotlib inline\n", "from scipy.stats import gmean\n", "import os\n", "sc.logging.print_header()\n", "\n", "# embed inline figures as JPEG (not the 2x 'retina' PNG default) to keep the notebook small\n", "sc.set_figure_params(ipython_format='jpeg')\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Load & Prep Data " ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ " As a simple example, we will look at ~25k PBMCs from 8 pooled patient lupus samples, each before and after IFN-beta stimulation ([Kang et al., 2018](https://www.nature.com/articles/nbt.4042); [GSE96583](https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE96583)). Note that by focusing on PBMCs, for the purpose of this tutorial, we assume that coordinated events occur among them.\n", "\n", "This dataset is downloaded from a link on Figshare; preprocessed for [pertpy](https://github.com/theislab/pertpy)." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2026-10-31T12:37:26.198568Z", "iopub.status.busy": "2026-10-31T12:37:26.197747Z", "iopub.status.idle": "2026-10-31T12:37:26.879838Z", "shell.execute_reply": "2026-10-31T12:37:26.878936Z" } }, "outputs": [], "source": [ "# load data as from CCC chapter\n", "adata = li.ds.kang_2018()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Showcase anndata object" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2026-10-31T12:37:26.887376Z", "iopub.status.busy": "2026-10-31T12:37:26.885741Z", "iopub.status.idle": "2026-10-31T12:37:26.906969Z", "shell.execute_reply": "2026-10-31T12:37:26.904837Z" } }, "outputs": [ { "data": { "text/html": [ "
| \n", " | nCount_RNA | \n", "nFeature_RNA | \n", "tsne1 | \n", "tsne2 | \n", "condition | \n", "cluster | \n", "cell_type | \n", "patient | \n", "nCount_SCT | \n", "nFeature_SCT | \n", "integrated_snn_res.0.4 | \n", "seurat_clusters | \n", "sample | \n", "cell_abbr | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| index | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
| AAACATACATTTCC-1 | \n", "3017.0 | \n", "877 | \n", "-27.640373 | \n", "14.966629 | \n", "ctrl | \n", "9 | \n", "CD14+ Monocytes | \n", "patient_1016 | \n", "1704.0 | \n", "711 | \n", "1 | \n", "1 | \n", "ctrl&1016 | \n", "CD14 | \n", "
| AAACATACCAGAAA-1 | \n", "2481.0 | \n", "713 | \n", "-27.493646 | \n", "28.924885 | \n", "ctrl | \n", "9 | \n", "CD14+ Monocytes | \n", "patient_1256 | \n", "1614.0 | \n", "662 | \n", "1 | \n", "1 | \n", "ctrl&1256 | \n", "CD14 | \n", "
| AAACATACCATGCA-1 | \n", "703.0 | \n", "337 | \n", "-10.468194 | \n", "-5.984389 | \n", "ctrl | \n", "3 | \n", "CD4 T cells | \n", "patient_1488 | \n", "908.0 | \n", "337 | \n", "6 | \n", "6 | \n", "ctrl&1488 | \n", "CD4T | \n", "
| AAACATACCTCGCT-1 | \n", "3420.0 | \n", "850 | \n", "-24.367997 | \n", "20.429285 | \n", "ctrl | \n", "9 | \n", "CD14+ Monocytes | \n", "patient_1256 | \n", "1738.0 | \n", "653 | \n", "1 | \n", "1 | \n", "ctrl&1256 | \n", "CD14 | \n", "
| AAACATACCTGGTA-1 | \n", "3158.0 | \n", "1111 | \n", "27.952170 | \n", "24.159738 | \n", "ctrl | \n", "4 | \n", "Dendritic cells | \n", "patient_1039 | \n", "1857.0 | \n", "928 | \n", "12 | \n", "12 | \n", "ctrl&1039 | \n", "DCs | \n", "
| \n", " | condition | \n", "ligand | \n", "ligand_cdf | \n", "ligand_complex | \n", "ligand_means | \n", "ligand_props | \n", "receptor | \n", "receptor_cdf | \n", "receptor_complex | \n", "receptor_means | \n", "receptor_props | \n", "source | \n", "target | \n", "inter_score | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "ctrl | \n", "HLA-B | \n", "1.000000 | \n", "HLA-B | \n", "2.031854 | \n", "0.984712 | \n", "CD3D | \n", "1.000000 | \n", "CD3D | \n", "0.622439 | \n", "0.608993 | \n", "CD4 T cells | \n", "CD4 T cells | \n", "1.000000 | \n", "
| 1 | \n", "ctrl | \n", "HLA-B | \n", "1.000000 | \n", "HLA-B | \n", "2.031854 | \n", "0.984712 | \n", "KLRD1 | \n", "1.000000 | \n", "KLRD1 | \n", "0.333456 | \n", "0.332922 | \n", "CD4 T cells | \n", "CD8 T cells | \n", "1.000000 | \n", "
| 2 | \n", "ctrl | \n", "HLA-C | \n", "1.000000 | \n", "HLA-C | \n", "1.384611 | \n", "0.912950 | \n", "CD8B | \n", "1.000000 | \n", "CD8B | \n", "0.262738 | \n", "0.255240 | \n", "CD4 T cells | \n", "CD8 T cells | \n", "1.000000 | \n", "
| 3 | \n", "ctrl | \n", "HLA-C | \n", "1.000000 | \n", "HLA-C | \n", "1.384611 | \n", "0.912950 | \n", "CD8A | \n", "1.000000 | \n", "CD8A | \n", "0.388470 | \n", "0.371147 | \n", "CD4 T cells | \n", "CD8 T cells | \n", "1.000000 | \n", "
| 4 | \n", "ctrl | \n", "CD48 | \n", "1.000000 | \n", "CD48 | \n", "0.127942 | \n", "0.164388 | \n", "CD2 | \n", "1.000000 | \n", "CD2 | \n", "0.765779 | \n", "0.621455 | \n", "CD4 T cells | \n", "CD8 T cells | \n", "1.000000 | \n", "
| ... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
| 3874 | \n", "stim | \n", "CD47 | \n", "0.911753 | \n", "CD47 | \n", "0.066570 | \n", "0.166667 | \n", "SIRPA | \n", "0.327294 | \n", "SIRPA | \n", "0.031316 | \n", "0.110701 | \n", "Megakaryocytes | \n", "Dendritic cells | \n", "0.327294 | \n", "
| 3875 | \n", "stim | \n", "CD47 | \n", "1.000000 | \n", "CD47 | \n", "0.213795 | \n", "0.272807 | \n", "SIRPA | \n", "0.327294 | \n", "SIRPA | \n", "0.031316 | \n", "0.110701 | \n", "CD4 T cells | \n", "Dendritic cells | \n", "0.327294 | \n", "
| 3876 | \n", "stim | \n", "SIRPA | \n", "0.327294 | \n", "SIRPA | \n", "0.031316 | \n", "0.110701 | \n", "CD47 | \n", "1.000000 | \n", "CD47 | \n", "0.447850 | \n", "0.645570 | \n", "Dendritic cells | \n", "CD14+ Monocytes | \n", "0.327294 | \n", "
| 3877 | \n", "stim | \n", "CD47 | \n", "1.000000 | \n", "CD47 | \n", "0.258852 | \n", "0.288889 | \n", "SIRPA | \n", "0.327294 | \n", "SIRPA | \n", "0.031316 | \n", "0.110701 | \n", "CD8 T cells | \n", "Dendritic cells | \n", "0.327294 | \n", "
| 3878 | \n", "stim | \n", "CD47 | \n", "1.000000 | \n", "CD47 | \n", "0.408296 | \n", "0.483146 | \n", "SIRPA | \n", "0.327294 | \n", "SIRPA | \n", "0.031316 | \n", "0.110701 | \n", "B cells | \n", "Dendritic cells | \n", "0.327294 | \n", "
3879 rows × 14 columns
\n", "