114 lines (106 with data), 12.7 kB
U
ùqþc¼8 ã @ sl d Z ddlZddlZddlZddlZddlmZ ddlm Z ddl
mZ ddlm
Z
mZ G dd deZdS ) a
Author: Pinar Demetci
Principal Investigator: Ritambhara Singh, Ph.D. from Brown University
08 August 2021
Updated: 23 February 2023
SCOTv2 algorithm: Single Cell alignment using Optimal Transport version 2
Correspondence: pinar_demetci@brown.edu, ritambhara@brown.edu
é N)Údijkstra)Ú
csr_matrix)Úkneighbors_graph)ÚStandardScalerÚ normalizec @ st e Zd ZdZdd Zdd Zd$dd Zd%d
dZdd Zdd Z d&ddZ
d'ddZdd Zd(dd Z
d)d"d#ZdS )*ÚSCOTv2a
SCOT algorithm for unsupervised alignment of single-cell multi-omic data.
https://www.biorxiv.org/content/10.1101/2020.04.28.066787v2 (original preprint)
https://www.liebertpub.com/doi/full/10.1089/cmb.2021.0446 (Journal of Computational Biology publication through RECOMB 2021 conference)
Input: domain1, domain2 in form of numpy arrays/matrices, where the rows correspond to samples and columns correspond to features.
Returns: aligned domain 1, aligned domain 2 in form of numpy arrays/matrices projected on domain 1
Example use:
# Given two numpy matrices, domain1 and domain2, where the rows are cells and columns are different genomic features:
scot= SCOT(domain1, domain2)
aligned_domain1, aligned_domain2 = scot.align(k=20, e=1e-3)
#If you can't pick the parameters k and e, you can try out our unsupervised self-tuning heuristic by running:
scot= SCOT(domain1, domain2)
aligned_domain1, aligned_domain2 = scot.align(selfTune=True)
Required parameters:
- k: Number of neighbors to be used when constructing kNN graphs. Default= min(min(n_1, n_2), 50), where n_i, for i=1,2 corresponds to the number of samples in the i^th domain.
- e: Regularization constant for the entropic regularization term in entropic Gromov-Wasserstein optimal transport formulation. Default= 1e-3
Optional parameters:
- normalize= Determines whether to normalize input data ahead of alignment. True or False (boolean parameter). Default = True.
- norm= Determines what sort of normalization to run, "l2", "l1", "max", "zscore". Default="l2"
- mode: "connectivity" or "distance". Determines whether to use a connectivity graph (adjacency matrix of 1s/0s based on whether nodes are connected) or a distance graph (adjacency matrix entries weighted by distances between nodes). Default="connectivity"
- metric: Sets the metric to use while constructing nearest neighbor graphs. some possible choices are "correlation", "minkowski". "correlation" is Pearson's correlation and "minkowski" is equivalent to Euclidean distance in its default form (). Default= "correlation".
- verbose: Prints loss while optimizing the optimal transport formulation. Default=True
- XontoY: Determines the direction of barycentric projection. True or False (boolean parameter). If True, projects domain1 onto domain2. If False, projects domain2 onto domain1. Default=True.
Note: If you want to specify the marginal distributions of the input domains and not use uniform distribution, please set the attributes p and q to the distributions of your choice (for domain 1, and 2, respectively)
after initializing a SCOT class instance and before running alignment and set init_marginals=False in .align() parameters
c C sT t |tkrt|dks td|| _g | _g | _g | _g | _g | _ g | _
g | _d S )Né ay As input, SCOTv2 requires a list, containing at least two numpy arrays to be aligned. Each numpy array/matrix corresponds to a dataset, with samples (cells) in rows and features (latent representations or genomic features) in columns. We recommend using latent representations (e.g. principal components for RNA-seq and topics - via cisTopic- for ATAC-seq/Methyl-seq).)ÚtypeÚlistÚlenÚAssertionErrorÚdataÚ marginalsÚgraphsÚ
graphDistsÚ couplingsZgwdistsÚflagsZaligned_data)Úselfr
© r ú&/Users/CCMB/Desktop/SCOT/src/scotv2.pyÚ__init__; s zSCOTv2.__init__c C sD t t| jD ].}| j| jd }t |¡| }| j |¡ q| jS )Nr )Úranger r
ÚshapeÚtorchÚonesr Úappend)r ÚiZ num_cellsZmarginalDistr r r Ú_init_marginalsJ s
zSCOTv2._init_marginalsÚl2Tc C s |dkst dtt| jD ]^}|dkrHt }| | j| ¡| j|<