{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Estimate Spatial Metabolic fluxes\n", "\n", "### Overview\n", "This tutorial demonstrates the complete workflow for analyzing spatial metabolic transcriptomics data using **SpMetaTME** on breast cancer tissue. The analysis includes:\n", "\n", "- **Data Loading & Preprocessing**: Loading 10X Visium spatial transcriptomics data\n", "- **Metabolic Modeling**: Load pretrained spMetaTME model\n", "- **Flux Inference**: Predicting metabolic reaction fluxes across tissue spots\n", "- **Domain Identification**: Identifying spatially distinct metabolic domains\n", "- **Interaction Inference**: Finding metabolic interactions in the tumor microenvironment (TME)\n", "- **Visualization & Analysis**: Exploring metabolic heterogeneity across tissue\n", "\n", "### Dataset Information\n", "- **Source**: Breast cancer tissue measured with 10X Visium platform\n", "- **Samples**: Breast_cancer_Block_A\n", "- **Dimensions**: 3,798 cells (n_obs) × 19,690 genes (n_vars)\n", "- **Key Features**: High-resolution spatial coordinates with gene expression profiles" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Import Required Libraries\n", "\n", "Import essential packages for spatial transcriptomics analysis, metabolic modeling, and visualization:\n", "- **scanpy**: Spatial transcriptomics preprocessing and visualisations\n", "- **matplotlib/seaborn**: Data visualization\n", "- **spmetatme**: Python package for metabolic flux inference\n", " - `plotting`: Specialized visualization functions\n", " - `train`: Model training and inference\n", " - `communication`: TME interaction analysis\n", " - `dataloader`: Metabolic data loading utilities\n", "\n", "**Configuration Parameters**:\n", "- `BATCH_SIZE = 80`: Number of spots/cells to be sampled per batch during model training\n", "- `K = 150`: Number of nearest neighbors for spatial graph construction" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "c:\\Users\\suraj\\anaconda3\\envs\\Demo_env\\Lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] } ], "source": [ "%load_ext autoreload\n", "%autoreload\n", "import matplotlib.pyplot as plt\n", "import seaborn as sns\n", "import scanpy as sc\n", "import spmetatme.plotting as pl\n", "from spmetatme.data.dataloader import MetabolicDataLoader\n", "from spmetatme.train import SpMetaTME\n", "from spmetatme.data.metabolic_model import get_model_path\n", "from spmetatme.communication import infer_TME_interaction\n", "from spmetatme.utils import preprocess_adata, get_available_metabolic_models\n", "\n", "from spmetatme.utils import convert_symbol_to_ensg #(Optional)\n", "import warnings\n", "warnings.simplefilter(action='ignore', category=FutureWarning)\n", "warnings.filterwarnings(\"ignore\")\n", "\n", "BATCH_SIZE = 80\n", "K = 150\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Explore Available Metabolic Models\n", "\n", "List all pre-built metabolic models available in SpMetaTME. These genome-scale metabolic models (GEMs) represent cancer-specific metabolic networks and are used to predict reaction fluxes from spatial transcriptomics data." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | version | \n", "organism | \n", "number of reactions | \n", "number of metabolites | \n", "gene identifier type | \n", "description | \n", "
|---|---|---|---|---|---|---|
| breast_cancer | \n", "1.1 | \n", "Homo sapiens | \n", "6561 | \n", "2919 | \n", "Ensemble gene id | \n", "Genome-scale metabolic model of human breast c... | \n", "
| colon_adenocarcinoma | \n", "1.1 | \n", "Homo sapiens | \n", "6646 | \n", "2872 | \n", "Ensemble gene id | \n", "Genome-scale metabolic model of human colon ad... | \n", "
| glioblastoma | \n", "1.1 | \n", "Homo sapiens | \n", "6102 | \n", "2460 | \n", "Ensemble gene id | \n", "Genome-scale metabolic model of human glioblas... | \n", "
| low_grade_glioma | \n", "1.1 | \n", "Homo sapiens | \n", "5940 | \n", "2460 | \n", "Ensemble gene id | \n", "Genome-scale metabolic model of human low grad... | \n", "
| lung_adenocarcinoma | \n", "1.1 | \n", "Homo sapiens | \n", "6145 | \n", "2660 | \n", "Ensemble gene id | \n", "Genome-scale metabolic model of human lung ade... | \n", "
| lung_squamous_cell_carcinoma | \n", "1.1 | \n", "Homo sapiens | \n", "6170 | \n", "2606 | \n", "Ensemble gene id | \n", "Genome-scale metabolic model of human lung squ... | \n", "
| ovarian_cancer | \n", "1.1 | \n", "Homo sapiens | \n", "5668 | \n", "2323 | \n", "Ensemble gene id | \n", "Genome-scale metabolic model of human ovarian ... | \n", "
| pancreatic_adenocarcinoma | \n", "1.1 | \n", "Homo sapiens | \n", "6129 | \n", "2594 | \n", "Ensemble gene id | \n", "Genome-scale metabolic model of human pancreat... | \n", "
| prostate_cancer | \n", "1.1 | \n", "Homo sapiens | \n", "7541 | \n", "3460 | \n", "Ensemble gene id | \n", "Genome-scale metabolic model of human prostate... | \n", "
| skin_cutaneous_melanoma | \n", "1.1 | \n", "Homo sapiens | \n", "6342 | \n", "2712 | \n", "Ensemble gene id | \n", "Genome-scale metabolic model of human skin cut... | \n", "
| kidney_renal_clear_cell_carcinoma | \n", "1.1 | \n", "Homo sapiens | \n", "7002 | \n", "3043 | \n", "Ensemble gene id | \n", "Genome-scale metabolic model of human kidney_r... | \n", "
| human_model | \n", "1.1 | \n", "Homo sapiens | \n", "7002 | \n", "2993 | \n", "Ensemble gene id | \n", "Curated generic human metabolic model. | \n", "
| mouse_model | \n", "1.1 | \n", "Mus musculus | \n", "6942 | \n", "2759 | \n", "mouse gene symbols | \n", "Genome-scale metabolic model of mouse metabolism. | \n", "