{ "cells": [ { "cell_type": "markdown", "id": "da313e0f-15a6-44a5-bf85-f27097cbd82b", "metadata": {}, "source": [ "# Characterizing Morphogenesis on Mouse Heart Organogenesis based on Gaussian Processes\n", "\n", "The formation of an embryo and constituent organs is characterized by a tightly regulated morphogenetic process.\n", "In this tutorial, you will learn how to predict each individual cell migrates over time based on two temporal snapshots of the mouse heart. Ultimately, this will allow you to connect macroscopic morphological changes with microscopic molecular expression dynamics in single cells across space." ] }, { "cell_type": "code", "execution_count": 4, "id": "30b55173-a1be-4226-9702-b6c012adde71", "metadata": { "execution": { "iopub.execute_input": "2024-12-02T22:39:31.660503Z", "iopub.status.busy": "2024-12-02T22:39:31.659927Z", "iopub.status.idle": "2024-12-02T22:39:34.728914Z", "shell.execute_reply": "2024-12-02T22:39:34.728376Z", "shell.execute_reply.started": "2024-12-02T22:39:31.660477Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running this notebook on: cuda\n", "Last run with spateo version: 1.1.0.dev44+cbea5b3.dirty\n" ] } ], "source": [ "import os\n", "os.environ['CUDA_VISIBLE_DEVICES'] = '0'\n", "\n", "import torch\n", "device = 'cuda' if torch.cuda.is_available() else 'cpu'\n", "print(\"Running this notebook on: \", device)\n", "\n", "import spateo as st\n", "print(\"Last run with spateo version:\", st.__version__)\n", "\n", "# Other imports\n", "import warnings, string\n", "import anndata as ad\n", "import dynamo as dyn\n", "import scanpy as sc\n", "import pandas as pd\n", "import numpy as np\n", "import matplotlib as mpl\n", "import matplotlib.pyplot as plt\n", "import seaborn as sns\n", "\n", "# Uncomment the following if running on the server\n", "import pyvista as pv\n", "pv.start_xvfb()\n", "\n", "sns.set_theme(context=\"paper\", style=\"ticks\", font_scale=1)\n", "warnings.filterwarnings('ignore')\n", "# %load_ext autoreload\n", "# %autoreload 2" ] }, { "cell_type": "code", "execution_count": 2, "id": "ccf2d6cf-c0c3-472e-b6cc-2a73733199d5", "metadata": { "execution": { "iopub.execute_input": "2024-12-02T22:39:17.300360Z", "iopub.status.busy": "2024-12-02T22:39:17.300095Z", "iopub.status.idle": "2024-12-02T22:39:17.350118Z", "shell.execute_reply": "2024-12-02T22:39:17.349631Z", "shell.execute_reply.started": "2024-12-02T22:39:17.300341Z" } }, "outputs": [], "source": [ "# initialize colormap\n", "lscmap = mpl.cm.get_cmap(\"vlag_r\")\n", "regions = [\"Left ventricle\", \"Right ventricle\", \"Outflow tract\", \"Right atrium\", \"Left atrium\"]\n", "regions_hex_list = [mpl.colors.to_hex(lscmap(i)) for i in np.linspace(0, 1, len(regions))]\n", "regions_colors = {i: j for i, j in zip(regions, regions_hex_list)}" ] }, { "cell_type": "markdown", "id": "e32b9c5e-a89e-42d7-9eb1-7db3b0797771", "metadata": {}, "source": [ "## Loading the Data\n", "\n", "In this tutorial, we will use the temporal data of mouse heart extracted from the two-time-point mouse embryo molecular holograms. You can download the raw data from [SpateoData](https://spateodata.aristoteleo.com/#mouse). After downloading, be sure to place the data in the appropriate directory." ] }, { "cell_type": "code", "execution_count": 6, "id": "93b92783-2bbe-48da-9035-e2a0b3faa44f", "metadata": { "execution": { "iopub.execute_input": "2024-12-02T22:44:20.174222Z", "iopub.status.busy": "2024-12-02T22:44:20.173853Z", "iopub.status.idle": "2024-12-02T22:44:39.252356Z", "shell.execute_reply": "2024-12-02T22:44:39.251788Z", "shell.execute_reply.started": "2024-12-02T22:44:20.174198Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "View of AnnData object with n_obs × n_vars = 19780 × 12163\n", " obs: 'area', 'n_genes_by_counts', 'total_counts', 'total_counts_mt', 'pct_counts_mt', 'n_counts', 'louvain', 'cellbin_SpatialDomain', 'slices', 'reclustering', 'heart_anno', 'heart_regions', 'stage', '3d_spatial_density_heart_regions'\n", " obsm: '3d_align_spatial', 'aligned_spatial_3D', 'aligned_spatial_3D_mm', 'aligned_spatial_3D_new'\n", " layers: 'total' View of AnnData object with n_obs × n_vars = 98966 × 17869\n", " obs: 'ctype_user', 'cml', 'slices', 'heart_anno', 'heart_regions', 'stage', '3d_spatial_density_heart_regions'\n", " obsm: '3d_align_spatial', 'aligned_spatial_3D', 'aligned_spatial_3D_mm', 'aligned_spatial_3D_new'\n", " layers: 'total'\n" ] } ], "source": [ "E95_adata = st.read_h5ad(f\"./data/mouse_E9.5_heart.h5ad\")\n", "# remove some useless genes\n", "E95_adata = E95_adata[:, ~E95_adata.var.index.str.endswith('Rik')]\n", "E95_adata = E95_adata[:, ~E95_adata.var.index.str.endswith('Rik8')]\n", "E95_adata = E95_adata[:, ~E95_adata.var.index.str.startswith('Gm')]\n", "E95_adata = E95_adata[:, ~E95_adata.var.index.str.startswith('a')]\n", "for letter1 in string.ascii_uppercase:\n", " for letter2 in string.ascii_uppercase:\n", " E95_adata = E95_adata[:, ~E95_adata.var.index.str.startswith(f'{letter1}{letter2}')]\n", " \n", "E115_adata = st.read_h5ad(f\"./data/mouse_E11.5_heart.h5ad\")\n", "# remove some useless genes\n", "E115_adata = E115_adata[:, ~E115_adata.var.index.str.endswith('Rik')]\n", "E115_adata = E115_adata[:, ~E115_adata.var.index.str.endswith('Rik8')]\n", "E115_adata = E115_adata[:, ~E115_adata.var.index.str.startswith('Gm')]\n", "E115_adata = E115_adata[:, ~E115_adata.var.index.str.startswith('a')]\n", "for letter1 in string.ascii_uppercase:\n", " for letter2 in string.ascii_uppercase:\n", " E115_adata = E115_adata[:, ~E115_adata.var.index.str.startswith(f'{letter1}{letter2}')]\n", "print(E95_adata, E115_adata)" ] }, { "cell_type": "markdown", "id": "625de2c9-8c44-4eab-be01-29f01e4ce48d", "metadata": {}, "source": [ "Let’s visualize the 3D temporal structure of the mouse heart." ] }, { "cell_type": "markdown", "id": "c5443fc0-464e-4722-ba5d-f6f16b3f5f5a", "metadata": {}, "source": [ "