alphapepttools.pp.nanlog

Contents

alphapepttools.pp.nanlog#

alphapepttools.pp.nanlog(adata, base=2, verbosity=1, layer=None, *, copy=False)#

Logarithmize a data matrix.

Apply arbitrary base logarithm transformation to AnnData.X, replacing invalid values with np.nan. Similar to the underlying numpy log functions, invalid values are replaced with np.nan, but a more detailed summary of which values were replaced is provided.

Current invalid values include:
  • NaN values

  • Zero values

  • Negative values

  • Positive infinity

  • Negative infinity

Parameters:
  • adata (AnnData) – Input data; negatives and/or zeros are converted to np.nan

  • base (int) – Base of the logarithm. Defaults to 2 (log2).

  • verbosity (int, default 1) – If 1, log warnings for invalid values found in the data.

  • layer (Optional[str] (default: None)) – Name of the layer to transform. If None (default), the data matrix X is used.

  • copy (bool (default: False)) – Whether to return a modified copy (True) of the anndata object. If False (default) modifies the object inplace

Return type:

AnnData

Returns:

Log-transformed data with invalid values replaced by np.nan. If copy=False modifies the anndata object at layer inplace and returns None. If copy=True, returns a modified copy.

Examples

The function can act on anndata objects inplace or return copies:

at.pp.nanlog(adata, layer=None, copy=False)
# will update adata.X and modify the object inplace

at.pp.nanlog(adata, layer=None, copy=True)
# will update adata.X and return a new object

at.pp.nanlog(adata, layer="layer", copy=False)
# will update "layer" in adata.layers and modify the object inplace