spateo.preprocessing.transform
#
Miscellaneous non-normalizing data transformations on AnnData objects
Module Contents#
Functions#
|
Computes the natural logarithm of the data matrix (unless different base is chosen using the base argument) |
|
Called if log1p is called with a sparse matrix input. |
|
Called if log1p is called with a numpy array input |
|
Called if log1p is called with an AnnData input |
|
Scale variables to unit variance and optionally zero mean. Variables that are constant across all observations |
|
Called if log1p is called with a sparse matrix input |
|
Called if log1p is called with a numpy array input |
|
Called if scale is called with an AnnData object |
|
Wrapper for computing row-wise or column-wise mean+variance on sparse array-likes. |
|
Mean and variance of sparse array. |
|
Given array for a csr matrix, returns means and variances for each column. |
|
Given array for a csc matrix, returns means and variances for each row. |
- spateo.preprocessing.transform.log1p(X: anndata.AnnData | numpy.ndarray | scipy.sparse.spmatrix, base: int | None = None, copy: bool = False)[source]#
Computes the natural logarithm of the data matrix (unless different base is chosen using the base argument)
- Parameters:
- X
Either full AnnData object or .X. Rows correspond to cells and columns to genes.
- base
Natural log is used by default.
- copy
If an
AnnData
is passed, determines whether a copy is returned.- layer
Layer to transform. If None, will transform .X. If given both argument to layer and obsm, argument to layer will take priority.
- obsm
Entry in .obsm to transform. If None, will transform .X.
- Returns:
If copy is True or input is numpy array/sparse matrix, returns updated data array. Otherwise, returns updated AnnData object.
- spateo.preprocessing.transform.log1p_sparse(X, *, base: int | None = None, copy: bool = False)[source]#
Called if log1p is called with a sparse matrix input.
- spateo.preprocessing.transform.log1p_array(X, *, base: int | None = None, copy: bool = False)[source]#
Called if log1p is called with a numpy array input
- spateo.preprocessing.transform.log1p_anndata(adata, *, base: int | None = None, copy: bool = False, layer: str | None = None, obsm: str | None = None) anndata.AnnData | None [source]#
Called if log1p is called with an AnnData input
- spateo.preprocessing.transform.scale(X: anndata.AnnData | scipy.sparse.spmatrix | numpy.ndarray, zero_center: bool = True, max_value: float | None = None, copy: bool = False, layer: str | None = None, obsm: str | None = None, return_mean_std: bool = False)[source]#
Scale variables to unit variance and optionally zero mean. Variables that are constant across all observations will be set to 0.
- Parameters:
- X
Either full AnnData object or .X. Rows correspond to cells and columns to genes.
- zero_center
If False, will not center variables.
- max_value
Truncate to this value after scaling.
- copy
If an
AnnData
is passed, determines whether a copy is returned.- layer
Layer to transform. If None, will transform .X. If given both argument to layer and obsm, argument to layer will take priority.
- obsm
Entry in .obsm to transform. If None, will transform .X.
- return_mean_std
Set True to return computed feature means and feature standard deviations.
- Returns:
Depending on copy returns or updates adata with a scaled adata.X, annotated with ‘mean’ and ‘std’ in adata.var.
- spateo.preprocessing.transform.scale_sparse(X, *, zero_center: bool = True, max_value: float | None = None, copy: bool = False, return_mean_std: bool = False)[source]#
Called if log1p is called with a sparse matrix input
- spateo.preprocessing.transform.scale_array(X, *, zero_center: bool = True, max_value: float | None = None, copy: bool = False, return_mean_std: bool = False)[source]#
Called if log1p is called with a numpy array input
- spateo.preprocessing.transform.scale_anndata(adata: anndata.AnnData, *, zero_center: bool = True, max_value: float | None = None, copy: bool = False, layer: str | None = None, obsm: str | None = None) anndata.AnnData | None [source]#
Called if scale is called with an AnnData object
- spateo.preprocessing.transform._get_mean_var(X, *, axis=0)[source]#
Wrapper for computing row-wise or column-wise mean+variance on sparse array-likes.
- spateo.preprocessing.transform.sparse_mean_variance_axis(mtx: scipy.sparse.spmatrix, axis: int)[source]#
Mean and variance of sparse array.
- Parameters:
- mtx
scipy.sparse.csr_matrix or scipy.sparse.csc_matrix
- axis
int Either 0 or 1. Determines which axis mean and variance are computed along