INNER CODE UNIT · Python
fit_size_factors
scverse/PyDESeq2 · src/pydeseq2/dds.py:551
def fit_size_factors(
self,
fit_type: Literal["ratio", "poscounts", "iterative"] | None = None,
control_genes: np.ndarray | list[str] | list[int] | pd.Index | None = None,
) -> None:
"""Fit sample-wise deseq2 normalization (size) factors.
Uses the median-of-ratios method: see :func:`pydeseq2.preprocessing.deseq2_norm`, unless each gene has at least one sample with zero read counts, in which case it switches to the ``iterative`` method.
Also available is the 'poscounts' method implemented in DESeq2 for the single-cell or metagenomics use case where there may be few or no features which have no zero values.
In this situation, size factors can depend on a very small number of features (or only one feature) leading to incorrect inference.
This method for calculating size factors will only exclude genes which have all-0 values (and are not amenable to inference anyway).
The "poscounts" method calculates the n-th root of the product of the non-zero (positive) counts.
Control genes can be optionally provided; if so, size factors will be fit to only the genes in this argument.
This is the same functionality as controlGenes in R DESeq2.
Any valid AnnData indexer (bool, int position, var_name string) is accepted.