scviva.tools.vision.NormData#

class scviva.tools.vision.NormData(data, gene_offsets, gene_scale_factors, cell_offsets, cell_scale_factors)[source]#

Sparse expression matrix with pre-computed normalisation parameters.

Stores the log-transformed sparse matrix together with per-gene and per-cell offset / scale-factor vectors so that the fully normalised value for element (i, j) can be computed on demand without materialising a dense intermediate matrix.

Normalised value for element (i, j):

step1 = (data[i, j] + gene_offsets[j]) * gene_scale_factors[j]
step2 = (step1 + cell_offsets[i]) * cell_scale_factors[i]

Parameters that are not used for a given method are set to neutral values (offsets=0, scale_factors=1).

Mirrors R VISION’s NormData S4 class from NormalizationMethods.R. Note that R uses genes × cells layout (so R’s rowOffsets are per-gene and R’s colOffsets are per-cell); the Python attribute names use the Python / AnnData convention (cells × genes).

Parameters:
data ndarray | spmatrix

Log-transformed expression matrix, dense or sparse.

gene_offsets ndarray

Per-gene offsets (R’s rowOffsets).

gene_scale_factors ndarray

Per-gene scale factors (R’s rowScaleFactors).

cell_offsets ndarray

Per-cell offsets (R’s colOffsets).

cell_scale_factors ndarray

Per-cell scale factors (R’s colScaleFactors).

Attributes table

Methods table

toarray()

Materialise the fully normalised dense matrix.

Attributes

NormData.data: ndarray | spmatrix#
NormData.gene_offsets: ndarray#
NormData.gene_scale_factors: ndarray#
NormData.cell_offsets: ndarray#
NormData.cell_scale_factors: ndarray#

Methods

NormData.toarray()[source]#

Materialise the fully normalised dense matrix.

Return type:

ndarray

Returns:

np.ndarray of shape (n_cells, n_genes) Fully normalised dense expression matrix.