mantispy.io.stamp#
- mantispy.io.stamp(adata, resolution=None, copy=False)#
Mark an
AnnDatabuilt 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".obshas 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:
- Returns:
None, or the stamped copy. Writes the schema version and the resolution touns["mantispy"], and adds the missing feature-annotation columns tovar.- Raises:
ValueError –
resolutionis not one of the three, orobslacks a column that resolution requires.
Notes
Only the
obscolumns 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.Xis one of the things it rather than this checks: the package stores features asfloat32, and a matrix that came out of scikit-learn ornumpy.load()isfloat64, so an embedding usually wantsadata.X = adata.X.astype("float32")before it is written.Any of the feature-annotation columns the schema requires that
vardoes 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 readsopenphenom_nahualX_17as thenahualXgroup of anopenphenomobject — and an embedding would then carry feature families named after the model’s own tensors. An object read byread_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")