Package: paste-bio
PASTEPASTE is a computational method that leverages both gene expression similarity and spatial distances between spots to align and integrate spatial transcriptomics data. In particular, there are two methods:pairwise_align: align spots across pairwise slices.center_align: integrate multiple slices into one center slice.You can read full paperhere.Additional examples and the code to reproduce the paper's analyses can be foundhere. Preprocessed datasets used in the paper can be found onzenodo.Recent NewsPASTE is now published inNature Methods!The code to reproduce the analisys can be foundhere.As of version 1.2.0, PASTE now supports GPU implementation via Pytorch. For more details, see the GPU section of theTutorial notebook.InstallationThe easiest way is to install PASTE on pypi:https://pypi.org/project/paste-bio/.pip install paste-bioOr you can install PASTE on bioconda:https://anaconda.org/bioconda/paste-bio.conda install -c bioconda paste-bioCheck out Tutorial.ipynb for an example of how to use PASTE.Alternatively, you can clone the respository and try the following example in a
notebook or the command line.Quick StartTo use PASTE we require at least two slices of spatial-omics data (both
expression and coordinates) that are in
anndata format (i.e. read in by scanpy/squidpy). We have included a breast
cancer dataset from [1] in thesample_data folderof this repo
that we will use as an example below to show how to use PASTE.importmatplotlib.pyplotaspltimportmatplotlib.patchesasmpatchesimportnumpyasnpimportscanpyasscimportpasteaspst# Load Slicesdata_dir='./sample_data/'# change this path to the data you wish to analyze# Assume that the coordinates of slices are named slice_name + "_coor.csv"defload_slices(data_dir,slice_names=["slice1","slice2"]):slices=[]forslice_nameinslice_names:slice_i=sc.read_csv(data_dir+slice_name+".csv")slice_i_coor=np.genfromtxt(data_dir+slice_name+"_coor.csv",delimiter=',')slice_i.obsm['spatial']=slice_i_coor# Preprocess slicessc.pp.filter_genes(slice_i,min_counts=15)sc.pp.filter_cells(slice_i,min_counts=100)slices.append(slice_i)returnslicesslices=load_slices(data_dir)slice1,slice2=slices# Pairwise align the slicespi12=pst.pairwise_align(slice1,slice2)# To visualize the alignment you can stack the slices# according to the alignment pislices,pis=[slice1,slice2],[pi12]new_slices=pst.stack_slices_pairwise(slices,pis)slice_colors=['#e41a1c','#377eb8']plt.figure(figsize=(7,7))foriinrange(len(new_slices)):pst.plot_slice(new_slices[i],slice_colors[i],s=400)plt.legend(handles=[mpatches.Patch(color=slice_colors[0],label='1'),mpatches.Patch(color=slice_colors[1],label='2')])plt.gca().invert_yaxis()plt.axis('off')plt.show()# Center align slices## We have to reload the slices as pairwise_alignment modifies the slices.slices=load_slices(data_dir)slice1,slice2=slices# Construct a center slice## choose one of the slices as the coordinate reference for the center slice,## i.e. the center slice will have the same number of spots as this slice and## the same coordinates.initial_slice=slice1.copy()slices=[slice1,slice2]lmbda=len(slices)*[1/len(slices)]# set hyperparameter to be uniform## Possible to pass in an initial pi (as keyword argument pis_init)## to improve performance, see Tutorial.ipynb notebook for more details.center_slice,pis=pst.center_align(initial_slice,slices,lmbda)## The low dimensional representation of our center slice is held## in the matrices W and H, which can be used for downstream analysesW=center_slice.uns['paste_W']H=center_slice.uns['paste_H']GPU implementationPASTE now is compatible with gpu via Pytorch. All we need to do is add the following two parameters to our main functions:pi12 = pst.pairwise_align(slice1, slice2, backend = ot.backend.TorchBackend(), use_gpu = True)

center_slice, pis = pst.center_align(initial_slice, slices, lmbda, backend = ot.backend.TorchBackend(), use_gpu = True)For more details, see the GPU section of theTutorial notebook.Command LineWe provide the option of running PASTE from the command line.First, clone the repository:git clone https://github.com/raphael-group/paste.gitNext, when providing files, you will need to provide two separate files: the gene expression data followed by spatial data (both as .csv) for the code to initialize one slice object.Sample execution (based on this repo):python paste-cmd-line.py -m center -f ./sample_data/slice1.csv ./sample_data/slice1_coor.csv ./sample_data/slice2.csv ./sample_data/slice2_coor.csv ./sample_data/slice3.csv ./sample_data/slice3_coor.csvNote:pairwisewill return pairwise alignment between each consecutive pair of slices (e.g. [slice1,slice2], [slice2,slice3]).FlagNameDescriptionDefault Value-mmodeSelect eitherpairwiseorcenter(str)pairwise-ffilesPath to data files (.csv)None-ddirecDirectory to store output filesCurrent Directory-aalphaAlpha parameter for PASTE(float)0.1-ccostExpression dissimilarity cost (klorEuclidean)(str)kl-pn_componentsn_components for NMF step incenter_align(int)15-llmbdaLambda parameter incenter_align(floats) probability vector of lengthn-iintial_sliceSpecify which file is also the intial slice incenter_align(int)1-tthresholdConvergence threshold forcenter_align(float)0.001-xcoordinatesOutput new coordinates (toggle to turn on)False-wweightsWeights files of spots in each slice (.csv)None-sstartInitial alignments for OT. If not given uses uniform (.csv structure similar to alignment output)Nonepairwise_alignoutputs a (.csv) file containing mapping of spots between each consecutive pair of slices. The rows correspond to spots of the first slice, and cols the second.center_alignoutputs two files containing the low dimensional representation (NMF decomposition) of the center slice gene expression, and files containing a mapping of spots between the center slice (rows) to each input slice (cols).Sample DatasetAdded sample spatial transcriptomics dataset consisting of four breast cancer slice courtesy of:[1] Ståhl, Patrik & Salmén, Fredrik & Vickovic, Sanja & Lundmark, Anna & Fernandez Navarro, Jose & Magnusson, Jens & Giacomello, Stefania & Asp, Michaela & Westholm, Jakub & Huss, Mikael & Mollbrink, Annelie & Linnarsson, Sten & Codeluppi, Simone & Borg, Åke & Pontén, Fredrik & Costea, Paul & Sahlén, Pelin Akan & Mulder, Jan & Bergmann, Olaf & Frisén, Jonas. (2016). Visualization and analysis of gene expression in tissue sections by spatial transcriptomics. Science. 353. 78-82. 10.1126/science.aaf2403.Note: Original data is (.tsv), but we converted it to (.csv).ReferencesRon Zeira, Max Land, Alexander Strzalkowski and Benjamin J. Raphael. "Alignment and integration of spatial transcriptomics data". Nature Methods (2022).https://doi.org/10.1038/s41592-022-01459-6