{ "cells": [ { "cell_type": "markdown", "source": [ "# 3D spatial transcriptomics Interpolation\n", "\n", "This notebook demonstrates the process of continuous expression pattern learning in the 3D volume model. Spateo contains the following four interpolation methods:\n", "\n", "1. The methods (Shepard, Gaussian and Linear) contained in the VTK;\n", "2. A new Gaussian Process method;\n", "3. The SparseVFC method contained in the Dynamo;\n", "4. A new Deep Learning method." ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 1, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2023-07-26 17:47:26.236300: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n" ] } ], "source": [ "import warnings\n", "import numpy as np\n", "import spateo as st\n", "import dynamo as dyn\n", "warnings.filterwarnings(\"ignore\")" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-07-26T09:47:29.145712175Z", "start_time": "2023-07-26T09:47:24.555930910Z" } } }, { "cell_type": "markdown", "source": [ "## Load the data\n" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 3, "outputs": [ { "data": { "text/plain": "AnnData object with n_obs × n_vars = 25921 × 8136\n obs: 'area', 'slices', 'anno_cell_type', 'anno_tissue', 'anno_germ_layer', 'actual_stage', 'spliced_Size_Factor', 'initial_spliced_cell_size', 'counts_X_Size_Factor', 'initial_counts_X_cell_size', 'Size_Factor', 'initial_cell_size', 'unspliced_Size_Factor', 'initial_unspliced_cell_size'\n uns: 'pp', '__type'\n obsm: '3d_align_spatial'\n layers: 'counts_X', 'spliced', 'unspliced', 'X_spliced', 'X_counts_X', 'X_unspliced'" }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cpo = [(553, 1098, 277), (1.967, -6.90, -2.21), (0, 0, 1)]\n", "\n", "adata = st.sample_data.drosophila(filename=\"E7-9h_cellbin.h5ad\")\n", "adata.uns[\"pp\"] = {}\n", "adata.uns[\"__type\"] = \"UMI\"\n", "dyn.pp.normalize(adata)\n", "dyn.pp.log1p(adata)\n", "adata" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-07-26T09:48:35.761105108Z", "start_time": "2023-07-26T09:48:31.913264829Z" } } }, { "cell_type": "code", "execution_count": 4, "outputs": [], "source": [ "# Down-sampling\n", "from dynamo.tools import sample\n", "sampling = sample(arr=np.asarray(adata.obs_names), n=10000, method=\"random\", X=adata.obsm[\"3d_align_spatial\"])\n", "adata = adata[sampling, :]" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-07-26T09:48:35.767310710Z", "start_time": "2023-07-26T09:48:35.761308680Z" } } }, { "cell_type": "markdown", "source": [ "## Reconstruct the voxel model corresponding to the 3D spatial transcriptomics data\n", "\n", "See also [3D Reconstruction](./3D%20Reconstruction.ipynb) for more details on 3D reconstructed models." ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-07-25T03:22:58.137172476Z", "start_time": "2023-07-25T03:22:57.852003112Z" } }, "outputs": [ { "data": { "text/plain": "View of AnnData object with n_obs × n_vars = 10000 × 8136\n obs: 'area', 'slices', 'anno_cell_type', 'anno_tissue', 'anno_germ_layer', 'actual_stage', 'Size_Factor', 'initial_cell_size', 'counts_X_Size_Factor', 'initial_counts_X_cell_size', 'unspliced_Size_Factor', 'initial_unspliced_cell_size', 'spliced_Size_Factor', 'initial_spliced_cell_size'\n uns: 'pp', '__type'\n obsm: '3d_align_spatial'\n layers: 'counts_X', 'spliced', 'unspliced', 'X_counts_X', 'X_unspliced', 'X_spliced'" }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 4 }, { "cell_type": "code", "execution_count": 5, "outputs": [ { "data": { "text/plain": "UnstructuredGrid (0x7f000b693460)\n N Cells: 17237\n N Points: 18780\n X Bounds: -2.588e+02, 2.593e+02\n Y Bounds: -1.092e+02, 9.780e+01\n Z Bounds: -9.657e+01, 8.376e+01\n N Arrays: 0", "text/html": "\n
UnstructuredGrid | Information |
---|---|
N Cells | 17237 |
N Points | 18780 |
X Bounds | -2.588e+02, 2.593e+02 |
Y Bounds | -1.092e+02, 9.780e+01 |
Z Bounds | -9.657e+01, 8.376e+01 |
N Arrays | 0 |