{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# SPACEc: TissUUmaps for interactive visualization\n", "Interactive visualization via TissUUmaps might be informative during multiple steps of the analysis. Apart from the general function provided with the TissUUmaps Python package, we provide specific functions that automatically phrase the input during multiple steps of the analysis." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Instructions\n", "\n", "To use the TissUUmaps viewer you need:\n", "- A pickle file that contains the segmentation output and images \n", "- An AnnData object containing the currently used single cell data\n", "\n", "The *tm_prepare_input* function reads the named content for one region. For that, the user has to provide a region column and a region name. The pickle file has to match the specified region. \n", "The function creates a folder that contains all necessary input files that are needed to launch the TissUUmaps session. Additionally, the function can launch the TissUUmaps session. If the session is launched from the function a tmap file is created in the input directory that allows to open the session again (both from jupyter and the standalone viewer app).\n", "Alternatively, the function can be used to prepare the directory and the viewer can be launched separately to modify the display options in jupyter as well as host ports etc.\n", "\n", "If the Jupyter viewer is too small (might be a problem on small monitors), the user can use the link (displayed if function is executed) to display TissUUmaps in the browser. " ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# import spacec first\n", "import spacec as sp\n", "\n", "# silencing warnings\n", "import warnings\n", "warnings.filterwarnings('ignore')\n", "\n", "#import standard packages\n", "import os\n", "import scanpy as sc\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "# Specify the path to the data\n", "root_path = \"/home/user/path/SPACEc/\" # inset your own path\n", "\n", "data_path = root_path + 'example_data/raw/' # where the data is stored\n", "\n", "# where you want to store the output\n", "output_dir = root_path + 'example_data/output/'\n", "\n", "os.makedirs(output_dir, exist_ok=True)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "AnnData object with n_obs × n_vars = 46789 × 59\n", " obs: 'DAPI', 'x', 'y', 'area', 'region_num', 'unique_region', 'condition', 'leiden_1', 'leiden_1_subcluster', 'cell_type_coarse', 'cell_type_coarse_subcluster', 'cell_type_coarse_f', 'cell_type_coarse_f_subcluster', 'cell_type_coarse_f_f', 'cell_type', 'CN_k20_n40', 'CN_k20_n30', 'CN_k20_n20', 'CN_k20_n25', 'CN_k20_n6', 'CN_k20_n6_annot'\n", " uns: 'CN_k20_n6_colors', 'Centroid_k20_n20', 'Centroid_k20_n25', 'Centroid_k20_n30', 'Centroid_k20_n40', 'Centroid_k20_n6', 'cell_type_coarse_f_colors', 'cell_type_colors', 'dendrogram_cell_type_coarse_f_subcluster', 'leiden', 'leiden_1_colors', 'neighbors', 'ppa_result_100', 'ppa_result_150', 'ppa_result_200', 'ppa_result_250', 'ppa_result_50', 'triDist', 'triDist_keyname', 'umap', 'unique_region_colors'\n", " obsm: 'X_pca', 'X_umap'\n", " layers: 'scaled'\n", " obsp: 'connectivities', 'distances'" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# read in the annotated anndata\n", "adata = sc.read(output_dir + 'adata_nn_demo_annotated_cn.h5ad')\n", "adata" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | DAPI | \n", "x | \n", "y | \n", "area | \n", "region_num | \n", "unique_region | \n", "condition | \n", "leiden_1 | \n", "leiden_1_subcluster | \n", "cell_type_coarse | \n", "... | \n", "cell_type_coarse_f | \n", "cell_type_coarse_f_subcluster | \n", "cell_type_coarse_f_f | \n", "cell_type | \n", "CN_k20_n40 | \n", "CN_k20_n30 | \n", "CN_k20_n20 | \n", "CN_k20_n25 | \n", "CN_k20_n6 | \n", "CN_k20_n6_annot | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "105.993197 | \n", "4.986395 | \n", "1472.238095 | \n", "147.0 | \n", "1 | \n", "reg002 | \n", "tonsillitis | \n", "23 | \n", "23,1 | \n", "Neutrophil | \n", "... | \n", "Neutrophil | \n", "Neutrophil | \n", "Neutrophil | \n", "Neutrophil | \n", "5 | \n", "5 | \n", "5 | \n", "5 | \n", "5 | \n", "Marginal Zone B-DC-Enriched | \n", "
| 1 | \n", "123.677686 | \n", "5.359504 | \n", "1322.851240 | \n", "242.0 | \n", "1 | \n", "reg002 | \n", "tonsillitis | \n", "13 | \n", "13 | \n", "M2 Macrophage | \n", "... | \n", "M2 Macrophage | \n", "M2 Macrophage | \n", "M2 Macrophage | \n", "M2 Macrophage | \n", "1 | \n", "1 | \n", "1 | \n", "1 | \n", "1 | \n", "Marginal Zone | \n", "
| 2 | \n", "107.203125 | \n", "5.710938 | \n", "1506.226562 | \n", "256.0 | \n", "1 | \n", "reg002 | \n", "tonsillitis | \n", "23 | \n", "23,1 | \n", "Neutrophil | \n", "... | \n", "Neutrophil | \n", "Neutrophil | \n", "Neutrophil | \n", "Neutrophil | \n", "5 | \n", "5 | \n", "5 | \n", "5 | \n", "5 | \n", "Marginal Zone B-DC-Enriched | \n", "
| 3 | \n", "49.660959 | \n", "8.544521 | \n", "641.938356 | \n", "292.0 | \n", "1 | \n", "reg002 | \n", "tonsillitis | \n", "21 | \n", "21 | \n", "recluster | \n", "... | \n", "B cell | \n", "B cell | \n", "B cell | \n", "B cell | \n", "4 | \n", "4 | \n", "4 | \n", "4 | \n", "4 | \n", "Germinal Center | \n", "
| 4 | \n", "148.702532 | \n", "9.006329 | \n", "1303.702532 | \n", "158.0 | \n", "1 | \n", "reg002 | \n", "tonsillitis | \n", "12 | \n", "12,1 | \n", "recluster | \n", "... | \n", "CD4+ T cell | \n", "CD4+ T cell | \n", "CD4+ T cell | \n", "CD4+ T cell | \n", "1 | \n", "1 | \n", "1 | \n", "1 | \n", "1 | \n", "Marginal Zone | \n", "
5 rows × 21 columns
\n", "