daf.storage.anndata¶
This stores the data inside an AnnData AnnData object.
Since AnnData is not really powerful enough to satisfy our needs (this was the main motivation for creationg
daf), this is mainly used to interface with other systems.
When accessing existing AnnData objects, you can either wrap it with an AnnDataWriter to allow modifying it
through daf, or with an AnnDataReader object to provide just read-only access. In both cases, you will see the
hard-wired obs, var and X names. As a convenience, you can call anndata_as_storage instead, which will
create an AnnDataReader and wrap it with a StorageView to rename these to more meaningful names.
To create a new AnnData object, call storage_as_anndata, giving it a StorageReader that exposes only the data
you wish to place in the result; this is typically done using a StorageView, which also renames some meaningful axes
and data names to obs, var and X.
Representation
We use the following scheme to map between daf data and AnnData fields:
0D data is easy, it is stored in the
unsfield ofAnnData.Axes other than
obsandvarrequire us to store their entries, which we do by using anunsentry with the nameaxis#.1D data other than per-
obsand per-vardata is stored in anunsentry namedaxis#property.2D data for
obsandvaraxes is stored in theX,layers,obsporvarpAnnDatafields, as appropriate.2D data for either
obsorvarand another axis is stored as a set of 1D annotations in theobsorvarAnnDatafields, one for each axis entry, namedother_axis=entry#property. It is debatable whether this makes it easier or harder to access this data in systems that directly useAnnData, but it is at least “technically correct”.2D data where neither axis is
obsorvaris stored in anunsentry namedrow_axis,column_axis#property.
Classes:
|
Implement the |
|
Implement the |
Functions:
|
Convert some |
|
View some |
- class daf.storage.anndata.AnnDataReader(adata: AnnData, *, name: str = 'anndata#')[source]¶
Bases:
StorageReaderImplement the
StorageReaderinterface forAnnData.If the
nameends with#, we append the object id to it to make it unique.Note
Do not modify the wrapped
AnnDataafter creating a reader. Modifications may or may not be visible in the reader, causing subtle problems.Attributes:
The wrapped
AnnDataobject.- adata¶
The wrapped
AnnDataobject.
- class daf.storage.anndata.AnnDataWriter(adata: AnnData, *, name: str = 'anndata#', copy: Optional[StorageReader] = None, overwrite: bool = False)[source]¶
Bases:
AnnDataReader,StorageWriterImplement the
StorageWriterinterface forAnnData.If
copyis specified, it is copied into theAnnData, using theoverwrite. This requires thecopyto haveobsandvaraxes. Typically you would be better off callingstorage_as_anndata.Note
Do not modify the wrapped
AnnDataafter creating a writer (other than through the writer object). Modifications may or may not be visible in the writer, causing subtle problems.Setting large 2D data for axes other than
obsandvarwill be inefficient.
- daf.storage.anndata.storage_as_anndata(storage: StorageReader) AnnData[source]¶
Convert some
storageinto anAnnDataobject.The storage needs to include an
obsand avaraxis, and anobs,var#Xmatrix. In general it should contain the data one wishes to store in theAnnDataobject. Typically this is achieved by creating aStorageViewhide_implicit=Truefor the full data; this view is also used to rename the meaningful axes and data names toobs,varandX.Note
It is often necessary to create several such views to extract several
AnnDataobjects from the samestorage, e.g. when the data contains both cells and cell-clusters/types, it is best to split it into twoAnnDataobjects, one for the cells data and another for the clusters/types data. Other data (e.g. per gene data) can be replicated in bothAnnDataobjects or stored in only one of them, as needed.
- daf.storage.anndata.anndata_as_storage(adata: AnnData, obs: str, var: str, X: str, name: str = 'anndata#') StorageReader[source]¶
View some
adata(AnnDataobject) as aStorageReaderto allow accessing it usingdaf.This creates a
StorageViewwhich maps the hard-wiredobsandvaraxes names and the hard-wiredXdata to hopefully more meaningful names.If the
nameends with#we append the object id to it to make it unique.Note
It is often necessary to split the same data set into multiple
AnnDataobjects, e.g. when the data contains both cells and cell-clusters/types, it is best to split it into twoAnnDataobjects, one for the cells data and another for the clusters/types data. To merge these back into a single storage, create aStorageChainby writing something likeStorageChain([anndata_as_storage(..), anndata_as_storage(...), ...]).