### Check Installation Status Source: https://spatialscope-tutorial.readthedocs.io/en/latest/installation.html Commands to verify the installation by checking the help message of the Cell_Type_Identification script. ```bash $ python ./src/Cell_Type_Identification.py -h # or directly if `python setup.py develop` has been run $ Cell_Type_Identification.py -h ``` -------------------------------- ### Clone Repository and Set Up Environment Source: https://spatialscope-tutorial.readthedocs.io/en/latest/installation.html Commands to clone the SpatialScope repository, create and activate a conda environment, install the package in develop mode, and apply a fix for squidpy. ```bash $ git clone https://github.com/YangLabHKUST/SpatialScope.git $ cd SpatialScope $ conda env create -f environment.yml $ conda activate SpatialScope $ python setup.py develop # fix bug of squidpy $ rsync ./src/_feature_mixin.py ~/.conda/envs/SpatialScope/lib/python3.9/site-packages/squidpy/im/_feature_mixin.py ``` -------------------------------- ### Step 3: Gene expression decomposition Source: https://spatialscope-tutorial.readthedocs.io/en/latest/usage.html Command for gene expression decomposition, utilizing a pre-trained model and specifying GPU resources. ```bash python ./src/Decomposition.py --tissue heart --out_dir ./output --SC_Data ./Ckpts_scRefs/Heart_D2/Ref_Heart_sanger_D2.h5ad --cell_class_column cell_type --ckpt_path ./Ckpts_scRefs/Heart_D2/model_5000.pt --spot_range 0,100 --gpu 0,1,2,3 ``` -------------------------------- ### Step 2: Cell type identification Source: https://spatialscope-tutorial.readthedocs.io/en/latest/usage.html Command to identify cell types using segmented nuclei data and a single-cell reference dataset. ```bash python ./src/Cell_Type_Identification.py --tissue heart --out_dir ./output --ST_Data ./output/heart/sp_adata_ns.h5ad --SC_Data ./Ckpts_scRefs/Heart_D2/Ref_Heart_sanger_D2.h5ad --cell_class_column cell_type ``` -------------------------------- ### Step 1: Nuclei segmentation Source: https://spatialscope-tutorial.readthedocs.io/en/latest/usage.html Command to perform nuclei segmentation. It requires paths to spatial data, image data, and an output directory. ```bash python ./src/Nuclei_Segmentation.py --tissue heart --out_dir ./output --ST_Data ./demo_data/V1_Human_Heart_spatial.h5ad --Img_Data ./demo_data/V1_Human_Heart_image.tif ``` -------------------------------- ### Get MERFISH data shape Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-MOp-MERFISH.html This code snippet displays the shape of the preprocessed MERFISH data. ```python ad_sp.shape ``` -------------------------------- ### Load Initial Proportions Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Cerebellum-Slideseq.html Loads initial proportion data from a pickle file. ```python with open('../output/cere/InitProp.pickle', 'rb') as handle: InitProp = pickle.load(handle) ``` -------------------------------- ### Cellular Communications - Representative Example 3 Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Cerebellum-Slideseq.html Plots the interaction between 'Nlgn2' and 'Nrxn3' genes in 'Granule' and 'Purkinje' cell types, respectively. ```python L_gene,R_gene,L_ct,R_ct = 'Nlgn2','Nrxn3','Granule','Purkinje' fig, ax = plt.subplots(1, 1, figsize=(10.2, 8),dpi=100,facecolor='#fafafa') PlotLRGenes(ad_scst,L_gene,R_gene,L_ct,R_ct,title='${}$'.format(L_gene+'-'+R_gene),ax=ax,invertY=False,s=20) ``` -------------------------------- ### Cellular Communications - Representative Example 2 Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Cerebellum-Slideseq.html Plots the interaction between 'Mdk' and 'Ptprz1' genes in 'Bergmann' and 'Granule' cell types, respectively. ```python L_gene,R_gene,L_ct,R_ct = 'Mdk','Ptprz1','Bergmann','Granule' fig, ax = plt.subplots(1, 1, figsize=(10.2, 8),dpi=100,facecolor='#fafafa') PlotLRGenes(ad_scst,L_gene,R_gene,L_ct,R_ct,title='${}$'.format(L_gene+'-'+R_gene),ax=ax,invertY=False,s=20) ``` -------------------------------- ### Cellular Communications - Representative Example 1 Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Cerebellum-Slideseq.html Plots the interaction between 'Apoe' and 'Sorl1' genes in 'MLI2' and 'Purkinje' cell types, respectively. ```python L_gene,R_gene,L_ct,R_ct = 'Apoe','Sorl1','MLI2','Purkinje' fig, ax = plt.subplots(1, 1, figsize=(10.2, 8),dpi=100,facecolor='#fafafa') PlotLRGenes(ad_scst,L_gene,R_gene,L_ct,R_ct,title='${}$'.format(L_gene+'-'+R_gene),ax=ax,invertY=False,s=10) ``` -------------------------------- ### Training scRNA-seq Reference Model Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html This command initiates the training of a score-based model for scRNA-seq reference data, utilizing multiple GPUs for parallel processing. ```bash python ./src/Train_scRef.py \ --ckpt_path ./Ckpts_scRefs/VISp \ --scRef ./Ckpts_scRefs/VISp/Ref_scRNA_VISp_qc2_2Kgenes.h5ad \ --cell_class_column cell_subclass \ --gpus 0,1,2,3 ``` -------------------------------- ### Import necessary libraries Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Imports common Python libraries for data manipulation, plotting, and scientific computing, along with custom utilities. ```python import numpy as np import pandas as pd import pathlib import matplotlib.pyplot as plt import matplotlib as mpl import seaborn as sns import scanpy as sc import sys sys.path.append('../src') from utils import * import warnings warnings.filterwarnings('ignore') ``` -------------------------------- ### Import PASTE and related libraries Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Imports the PASTE library for spatial alignment and other necessary scientific computing libraries. ```python import paste as pst from scipy.spatial.distance import pdist import matplotlib.patches as mpatches ``` -------------------------------- ### Get statistical significance of gene pair expression changes upon cell-cell interaction Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Human-Heart-CCell-interaction.html This code snippet calculates the statistical significance of gene pair expression changes considering spatial interactions between cells. ```R spatial_all_scores = spatCellCellcom(my_giotto_object, spatial_network_name = 'Delaunay_network', cluster_column = 'cell_types', random_iter = 500, gene_set_1 = select_ligands, gene_set_2 = select_receptors, adjust_method = 'fdr', do_parallel = T, cores = 4, verbose = 'none') ``` -------------------------------- ### Running SpatialScope Gene Expression Decomposition Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html These commands execute the gene expression decomposition step of the SpatialScope pipeline, processing different ranges of spots and utilizing specified GPUs. ```bash python ./src/Decomposition.py --tissue cortex --out_dir ./output --SC_Data ./Ckpts_scRefs/VISp/Ref_scRNA_VISp_qc2_2Kgenes.h5ad --cell_class_column cell_subclass --ckpt_path ./Ckpts_scRefs/VISp/model_5000.pt --spot_range 0,500 --gpu 2,3,4,8 python ./src/Decomposition.py --tissue cortex --out_dir ./output --SC_Data ./Ckpts_scRefs/VISp/Ref_scRNA_VISp_qc2_2Kgenes.h5ad --cell_class_column cell_subclass --ckpt_path ./Ckpts_scRefs/VISp/model_5000.pt --spot_range 500,1000 --gpu 2,3,4,8 python ./src/Decomposition.py --tissue cortex --out_dir ./output --SC_Data ./Ckpts_scRefs/VISp/Ref_scRNA_VISp_qc2_2Kgenes.h5ad --cell_class_column cell_subclass --ckpt_path ./Ckpts_scRefs/VISp/model_5000.pt --spot_range 1000,1715 --gpu 1,2,4,8 ``` -------------------------------- ### Loading Data Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Loads two .h5ad files, slice1 and slice2, which have undergone nuclei segmentation. ```python slice1 = sc.read(slice1_file) slice2 = sc.read(slice2_file) ``` -------------------------------- ### Get statistical significance of gene pair expression changes based on expression Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Human-Heart-CCell-interaction.html This code snippet calculates the statistical significance of gene pair expression changes based solely on expression levels within cell clusters. ```R expr_only_scores = exprCellCellcom(gobject = my_giotto_object, cluster_column = 'cell_types', random_iter = 500, gene_set_1 = select_ligands, gene_set_2 = select_receptors) ``` -------------------------------- ### Loading and Preprocessing Slice 2 Data Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Loads the AnnData object for 'slice2' and applies an exponential transformation to its expression matrix. ```python slice2_file = '../demo_data/Visium_MouceBrain_Cortex_section2.h5ad' slice2 = sc.read(slice2_file) slice2.X = np.exp(slice2.X.A)-1 ``` -------------------------------- ### Initialize ImageContainer Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Human-Heart.html Loads the human heart image into an ImageContainer for spatial analysis. ```python import squidpy as sq image = plt.imread('../demo_data/V1_Human_Heart_image.tif') img = sq.im.ImageContainer(image) ``` -------------------------------- ### Load and preprocess scRNA-seq reference data Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Loads a scRNA-seq reference dataset, filters it for the 'VISp' region and specific cell subclasses, and prepares it for downstream analysis. ```python ad_sc = sc.read('adata_processed_sc.h5ad') ad_sc = ad_sc[ad_sc.obs['dissected_region']=='VISp'] ad_sc = ad_sc[ad_sc.obs['cell_subclass']!='nan'] ad_sc = ad_sc[ad_sc.obs['cell_subclass']!='No Class'] ad_sc.obs['cell_subclass'] = ad_sc.obs['cell_subclass'].astype(str) ad_sc.obs.loc[ad_sc.obs.cell_subclass=='NP','cell_subclass'] = 'L5 NP' cell_type_column = 'cell_subclass' ad_sc.X.max(),ad_sc.shape ``` -------------------------------- ### Stack slices pairwise Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Stacks slices pairwise after alignment. ```python slices, pis = [slice1, slice2], [pi12] new_slices = pst.stack_slices_pairwise(slices, pis) ``` -------------------------------- ### Create Giotto Object Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Human-Heart-CCell-interaction.html Initializes a Giotto object with raw expression data, spatial locations, cell metadata, and Python path for instructions. ```R my_instructions = createGiottoInstructions(python_path='/home/xwanaf/.conda/envs/rbayes/bin/python') my_giotto_object = createGiottoObject(raw_exprs = path_to_matrix, spatial_locs = path_to_locations, cell_metadata = my_cell_metadata, instructions = my_instructions) my_giotto_object@cell_metadata$cell_types <- my_giotto_object@cell_metadata$V1 ``` -------------------------------- ### Load sampled cells and initialize plotting Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Human-Heart.html Loads sampled cells using scRef and sets up plotting context. ```python sampled_cells = sc.read('../Ckpts_scRefs/Heart_D2/model_5000.h5ad') # 2K cells sampled from the learned gene expression distribution of scRef cell_type_key='cell_type' sns.set_context('paper',font_scale=1.5) ada_all = PlotSampledData(sampled_cells,ad_sc,cell_type_key,palette=color_dict) ``` -------------------------------- ### Import Libraries Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-MOp-MERFISH.html Imports necessary Python libraries for data analysis and visualization, including scanpy, numpy, pandas, and matplotlib. ```python import numpy as np import pandas as pd import pathlib import matplotlib.pyplot as plt import matplotlib as mpl import seaborn as sns import scanpy as sc import pickle import sys sys.path.append('../src') from utils import * import warnings warnings.filterwarnings('ignore') ``` -------------------------------- ### Writing AnnData to File Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Saves the processed AnnData object to a HDF5 file. ```python slice_3D.write('../output/cortex/sp_adata_ns.h5ad') ``` -------------------------------- ### Run Cell Type Identification Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html This command executes the cell type identification script with specified parameters for the cortex dataset. ```bash ./src/Cell_Type_Identification.py --tissue cortex --out_dir ./output --ST_Data ./output/cortex/sp_adata_ns.h5ad --SC_Data ./Ckpts_scRefs/VISp/Ref_scRNA_VISp_qc2_2Kgenes.h5ad --cell_class_column cell_subclass --nu 15 ``` -------------------------------- ### Import Libraries Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Human-Heart.html Imports necessary Python libraries for data analysis and visualization, including numpy, pandas, matplotlib, seaborn, and scanpy. ```python import numpy as np import pandas as pd import pathlib import matplotlib.pyplot as plt import matplotlib as mpl import seaborn as sns import scanpy as sc import sys sys.path.append('../src') from utils import * import warnings warnings.filterwarnings('ignore') ``` -------------------------------- ### Prepare slices for alignment Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html This code snippet prepares two slices, slice1 and slice2, for alignment by modifying their index and cell_locations attributes. It ensures that the names are unique and appends slice identifiers to them. ```python slice1.obs.index = ['slice1-'+_ for _ in slice1.obs.index] slice2.obs.index = ['slice2-'+_ for _ in slice2.obs.index] slice1.uns['cell_locations']['slice_index'] = 'slice1' slice2.uns['cell_locations']['slice_index'] = 'slice2' slice1.uns['cell_locations']['spot_index'] = slice1.uns['cell_locations']['spot_index'].map(lambda x:'slice1-'+x) slice2.uns['cell_locations']['spot_index'] = slice2.uns['cell_locations']['spot_index'].map(lambda x:'slice2-'+x) slice1.uns['cell_locations']['cell_index'] = slice1.uns['cell_locations']['cell_index'].map(lambda x:'slice1-'+x) slice2.uns['cell_locations']['cell_index'] = slice2.uns['cell_locations']['cell_index'].map(lambda x:'slice2-'+x) slice1.obs_names_make_unique() slice2.obs_names_make_unique() slice1.var_names_make_unique() slice2.var_names_make_unique() ``` -------------------------------- ### Load Visium Data Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Loads two sections of Visium mouse brain cortex data using scanpy. ```python slice1_file = '../demo_data/Visium_MouseBrain_Cortex_section1.h5ad' slice2_file = '../demo_data/Visium_MouseBrain_Cortex_section2.h5ad' slice1 = sc.read(slice1_file) slice2 = sc.read(slice2_file) ``` -------------------------------- ### Train scRNA-seq reference model Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-MOp-MERFISH.html This command trains a scRNA-seq reference model using four GPUs. The checkpoints and sampled pseudo-cells will be saved in the specified ckpt_path. ```bash python ./src/Train_scRef.py \ --ckpt_path ./Ckpts_scRefs/MOp \ --scRef ./Ckpts_scRefs/MOp/Ref_snRNA_mop_qc3_2Kgenes.h5ad \ --cell_class_column subclass_label \ --gpus 0,1,2,3 ``` -------------------------------- ### Data Preparation for Visualization Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Extracts x, y, z coordinates for cells from two different slices and assigns them to separate variables. ```python xyz1 = celltype_res.loc[celltype_res['slice_index']=='slice1',['x','y','z']].values xyz2 = celltype_res.loc[celltype_res['slice_index']=='slice2',['x','y','z']].values x1,y1,z1 = xyz1[:,0],xyz1[:,1],xyz1[:,2] x2,y2,z2 = xyz2[:,0],xyz2[:,1],xyz2[:,2] ``` -------------------------------- ### Load Libraries Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Human-Heart-CCell-interaction.html Loads the necessary Giotto and data.table libraries. ```R library(Giotto) library(data.table) ``` -------------------------------- ### Load spatial transcriptomics slices Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Loads two slices of Visium Mouse Brain Cortex data for alignment. ```python slice1_file = '../demo_data/Visium_MouseBrain_Cortex_section1.h5ad' slice2_file = '../demo_data/Visium_MouseBrain_Cortex_section2.h5ad' ``` -------------------------------- ### Log transform and perform PCA Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Applies log transformation to the data and performs Principal Component Analysis (PCA). ```python sc.pp.log1p(ad_sc) sc.pp.pca(ad_sc,svd_solver='arpack', n_comps=30, use_highly_variable=True) ad_sc.X.max() ``` -------------------------------- ### Plot Visium Cells for Slice 2 Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Generates a visualization of cells in slice2, colored by their identified cell type. ```python fig, ax = plt.subplots(1,1,figsize=(10, 8),dpi=130) PlotVisiumCells(slice2,"discrete_label_ct",size=0.4,alpha_img=0.1,lw=0.7,palette=color_dict,ax=ax) ``` -------------------------------- ### Compute neighbors and UMAP Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Calculates the neighborhood graph and performs Uniform Manifold Approximation and Projection (UMAP) for visualization. ```python sc.pp.neighbors(ad_sc, metric='cosine', n_neighbors=30, n_pcs = 30) sc.tl.umap(ad_sc, min_dist = 0.3, spread = 1, maxiter=100) ``` -------------------------------- ### Import Libraries Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Cerebellum-Slideseq.html Imports necessary Python libraries for data manipulation, plotting, and single-cell analysis. ```python import numpy as np import pandas as pd import pathlib import matplotlib.pyplot as plt import matplotlib as mpl import seaborn as sns import scanpy as sc import sys sys.path.append('../src') from utils import * import pickle import warnings warnings.filterwarnings('ignore') ``` -------------------------------- ### Load and Preprocess scRNA-seq Reference Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Human-Heart.html Loads the raw scRNA-seq data, filters cells and genes based on quality metrics, selects a specific donor, and samples cells to balance cell type representation. ```python ad_sc = sc.read('global_raw.h5ad') ad_sc = ad_sc[ad_sc.obs['cell_type']!='doublets'] ad_sc = ad_sc[ad_sc.obs['cell_type']!='NotAssigned'] ad_sc = ad_sc[ad_sc.obs['cell_type']!='Mesothelial'] ad_sc = ad_sc[ad_sc.obs['cell_source']=='Sanger-Nuclei'] cell_type_column = 'cell_type' sc.pp.filter_cells(ad_sc, min_counts=500) sc.pp.filter_cells(ad_sc, max_counts=20000) sc.pp.filter_genes(ad_sc, min_cells=5) ad_sc = ad_sc[:,~np.array([_.startswith('MT-') for _ in ad_sc.var.index])] ad_sc = ad_sc[:,~np.array([_.startswith('mt-') for _ in ad_sc.var.index])] ad_sc = ad_sc[ad_sc.obs['donor']=='D2'].copy() # reduce batch effect among doners ad_sc = ad_sc[ad_sc.obs.index.isin(ad_sc.obs.groupby('cell_type').apply( lambda x: x.sample(frac=3000/x.shape[0],replace=False) if x.shape[0]>3000 else x).reset_index(level=0,drop=True).index)].copy() ad_sc.X.max(),ad_sc.shape ``` -------------------------------- ### Plot aligned slices Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Plots the aligned slices with specified colors and legend. ```python slice_colors = ['#e41a1c','#377eb8'] slice_colors = ['teal', 'orange'] slice_colors = ['#377eb8', 'orange'] plt.figure(figsize=(11,7)) for i in range(len(new_slices)): pst.plot_slice(new_slices[i],slice_colors[i],s=350) plt.legend(handles=[mpatches.Patch(color=slice_colors[0], label='Cortex slice 1'),mpatches.Patch(color=slice_colors[1], label='Cortex slice 2')], fontsize=29,bbox_to_anchor=(.96,.72)) plt.gca().invert_yaxis() plt.axis('off') plt.show() ``` -------------------------------- ### Write AnnData to File Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Human-Heart.html Saves the processed AnnData object to a .h5ad file. ```python ad_scst_crop.write('../demo_data/human_heart_ROI_generated_cells.h5ad') ``` -------------------------------- ### Train scRNA-seq reference model Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Human-Heart.html Command to train a scRNA-seq reference model using four GPUs. It specifies checkpoint path, reference data, cell class column, and training parameters like sigma values and learning rate step. ```python python ./src/Train_scRef.py \ --ckpt_path ./Ckpts_scRefs/Heart_D2 \ --scRef ./Ckpts_scRefs/Heart_D2/Ref_Heart_sanger_D2.h5ad \ --cell_class_column cell_type \ --gpus 0,1,2,3 \ --sigma_begin 50 --sigma_end 0.002 --step_lr 3e-7 ``` -------------------------------- ### Plot Visium Cells for Slice 1 Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Generates a visualization of cells in slice1, colored by their identified cell type. ```python fig, ax = plt.subplots(1,1,figsize=(10, 8),dpi=130) PlotVisiumCells(slice1,"discrete_label_ct",size=0.4,alpha_img=0.1,lw=0.7,palette=color_dict,ax=ax) ``` -------------------------------- ### Load Human Heart Data Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Human-Heart.html Loads the human heart dataset from a specified H5AD file. ```python ad_scst_crop = sc.read('../demo_data/human_heart_ROI_generated_cells.h5ad') ``` -------------------------------- ### Define Color Dictionary for Cell Types Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html A dictionary mapping cell type names to specific colors for visualization. ```python color_dict = {'Astro': '#1f77b4', 'CR': '#aec7e8', 'Endo': '#ffbb78', 'L2/3 IT': '#ff7f0e', 'L4': '#2ca02c', 'L5 IT': '#bcbd22', 'L5 NP': '#d62728', 'L5 PT': '#ff9896', 'L6 CT': '#17becf', 'L6 IT': '#c5b0d5', 'L6b': '#8c564b', 'Lamp5': '#c49c94', 'Macrophage': '#e377c2', 'Meis2': '#f7b6d2', 'Oligo': '#7f7f7f', 'Peri': '#c7c7c7', 'Pvalb': '#98df8a', 'SMC': '#dbdb8d', 'Serpinf1': '#9467bd', 'Sncg': '#9edae5', 'Sst': '#82A8CE', 'VLMC': '#B87BCE', 'Vip': '#3FC241'} ``` -------------------------------- ### Plotting Visium Cells for Slice 2 Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Generates a plot of Visium cells for slice2, visualizing cell numbers with specified parameters. ```python fig, ax = plt.subplots(1,1,figsize=(12, 6),dpi=100) PlotVisiumCells(slice2,"cell_nums",0.23,0.35,0.3,ax=ax) ``` -------------------------------- ### Display Cell Locations Head Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Displays the first few rows of the cell locations DataFrame for slice1. ```python slice1.uns['cell_locations'].head() ``` -------------------------------- ### Crop and display image section Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Human-Heart.html Crops a specific corner of the image and displays it channel-wise. ```python crop = img.crop_corner(0, 0) crop.show(channelwise=True,layer='image') ``` -------------------------------- ### Incorporate ligand-receptor genes and update markers Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Adds ligand-receptor genes to the list of markers and updates the 'Marker' and 'highly_variable' attributes in the AnnData object. ```python ligand_recept = list(set(pd.read_csv('../extdata/ligand_receptors.txt',sep=' ').melt()['value'].values)) # if scRNA-seq reference is from human tissue, run following code to make gene name consistent # ligand_recept = [_.upper() for _ in ligand_recept] markers = markers+ligand_recept ad_sc.var.loc[ad_sc.var.index.isin(markers),'Marker'] = True ad_sc.var['Marker'] = ad_sc.var['Marker'].fillna(False) ad_sc.var['highly_variable'] = ad_sc.var['Marker'] ``` -------------------------------- ### Original spatial coordinates Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Displays the original spatial coordinates of slice1. ```python slice1.obsm['spatial'] ``` -------------------------------- ### Visualize UMAP projection Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Generates a UMAP plot colored by cell subclass to visualize the clustering of cell types. ```python fig, axs = plt.subplots(1, 1, figsize=(10, 10)) sc.pl.umap( ad_sc, color=cell_type_column, size=10, frameon=False, show=False, ax=axs,legend_loc='on data' ) plt.tight_layout() ``` -------------------------------- ### Loading and Concatenating ST Data Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Loads multiple AnnData objects representing different slices of mouse brain ST data and concatenates them into a single object. It then filters for data from 'slice2'. ```python ad_scsts_list = [] ad_scsts_list.append(sc.read('../output/cortex/generated_cells_spot0_500.h5ad')) ad_scsts_list.append(sc.read('../output/cortex/generated_cells_spot500_1000.h5ad')) ad_scsts_list.append(sc.read('../output/cortex/generated_cells_spot1000_1715.h5ad')) ad_scsts = ad_scsts_list[0].concatenate( ad_scsts_list[1:], batch_key="_", uns_merge="unique", index_unique=None ) ad_scst_slice2 = ad_scsts[ad_scsts.obs.slice_index=='slice2'] ``` -------------------------------- ### Plotting Visium Cells for Slice 1 Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Generates a plot of Visium cells for slice1, visualizing cell numbers with specified parameters. ```python fig, ax = plt.subplots(1,1,figsize=(12, 6),dpi=100) PlotVisiumCells(slice1,"cell_nums",0.23,0.35,0.3,ax=ax) ``` -------------------------------- ### Displaying Cell Locations Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Displays the head of the 'cell_locations' DataFrame from slice1, showing spatial coordinates and cell indices. ```python slice1.uns['cell_locations'].head() ``` -------------------------------- ### Plotting Sampled Data from scRef and Pseudo-cells Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html This code snippet visualizes sampled pseudo-cells against the scRNA-seq reference data, using a specified cell type key and color palette. ```python ad_sc = sc.read('../Ckpts_scRefs/VISp/Ref_scRNA_VISp_qc2_2Kgenes.h5ad') sampled_cells = sc.read('../Ckpts_scRefs/VISp/model_5000.h5ad') # 2K cells sampled from the learned gene expression distribution of scRef cell_type_key='cell_subclass' sns.set_context('paper',font_scale=1.5) adata_all = PlotSampledData(sampled_cells,ad_sc,cell_type_key,palette=color_dict) ``` -------------------------------- ### Benchmarking imputation accuracy Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-MOp-MERFISH.html Shell script to run the decomposition script for benchmarking imputation accuracy across different spot ranges. ```bash set -ex; declare -a arr=("0,1000" "1000,2000" "2000,3000" "3000,4000" "4000,5000" "5000,5551") for i in "${arr[@]}" doprint python ./src/Decomposition.py –tissue merfish –out_dir ./output –SC_Data ./Ckpts_scRefs/MOp/Ref_snRNA_mop_qc3_2Kgenes.h5ad –cell_class_column subclass_label –ckpt_path ./Ckpts_scRefs/MOp/model_5000.pt –spot_range $i –replicates 5 –leave_out_test –test_genes Cux2,Otof,Rorb,Rspo1,Sulf2,Fezf2,Osr1 –gpu 2,3,4,8 done ``` -------------------------------- ### Visualize UMAP by Cell States Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Human-Heart.html Generates a UMAP visualization colored by 'cell_states' to explore potential sub-populations or states within the cell types. ```python fig, axs = plt.subplots(1, 1, figsize=(10, 10)) sc.pl.umap( ad_sc, color="cell_states", size=10, frameon=False, show=False, ax=axs,legend_loc='on data' ) plt.tight_layout() ``` -------------------------------- ### Data Transformation and Visualization Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-MOp-MERFISH.html Applies exponential transformation if necessary and visualizes the distribution of total counts per cell. ```python if ad_sc.X.max()<20: ad_sc.X = np.exp(ad_sc.X)-1 plt.hist(ad_sc.X.sum(1),bins=100) plt.show() ``` -------------------------------- ### Identify highly variable and marker genes Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Identifies highly variable genes and cell type marker genes, combining them for further analysis. ```python sc.pp.highly_variable_genes(ad_sc, flavor='seurat_v3',n_top_genes=1000) ad_sc.uns['log1p'] = {} ad_sc.uns['log1p']['base'] = None sc.tl.rank_genes_groups(ad_sc, groupby=cell_type_column, method='wilcoxon') markers_df = pd.DataFrame(ad_sc.uns["rank_genes_groups"]["names"]).iloc[0:30, :] markers = list(np.unique(markers_df.melt().value.values)) markers = list(set(ad_sc.var.loc[ad_sc.var['highly_variable']==1].index)|set(markers)) # highly variable genes + cell type marker genes len(markers) ``` -------------------------------- ### Display Cell Type Results Head Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Displays the first few rows of the cell type results DataFrame. ```python celltype_res.head() ``` -------------------------------- ### Plotting Visium Cells Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html This code snippet visualizes Visium cells from a spatial transcriptomics slice, subsetting by a specific cell class and using a defined color palette. ```python fig, ax = plt.subplots(1,1,figsize=(10, 8),dpi=130) l_class = ['L4']#, 'L6 CT', 'L6b'] PlotVisiumCells(slice2,"discrete_label_ct",size=0.7,alpha_img=0.1,lw=0.7,subset=l_class,palette=color_dict,ax=ax) ``` -------------------------------- ### Load and process ligand-receptor data Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Human-Heart-CCell-interaction.html This code snippet loads mouse ligand-receptor data, processes it to identify detected ligands and receptors in the dataset, and selects them for further analysis. ```R LR_data = data.table::fread(system.file("extdata", "mouse_ligand_receptors.txt", package = 'Giotto')) LR_data$L_upper = toupper(LR_data$mouseLigand) LR_data$R_upper = toupper(LR_data$mouseReceptor) LR_data[, ligand_det := ifelse(L_upper %in% my_giotto_object@gene_ID, T, F)] LR_data[, receptor_det := ifelse(R_upper %in% my_giotto_object@gene_ID, T, F)] LR_data_det = LR_data[ligand_det == T & receptor_det == T] select_ligands = LR_data_det$L_upper select_receptors = LR_data_det$R_upper ``` -------------------------------- ### Gene expression decomposition (first 1000 spots) Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Human-Heart.html Command to perform gene expression decomposition for the first 1000 spots, specifying tissue, output directory, single-cell data, checkpoint path, spot range, and GPUs. ```python python ./src/Decomposition.py --tissue heart --out_dir ./output --SC_Data ./Ckpts_scRefs/Heart_D2/Ref_Heart_sanger_D2.h5ad --cell_class_column cell_type --ckpt_path ./Ckpts_scRefs/Heart_D2/model_5000.pt --spot_range 0,1000 --gpu 0,1,2,3 ``` -------------------------------- ### Comparing Max Expression Values Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Compares the maximum expression values between the preprocessed 'slice2' data and the filtered 'ad_scst_slice2' data. ```python slice2.X.max(),ad_scst_slice2.X.max() ``` -------------------------------- ### Gene expression decomposition (spots 1000-2000) Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Human-Heart.html Command to perform gene expression decomposition for spots 1000 to 2000. ```python python ./src/Decomposition.py --tissue heart --out_dir ./output --SC_Data ./Ckpts_scRefs/Heart_D2/Ref_Heart_sanger_D2.h5ad --cell_class_column cell_type --ckpt_path ./Ckpts_scRefs/Heart_D2/model_5000.pt --spot_range 1000,2000 --gpu 0,1,2,3 ``` -------------------------------- ### Aligned spatial coordinates Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Displays the aligned spatial coordinates of slice1. ```python slice1.obsm['spatial_align'] ``` -------------------------------- ### Load AnnData object Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-MOp-MERFISH.html Loads the spatial data from a specified HDF5 file into an AnnData object. ```python ad_sp = sc.read('../output/merfish/sp_adata.h5ad') ``` -------------------------------- ### Plotting Visium Cells (L6 CT subset) Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Similar to the previous snippet, this visualizes Visium cells but subsets for the 'L6 CT' cell class. ```python fig, ax = plt.subplots(1,1,figsize=(10, 8),dpi=130) l_class = ['L6 CT']#, 'L6 CT', 'L6b'] PlotVisiumCells(slice2,"discrete_label_ct",size=0.7,alpha_img=0.1,lw=0.7,subset=l_class,palette=color_dict,ax=ax) ``` -------------------------------- ### Combine aligned cell locations Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Combines the aligned cell locations from slice1 and slice2. ```python spatial_align = np.vstack((slice1.obsm['spatial_align'],slice2.obsm['spatial_align'])) cell_locations_align = slice1.uns['cell_locations'].append(slice2.uns['cell_locations']).reset_index(drop=True) ``` -------------------------------- ### Prepare data for cell-cell interaction analysis Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Human-Heart.html Saves the expression matrix, coordinates, and cell types to files for downstream cell-cell interaction analysis. ```python ad_scst_crop = sc.read('../demo_data/human_heart_ROI_generated_cells.h5ad') ad_scst_crop.to_df().T.to_csv('../output/heart/express.txt', sep=' ') ad_scst_crop.obs.loc[:,['x', 'y']].to_csv('../output/heart/coords.txt', sep=' ', index = False) ad_scst_crop.obs['discrete_label_ct'].to_csv('../output/heart/cell_type.txt', sep=' ', index = False, header = False) ``` -------------------------------- ### Preprocessing MERFISH data Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-MOp-MERFISH.html This code snippet reads MERFISH data, renames columns, creates cell location information, and saves the preprocessed data. ```python ad_sp = sc.read('../demo_data/MERFISH_mop.h5ad') ad_sp.obs = ad_sp.obs.rename(columns = {'X':'x', 'Y':'y'}) cell_locations = ad_sp.obs.copy() cell_locations['spot_index'] = np.array(cell_locations.index) cell_locations['cell_index'] = cell_locations['spot_index'].map(lambda x:x+'_0') cell_locations['cell_nums'] = np.ones(cell_locations.shape[0]).astype(int) ad_sp.uns['cell_locations'] = cell_locations ad_sp.write('../demo_data/MERFISH_mop_preprocess.h5ad') ``` -------------------------------- ### Concatenate MERFISH .h5ad files Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-MOp-MERFISH.html Concatenates multiple MERFISH .h5ad files into a single AnnData object. ```python ad_res = ConcatCells(s=0,e=6000,inter=1000,es=5551,file_path='../output/merfish/',prefix='generated_cells_spot',suffix='.h5ad') ``` -------------------------------- ### Pairwise align the slices Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Aligns two slices pairwise using the `pairwise_align` function. ```python pi12 = pst.pairwise_align(slice1, slice2) ``` -------------------------------- ### Accessing Spatial Data Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Retrieves the spatial alignment data stored in the 'spatial' attribute of the .obsm accessor. ```python slice_3D.obsm['spatial'] ``` -------------------------------- ### Train Score-Based Model Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Cerebellum-Slideseq.html Trains a score-based model using four GPUs, specifying checkpoint path, scRNA-seq reference data, cell class column, and GPU IDs. ```bash python ./src/Train_scRef.py \ --ckpt_path ./Ckpts_scRefs/Cerebellum \ --scRef ./Ckpts_scRefs/Cerebellum/Ref_snRNA_cerebellum_qc.h5ad \ --cell_class_column cell_type \ --gpus 0,1,2,3 ``` -------------------------------- ### Load Cell Type Results Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Reads the cell type identification results from a CSV file into a pandas DataFrame. ```python celltype_res = pd.read_csv('../output/cortex/CellTypeLabel_nu15.csv',index_col=0) ``` -------------------------------- ### Load and preprocess single-cell data Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Human-Heart.html Loads a dataset, filters for Smooth Muscle Cells, logs the data, and prepares it for analysis. It also loads a reference dataset, filters it, and renames cell states. ```python ad_scst_crop = sc.read('../demo_data/human_heart_ROI_generated_cells.h5ad') smscells_gx = ad_scst_crop[ad_scst_crop.obs['discrete_label_ct']=='Smooth_muscle_cells'].copy() smscells_gx.obs['cell_type'] = 'Generated_SMC_Cells' smscells_gx.obs['cell_states'] = 'Generated_SMC_Cells' sc.pp.log1p(smscells_gx) ad_sc = sc.read('../Ckpts_scRefs/Heart_D2/Ref_Heart_sanger_D2.h5ad') ad_sc = ad_sc[ad_sc.obs['cell_type'].isin(['Endothelial','Smooth_muscle_cells'])] ad_sc = ad_sc[~ad_sc.obs['cell_states'].isin(['EC4_immune','EC10_CMC-like','EC9_FB-like','EC8_ln'])] ad_sc = ad_sc[:,ad_sc.var.Marker] rename_dict = { 'EC1_cap':'EC_cap', 'EC3_cap':'EC_cap', 'EC2_cap':'EC_cap' } ad_sc.obs['cell_states'] = ad_sc.obs['cell_states'].map(lambda x:rename_dict[x] if x in rename_dict.keys() else x) ``` -------------------------------- ### Visualize UMAP results Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Human-Heart.html Generates a UMAP plot colored by cell states to visualize the clustering of different cell types. ```python fig, axs = plt.subplots(1, 1, figsize=(11, 10),dpi=100) plt.rcParams["legend.markerscale"] = 1.3 sns.set_context('paper',font_scale=2.2) sc.pl.umap( adata_all, color="cell_states", size=80, frameon=False, palette='Set1', alpha=0.7, show=False, ax=axs#,legend_loc='on data' ) plt.tight_layout() ``` -------------------------------- ### Inspect AnnData Object Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Human-Heart.html Displays the structure and summary of the AnnData object, including observations, variables, and unstructured data. ```python ad_scst_crop ``` -------------------------------- ### KDE Plot for Right Gene Expression (Slide-seq vs SpatialScope) Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Cerebellum-Slideseq.html Generates a Kernel Density Estimate plot for the expression of the right gene in a specific cell type, comparing Slide-seq and SpatialScope data. ```python gene = R_gene celltype = R_ct sns.set_context('paper',font_scale=2.4) fig, ax = plt.subplots(1, 1, figsize=(8, 6),dpi=100) sns.kdeplot(data=ad_sp[ad_sp.obs['discrete_label_ct']==celltype,gene].to_df(), x=gene,ax=ax,fill=True,color='#D6D657',label='Slide-seq') sns.kdeplot(data=ad_scst[ad_scst.obs['discrete_label_ct']==celltype,gene].to_df(), x=gene,ax=ax,fill=True,color='#BF8AD0',label='SpatialScope',clip=[-1,10]) ax.set_xlabel('${}$ expression in {}'.format(gene,celltype)) #plt.legend(loc='best') ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) plt.show() ``` -------------------------------- ### Assign aligned spatial coordinates Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Assigns the aligned spatial coordinates to the slices. ```python slice1.obsm['spatial_align'] = new_slices[0].obsm['spatial'] slice2.obsm['spatial_align'] = new_slices[1].obsm['spatial'] ``` -------------------------------- ### PCA and Neighbor Graph Construction Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Human-Heart.html Applies log transformation, performs Principal Component Analysis (PCA) using highly variable genes, and constructs a neighbor graph for dimensionality reduction. ```python ad_sc.var.loc[ad_sc.var.index.isin(markers),'Marker'] = True ad_sc.var['Marker'] = ad_sc.var['Marker'].fillna(False) ad_sc.var['highly_variable'] = ad_sc.var['Marker'] sc.pp.log1p(ad_sc) sc.pp.pca(ad_sc,svd_solver='arpack', n_comps=30, use_highly_variable=True) ad_sc.X.max() ``` ```python sc.pp.neighbors(ad_sc, metric='cosine', n_neighbors=30, n_pcs = 30) sc.tl.umap(ad_sc, min_dist = 0.5, spread = 1, maxiter=60) ``` -------------------------------- ### Gene expression decomposition (spots 2000-3000) Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Human-Heart.html Command to perform gene expression decomposition for spots 2000 to 3000. ```python python ./src/Decomposition.py --tissue heart --out_dir ./output --SC_Data ./Ckpts_scRefs/Heart_D2/Ref_Heart_sanger_D2.h5ad --cell_class_column cell_type --ckpt_path ./Ckpts_scRefs/Heart_D2/model_5000.pt --spot_range 2000,3000 --gpu 0,1,2,3 ``` -------------------------------- ### UMAP Visualization Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-MOp-MERFISH.html Generates a UMAP plot colored by cell type to visualize the clustering of cell populations. ```python fig, axs = plt.subplots(1, 1, figsize=(10, 10)) sc.pl.umap( ad_sc, color=cell_type_column, size=15, frameon=False, show=False, ax=axs,legend_loc='on data' ) plt.tight_layout() ``` -------------------------------- ### 3D Scatter Plot of Cell Types Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Generates a 3D scatter plot to visualize cell locations and types for two slices, using a predefined color map. ```python from matplotlib import pyplot as plt from mpl_toolkits.mplot3d import Axes3D fig = plt.figure(figsize=(10,5),dpi=200) ax = fig.gca(projection='3d')# fig.add_subplot(projection='3d') ax.get_proj = lambda: np.dot(Axes3D.get_proj(ax), np.diag([0.85, 1.6, 0.8, 1])) ax.scatter(x1, y1, z1, c=slice1.uns['cell_locations']['discrete_label_ct'].map(color_dict), s=1.5, alpha=1) ax.scatter(x2, y2, z2, c=slice2.uns['cell_locations']['discrete_label_ct'].map(color_dict), s=1.5, alpha=1) ax.set_xlabel('$x$') ax.set_ylabel('$y$') ax.set_zlabel('$z$') #ax.set_box_aspect([np.ptp(i) for i in data]) # equal aspect ratio ``` -------------------------------- ### Accessing Maximum Value in AnnData X Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Retrieves the maximum value from the .X attribute of the AnnData object. ```python slice_3D.X.max() ``` -------------------------------- ### Update spatial coordinates for alignment Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-Brain.html Updates the spatial coordinates for alignment by adding a new dimension. ```python new_slices[0].obsm['spatial'] = np.hstack((new_slices[0].obsm['spatial'], np.zeros((new_slices[0].obsm['spatial'].shape[0],1)))) new_slices[1].obsm['spatial'] = np.hstack((new_slices[1].obsm['spatial'], (pdist(new_slices[0].obsm['spatial']).min()**2/2)**.5/2 * np.ones((new_slices[1].obsm['spatial'].shape[0],1)))) ``` -------------------------------- ### Color Dictionary and Label Names Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Mouse-MOp-MERFISH.html Defines a color dictionary for mapping cell types to specific colors and a list of label names for cell types. ```python color_dict = {'Astro': '#1f77b4', 'Endo': '#aec7e8', 'L2/3 IT': '#ff7f0e', 'L5 ET': '#ffbb78', 'L5 IT': '#2ca02c', 'L5/6 NP': '#98df8a', 'L6 CT': '#d62728', 'L6 IT': '#ff9896', 'L6b': '#9467bd', 'Lamp5': '#c5b0d5', 'Micro': '#8c564b', 'Oligo': '#c49c94', 'OPC': '#e377c2', 'Peri': '#f7b6d2', 'Pvalb': '#7f7f7f', 'PVM': '#a3a2a2', 'Sncg': '#bcbd22', 'Sst': '#dbdb8d', 'Vip': '#17becf', 'VLMC': '#9edae5', 'None': '#dbd9d9'} labelnames = ['Astro', 'Endo', 'L2/3 IT', 'L5 IT', 'L5 ET', 'L5/6 NP', 'L6 IT', 'L6 CT', 'L6b', 'Lamp5', 'Micro', 'Oligo', 'OPC', 'Peri', 'Pvalb', 'PVM', 'Sncg', 'Sst', 'Vip', 'VLMC'] ``` -------------------------------- ### Display cropped image object Source: https://spatialscope-tutorial.readthedocs.io/en/latest/notebooks/Human-Heart.html Displays the ImageContainer object after cropping. ```python crop ```