mantispy.io.stamp#
- mantispy.io.stamp(adata, resolution=None, *, feature_kind=None, object_type='Object', grouped_by=None, perturbation=None, copy=False)[source]#
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:
"object","well"or"aggregate".obshas to carry the columns that resolution requires.Nonekeeps whatever resolution the object already records; an object that records none must be given one, since guessing could silently mislabel it (the internalschema.stampandschema.get_resolutionalso refuse to assume one).- feature_kind
str|None(default:None) The representation every feature carries:
"measurement","embedding"or"derived". Pass it when the whole matrix is one kind (a matrix of embeddings is"embedding"); it fills every feature. Leave itNoneonly whenvar["feature_kind"]is already complete and valid (as a mantispy-read object’s is).- object_type
str(default:'Object') For
"object"resolution, the name written toMetadata_ObjectTypewhenobsdoes not already carry one, e.g."cell".- grouped_by
Sequence[str] |None(default:None) For
"aggregate"resolution, the columns that define one row; required there since there is no default.- perturbation
Mapping[str,str] |None(default:None) Optional record of where perturbation identity lives:
column(theobscolumn naming the perturbation) andcontrol_column(defaultMetadata_Control_Type). Left unset, an object with aMetadata_Perturbationcolumn records that, and one without records nothing. Tools such asconsensus()andmap()read it as their default column.- copy
bool(default:False) Return a stamped copy instead of stamping in place.
- adata
- 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
Stamping runs the full
validate()contract (spec 16.1), so a stamped object is a valid mantispy object or the stamp is rejected; the check runs on a copy first, so a rejected stamp leaves the caller’s object untouched.validatestill returns the warnings it does not block on. That includesX: the package stores features asfloat32, and a matrix that came out of scikit-learn ornumpy.load()isfloat64, so an embedding wantsadata.X = adata.X.astype("float32")before it is stamped.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", feature_kind="embedding")