mantispy.io.stamp

Contents

mantispy.io.stamp#

mantispy.io.stamp(adata, resolution=None, copy=False)#

Mark an AnnData built elsewhere as a mantispy object.

Every reader here, and every tool that returns a new object, records this already. This is the entry point for an object that did not come from one of them: a published h5ad, another pipeline’s output, a subset assembled in a notebook, or a matrix of learned embeddings with its metadata alongside.

Parameters:
  • adata (AnnData) – The object to stamp.

  • resolution (str | None (default: None)) – What one row is: "cell", "well" or "perturbation". obs has to carry the columns that resolution requires. The default keeps whatever resolution the object already records, and falls back to "well" for an object that records none, so re-stamping a subset does not quietly demote it.

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

Return type:

AnnData | None

Returns:

None, or the stamped copy. Writes the schema version and the resolution to uns["mantispy"], and adds the missing feature-annotation columns to var.

Raises:

ValueErrorresolution is not one of the three, or obs lacks a column that resolution requires.

Notes

Only the obs columns the resolution requires are checked, because that is what the rest of the package dispatches on. validate() gives the full report, including what it warns about rather than blocks. X is one of the things it rather than this checks: the package stores features as float32, and a matrix that came out of scikit-learn or numpy.load() is float64, so an embedding usually wants adata.X = adata.X.astype("float32") before it is written.

Any of the feature-annotation columns the schema requires that var does not already have are added empty, and columns already present are left as they are. They are not filled by parsing the feature names: the parser finds structure in names that have none — it reads openphenom_nahualX_17 as the nahualX group of an openphenom object — and an embedding would then carry feature families named after the model’s own tensors. An object read by read_profiles() already has the parsed annotation and keeps it.

Examples

Bringing in a matrix of learned embeddings, one row per well:

>>> import anndata as ad
>>> import mantispy as mt
>>> adata = ad.AnnData(embeddings, obs=metadata)
>>> mt.io.stamp(adata, resolution="well")