{ "cells": [ { "cell_type": "markdown", "id": "847509ee-0208-4c2c-be1e-05c171775fd0", "metadata": {}, "source": [ "# Niche based PILOT trajectory inference\n", "\n", "**NicheSphere** is an sc-verse compatible Python library which allows the user to find differentially co-localized cellular niches and biological processes involved in their interactions based on cell type pairs co-localization probabilities in different conditions. Cell type pair co-localization probabilities are obtained in different ways: from deconvoluted Visium 10x / PIC-seq data (probabilities of finding each cell type in each spot / multiplet), or counting cell boundaries overlaps for each cell type pair in single cell spatial data (MERFISH , CODEX ...). This tutorial will use groups of cells that converge or split in disease (Ischemia) based on differential co-localization which were defined using NicheSphere.\n", "\n", "**PILOT** allows sample level trajectory analysis based on cell type proportions using optimal transport. \n", "\n", "In this tutorial we will **leverage PILOT trajectory inference** adding spatial information by **using NicheSphere resulting niches** to calculate distances between samples.\n" ] }, { "cell_type": "markdown", "id": "873ee639-6b4e-4103-b57a-f117052a55f2", "metadata": {}, "source": [ "## 1. Libraries and functions" ] }, { "cell_type": "code", "execution_count": 1, "id": "9d5aab80-bda1-44ea-bb0c-e8207be9f3ce", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "During startup - Warning messages:\n", "1: Setting LC_MONETARY failed, using \"C\" \n", "2: Setting LC_PAPER failed, using \"C\" \n", "3: Setting LC_MEASUREMENT failed, using \"C\" \n" ] } ], "source": [ "import pilotpy as pl\n", "import scanpy as sc\n", "import pandas as pd\n", "import scipy\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import os\n", "from PIL import Image\n", "import mudata as md" ] }, { "cell_type": "markdown", "id": "19d4de0c-14d7-4bb1-ac21-5a1401082487", "metadata": {}, "source": [ "## 2. Data at first glance" ] }, { "cell_type": "markdown", "id": "eab7e97a-3d46-4aec-807b-0e5e983550d8", "metadata": {}, "source": [ "In this example we will use the **Visium** data from the Myocardial Infarction atlas from Kuppe, C. et. Al., 2022" ] }, { "cell_type": "code", "execution_count": 2, "id": "1fd98ae6-15e7-4e4a-88d4-d7c1665a05a2", "metadata": {}, "outputs": [], "source": [ "mudata=md.read('heart_MI_ST_SC_23samples.h5mu')" ] }, { "cell_type": "markdown", "id": "b9b3b92c-7be5-4b8d-8bf8-1384957b22e5", "metadata": {}, "source": [ "**Conditions**\n", "\n", "We will need the following metadata to subset the samples in different conditions. This table contains a **sample** column with sample names , and a **sampleType** column with the corresponding conditions. " ] }, { "cell_type": "code", "execution_count": 3, "id": "8457a65f-5cda-4b71-9951-abb39e65727d", "metadata": {}, "outputs": [], "source": [ "sampleTypesDF=pd.read_csv('./MI_sampleTypesDF.csv', index_col=0)" ] }, { "cell_type": "markdown", "id": "85888e49-f6d2-426b-8e72-75d4e333a19e", "metadata": {}, "source": [ "For the **coloc tutorial** we did cell type deconvolution on the visium slices using the associated scRNA-seq data, obtaining a cell types x spots matrix of probabilities of each cell type for each spot." ] }, { "cell_type": "code", "execution_count": 4, "id": "f5193b54-4c98-4495-bac7-5527a180051d", "metadata": {}, "outputs": [], "source": [ "CTprops=pd.read_csv('./CTprops.csv', index_col=0)" ] }, { "cell_type": "markdown", "id": "8d849bc9-5d02-4816-8919-4aee952f3b8f", "metadata": {}, "source": [ "Then, we computed cell type pair co-localization probabilities per sample from these cell type probabilities." ] }, { "cell_type": "code", "execution_count": 5, "id": "1ae994d6-c7ba-4379-b976-539bb30d1ace", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | Fib1_SCARA5-Fib1_SCARA5 | \n", "Fib1_SCARA5-damaged_CM | \n", "Fib1_SCARA5-Capillary_Endo | \n", "Fib1_SCARA5-LYVE_FOLR_Macrophages | \n", "Fib1_SCARA5-Fib3_C7 | \n", "Fib1_SCARA5-healthy_CM | \n", "Fib1_SCARA5-Fib2_Myofib | \n", "Fib1_SCARA5-Endocardial_Endo | \n", "Fib1_SCARA5-Arterial_Endo | \n", "Fib1_SCARA5-Neuronal | \n", "... | \n", "NK_T-CCL18_Macrophages | \n", "NK_T-perivascular_fibroblasts | \n", "NK_T-CD_4 | \n", "NK_T-vSMCs_2 | \n", "NK_T-Lymphatic_Endo | \n", "NK_T-NK | \n", "NK_T-CD_8 | \n", "NK_T-Purkinje_fibers | \n", "NK_T-Adipo | \n", "NK_T-NK_T | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| control_P17 | \n", "0.017603 | \n", "0.000308 | \n", "0.000992 | \n", "0.000251 | \n", "0.007062 | \n", "0.002586 | \n", "0.004724 | \n", "0.000943 | \n", "0.000412 | \n", "0.000351 | \n", "... | \n", "2.290066e-15 | \n", "0.0 | \n", "3.915381e-05 | \n", "0.0 | \n", "0.0 | \n", "4.538656e-08 | \n", "4.556003e-08 | \n", "0.0 | \n", "0.000000e+00 | \n", "0.000268 | \n", "
| RZ_P9 | \n", "0.009307 | \n", "0.000429 | \n", "0.000738 | \n", "0.000003 | \n", "0.005204 | \n", "0.001439 | \n", "0.001625 | \n", "0.000065 | \n", "0.000168 | \n", "0.000046 | \n", "... | \n", "0.000000e+00 | \n", "0.0 | \n", "4.640548e-05 | \n", "0.0 | \n", "0.0 | \n", "9.954633e-05 | \n", "1.643486e-05 | \n", "0.0 | \n", "0.000000e+00 | \n", "0.000784 | \n", "
| IZ_P15 | \n", "0.030351 | \n", "0.000000 | \n", "0.000027 | \n", "0.000186 | \n", "0.001200 | \n", "0.000000 | \n", "0.003112 | \n", "0.000072 | \n", "0.000062 | \n", "0.000000 | \n", "... | \n", "0.000000e+00 | \n", "0.0 | \n", "0.000000e+00 | \n", "0.0 | \n", "0.0 | \n", "0.000000e+00 | \n", "0.000000e+00 | \n", "0.0 | \n", "0.000000e+00 | \n", "0.000000 | \n", "
| RZ_P6 | \n", "0.040470 | \n", "0.000441 | \n", "0.002752 | \n", "0.000361 | \n", "0.008687 | \n", "0.002928 | \n", "0.007878 | \n", "0.000176 | \n", "0.001022 | \n", "0.001170 | \n", "... | \n", "0.000000e+00 | \n", "0.0 | \n", "7.998369e-25 | \n", "0.0 | \n", "0.0 | \n", "8.593925e-28 | \n", "0.000000e+00 | \n", "0.0 | \n", "0.000000e+00 | \n", "0.000438 | \n", "
| RZ_BZ_P3 | \n", "0.021508 | \n", "0.000292 | \n", "0.000567 | \n", "0.000057 | \n", "0.002408 | \n", "0.000483 | \n", "0.006635 | \n", "0.000123 | \n", "0.000052 | \n", "0.000052 | \n", "... | \n", "0.000000e+00 | \n", "0.0 | \n", "0.000000e+00 | \n", "0.0 | \n", "0.0 | \n", "8.585311e-06 | \n", "0.000000e+00 | \n", "0.0 | \n", "7.294563e-35 | \n", "0.000897 | \n", "
5 rows × 1089 columns
\n", "