.filter_by_var_consistency

proteopy.pp.filter_by_var_consistency(adata, threshold, key=None, remove_na=True, verbose=False, inplace=True)[source]

Filter variables by a per-variable consistency score.

Keeps the variables whose adata.var[key] is at least threshold, e.g. the minimum batch-pair correlation computed by var_consistency().

Parameters:
  • adata (AnnData) – AnnData object in proteodata format.

  • threshold (int | float) – Minimum score a variable needs to be kept (score >= threshold).

  • key (str | None) – Numeric column in adata.var holding the score. If None, it is inferred as the single adata.var column ending in '_corr_min', i.e. the minimum pairwise correlation stored by var_consistency().

  • remove_na (bool) – Remove variables whose score is NaN (undefined). If False, they are kept.

  • verbose (bool) – Print how many variables are kept, removed and undefined.

  • inplace (bool) – If True, modify adata in place. If False, return a filtered copy of adata.

Returns:

The filtered copy of adata if inplace=False, otherwise None.

Return type:

AnnData | None

Raises:
  • KeyError – If key is not a column of adata.var.

  • ValueError – If key is None and not exactly one adata.var column ends in '_corr_min'.

  • TypeError – If key is not an integer or float column, threshold is not an int or float, or a flag is not a bool.

Examples

>>> import proteopy as pr
>>> pr.pp.var_consistency(
...     adata,
...     batch_key="replicate",
...     group_by=["condition", "fraction"],
... )
>>> pr.pp.filter_by_var_consistency(adata, threshold=0.25)

Pass key when several consistency scores are stored, or to filter on another summary:

>>> pr.pp.filter_by_var_consistency(
...     adata,
...     threshold=0.5,
...     key="replicate_corr_median",
... )