94 lines (85 with data), 9.0 kB
a
¶Åña* ã @ s\ d Z ddlZddlZddlmZ ddlmZ ddlm Z ddl
mZmZ G dd de
ZdS ) aC
Authors: Pinar Demetci, Rebecca Santorella
Principal Investigator: Ritambhara Singh, Ph.D. from Brown University
12 February 2020
Updated: 27 November 2020
SCOT algorithm (version 1): Single Cell alignment using Optimal Transport
Correspondence: pinar_demetci@brown.edu, rebecca_santorella@brown.edu, ritambhara@brown.edu
é N)Údijkstra)Ú
csr_matrix)Úkneighbors_graph)ÚStandardScalerÚ normalizec
@ sn e Zd ZdZdd Zdd Zddd Zddd
Zdd ZdddZ d ddZ
d!ddZd"ddZd#ddZ
dS )$ÚSCOTa
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 sF || _ || _d | _d | _d | _d | _d | _d | _d | _d | _ d | _
d S )N)ÚXÚyÚpÚqÚCxÚCyÚcouplingÚgwdistÚflagÚ X_alignedÚ y_aligned)ÚselfZdomain1Zdomain2© r úB/Users/pinardemetci/Documents/newSCOT/SCOT/examples/../src/scot.pyÚ__init__; s z
SCOT.__init__c C s, t | jjd ¡| _t | jjd ¡| _d S )Nr )ÚotZunifr Úshaper
r r )r r r r Úinit_marginalsM s zSCOT.init_marginalsÚl2Tc C s |dv sJ d|dks |d kr&d}nd}|dkrXt }| | j¡| | j¡ | _| _n&t| j||dt| j||d | _| _d S )N)Úl1r ÚmaxÚzscorezåNorm argument has to be either one of 'max', 'l1', 'l2' or 'zscore'. If you would like to perform another type of normalization, please give SCOT the normalize data and set the argument normalize=False when running the algorithm.Té r r )ÚnormÚaxis)r Z
fit_transformr r r )r r ZbySampler Zscalerr r r r R s zSCOT.normalizeÚconnectivityÚcorrelationc C sZ |dv sJ d|dkrd}nd}t | j||||d| _t | j||||d| _| j| jfS )N)r! ZdistancezENorm argument has to be either one of 'connectivity', or 'distance'. r! TF)ÚmodeÚmetricÚinclude_self)r r ÚXgraphr Úygraph)r Úkr# r$ r% r r r Úconstruct_grapha s zSCOT.construct_graphc C s t t| jddd}t t| jddd}t ||tjk ¡}t ||tjk ¡}||||k<