{ "cells": [ { "cell_type": "markdown", "id": "25be46ae", "metadata": {}, "source": [ ".. note::\n", " To download the tutorial data, use the following commands:\n", "\n", " **All tutorial data:**\n", " ```python\n", " from recon.data import fetch_all_tutorial_data\n", " fetch_all_tutorial_data(data_dir='./data')\n", " ```\n", "\n", " **Specific file (e.g., RNA data):**\n", " ```python\n", " from recon.data import fetch_tutorial_data\n", " fetch_tutorial_data('perturbation_tuto/rna.h5ad', data_dir='./data')\n", " ```" ] }, { "cell_type": "markdown", "id": "6c7bd3a8", "metadata": {}, "source": [ "# Visualizing Molecular Cascades with Sankey Diagrams\n", "\n", "This tutorial demonstrates how to use ReCoN's Sankey diagram functions to visualize molecular cascades across cell types. These visualizations help understand how signals propagate from ligands through receptors, transcription factors (TFs), and target genes.\n", "\n", "**What you will learn:**\n", "- How to create intracellular cascades (Receptor → TF → Gene)\n", "- How to visualize ligand-receptor signaling (Ligand → Receptor → TF → Gene)\n", "- How to display full intercellular cascades with upstream regulators" ] }, { "cell_type": "markdown", "id": "5b5f4c59", "metadata": {}, "source": [ "## Setup" ] }, { "cell_type": "code", "execution_count": 1, "id": "c68cf60b", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import scanpy as sc # single cell data\n", "import pandas as pd # data manipulation\n", "import liana as li # cell communication\n", "import recon # multilayer and perturbation prediction\n", "import recon.data\n", "import recon.explore\n", "import recon.plot.sankey_paths" ] }, { "cell_type": "code", "execution_count": 2, "id": "f4e39c89", "metadata": {}, "outputs": [], "source": [ "# Load example scRNA-seq data\n", "rna = sc.read_h5ad(\"./data/perturbation_tuto/rna.h5ad\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "22d5af63", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['B_cell',\n", " 'ILC',\n", " 'Macrophage',\n", " 'MigDC',\n", " 'Monocyte',\n", " 'NK_cell',\n", " 'Neutrophil',\n", " 'T_cell_CD4',\n", " 'T_cell_CD8',\n", " 'T_cell_gd',\n", " 'Treg',\n", " 'cDC1',\n", " 'cDC2',\n", " 'eTAC',\n", " 'pDC']" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Check available cell types\n", "rna.obs[\"celltype\"].unique().tolist()" ] }, { "cell_type": "markdown", "id": "191faa86", "metadata": {}, "source": [ "## Create ReCoN's Multilayer Network\n", "\n", "### 1. Import Gene Regulatory Network (GRN)" ] }, { "cell_type": "code", "execution_count": 4, "id": "f0c87776", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Unnamed: 0targetsourceweight
00Pax5Mbd1_TF0.000095
22Pax5Smad5_TF0.000092
11Pax5Smad1_TF0.000092
\n", "
" ], "text/plain": [ " Unnamed: 0 target source weight\n", "0 0 Pax5 Mbd1_TF 0.000095\n", "2 2 Pax5 Smad5_TF 0.000092\n", "1 1 Pax5 Smad1_TF 0.000092" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "grn_path = \"./data/perturbation_tuto/grn.csv\"\n", "grn = pd.read_csv(grn_path)\n", "grn = grn.sort_values(by=\"weight\", ascending=False)[:500_000]\n", "grn[\"source\"] = grn[\"source\"].str.capitalize()\n", "grn[\"source\"] = grn[\"source\"] + '_TF'\n", "grn[\"target\"] = grn[\"target\"].str.capitalize()\n", "grn.head(3)" ] }, { "cell_type": "markdown", "id": "816a7ee1", "metadata": {}, "source": [ "### 2. Compute Cell-Cell Communication with LIANA+" ] }, { "cell_type": "code", "execution_count": 5, "id": "880ba378", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Using resource `mouseconsensus`.\n", "Using `.X`!\n", "/pasteur/appa/homes/rtrimbou/miniconda3/envs/snakemake/envs/recon-grn/lib/python3.10/site-packages/anndata/_core/anndata.py:430: FutureWarning: The dtype argument is deprecated and will be removed in late 2024.\n", "15364 features of mat are empty, they will be removed.\n", "Make sure that normalized counts are passed!\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/pasteur/appa/homes/rtrimbou/miniconda3/envs/snakemake/envs/recon-grn/lib/python3.10/site-packages/liana/method/_pipe_utils/_pre.py:146: ImplicitModificationWarning: Trying to modify attribute `.obs` of view, initializing view as actual.\n", "/pasteur/appa/homes/rtrimbou/miniconda3/envs/snakemake/envs/recon-grn/lib/python3.10/site-packages/liana/method/_pipe_utils/_pre.py:149: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.\n", "0.36 of entities in the resource are missing from the data.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Generating ligand-receptor stats for 1296 samples and 937 features\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 1000/1000 [00:04<00:00, 230.63it/s]\n" ] } ], "source": [ "li.method.cellphonedb(\n", " rna, \n", " resource_name=\"mouseconsensus\",\n", " expr_prop=0.00,\n", " use_raw=False,\n", " groupby=\"celltype\",\n", " verbose=True, \n", " key_added='cpdb_res'\n", ")" ] }, { "cell_type": "code", "execution_count": 6, "id": "be6a5abd", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
sourcetargetweightcelltype_sourcecelltype_target
406685AppCd74102.485008cDC2cDC1
405645CopaCd74102.370003cDC1cDC1
410237CopaCd74102.366211eTACcDC1
\n", "
" ], "text/plain": [ " source target weight celltype_source celltype_target\n", "406685 App Cd74 102.485008 cDC2 cDC1\n", "405645 Copa Cd74 102.370003 cDC1 cDC1\n", "410237 Copa Cd74 102.366211 eTAC cDC1" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Format cell communication network for ReCoN\n", "ccc_network = rna.uns[\"cpdb_res\"].copy()\n", "ccc_network = ccc_network[[\"ligand\", \"receptor\", \"lr_means\", \"source\", \"target\"]]\n", "ccc_network = ccc_network.rename(columns={\n", " \"lr_means\": \"weight\",\n", " \"source\": \"celltype_source\",\n", " \"target\": \"celltype_target\",\n", " \"ligand\": \"source\",\n", " \"receptor\": \"target\"\n", "})\n", "ccc_network = ccc_network[ccc_network['weight'] != 0]\n", "ccc_network.head(3)" ] }, { "cell_type": "markdown", "id": "09575c6f", "metadata": {}, "source": [ "### 3. Load Receptor-Gene Links" ] }, { "cell_type": "code", "execution_count": 7, "id": "6d7703ca", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
sourcetargetweight
2A1bgAbca10.005156
3A1bgAbcb1a0.005877
4A1bgAbcb1b0.005877
7A1bgAcsl10.005915
8A1bgAdk0.005092
\n", "
" ], "text/plain": [ " source target weight\n", "2 A1bg Abca1 0.005156\n", "3 A1bg Abcb1a 0.005877\n", "4 A1bg Abcb1b 0.005877\n", "7 A1bg Acsl1 0.005915\n", "8 A1bg Adk 0.005092" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "receptor_genes = recon.data.load_data.load_receptor_genes(\"mouse_receptor_gene_from_NichenetPKN\")\n", "genes = np.unique(grn['source'].tolist() + grn['target'].tolist())\n", "receptor_genes = receptor_genes[receptor_genes['target'].isin(genes)]\n", "receptor_genes.head()" ] }, { "cell_type": "markdown", "id": "0c90d0f3", "metadata": {}, "source": [ "### 4. Define Seeds and Parameters" ] }, { "cell_type": "code", "execution_count": 8, "id": "e1e3139f", "metadata": {}, "outputs": [], "source": [ "# Define seed genes (example: inflammatory signaling genes)\n", "seed_genes = [\"Nfkb1\", \"Tnf\", \"Il6\", \"Ccl2\", \"Cxcl10\"]\n", "\n", "# Define focal cell type\n", "focal_celltype = \"Macrophage\"\n", "\n", "# Add celltype suffix for seeds\n", "seeds_with_suffix = {f\"{g}::{focal_celltype}\": 1.0 for g in seed_genes}" ] }, { "cell_type": "code", "execution_count": 9, "id": "cd05f450", "metadata": {}, "outputs": [], "source": [ "# Network parameters\n", "cell_communication_graph_directed = False\n", "cell_communication_graph_weighted = True\n", "restart_proba = 0.6\n", "grn_graph_weighted = True\n", "grn_graph_directed = False" ] }, { "cell_type": "markdown", "id": "da6509fe", "metadata": {}, "source": [ "## Assemble the Multicellular Network" ] }, { "cell_type": "code", "execution_count": 10, "id": "336f9ce0", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/pasteur/helix/projects/ml4ig_hot/Users/rtrimbou/ReCoN/src/recon/explore/recon.py:122: UserWarning: \n", " No receptor_graph provided,\n", " an empty receptor graph will be created.\n", " \n", "/pasteur/helix/projects/ml4ig_hot/Users/rtrimbou/ReCoN/src/recon/explore/recon.py:387: UserWarning: The celltypes dictionary was converted toa list of Celltype objects.\n", "The keys of the dictionary will be the celltype names.\n" ] } ], "source": [ "celltypes = [\"B_cell\", \"pDC\", \"Macrophage\", \"NK_cell\", \"T_cell_CD4\", \"T_cell_CD8\"]\n", "\n", "multicell = recon.explore.Multicell(\n", " celltypes={celltype: recon.explore.Celltype(\n", " grn_graph=grn,\n", " receptor_grn_bipartite=receptor_genes,\n", " celltype_name=celltype,\n", " receptor_graph_directed=False,\n", " receptor_graph_weighted=False,\n", " grn_graph_directed=grn_graph_directed,\n", " grn_graph_weighted=grn_graph_weighted,\n", " receptor_grn_bipartite_graph_directed=False,\n", " receptor_grn_bipartite_graph_weighted=True,\n", " seeds=[]\n", " ) for celltype in celltypes},\n", " cell_communication_graph=ccc_network.iloc[\n", " ccc_network[\"celltype_source\"].isin(celltypes).values & \n", " ccc_network[\"celltype_target\"].isin(celltypes).values, :\n", " ],\n", " cell_communication_graph_directed=cell_communication_graph_directed,\n", " cell_communication_graph_weighted=cell_communication_graph_weighted,\n", " bipartite_grn_cell_communication_directed=False,\n", " bipartite_grn_cell_communication_weighted=False,\n", " bipartite_cell_communication_receptor_directed=False,\n", " bipartite_cell_communication_receptor_weighted=False,\n", " seeds=seeds_with_suffix,\n", ")" ] }, { "cell_type": "markdown", "id": "8854be24", "metadata": {}, "source": [ "### Set Lambda for Upstream Exploration" ] }, { "cell_type": "code", "execution_count": 11, "id": "0bf00798", "metadata": {}, "outputs": [], "source": [ "multicell.lamb = recon.explore.set_lambda(\n", " multicell,\n", " direction=\"upstream\",\n", " strategy=\"intercell\",\n", ")" ] }, { "cell_type": "markdown", "id": "002f880b", "metadata": {}, "source": [ "### Run Random Walk with Restart" ] }, { "cell_type": "code", "execution_count": 12, "id": "940098e3", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Seeds are provided as a dictionary with weights per seed.\n", "Creating a multixrank object with seeds as a dictionary.\n", "cell_communication\n", "receptor\n", "gene\n", "receptor\n", "gene\n", "receptor\n", "gene\n", "receptor\n", "gene\n", "receptor\n", "gene\n", "receptor\n", "gene\n", "Identifying produced ligands in response to the perturbation.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/pasteur/helix/projects/ml4ig_hot/Users/rtrimbou/ReCoN/src/recon/explore/recon.py:588: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", "/pasteur/helix/projects/ml4ig_hot/Users/rtrimbou/ReCoN/src/recon/explore/recon.py:588: SettingWithCopyWarning: \n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n" ] } ], "source": [ "# Run multicellular exploration\n", "results = multicell.explore(restart_proba=restart_proba)\n", "\n", "# Format results as gene profiles per cell type\n", "cell_type_profiles = recon.explore.format_multicell_results(results, celltypes=celltypes)" ] }, { "cell_type": "code", "execution_count": 13, "id": "bd3eabd9", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
multiplexnodelayerscore
5662Macrophage_grnNfkb1::Macrophagegene0.200103
2043Macrophage_grnCxcl10::Macrophagegene0.200019
9170Macrophage_grnTnf::Macrophagegene0.200013
705Macrophage_receptorfake_receptor::Macrophagereceptor0.049329
8302Macrophage_grnSp100_TF::Macrophagegene0.008345
...............
1798cell_communicationPtpra-T_cell_CD8cell_communication0.000000
1797cell_communicationPtpra-T_cell_CD4cell_communication0.000000
1796cell_communicationPtpra-NK_cellcell_communication0.000000
617cell_communicationClec1b-Macrophagecell_communication0.000000
1531cell_communicationMttp-B_cellcell_communication0.000000
\n", "

69791 rows × 4 columns

\n", "
" ], "text/plain": [ " multiplex node layer \\\n", "5662 Macrophage_grn Nfkb1::Macrophage gene \n", "2043 Macrophage_grn Cxcl10::Macrophage gene \n", "9170 Macrophage_grn Tnf::Macrophage gene \n", "705 Macrophage_receptor fake_receptor::Macrophage receptor \n", "8302 Macrophage_grn Sp100_TF::Macrophage gene \n", "... ... ... ... \n", "1798 cell_communication Ptpra-T_cell_CD8 cell_communication \n", "1797 cell_communication Ptpra-T_cell_CD4 cell_communication \n", "1796 cell_communication Ptpra-NK_cell cell_communication \n", "617 cell_communication Clec1b-Macrophage cell_communication \n", "1531 cell_communication Mttp-B_cell cell_communication \n", "\n", " score \n", "5662 0.200103 \n", "2043 0.200019 \n", "9170 0.200013 \n", "705 0.049329 \n", "8302 0.008345 \n", "... ... \n", "1798 0.000000 \n", "1797 0.000000 \n", "1796 0.000000 \n", "617 0.000000 \n", "1531 0.000000 \n", "\n", "[69791 rows x 4 columns]" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# View results\n", "results.sort_values(by=\"score\", ascending=False)" ] }, { "cell_type": "markdown", "id": "779c0d3c", "metadata": {}, "source": [ "---\n", "\n", "## Visualize Molecular Cascades with Sankey Diagrams\n", "\n", "ReCoN provides three types of Sankey diagrams to visualize molecular cascades:\n", "\n", "| Function | Layers | Use Case |\n", "|----------|--------|----------|\n", "| `plot_intracell_sankey` | Receptor → TF → Gene | Intracellular regulation only |\n", "| `plot_ligand_sankey` | Ligand → Receptor → TF → Gene | Cross-cell signaling (4 layers) |\n", "| `plot_intercell_sankey` | Before-Receptor → Before-TF → Ligand → Receptor → TF → Gene | Full cascade with upstream regulators (6 layers) |" ] }, { "cell_type": "markdown", "id": "d417b55a", "metadata": {}, "source": [ "### 1. Intracellular Cascade (Receptor → TF → Gene)\n", "\n", "Shows regulation within a single cell type: how receptors connect to transcription factors that regulate the seed genes." ] }, { "cell_type": "code", "execution_count": 14, "id": "bb5ce676", "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "link": { "color": [ "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)", "rgba(160, 160, 160, 0.4)" ], "source": { "bdata": "AAAAAAAAAAAACgoKCgoKCgoKCwsLCwsNDQ0NDQ0NDQ0ODg4ODg4ODg4OEREREREREhISEhISEhISEhISEhQUFBQUFBQUFRUVFRUVFRUWFgMQCQcCAQ8EAQgTDAUGCRMEBAMPAgwFBwUGEwYICBAPEA==", "dtype": "i1" }, "target": { "bdata": "AQIDBAUGBwgJAQIDBAUGBwgJAgUGCAwBAgMEBQYHCAkBAw8EBQYHCAkQAQUGBwgMAQIDDwQFBgcICQwTEAMEBQYHCAkMAQIDBAUHCAkCBRcXGBcXGBcXFxcXFxcXFxgZGBgYGBgZGBgZGRgYGRkZGA==", "dtype": "i1" }, "value": { "bdata": "5F4l+cX/cj/aksHNYOZ1P8/sLqK7Um8/dAQ6J3JVYz8PROfs2QexP78kaqURK2Y/W67myTFVcz/V7nwtLB93P3TTi7uWvWo/Q1BnKEp6mz/XQvJNfxK9P6j0VgXzWnI/SONSaG3EZz+3QIMjpRiWPyVRuQo3h2g/8zM2IOYPdj9heO4kIBd6P2G/C93Ji60/05zizFlIhz/AYzvdMH2VP/ZuYexMc3k/zonZscnukj9LBZzCjh6HPwxhP+Jnqok/llSlKxIFkj/tUg4sbipzP7DaTX/x/2g/TgnJeg+khD8p8qxR9O5nP3y5AFmn4HY/yPI4bKq9lz/+b8sFmOp2PwzKACNbI3I/RkMgk/vJdD+LznsVkuqfP2DhMz1z1mk/gP6F7/xAgz/yMQl4D0RmP+XGq8WoNHQ/Moml1cVReT/ndg0Ralt0P12EHjW8tp4/m2gvIMt5bD8o7rirVQKZP5zH8+KYfng/uKp1m4/7Yj/YHtXMQLRxPwbFFu06624/z2gPOGNzez+1uw7jCSSTP2tcfZ9Xo4Y/eca90eIBaD8Ia2tW6Y2DPzq8Q5eX0n8/XUpjR8y3bj+SUL4Cn+iAP0IjFvKcXow/3bOntfKpmj8CGyE3sIt4P8M27KhXf2Q/LJhwWNbIaj8rbUzKb55sP6ESy/gRjGM/sKrqAw2Ucj9mKBHN5zpkPxVt4igL7nA/f+Pf4NCheT8C9xdDTz1vPyT47giefWQ/orxCAX6ScT/dUh6RspN6P3bUY9S2u3A//GRlUN1Paz/UD8/Y6UOgPwKg0TUsaXQ/AaUzf206cT9JAtDQfAWhPw9o/fWheJ0/sJ4/TkuQtj/IcusR2cW1P5a4WmxhkbM/PBOjx1Oqsj943NwGYsGwP/zZEnz49a4/wnesD/QTrD+0c3Qi2+6rP9EbVZwA4as/lfwCPV73pj9h3+oA/takPxbBA4r7zKI/Ajsa9XCNoj88nSIzPdahPwANMV0HA50/7iGIqZHVlz+yyFAJsPqSP/9fN1zZt5I/GeEG026tkj8EjaPxL6SRP8ulWW68MY8/f7XVJHgQjT9dLRBqJOWMP0QeE6Ernos/gscXbv0xiz+vp+1gxd6JPyFmAYmTv4U/LKsUgT1NhD9W9fMxje2DP1m1fblhSYM/hPRRtnADgz/4zsnG4JyCPyhzAC05K4I/LzkeQDDmgT8=", "dtype": "f8" } }, "node": { "label": [ "Cd40lg_receptor", "Cebpa", "Irf2", "Max", "Mlxip", "Nfkb2", "Pbx3", "Pou2f1", "Rbpj", "Sp100", "Ifngr2_receptor", "Il12rb2_receptor", "Zfp3", "Il13ra1_receptor", "Il18rap_receptor", "Mbtps2", "Zfp691", "Il1r2_receptor", "Il27ra_receptor", "Zfp410", "Il2rb_receptor", "Il5ra_receptor", "Tnfrsf12a_receptor", "Nfkb1", "Cxcl10", "Tnf" ], "line": { "color": "black", "width": 0.5 }, "pad": 15, "thickness": 20 }, "orientation": "h", "type": "sankey" } ], "layout": { "annotations": [ { "font": { "size": 16 }, "showarrow": false, "text": "Receptors", "x": 0, "y": -0.15 }, { "font": { "size": 16 }, "showarrow": false, "text": "TFs", "x": 0.5, "y": -0.15 }, { "font": { "size": 16 }, "showarrow": false, "text": "Genes", "x": 1, "y": -0.15 } ], "font": { "color": "black", "size": 14 }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermap": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermap" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } }, "title": { "text": "Top regulators in Macrophage: Receptor → TF → Gene" } } }, "text/html": [ "
\n", "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "recon.plot.sankey_paths.plot_intracell_sankey(\n", " multicell_obj=multicell,\n", " results=results,\n", " cell_type=focal_celltype,\n", " seeds=seed_genes,\n", " top_receptor_n=10, # Number of top receptors to include\n", " top_tf_n=15, # Number of top TFs to include\n", " flow=\"upstream\", # Direction: receptor → TF → gene\n", " save_path=None\n", ")" ] }, { "cell_type": "markdown", "id": "f54c58b0", "metadata": {}, "source": [ "### 2. Ligand-Receptor Cascade (Ligand → Receptor → TF → Gene)\n", "\n", "Shows how ligands from other cell types activate receptors in the focal cell type, leading to TF activation and gene regulation." ] }, { "cell_type": "code", "execution_count": 15, "id": "265ffc4e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Ligand source cells: ['B_cell', 'pDC', 'NK_cell', 'T_cell_CD4', 'T_cell_CD8']\n" ] } ], "source": [ "# Define ligand source cell types (cells that send signals)\n", "ligand_source_cells = [ct for ct in celltypes if ct != focal_celltype]\n", "print(f\"Ligand source cells: {ligand_source_cells}\")" ] }, { "cell_type": "code", "execution_count": 33, "id": "c8b3fbb7", "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "link": { "color": [ "rgba(50, 239, 197, 0.6)", "rgba(79, 178, 195, 0.6)", "rgba(50, 239, 197, 0.6)", "rgba(50, 239, 197, 0.6)", "rgba(50, 239, 197, 0.6)", "rgba(50, 239, 197, 0.6)", "rgba(50, 239, 197, 0.6)", "rgba(13, 111, 88, 0.6)", "rgba(26, 4, 86, 0.6)", "rgba(26, 4, 86, 0.6)", "rgba(79, 178, 195, 0.6)", "rgba(79, 178, 195, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(26, 4, 86, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)" ], "source": { "bdata": "AAIDBQcICAoLCwwNDg4PEQEBAQEBARAQCQkJCQkJBgYGBgQEFBcTEhgVEhYXFRUUGBMWFhg=", "dtype": "i1" }, "target": { "bdata": "AQEEBgYJCQYJCQYGCQkQEBITFBUWFxMWEhQYFRYXFBUWFxMWGRoZGhkZGRkZGxoaGhobGhs=", "dtype": "i1" }, "value": { "bdata": "AAAAIK+30T8AAABggobDPwAAAEB1X74/AAAAoDLtrD8AAACgKCSnPwAAAICjP6Q/AAAAgKM/pD8AAACAoz+kPwAAAICjP6Q/AAAAgKM/pD8AAACAoz+kPwAAAICjP6Q/AAAAoCgklz8AAACgKCSXPwAAAGAeW5E/AAAAoCgkhz80UD6bY52uP2a7t8gZMtA/7Qx6uWxzhD8j+7zsFHt6P1sembl1nqg/4rubkqt1wD/98SDk1vCZPynSyvBB8ac/nixI/3s1hD+zUGHglimHP8Mir/2yx7E/iO4W553JfD8goycOunOVPzxYHMBlroY/Bh7M6ePifz/fMtaKYcd1P6bm4aQLs4Q/pHMpmi1ngT9Caxyv/2qwP9z9FOrEI8k/xYq6T6QKwj/qIdBS5+6+P3PHprSsp7k/J0eHKiJEtz8iYzLBZCW3PytXMwLqGbc/OTQr3s0Hsz+B1xdla4+tP//MugTtv6M/pufoClAFnz9qtBfqDPSePzPALZJ4PJ0/R+guqDLZmT9xNWwCYBWYP9tXqwqJ4pY/qDWC2c5vlT9QuqWUQhyOPw==", "dtype": "f8" } }, "node": { "label": [ "Ifng", "Ifngr2_receptor", "Ifng", "Tnfsf12", "Tnfrsf12a_receptor", "Il2", "Il2rb_receptor", "Il15", "Il18", "Il18rap_receptor", "Il15", "Il18", "Il2", "Il15", "Il18", "Ebi3", "Il12rb2_receptor", "Il12a", "Cebpa", "Irf2", "Max", "Mlxip", "Nfkb2", "Sp100", "Mbtps2", "Nfkb1", "Cxcl10", "Tnf" ], "line": { "color": "black", "width": 0.5 }, "pad": 15, "thickness": 20 }, "orientation": "h", "type": "sankey" } ], "layout": { "annotations": [ { "align": "left", "bgcolor": "rgba(26, 4, 86, 0.6)", "bordercolor": "black", "borderwidth": 0.5, "font": { "size": 12 }, "showarrow": false, "text": "B_cell", "x": 1.02, "xanchor": "left", "y": 1 }, { "align": "left", "bgcolor": "rgba(100,200,100,1)", "bordercolor": "black", "borderwidth": 0.5, "font": { "size": 12 }, "showarrow": false, "text": "Macrophage", "x": 1.02, "xanchor": "left", "y": 0.95 }, { "align": "left", "bgcolor": "rgba(50, 239, 197, 0.6)", "bordercolor": "black", "borderwidth": 0.5, "font": { "size": 12 }, "showarrow": false, "text": "NK_cell", "x": 1.02, "xanchor": "left", "y": 0.9 }, { "align": "left", "bgcolor": "rgba(79, 178, 195, 0.6)", "bordercolor": "black", "borderwidth": 0.5, "font": { "size": 12 }, "showarrow": false, "text": "T_cell_CD4", "x": 1.02, "xanchor": "left", "y": 0.85 }, { "align": "left", "bgcolor": "rgba(13, 111, 88, 0.6)", "bordercolor": "black", "borderwidth": 0.5, "font": { "size": 12 }, "showarrow": false, "text": "T_cell_CD8", "x": 1.02, "xanchor": "left", "y": 0.8 }, { "align": "left", "bgcolor": "rgba(55, 158, 221, 0.6)", "bordercolor": "black", "borderwidth": 0.5, "font": { "size": 12 }, "showarrow": false, "text": "pDC", "x": 1.02, "xanchor": "left", "y": 0.75 }, { "font": { "size": 16 }, "showarrow": false, "text": "Ligands", "x": 0, "y": -0.15 }, { "font": { "size": 16 }, "showarrow": false, "text": "Receptors", "x": 0.33, "y": -0.15 }, { "font": { "size": 16 }, "showarrow": false, "text": "TFs", "x": 0.66, "y": -0.15 }, { "font": { "size": 16 }, "showarrow": false, "text": "Genes", "x": 1, "y": -0.15 } ], "font": { "color": "black", "size": 14 }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermap": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermap" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } }, "title": { "text": "Top regulators from other cell types:\n Ligand → Receptor → TF → Gene" } } }, "text/html": [ "
\n", "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "recon.plot.sankey_paths.plot_ligand_sankey(\n", " multicell_obj=multicell,\n", " results=results,\n", " cell_type=focal_celltype,\n", " seeds=seed_genes,\n", " ligand_cells=ligand_source_cells,\n", " top_ligand_n=20, # Number of top ligands to include\n", " top_receptor_n=10, # Number of top receptors to include\n", " top_tf_n=10, # Number of top TFs to include\n", " per_celltype=True, # Select top ligands per source cell type (more balanced)\n", " flow=\"upstream\",\n", " save_path=None\n", ")" ] }, { "cell_type": "markdown", "id": "b28fc6bf", "metadata": {}, "source": [ "### 3. Full Intercellular Cascade (6 Layers)\n", "\n", "Shows the complete regulatory cascade including:\n", "1. **Before-Receptors**: Receptors in ligand-producing cells\n", "2. **Before-TFs**: TFs that regulate ligand production\n", "3. **Ligands**: Signaling molecules from other cell types\n", "4. **Receptors**: Receptors in the focal cell type\n", "5. **TFs**: Transcription factors in the focal cell type\n", "6. **Target genes**: The seed genes of interest\n", "\n", "```{warning}\n", "**Fewer cell types than expected?**\n", "\n", "The 6-layer cascade requires **full connectivity** across all layers. Only cell types where the chain Receptor→TF→Ligand is connected to your focal cell will appear. If you see fewer cell types than in `plot_ligand_sankey`, this is expected - it means some cell types lack the upstream regulatory paths (receptor→TF→ligand edges) in the prior knowledge network.\n", "\n", "To debug, use `verbose=True` to see filtering details.\n", "```\n", "\n", "```{tip}\n", "If layers become disconnected (e.g., `before_tf_ligand` has 0 rows), try increasing `before_top_n` or `top_ligand_n` to include more candidate edges.\n", "```" ] }, { "cell_type": "code", "execution_count": 50, "id": "4a0c74d8", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "[extract_receptor_ligand_pairs] === INPUT ===\n", " Input ligands: 100\n", " Examples: ['Ifng-NK_cell', 'Tnfsf12-NK_cell', 'Ifng-T_cell_CD4']\n", " Input receptors: 50\n", " Examples: ['Ifngr2_receptor::Macrophage', 'Cd40lg_receptor::Macrophage', 'Il18rap_receptor::Macrophage']\n", "\n", "[extract_receptor_ligand_pairs] === RECEPTOR-LIGAND LAYER ===\n", " Shape: (2442, 7)\n", " Columns: ['ligand', 'receptor', 'receptor_clean', 'weight', 'celltype_source', 'celltype_target', 'network_key']\n", " Sample rows (first 3):\n", " ligand receptor receptor_clean weight celltype_source celltype_target network_key\n", "Rps19::T_cell_CD8 C5ar1::Macrophage C5ar1_receptor::Macrophage 17.714996 T_cell_CD8 Macrophage cell_communication\n", " Copa::pDC Cd74::Macrophage Cd74_receptor::Macrophage 17.494999 pDC Macrophage cell_communication\n", " Copa::NK_cell Cd74::Macrophage Cd74_receptor::Macrophage 17.480000 NK_cell Macrophage cell_communication\n", "\n", "[extract_receptor_ligand_pairs] === FILTERING RESULT ===\n", " Filtered pairs: 72 rows\n", " Sample filtered pairs (first 3):\n", " ligand receptor weight\n", " Grn::pDC Tnfrsf1b::Macrophage 3.165001\n", "Cd28::T_cell_CD4 Cd80::Macrophage 0.360000\n", "Cd28::T_cell_CD8 Cd80::Macrophage 0.325000\n", "\n", "[extract_gene_tf_pairs] === INPUT ===\n", " Input genes: 5 - ['Nfkb1::Macrophage', 'Tnf::Macrophage', 'Il6::Macrophage']\n", " Input TFs: 20 - ['Sp100_TF::Macrophage', 'Cebpa_TF::Macrophage', 'Prdm11_TF::Macrophage']\n", "\n", "[extract_gene_tf_pairs] === TF-GENE LAYER ===\n", " Shape: (500000, 5)\n", " Columns: ['Unnamed: 0', 'target', 'source', 'weight', 'network_key']\n", " Unique sources (TFs): 360\n", " Unique targets (genes): 10168\n", " Sample rows (first 3):\n", " Unnamed: 0 target source weight network_key\n", " 0 Pax5::Macrophage Mbd1_TF::Macrophage 0.000095 Macrophage_grn\n", " 2 Pax5::Macrophage Smad5_TF::Macrophage 0.000092 Macrophage_grn\n", " 1 Pax5::Macrophage Smad1_TF::Macrophage 0.000092 Macrophage_grn\n", "\n", "[extract_gene_tf_pairs] === FILTERING RESULT ===\n", " Filtered pairs: 47 rows\n", " Sample filtered pairs (first 3):\n", " source target weight\n", "Prdm11_TF::Macrophage Nfkb1::Macrophage 0.000029\n", " Max_TF::Macrophage Nfkb1::Macrophage 0.000013\n", "Zfp691_TF::Macrophage Nfkb1::Macrophage 0.000012\n", "\n", "[extract_receptor_tf_pairs] === INPUT ===\n", " Input TFs: 20 - ['Sp100_TF::Macrophage', 'Cebpa_TF::Macrophage', 'Prdm11_TF::Macrophage']\n", " Input TFs (cleaned): ['Sp100::Macrophage', 'Cebpa::Macrophage', 'Prdm11::Macrophage']\n", " Input receptors: 50 - ['Ifngr2_receptor::Macrophage', 'Cd40lg_receptor::Macrophage', 'Il18rap_receptor::Macrophage']\n", "\n", "[extract_receptor_tf_pairs] === BIPARTITE LAYER ===\n", " Shape: (434183, 4)\n", " Columns: ['col2', 'col1', 'weight', 'network_key']\n", " Unique col1 (genes/TFs): 9892\n", " Unique col2 (receptors): 705\n", " Sample rows (first 3):\n", " col2 col1 weight network_key\n", "A1bg_receptor::Macrophage Abca1::Macrophage 0.005156 Macrophage_grn-Macrophage_receptor\n", "A1bg_receptor::Macrophage Abcb1a::Macrophage 0.005877 Macrophage_grn-Macrophage_receptor\n", "A1bg_receptor::Macrophage Abcb1b::Macrophage 0.005877 Macrophage_grn-Macrophage_receptor\n", "\n", "[extract_receptor_tf_pairs] === FILTERING RESULT ===\n", " Filtered pairs: 381 rows\n", " Sample filtered pairs (first 3):\n", " col1 col2 weight\n", " Arid5b::Macrophage Adam15_receptor::Macrophage 0.005325\n", "Bhlhe40::Macrophage Adam15_receptor::Macrophage 0.009077\n", " Cebpa::Macrophage Adam15_receptor::Macrophage 0.005940\n" ] }, { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "link": { "color": [ "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(160,160,160,0.4)", "rgba(160,160,160,0.4)", "rgba(160,160,160,0.4)", "rgba(160,160,160,0.4)", "rgba(160,160,160,0.4)", "rgba(160,160,160,0.4)", "rgba(160,160,160,0.4)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)" ], "source": { "bdata": "AAAAAAAAAAgICAgICAoKCgoKCwsLCwsLDAwMDAwMDA0NDQ0NDQ0ODg4ODg4ODg8PDw8PDxAQEBAQEREREREREREFAwEGBAECAgYHBAkHBxMWFRQWFhIYGBgYGBgbGxsbGxsbFxcXFxcZGRkZGRoaGhoaGhoaICIeHSUlISQfHBwjHSIkHyAfIx4jISE=", "dtype": "i1" }, "target": { "bdata": "AQIDBAUGBwECBAUJBwECBAUHAQIEBQkHAQIDBAUJBwECAwQFBgcBAgMEBQkGBwECBAUJBwECBAUHAQIDBAUJBgcSExQTFRYVFBUSFBIVExcXGBkZGhscHR4fICEdHiIfIyEkHSUeIh8dJR4iHxwdJR4iHyAhJiYmJicmJiYmJigmKCcnKCcnKCcnJyg=", "dtype": "i1" }, "value": { "bdata": "F5/piyzNgz8sLvS9ahuQPwvAhYy+93Q/CVx/xe9vhz9+3JTbtIOTP59+XXMxqn4/IZcPNsZ+gD/rAECQnK2DPz7L2lmO7IE/FUZRlEQ6hT9jnWFTF9q8P06wzjVLgXM/tBn5PbiMfj9HnnYMP2B6PyCV9KvPiZc/GetS1eCPdD+BoS2EFA2VPwnqRZ1523M/XqPfCfMnhT9ULp2oKbeCPwEm1wJ6pIM/h8XW18Rghj8NV4ZbLjdzP78n9nIheX0/JRjyodOqsD/oAATT80yEP+8OzBB3qK8/l3puJbTdhT8fyG1N++CDP+BynPdx8XY/YMX4dW5QgT/VDEI4/qaJP9X4hrDVYJE/5/1IGrMmeT9LRffDWTeNP/PAUfVnLZM/5flJeR9pez8EsYLMr/6CP1Ei5rPojoo/EXPp9zAblj9OAM+hmc16PzHy0oKpP5E/waweu5UJqj+QIFMc2V91P2Q9I4YQ+Ic/0y3GdRbRiT+CLlry1RV8P6+9JX0TV4A/Vgy/sJVvgz8G3njIHZ+wPwdzpy4+aa4/09mgPkAdeT/tDs7NK0l5P9XEznFThn4/kKtA6Sj/gT+iFS+6xK97P6BlDMSe/Xg/BJVVE0+Siz8DoqdC/xyGP6uP/DSolnk/hHlRAW2GjT90/FWRMouDP1rWxcS4dng/mrgKvf4YdT+uS38zSc+AP0j4ml/zmss//hKGteKpyD/pzXQjoEq4Pznc9NZPgLQ/XuVSRiUvsT8ADsl10oKpP433qLBmt6g/f4JQZ0Ewpz8Tv71uq6GmPzbfR3xkKaI/PIUVGJAToT9JJGsdZAOhP0XI5DmH9Z8/uv+OvXVinT8AAACgzWjqPwAAACDmtK4/AAAA4FcJrD8AAADAVwmcPwAAAMBzXJU/AAAAQOWwgj8AAADAc1xlP2n61AZaCIY/KUfuxTCwoz95QYd7+P6hP2Rgorl2M4U/yZiBvTbZhD9m000TvA+GP7M/HLJfsbI/CEU2diwQiD/oe2NynhuoP1QKog8vQLY/EXUNOT1amj8f1c/KlZqzP1IvQyxY8Kc/tddihBgYhz+aaBuzdzuXPwh+gytLzYk/g52gd/pRkD/50hICjN6oP0Hih99tl6I/6R6FzjBgoD+34thx7madPy6B7G2pHaU/8RpWoNmJtj9tua3qUfODPwvUEKBjEZs/7JLlIFuvmj9DjBEY+UCVPx76NsAhCpM/ys4FPR96rD+1cC/kxZ2EP9esIUhnS4g/JUHLcZ6XuD8d4Efmjri2P1id32XhGLY/lGdTKHXytD/d86nS9Jq0P/wZzhej2rA/gAdgMUiWrj8d1cg52zqrP+jEG3P3Lao/TKWi032xpz/MrV+k+gemPwZfMYVnSqU/6h2mE352oT+DmcWSRFSVP6wRBMp4NJU/7rB+I4VElD9cAnF0IfWTP7huqfQw/JI/gD8Okqbrjz+LN+w2BrKOP5xbVvqnP40/p62XXLNOjD8Df+bKC+iLPw==", "dtype": "f8" } }, "node": { "label": [ "Crlf2", "Creb3l2", "Max", "Mypop", "Nfia", "Sp100", "Zfp3", "Zfp384", "Ifngr2", "Zfp263", "Il10ra", "Il13ra1", "Il18rap", "Il21r", "Il27ra", "Il5ra", "Il7r", "Ptgdr2", "Il12a", "Grn", "App", "Cd28", "Tnf", "Tnfrsf1b", "Cd80", "Tnfrsf21", "Traf2", "Il12rb2", "Arid5b", "Bhlhe40", "Egr2", "Nfkb2", "Pou2f1", "Rbpj", "Irf2", "Pbx3", "Zfp3", "Cebpa", "Nfkb1", "Cxcl10", "Tnf" ], "line": { "color": "black", "width": 0.5 }, "pad": 15, "thickness": 20 }, "orientation": "h", "type": "sankey" } ], "layout": { "annotations": [ { "align": "left", "bgcolor": "rgba(100,200,100,1)", "bordercolor": "black", "borderwidth": 0.5, "font": { "size": 12 }, "showarrow": false, "text": "Macrophage", "x": 1.02, "xanchor": "left", "y": 1 }, { "align": "left", "bgcolor": "rgba(55, 158, 221, 0.6)", "bordercolor": "black", "borderwidth": 0.5, "font": { "size": 12 }, "showarrow": false, "text": "pDC", "x": 1.02, "xanchor": "left", "y": 0.95 }, { "font": { "size": 16 }, "showarrow": false, "text": "Upstream Receptors", "x": 0, "y": -0.15 }, { "font": { "size": 16 }, "showarrow": false, "text": "Upstream TFs", "x": 0.2, "y": -0.15 }, { "font": { "size": 16 }, "showarrow": false, "text": "Ligands", "x": 0.4, "y": -0.15 }, { "font": { "size": 16 }, "showarrow": false, "text": "Receptors", "x": 0.6, "y": -0.15 }, { "font": { "size": 16 }, "showarrow": false, "text": "TFs", "x": 0.8, "y": -0.15 }, { "font": { "size": 16 }, "showarrow": false, "text": "Genes", "x": 1, "y": -0.15 } ], "font": { "color": "black", "size": 14 }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermap": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermap" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } }, "title": { "text": "Upstream Receptor → Upstream TF → Ligand → Downstream Receptor → Downstream TF → Gene" } } }, "text/html": [ "
\n", "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "recon.plot.sankey_paths.plot_intercell_sankey(\n", " multicell_obj=multicell,\n", " results=results,\n", " cell_type=focal_celltype,\n", " seeds=seed_genes,\n", " ligand_cells=ligand_source_cells,\n", " top_ligand_n=20, # Number of top ligands\n", " top_receptor_n=50, # Number of top receptors in focal cell\n", " top_tf_n=20, # Number of top TFs in focal cell\n", " before_top_n=10, # Number of top regulators in ligand-producing cells\n", " per_celltype=True,\n", " flow=\"upstream\",\n", " verbose=True, # Show filtering details\n", " save_path=None\n", ")" ] }, { "cell_type": "markdown", "id": "afe20ad8", "metadata": {}, "source": [ "## Saving Plots\n", "\n", "All Sankey plot functions accept a `save_path` parameter to export the interactive HTML file:" ] }, { "cell_type": "code", "execution_count": 43, "id": "739ff621", "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "link": { "color": [ "rgba(50, 239, 197, 0.6)", "rgba(79, 178, 195, 0.6)", "rgba(50, 239, 197, 0.6)", "rgba(50, 239, 197, 0.6)", "rgba(26, 4, 86, 0.6)", "rgba(13, 111, 88, 0.6)", "rgba(50, 239, 197, 0.6)", "rgba(79, 178, 195, 0.6)", "rgba(79, 178, 195, 0.6)", "rgba(79, 178, 195, 0.6)", "rgba(50, 239, 197, 0.6)", "rgba(13, 111, 88, 0.6)", "rgba(79, 178, 195, 0.6)", "rgba(50, 239, 197, 0.6)", "rgba(50, 239, 197, 0.6)", "rgba(13, 111, 88, 0.6)", "rgba(50, 239, 197, 0.6)", "rgba(50, 239, 197, 0.6)", "rgba(50, 239, 197, 0.6)", "rgba(13, 111, 88, 0.6)", "rgba(26, 4, 86, 0.6)", "rgba(26, 4, 86, 0.6)", "rgba(79, 178, 195, 0.6)", "rgba(79, 178, 195, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(26, 4, 86, 0.6)", "rgba(55, 158, 221, 0.6)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)", "rgba(100,200,100,1)" ], "source": { "bdata": "AAIDBQcICQoLDA4PEBIUFRYXFxkaGhscHR0eIAEBAQEBAQEBAR8fHx8fGBgYGBgYGBgYGA0NDQ0NDQ0NDQ0NDRMTExMTExMTBgYGEREREREREQQEIywpJyIhKyQhKColJikkJCMrIiolJyUmJigoLCss", "dtype": "i1" }, "target": { "bdata": "AQEEBgYGBgYGDQ0GERMRERMYGBMYGBMTGBgfHyEiIyQlJicoKSIlJigqISMrJCUmJygpLCEiIyskJSYnKCkqLCMkJSYnKCkqISIlISIjJScoKSIlLS0uLS0uLS0tLS0tLS0vLi4uLi4vLi4vLi4vLy8u", "dtype": "i1" }, "value": { "bdata": "AAAAwKdbwz8AAACgVVW1PwAAAEC0l7A/AAAA4CW0pz8AAADgJbSnPwAAAOCaH6Y/AAAA4Jofpj8AAADAD4ukPwAAAMAPi6Q/AAAAwIT2oj8AAADAhPaiPwAAAKD5YaE/AAAAYN2anz8AAABg3ZqfPwAAACDHcZw/AAAAIMdxnD8AAABAsUiZPwAAACCbH5Y/AAAAIJsflj8AAAAgmx+WPwAAACCbH5Y/AAAAIJsflj8AAAAgmx+WPwAAACCbH5Y/AAAAQLFIiT8AAABAsUiJPwAAAOCE9oI/AAAAQLFIeT/StiN9fcOiP5K1A/Y92sM/iqQb0IUReT9REO8Z3DpwP26d1WN7LZ4/s4pBvd+/cD9Aznx9iSF+P2a3GcX10IE/HRqcYxEttD+r0dKCQ8yPPwDKsDIsWZ0/bxQl0xZhgT/mrp5dbtuZP6nsP3Mvk48/86ct0pjFeD8PNW3ya2R8PxK6jX9ry6U/vgiEl8ukcT8//97esUuKP6mskaDGaG4/YGcnPXyYez+Tn6C1MUqBP1Q5zRpqzXs/3MDufzX5pD9LHPkQp9mAP5ikf0YovJA/MF/KAhxOiD9u3Z7w5QBtPyqHSrtUoYI/U+ohGgY7hj+9WmMLjiFwP7zfs9TZpIU/JVIgzuj3iz8Z6LrmQtKKP9cEN70MK3M/yyuY0gvFaz8GlGjs/IpzP7ucurk8smo/Vq0kIYJfeT+zzPUWBKFrP2i9QHAoH3c/5Z9iYtqAgT87ZVUEG1V1PzSnZnEg/Gs/XbzAHEGjhT8XkyfmUhyBP0XRt+hyWJk/y4jbdhiEjT919Oytx+tsP+s+w7/ep5A/heTIVKawmz9P03GPUDVxP1yd+RyMJHM/XFmU8TeAjD9qM/ir/B+kP7D5DRrk0L4/q3zyJGdKtz/85HMYlu60Pys22xtt97M/loH9uWXssT80NCwZP4+wP9f4kTkHCa4/1bOWQ1jhrT/EM7iChtKtPwsXy5Q4kag/Vv5YfuVKpj+QTmfKhtijP2SoOaKNFKM/eJVFCMUInz9YE5Je6X6ZP27jSv/jBZQ/sGh+k7/6kz8Qkj0pA9+SP1TnnFo2r5A/t5aRqyUXjz8HH2q7zOiOP0EhFdsIi40/++x5FVAXjT/w6nZhcqyLP7u+5K+xQ4c/ahC+vC5RhT/tQzGEkaGEPyqLylbAVoQ/4qOsFwrpgz/9Sw46dm+DP3XGu1CdJYM/", "dtype": "f8" } }, "node": { "label": [ "Ifng", "Ifngr2_receptor", "Ifng", "Tnfsf12", "Tnfrsf12a_receptor", "Tnfsf14", "Ltbr_receptor", "Lta", "Lta", "Lta", "Lta", "Tnfsf14", "Il21", "Il21r_receptor", "Il4", "Tnfsf14", "Tnfsf11", "Tnfrsf11a_receptor", "Il2", "Il2rb_receptor", "Tnfsf11", "Tnfsf11", "Il15", "Il18", "Il18rap_receptor", "Il15", "Il18", "Il2", "Il15", "Il18", "Ebi3", "Il12rb2_receptor", "Il12a", "Cebpa", "Irf2", "Max", "Mlxip", "Nfkb2", "Pbx3", "Pou2f1", "Rbpj", "Sp100", "Zfp3", "Mbtps2", "Zfp691", "Nfkb1", "Cxcl10", "Tnf" ], "line": { "color": "black", "width": 0.5 }, "pad": 15, "thickness": 20 }, "orientation": "h", "type": "sankey" } ], "layout": { "annotations": [ { "align": "left", "bgcolor": "rgba(26, 4, 86, 0.6)", "bordercolor": "black", "borderwidth": 0.5, "font": { "size": 12 }, "showarrow": false, "text": "B_cell", "x": 1.02, "xanchor": "left", "y": 1 }, { "align": "left", "bgcolor": "rgba(100,200,100,1)", "bordercolor": "black", "borderwidth": 0.5, "font": { "size": 12 }, "showarrow": false, "text": "Macrophage", "x": 1.02, "xanchor": "left", "y": 0.95 }, { "align": "left", "bgcolor": "rgba(50, 239, 197, 0.6)", "bordercolor": "black", "borderwidth": 0.5, "font": { "size": 12 }, "showarrow": false, "text": "NK_cell", "x": 1.02, "xanchor": "left", "y": 0.9 }, { "align": "left", "bgcolor": "rgba(79, 178, 195, 0.6)", "bordercolor": "black", "borderwidth": 0.5, "font": { "size": 12 }, "showarrow": false, "text": "T_cell_CD4", "x": 1.02, "xanchor": "left", "y": 0.85 }, { "align": "left", "bgcolor": "rgba(13, 111, 88, 0.6)", "bordercolor": "black", "borderwidth": 0.5, "font": { "size": 12 }, "showarrow": false, "text": "T_cell_CD8", "x": 1.02, "xanchor": "left", "y": 0.8 }, { "align": "left", "bgcolor": "rgba(55, 158, 221, 0.6)", "bordercolor": "black", "borderwidth": 0.5, "font": { "size": 12 }, "showarrow": false, "text": "pDC", "x": 1.02, "xanchor": "left", "y": 0.75 }, { "font": { "size": 16 }, "showarrow": false, "text": "Ligands", "x": 0, "y": -0.15 }, { "font": { "size": 16 }, "showarrow": false, "text": "Receptors", "x": 0.33, "y": -0.15 }, { "font": { "size": 16 }, "showarrow": false, "text": "TFs", "x": 0.66, "y": -0.15 }, { "font": { "size": 16 }, "showarrow": false, "text": "Genes", "x": 1, "y": -0.15 } ], "font": { "color": "black", "size": 14 }, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermap": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermap" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } }, "title": { "text": "Top regulators from other cell types:\n Ligand → Receptor → TF → Gene" } } }, "text/html": [ "
\n", "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Save ligand cascade to HTML\n", "recon.plot.sankey_paths.plot_ligand_sankey(\n", " multicell_obj=multicell,\n", " results=results,\n", " cell_type=focal_celltype,\n", " seeds=seed_genes,\n", " ligand_cells=ligand_source_cells,\n", " top_ligand_n=20,\n", " top_receptor_n=20,\n", " top_tf_n=15,\n", " per_celltype=True,\n", " flow=\"upstream\",\n", " save_path=\"macrophage_ligand_cascade.html\"\n", ")" ] }, { "cell_type": "markdown", "id": "ce6e05a5", "metadata": {}, "source": [ "---\n", "\n", "## Key Parameters Reference\n", "\n", "| Parameter | Description |\n", "|-----------|-------------|\n", "| `cell_type` | Focal cell type receiving signals |\n", "| `seeds` | Target genes of interest (list of gene names without celltype suffix) |\n", "| `ligand_cells` | Cell types that can produce ligands |\n", "| `top_ligand_n` | Number of top-scoring ligands to include |\n", "| `top_receptor_n` | Number of top-scoring receptors to include |\n", "| `top_tf_n` | Number of top-scoring TFs to include |\n", "| `before_top_n` | Number of upstream regulators in ligand-producing cells (for 6-layer plot) |\n", "| `per_celltype` | If `True`, select top ligands per source cell type (more balanced view) |\n", "| `flow` | `\"upstream\"` (ligand→gene) or `\"downstream\"` (gene→ligand) |\n", "| `save_path` | Path to save HTML file (`None` = display only) |\n", "| `verbose` | If `True`, print debugging information about layer sizes |" ] }, { "cell_type": "markdown", "id": "252e43f8", "metadata": {}, "source": [ "## Interpreting Sankey Diagrams\n", "\n", "- **Node layers** (left to right in upstream flow): Ligands → Receptors → TFs → Genes\n", "- **Link thickness**: Proportional to edge weights in the network\n", "- **Colors**: Different colors distinguish between source cell types for ligands\n", "- **Interactive**: Hover over nodes and links to see detailed information" ] }, { "cell_type": "markdown", "id": "c65dfb86", "metadata": {}, "source": [] }, { "cell_type": "markdown", "id": "95acbdf5", "metadata": {}, "source": [] }, { "cell_type": "markdown", "id": "b6332505", "metadata": {}, "source": [] } ], "metadata": { "kernelspec": { "display_name": "recon-grn", "language": "python", "name": "recon-grn" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.19" } }, "nbformat": 4, "nbformat_minor": 5 }