{ "cells": [ { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "## CellPhoneDB v5 new outputs" ] }, { "cell_type": "markdown", "id": "1", "metadata": {}, "source": [ "From version 5 of [CellPhoneDB](https://www.github.com/ventolab/cellphonedb), there is a new output file - `interaction_scores`. \n", "\n", "According to the official repository, this table corresponds to:\n", "\n", "`interaction_scores`: stores the new score generated. This score ranges from 0-100.\n", " \n", "To score interactions CellPhoneDB v5 employs the following protocol:\n", " \n", "1. Exclude genes not participating in any interaction and those expressed in less than k% of cells within a given cell type.\n", "2. Calculate the mean expression (G) of each gene (i) within each cell type (j).\n", "3. For heteromeric proteins, aggregate the mean gene expression of each subunit (n) employing the geometric mean.\n", "4. Scale mean gene/heteromer expression across cell types between 0 and 100.\n", "5. Calculate the product of the scale mean expression of the interaction proteins as a proxy of the interaction relevance.\n", "\n", "`cellsign`: accepts the new `CellSign` data.\n", "\n", "The aim of the CellSign module is to identify activated receptors and prioritise high-confidence interactions by leveraging the activity of the downstream transcription factors (TFs). CellSign relies on a database of receptors linked to their putative downstream TFs.\n", "\n", "`ktplotspy` will support these output via inclusion into the existing `plot_cpdb` function. We will gradually enable their functionality across the other functions, as well as with in the R package eventually." ] }, { "cell_type": "markdown", "id": "2", "metadata": {}, "source": [ "**Import libraries**" ] }, { "cell_type": "code", "execution_count": null, "id": "3", "metadata": {}, "outputs": [], "source": [ "import anndata as ad\n", "import pandas as pd\n", "import ktplotspy as kpy\n", "import matplotlib.pyplot as plt\n", "\n", "from pathlib import Path" ] }, { "cell_type": "code", "execution_count": null, "id": "4", "metadata": {}, "outputs": [], "source": [ "# read in the files\n", "# 1) .h5ad file used for performing cellphonedb\n", "DATADIR = Path(\"../../data/\")\n", "adata = ad.read_h5ad(DATADIR / \"ventolab_tutorial_small_adata.h5ad\")\n", "\n", "# 2) output from cellphonedb\n", "means = pd.read_csv(DATADIR / \"out_v5\" / \"degs_analysis_means_07_27_2023_151846.txt\", sep=\"\\t\")\n", "relevant_interactions = pd.read_csv(DATADIR / \"out_v5\" / \"degs_analysis_relevant_interactions_07_27_2023_151846.txt\", sep=\"\\t\")\n", "interaction_scores = pd.read_csv(DATADIR / \"out_v5\" / \"degs_analysis_interaction_scores_07_27_2023_151846.txt\", sep=\"\\t\")\n", "cellsign = pd.read_csv(DATADIR / \"out_v5\" / \"degs_analysis_CellSign_active_interactions_07_27_2023_151846.txt\", sep=\"\\t\")" ] }, { "cell_type": "code", "execution_count": null, "id": "5", "metadata": {}, "outputs": [], "source": [ "kpy.plot_cpdb_heatmap(pvals=relevant_interactions, degs_analysis=True, figsize=(5, 5), title=\"Sum of significant interactions\")" ] }, { "cell_type": "code", "execution_count": null, "id": "6", "metadata": {}, "outputs": [], "source": [ "kpy.plot_cpdb(\n", " adata=adata,\n", " cell_type1=\"PV MYH11|PV STEAP4|PV MMPP11\",\n", " cell_type2=\"EVT_1|EVT_2|GC|iEVT|eEVT|VCT_CCC\",\n", " means=means,\n", " pvals=relevant_interactions,\n", " celltype_key=\"cell_labels\",\n", " genes=[\"TGFB2\", \"CSF1R\"],\n", " figsize=(12, 3),\n", " title=\"Interactions between\\nPV and trophoblast \",\n", " max_size=4,\n", " highlight_size=0.75,\n", " degs_analysis=True,\n", " standard_scale=True,\n", ")" ] }, { "cell_type": "markdown", "id": "7", "metadata": {}, "source": [ "### Interaction scores\n", "\n", "Let's start with interaction scores. If a dataframe corresponding to the `interaction_scores` file is provided, you can toggle the alpha transparency of the interactions by the interaction score (interaction ranking is simply the score/100)." ] }, { "cell_type": "code", "execution_count": null, "id": "8", "metadata": {}, "outputs": [], "source": [ "kpy.plot_cpdb(\n", " adata=adata,\n", " cell_type1=\"PV MYH11|PV STEAP4|PV MMPP11\",\n", " cell_type2=\"EVT_1|EVT_2|GC|iEVT|eEVT|VCT_CCC\",\n", " means=means,\n", " pvals=relevant_interactions,\n", " celltype_key=\"cell_labels\",\n", " genes=[\"TGFB2\", \"CSF1R\"],\n", " figsize=(12, 3),\n", " title=\"Interactions between\\nPV and trophoblast\",\n", " max_size=3,\n", " highlight_size=0.75,\n", " degs_analysis=True,\n", " standard_scale=True,\n", " interaction_scores=interaction_scores,\n", " scale_alpha_by_interaction_scores=True,\n", ")" ] }, { "cell_type": "markdown", "id": "9", "metadata": {}, "source": [ "You can also specify a minimum interaction score to keep, removing all interactions lesser than this value." ] }, { "cell_type": "code", "execution_count": null, "id": "10", "metadata": {}, "outputs": [], "source": [ "kpy.plot_cpdb(\n", " adata=adata,\n", " cell_type1=\"PV MYH11|PV STEAP4|PV MMPP11\",\n", " cell_type2=\"EVT_1|EVT_2|GC|iEVT|eEVT|VCT_CCC\",\n", " means=means,\n", " pvals=relevant_interactions,\n", " celltype_key=\"cell_labels\",\n", " genes=[\"TGFB2\", \"CSF1R\"],\n", " figsize=(12, 3),\n", " title=\"Interactions between\\nPV and trophoblast \",\n", " max_size=6,\n", " highlight_size=0.75,\n", " degs_analysis=True,\n", " standard_scale=True,\n", " interaction_scores=interaction_scores,\n", " min_interaction_score=20,\n", ")" ] }, { "cell_type": "markdown", "id": "11", "metadata": {}, "source": [ "or specify both to have the alpha transparency shown too." ] }, { "cell_type": "code", "execution_count": null, "id": "12", "metadata": {}, "outputs": [], "source": [ "kpy.plot_cpdb(\n", " adata=adata,\n", " cell_type1=\"PV MYH11|PV STEAP4|PV MMPP11\",\n", " cell_type2=\"EVT_1|EVT_2|GC|iEVT|eEVT|VCT_CCC\",\n", " means=means,\n", " pvals=relevant_interactions,\n", " celltype_key=\"cell_labels\",\n", " genes=[\"TGFB2\", \"CSF1R\"],\n", " figsize=(12, 3),\n", " title=\"Interactions between\\nPV and trophoblast \",\n", " max_size=6,\n", " highlight_size=0.75,\n", " degs_analysis=True,\n", " standard_scale=True,\n", " interaction_scores=interaction_scores,\n", " scale_alpha_by_interaction_scores=True,\n", " min_interaction_score=20,\n", ")" ] }, { "cell_type": "markdown", "id": "13", "metadata": {}, "source": [ "### CellSign\n", "\n", "If a dataframe corresponding to the `cellsign` file is provided, you can toggle the filter the interactions by the results" ] }, { "cell_type": "code", "execution_count": null, "id": "14", "metadata": {}, "outputs": [], "source": [ "kpy.plot_cpdb(\n", " adata=adata,\n", " cell_type1=\"PV MYH11\",\n", " cell_type2=\"EVT_1|EVT_2|GC|iEVT|eEVT|VCT_CCC\",\n", " means=means,\n", " pvals=relevant_interactions,\n", " celltype_key=\"cell_labels\",\n", " figsize=(12, 4),\n", " title=\"Interactions between\\nPV and trophoblast with\\ndownstream significance\",\n", " max_size=6,\n", " highlight_size=0.75,\n", " degs_analysis=True,\n", " standard_scale=True,\n", " cellsign=cellsign,\n", " filter_by_cellsign=True,\n", ")" ] }, { "cell_type": "markdown", "id": "15", "metadata": {}, "source": [ "and also scale the alpha value (50% for 0 and 100% for 1)." ] }, { "cell_type": "code", "execution_count": null, "id": "16", "metadata": {}, "outputs": [], "source": [ "kpy.plot_cpdb(\n", " adata=adata,\n", " cell_type1=\"PV MYH11\",\n", " cell_type2=\"EVT_1|EVT_2|GC|iEVT|eEVT|VCT_CCC\",\n", " means=means,\n", " pvals=relevant_interactions,\n", " celltype_key=\"cell_labels\",\n", " figsize=(12, 4),\n", " title=\"Interactions between\\nPV and trophoblast with\\ndownstream significance\",\n", " max_size=6,\n", " highlight_size=0.75,\n", " degs_analysis=True,\n", " standard_scale=True,\n", " cellsign=cellsign,\n", " filter_by_cellsign=True,\n", " scale_alpha_by_cellsign=True,\n", ")" ] }, { "cell_type": "markdown", "id": "17", "metadata": {}, "source": [ "### Additional plotting options\n", "\n", "From now on, `is_integrin`, `directionality` and `classification` are transferred to final output table in `plot_cpdb`. This means you will be able to use something like `facet_grid`/`facet_wrap` to plot them!\n" ] }, { "cell_type": "code", "execution_count": null, "id": "18", "metadata": {}, "outputs": [], "source": [ "from plotnine import facet_wrap\n", "\n", "p = kpy.plot_cpdb(\n", " adata=adata,\n", " cell_type1=\"PV MYH11\",\n", " cell_type2=\"EVT_1|EVT_2|GC|iEVT|eEVT|VCT_CCC\",\n", " means=means,\n", " pvals=relevant_interactions,\n", " celltype_key=\"cell_labels\",\n", " genes=[\"TGFB2\", \"CSF1R\", \"COL1A1\"],\n", " figsize=(12, 5),\n", " title=\"Interactions between PV and trophoblast\\nsplit by classification\",\n", " max_size=6,\n", " highlight_size=0.75,\n", " degs_analysis=True,\n", " standard_scale=True,\n", ")\n", "p + facet_wrap(\"~ classification\", ncol=1)" ] }, { "cell_type": "code", "execution_count": null, "id": "19", "metadata": {}, "outputs": [], "source": [ "p = kpy.plot_cpdb(\n", " adata=adata,\n", " cell_type1=\"PV MYH11\",\n", " cell_type2=\"EVT_1|EVT_2|GC|iEVT|eEVT|VCT_CCC\",\n", " means=means,\n", " pvals=relevant_interactions,\n", " celltype_key=\"cell_labels\",\n", " genes=[\"TGFB2\", \"CSF1R\", \"COL1A1\"],\n", " figsize=(12, 5),\n", " title=\"Interactions between PV and trophoblast\\nsplit by classification and integrin\",\n", " max_size=6,\n", " highlight_size=0.75,\n", " degs_analysis=True,\n", " standard_scale=True,\n", ")\n", "p + facet_wrap(\"~ classification + is_integrin\", ncol=1)" ] }, { "cell_type": "code", "execution_count": null, "id": "20", "metadata": {}, "outputs": [], "source": [ "p = kpy.plot_cpdb(\n", " adata=adata,\n", " cell_type1=\"PV MYH11\",\n", " cell_type2=\"EVT_1|EVT_2|GC|iEVT|eEVT|VCT_CCC\",\n", " means=means,\n", " pvals=relevant_interactions,\n", " celltype_key=\"cell_labels\",\n", " genes=[\"TGFB2\", \"CSF1R\", \"COL1A1\"],\n", " figsize=(12, 4),\n", " title=\"Interactions between PV and trophoblast\\nsplit by directionality\",\n", " max_size=6,\n", " highlight_size=0.75,\n", " degs_analysis=True,\n", " standard_scale=True,\n", ")\n", "p + facet_wrap(\"~ directionality\", ncol=1)" ] }, { "cell_type": "code", "execution_count": null, "id": "21", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "2.7.undefined" } }, "nbformat": 4, "nbformat_minor": 5 }