API

import paste3

PASTE Alignment

paste.pairwise_align(a_slice, b_slice[, ...])

Returns a mapping \(( \Pi = [\pi_{ij}] )\) between spots in one slice and spots in another slice while preserving gene expression and spatial distances of mapped spots, where \(\pi_{ij}\) describes the probability that a spot i in the first slice is aligned to a spot j in the second slice.

paste.center_align(initial_slice, slices[, ...])

Infers a "center" slice consisting of a low rank expression matrix \(X = WH\) and a collection of \(\pi\) of mappings from the spots of the center slice to the spots of each input slice.

Visualization

visualization.stack_slices_pairwise(slices, pis)

Align spatial coordinates of sequential pairwise slices.

visualization.stack_slices_center(...)

Align spatial coordinates of a list of slices to a center_slice.

visualization.plot_slice(slice, color[, ax, s])

Plots slice spatial coordinates.

Model Selection

model_selection.create_graph(adata[, degree])

Converts spatial coordinates into graph using networkx library.

model_selection.generate_graph_from_labels(...)

Creates and returns the graph and dictionary {node: cluster_label}

model_selection.edge_inconsistency_score(g, ...)

model_selection.calculate_convex_hull_edge_inconsistency(...)

model_selection.plot_edge_curve(m_list, ...)

GLMPCA

glmpca.ortho(U, V, A[, X, G, Z])

U is NxL array of cell factors V is JxL array of loadings onto genes X is NxKo array of cell specific covariates A is JxKo array of coefficients of X Z is JxKf array of gene specific covariates G is NxKf array of coefficients of Z assume the data Y is of dimension JxN imputed expression: E[Y] = g^{-1}(R) where R = VU'+AX'+ZG'

glmpca.mat_binom_dev(X, P, n)

binomial deviance for two arrays X,P are JxN arrays n is vector of length N (same as cols of X,P)

glmpca.glmpca_init(Y, fam[, sz, nb_theta])

create the glmpca_family object and initialize the A array (regression coefficients of X) Y is the data (JxN array) fam is the likelihood sz optional vector of size factors, default: sz=colMeans(Y) or colSums(Y) sz is ignored unless fam is 'poi' or 'nb'

glmpca.est_nb_theta(y, mu, th)

given count data y and predicted means mu>0, and a neg binom theta "th" use Newton's Method to update theta based on the negative binomial likelihood note this uses observed rather than expected information regularization: let u=log(theta).

glmpca.glmpca(Y, L[, fam, ctl, penalty, ...])

GLM-PCA This function implements the GLM-PCA dimensionality reduction method for high-dimensional count data. The basic model is R = AX'+ZG'+VU', where E[Y]=M=linkinv(R). Regression coefficients are A and G, latent factors are U, and loadings are V. The objective function being optimized is the deviance between Y and M, plus an L2 (ridge) penalty on U and V. Note that glmpca uses a random initialization, so for fully reproducible results one should set the random seed. :type Y: :param Y: columns. :type Y: array_like of count data with features as rows and observations as :type L: :param L: :type L: the desired number of latent dimensions (integer). :type fam: :param fam: :type fam: string describing the likelihood to use for the data. Possible values include: :param - poi: :type - poi: Poisson :param - nb: :type - nb: negative binomial :param - mult: :type - mult: binomial approximation to multinomial :param - bern: :type - bern: Bernoulli :type ctl: Optional[dict] :param ctl: :type ctl: a dictionary of control parameters for optimization. Valid keys: :param - maxIter: :type - maxIter: an integer, maximum number of iterations :param - eps: :type - eps: a float, maximum relative change in deviance tolerated for convergence :param - optimizeTheta: distribution is optimized (default), or fixed to the value provided in nb_theta. :type - optimizeTheta: a bool, indicating if the overdispersion parameter of the NB :type penalty: :param penalty: Regression coefficients are not penalized. :type penalty: the L2 penalty for the latent factors (default = 1). :type init: Optional[dict] :param init: loadings (V) matrices. :type init: a dictionary containing initial estimates for the factors (U) and :type nb_theta: :param nb_theta: if nb_theta goes to infinity, this is equivalent to Poisson Note that the alpha in the statsmodels package is 1/nb_theta. If ctl["optimizeTheta"] is True, this is used as initial value for optimization :type nb_theta: negative binomial dispersion parameter. Smaller values mean more dispersion :type X: :param X: same values (eg. 1 for intercept) will be removed. This is because we force the intercept and want to avoid collinearity. :type X: array_like of column (observations) covariates. Any column with all :type Z: :param Z: :type Z: array_like of row (feature) covariates, usually not needed. :type sz: :param sz: :type sz: numeric vector of size factors to use in place of total counts.

Miscellaneous

helper.match_spots_using_spatial_heuristic(...)

Matches spatial coordinates between two datasets using either optimal transport or bipartite matching based on spatial proximity.