Skip to content

Commit

Permalink
version 1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mrland99 committed Aug 3, 2021
1 parent deaf945 commit 33fe06e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 108 deletions.
15 changes: 8 additions & 7 deletions build/lib/paste/PASTE.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import ot
from sklearn.decomposition import NMF
from scipy.spatial import distance_matrix
import scipy
from numpy import linalg as LA
from .helper import kl_divergence, intersect
from .helper import kl_divergence, intersect, to_dense_array

def pairwise_align(sliceA, sliceB, alpha = 0.1, G_init = None, a_distribution = None, b_distribution = None, norm = False, numItermax = 200, return_obj = False, verbose = False, **kwargs):
"""
Expand Down Expand Up @@ -33,8 +34,8 @@ def pairwise_align(sliceA, sliceB, alpha = 0.1, G_init = None, a_distribution =

D_A = distance_matrix(sliceA.obsm['spatial'], sliceA.obsm['spatial'])
D_B = distance_matrix(sliceB.obsm['spatial'], sliceB.obsm['spatial'])
s_A = sliceA.X + 0.01
s_B = sliceB.X + 0.01
s_A = to_dense_array(sliceA.X) + 0.01
s_B = to_dense_array(sliceB.X) + 0.01
M = kl_divergence(s_A, s_B)

if a_distribution is None:
Expand All @@ -48,8 +49,8 @@ def pairwise_align(sliceA, sliceB, alpha = 0.1, G_init = None, a_distribution =
b = b_distribution

if norm:
D1 /= D1[D1>0].min().min()
D2 /= D2[D2>0].min().min()
D_A /= D_A[D_A>0].min().min()
D_B /= D_B[D_B>0].min().min()

if G_init is None:
pi, logw = ot.gromov.fused_gromov_wasserstein(M, D_A, D_B, a, b, loss_fun='square_loss', alpha= alpha, log=True, numItermax=numItermax,verbose=verbose)
Expand Down Expand Up @@ -99,7 +100,7 @@ def center_align(A, slices, lmbda, alpha = 0.1, n_components = 15, threshold = 0
W = model.fit_transform(A.X)
else:
pis = pis_init
W = model.fit_transform(A.shape[0]*sum([lmbda[i]*np.dot(pis[i], slices[i].X) for i in range(len(slices))]))
W = model.fit_transform(A.shape[0]*sum([lmbda[i]*np.dot(pis[i], to_dense_array(slices[i].X)) for i in range(len(slices))]))
H = model.components_
center_coordinates = A.obsm['spatial']

Expand Down Expand Up @@ -146,7 +147,7 @@ def center_ot(W, H, slices, center_coordinates, common_genes, alpha, norm = Fals
def center_NMF(W, H, slices, pis, lmbda, n_components, random_seed, verbose = False):
print('Solving Center Mapping NMF Problem:')
n = W.shape[0]
B = n*sum([lmbda[i]*np.dot(pis[i], slices[i].X) for i in range(len(slices))])
B = n*sum([lmbda[i]*np.dot(pis[i], to_dense_array(slices[i].X)) for i in range(len(slices))])
model = NMF(n_components=n_components, solver = 'mu', beta_loss = 'kullback-leibler', init='random', random_state = random_seed, verbose = verbose)
W_new = model.fit_transform(B)
H_new = model.components_
Expand Down
21 changes: 10 additions & 11 deletions build/lib/paste/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,17 @@ def kl_divergence(X, Y):
return np.asarray(D)


def intersect(a, b):
def intersect(lst1, lst2):
"""
param: a - list
param: b - list
param: lst1 - list
param: lst2 - list
return: list of common elements
"""
a_set = set(a)
b_set = set(b)
if (a_set & b_set):
return list(a_set & b_set)
else:
print("No common elements")


temp = set(lst2)
lst3 = [value for value in lst1 if value in temp]
return lst3

def norm_and_center_coordinates(X):
"""
Expand Down Expand Up @@ -77,4 +74,6 @@ def match_spots_using_spatial_heuristic(X,Y,use_ot=True):
pi[row_ind, col_ind] = 1/max(n1,n2)
if n1<n2: pi[:, [(j not in col_ind) for j in range(n2)]] = 1/(n1*n2)
elif n2<n1: pi[[(i not in row_ind) for i in range(n1)], :] = 1/(n1*n2)
return pi
return pi

to_dense_array = lambda X: np.array(X.todense()) if isinstance(X,scipy.sparse.csr.spmatrix) else X
84 changes: 0 additions & 84 deletions build/lib/paste/paste-cmd-line.py

This file was deleted.

Binary file added dist/paste-bio-1.1.1.tar.gz
Binary file not shown.
Binary file added dist/paste_bio-1.1.1-py3-none-any.whl
Binary file not shown.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = paste-bio
version = 1.1.0
version = 1.1.1
author = Max Land
author_email = max.ruikang.land@gmail.com
description = A computational method to align and integrate spatial transcriptomics experiments.
Expand Down
18 changes: 13 additions & 5 deletions src/paste_bio.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: paste-bio
Version: 1.1.0
Version: 1.1.1
Summary: A computational method to align and integrate spatial transcriptomics experiments.
Home-page: https://github.com/raphael-group/paste
Author: Max Land
Expand All @@ -17,7 +17,9 @@ License-File: LICENSE

# PASTE

PASTE is a computational method that leverages both gene expression similarity and spatial distances between spots align and integrate spatial transcriptomics data. In particular, there are two methods:
![PASTE Overview](https://github.com/raphael-group/paste/blob/main/paste_overview.png)

PASTE 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:
1. `pairwise_align`: align spots across pairwise slices.
2. `center_align`: integrate multiple slices into one center slice.

Expand All @@ -29,6 +31,8 @@ PASTE is actively being worked on with future updates coming.

As of version 1.1.0, PASTE now runs on AnnData making it very easy to integrate with Scanpy for better downstream analysis. Hooray!

This also means that the old version that uses the `STLayer` object is now deprecated.

### Dependencies

To run PASTE, you will need the following Python packages:
Expand All @@ -41,13 +45,17 @@ To run PASTE, you will need the following Python packages:

### Installation

The easiest way is to install PASTE on pypi: https://pypi.org/project/paste-bio/.
The easiest way is to install PASTE on pypi: https://pypi.org/project/paste-bio/.

`pip install paste-bio`

Or you can install PASTE on bioconda: https://anaconda.org/bioconda/paste-bio.

`pip install paste-bio`
`conda install -c bioconda paste-bio`

Check out Tutorial.ipynb for an example of how to use PASTE.

Or you can clone the respository and run from command line (see below).
Lastly, you can clone the respository and run from command line (see below).


### Command Line
Expand Down

0 comments on commit 33fe06e

Please sign in to comment.