smftools.preprocessing.clean_NaN

Contents

smftools.preprocessing.clean_NaN#

smftools.preprocessing.clean_NaN(adata, layer=None, uns_flag='clean_NaN_performed', bypass=False, force_redo=True, layers_to_build=None, on_layer=None, keep_in_adata=True)#

Append layers to adata that contain NaN-cleaning strategies.

Uses numpy float32 operations throughout to avoid the memory overhead of converting to a float64 pandas DataFrame.

Parameters:
  • adata (AnnData) -- AnnData object.

  • layer (str | None (default: None)) -- Layer to fill NaN values in. If None, uses adata.X.

  • uns_flag (str (default: 'clean_NaN_performed')) -- Flag in adata.uns indicating prior completion.

  • bypass (bool (default: False)) -- Whether to skip processing.

  • force_redo (bool (default: True)) -- Whether to rerun even if uns_flag is set.

  • layers_to_build (Optional[List[str]] (default: None)) -- Which NaN-fill strategy layers to create. Valid values: fill_nans_closest, nan0_0minus1, nan1_12, nan_minus_1, nan_half. Defaults to ["nan0_0minus1", "nan_half"].

  • on_layer (Optional[Callable[[str, ndarray], None]] (default: None)) -- Optional callback invoked as on_layer(name, array) immediately after each variant is computed -- lets a caller write (and free) it right away instead of waiting for every variant to accumulate in adata.layers first. Each variant derives independently from the same source (layer or X), so this is safe regardless of call order.

  • keep_in_adata (bool (default: True)) -- When False, a variant is not also assigned into adata.layers after on_layer fires -- avoids holding both the callback's copy and an adata.layers copy at once. Ignored (a variant is always assigned) when on_layer is None, since that's the only place the array would otherwise end up.

Return type:

None