mantispy.pp.sphere

Contents

mantispy.pp.sphere#

mantispy.pp.sphere(adata, method='ZCA-cor', reference='negcon', epsilon=1e-06, by=None, key_added=None, copy=False)[source]#

Whiten profiles with a transform fitted on the reference rows.

Parameters:
  • adata (AnnData) – Object to sphere. Usually well-level profiles.

  • method (str (default: 'ZCA-cor')) – "ZCA" and "ZCA-cor" rotate back into the original feature basis, so the output columns still correspond to features and var still describes them. "PCA" and "PCA-cor" return principal components, which var no longer describes, and warn about it unless key_added is set. The -cor variants whiten the correlation instead of the covariance, so high-variance features do not dominate.

  • reference (str | None (default: 'negcon')) – Rows to fit on: "negcon" for the controls, None for everything, or the name of a boolean obs column.

  • epsilon (float | str (default: 1e-06)) – Regularization added to the singular values, or "auto" to pick it from the data. "auto" scores each candidate by the mean of its activity and replicability mAP on the transformed profiles and keeps the argmax, starting from the jump-profiling-recipe grid and then sampling past both ends and between points when the best sits there, so the chosen value can fall outside the recipe’s range. It needs copairs, Metadata_Perturbation, Metadata_Plate and a negcon reference; the search is global, so by only changes how the chosen value is applied. Every candidate, its score and the chosen value are written to uns["mantispy"]["sphere_epsilon"].

  • by (str | None (default: None)) – Fit and apply separately within each group of this column, e.g. per batch.

  • key_added (str | None (default: None)) – Write to layers[key_added] instead of overwriting X.

  • copy (bool (default: False)) – Return a modified copy instead of mutating in place.

Return type:

AnnData | None

Returns:

None, or the modified copy. Writes X or layers[key_added].

Raises:
  • ImportError – epsilon="auto" was asked but copairs, the extra the sweep scores with, is not installed.

  • ValueError – If method is unknown, epsilon is neither a float nor "auto", reference selects no rows, a group has fewer than two reference rows, the reference holds missing or infinite values, a -cor method meets a zero-variance feature, the reference matrix is not full rank, epsilon="auto" is asked without the columns and reference the sweep needs, or every epsilon="auto" candidate scored non-finite.