{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 4. Improve Efficiency and Scalibity\n", "\n", "With advancements in biotechnology, the resolution of spatial transcriptomics (ST) has evolved from the spot level to single-cell and even subcellular levels, with a single slice containing from hundreds to 500,000 data points. This scale of data poses a significant challenge for computational tools. In this tutorial, we will introduce several methods that can significantly accelerate runtime and increase scalability for Spateo alignment. Specifically, Spateo incorporates GPU hardware acceleration, sparse computation, stochastic variational inference (SVI), inducing variables, and downsampling techniques. We believe these methods will enable Spateo to efficiently handle various types of data." ] }, { "cell_type": "code", "execution_count": 41, "metadata": { "execution": { "iopub.execute_input": "2024-11-11T00:41:39.938367Z", "iopub.status.busy": "2024-11-11T00:41:39.937810Z", "iopub.status.idle": "2024-11-11T00:41:40.024443Z", "shell.execute_reply": "2024-11-11T00:41:40.023945Z", "shell.execute_reply.started": "2024-11-11T00:41:39.938340Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running this notebook on: cuda\n", "Last run with spateo version: 1.1.0.dev30+084c763.dirty\n", "The autoreload extension is already loaded. To reload it, use:\n", " %reload_ext autoreload\n" ] } ], "source": [ "import os\n", "os.environ['CUDA_VISIBLE_DEVICES'] = '3'\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\n", "warnings.filterwarnings('ignore')\n", "import matplotlib.pyplot as plt\n", "import scanpy as sc\n", "import anndata as ad\n", "import numpy as np\n", "import time\n", "\n", "%config InlineBackend.print_figure_kwargs={'facecolor' : \"w\"}\n", "%config InlineBackend.figure_format='retina'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## About the Data\n", "\n", "In this tutorial, we will use several ST data with different resolution/cell number based on various techniques. You can download the processed data from the links below. Once downloaded, ensure that you place the data in the appropriate directory.\n", "\n", "- [SCC (squamous cell carcinoma) patient 9 slice #1](https://drive.google.com/file/d/1fPAxQl56-e8dP23M8RF9s2VZT884C2Rw/view?usp=drive_link)\n", "- [SCC (squamous cell carcinoma) patient 9 slice #2](https://drive.google.com/file/d/1fTax8motkn5nDEG3Iluu0RteXkKcobCI/view?usp=drive_link)\n", "- [Mouse embryo E9.5 (Stereo-Seq) slice #14](https://drive.google.com/file/d/1eqGjZ2vc11SQ2cuEzFTjA2eu7WpHy5Yd/view?usp=drive_link)\n", "- [Mouse embryo E9.5 (Stereo-Seq) slice #15](https://drive.google.com/file/d/1eyoZcYfZY-VlWIJnnHgeE0zdSTKQTWLC/view?usp=drive_link)\n", "- [Adult mouse brain (STARMap Plus) 20% overlap slice #1](https://drive.google.com/file/d/1fEPar7weOVzTShIXCNiI3gNHoMGpBkfi/view?usp=drive_link)\n", "- [Adult mouse brain (STARMap Plus) 20% overlap slice #2](https://drive.google.com/file/d/1fLiAFB8vKkbX4pFpZb-ISu2x7tk2ez_0/view?usp=drive_link)\n", "- [Drosophila (Stereo-Seq) E7-9h slice #16](https://drive.google.com/file/d/1eliFZnkVureDnvG0Gdz0ejxsmR2OD_Xh/view?usp=drive_link)\n", "- [Drosophila (Stereo-Seq) E7-9h slice #17](https://drive.google.com/file/d/1eksLSPKusw2H-b3y5ad-e4e69g1sLgUT/view?usp=drive_link)\n", "- [Adult mouse hemibrain (MERFISH) slice #78](https://drive.google.com/file/d/1efKb2GJU8pUAYSA4ueB375aj8RfacyZJ/view?usp=drive_link)\n", "- [Adult mouse hemibrain (MERFISH) slice #79](https://drive.google.com/file/d/1ef4eQHA3ywaIBUCkZL2ysyRDkjWa1qIS/view?usp=drive_link)\n", "- [Adult mouse brain cell atlas (MERFISH) slice #30](https://drive.google.com/file/d/1egO1ii_f_JT8EC0joFd9HWPPPvx5rJlR/view?usp=drive_link)\n", "- [Adult mouse brain cell atlas (MERFISH) slice #31](https://drive.google.com/file/d/1ejrSR7dezjbbpDFrhUPOs-Mx_fzaWK9E/view?usp=drive_link)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## GPU hardware acceleration\n", "\n", "If your device or server supports CUDA, you can leverage GPU parallel computing to significantly accelerate computational efficiency. By passing `device='cuda'` or `device='your GPU ID'` to `st.align.morpho_align`, you can enable GPU-based computation.\n", "\n", "