spateo.tools.ST_regression#

General and generalized linear modeling of spatial transcriptomics

Option to call functions from ST_regression (e.g. st.tl.ST_regression.Niche_Model) or directly from Spateo (e.g. st.tl.Niche_Model).

Submodules#

Package Contents#

Classes#

Category_Model

Wraps all necessary methods for data loading and preparation, model initialization, parameterization,

Lagged_Model

Wraps all necessary methods for data loading and preparation, model initialization, parameterization,

Niche_LR_Model

Wraps all necessary methods for data loading and preparation, model initialization, parameterization,

Niche_Model

Wraps all necessary methods for data loading and preparation, model initialization, parameterization,

class spateo.tools.ST_regression.Category_Model(*args, **kwargs)[source]#

Bases: Base_Model

Wraps all necessary methods for data loading and preparation, model initialization, parameterization, evaluation and prediction when instantiating a model for spatially-aware (but not spatially lagged) regression using categorical variables (specifically, the prevalence of categories within spatial neighborhoods) to predict the value of gene expression.

Arguments passed to :class Base_Model. The only keyword argument that is used for this class is ‘n_neighbors’.

Parameters
args

Positional arguments to :class Base_Model

kwargs

Keyword arguments to :class Base_Model

class spateo.tools.ST_regression.Lagged_Model(model_type: str = 'ligand', lig: Union[None, str, List[str]] = None, rec: Union[None, str, List[str]] = None, rec_ds: Union[None, str, List[str]] = None, species: Literal[human, mouse, axolotl] = 'human', normalize: bool = True, smooth: bool = False, log_transform: bool = True, *args, **kwargs)[source]#

Bases: Base_Model

Wraps all necessary methods for data loading and preparation, model initialization, parameterization, evaluation and prediction when instantiating a model for spatially-lagged regression.

Can specify one of two models: “ligand”, which uses the spatial lag of ligand genes and the spatial lag of the regression target to predict the regression target, or “niche”, which uses the spatial lag of cell type colocalization and the spatial lag of the regression target to predict the regression target.

If “ligand” is specified, arguments to lig must be given, and it is recommended to provide species as well- default for this is human.

Arguments passed to :class Base_Model.

Parameters
model_type

Either “ligand” or “niche”, specifies whether to fit a model that incorporates the spatial lag of ligand expression or the spatial lag of cell type colocalization.

lig

Name(s) of ligands to use as predictors

rec

Name(s) of receptors to use as regression targets. If not given, will search through database for all genes that correspond to the provided genes from ‘ligands’.

rec_ds

Name(s) of receptor-downstream genes to use as regression targets. If not given, will search through database for all genes that correspond to receptor-downstream genes.

species

Specifies L:R database to use

normalize

Perform library size normalization, to set total counts in each cell to the same number (adjust for cell size)

smooth

To correct for dropout effects, leverage gene expression neighborhoods to smooth expression

log_transform

Set True if log-transformation should be applied to expression (otherwise, will assume preprocessing/log-transform was computed beforehand)

args

Additional positional arguments to :class Base_Model

kwargs

Additional keyword arguments to :class Base_Model

run_GM_lag() Tuple[pandas.DataFrame, pandas.DataFrame, pandas.DataFrame]#

Runs spatially lagged two-stage least squares model

single(cur_g: str, X: pandas.DataFrame, X_variable_names: List[str], param_labels: List[str], adata: anndata.AnnData, w: numpy.ndarray, layer: Union[None, str] = None) Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]#

Defines model run process for a single feature- not callable by the user, all arguments populated by arguments passed on instantiation of :class Base_Model.

Parameters
cur_g

Name of the feature to regress on

X

Values used for the regression

X_variable_names

Names of the variables used for the regression

param_labels

Names of categories- each computed parameter corresponds to a single element in param_labels

adata

AnnData object to store results in

w

Spatial weights array

layer

Specifies layer in AnnData to use- if None, will use .X.

Returns

Coefficients for each categorical group for each feature pred: Predicted values from regression for each feature resid: Residual values from regression for each feature

Return type

coeffs

class spateo.tools.ST_regression.Niche_LR_Model(lig: Union[None, str, List[str]], rec: Union[None, str, List[str]] = None, rec_ds: Union[None, str, List[str]] = None, species: Literal[human, mouse, axolotl] = 'human', niche_lr_r_lag: bool = True, *args, **kwargs)[source]#

Bases: Base_Model

Wraps all necessary methods for data loading and preparation, model initialization, parameterization, evaluation and prediction when instantiating a model for spatially-aware regression using the prevalence of and connections between categories within spatial neighborhoods and the cell type-specific expression of ligands and receptors to predict the regression target.

Arguments passed to :class Base_Model.

Parameters
lig

Name(s) of ligands to use as predictors

rec

Name(s) of receptors to use as regression targets. If not given, will search through database for all genes that correspond to the provided genes from ‘ligands’

rec_ds

Name(s) of receptor-downstream genes to use as regression targets. If not given, will search through database for all genes that correspond to receptors

species

Specifies L:R database to use

niche_lr_r_lag

Only used if ‘mod_type’ is “niche_lr”. Uses the spatial lag of the receptor as the dependent variable rather than each spot’s unique receptor expression. Defaults to True.

args

Additional positional arguments to :class Base_Model

kwargs

Additional keyword arguments to :class Base_Model

class spateo.tools.ST_regression.Niche_Model(*args, **kwargs)[source]#

Bases: Base_Model

Wraps all necessary methods for data loading and preparation, model initialization, parameterization, evaluation and prediction when instantiating a model for spatially-aware regression using both the prevalence of and connections between categories within spatial neighborhoods to predict the value of gene expression.

Arguments passed to :class Base_Model.

Parameters
args

Positional arguments to :class Base_Model

kwargs

Keyword arguments to :class Base_Model