anndata_facade ¶
Facade that presents a
DafReader
or
DafWriter
as an
AnnData
-like object.
Given two axis names and a primary matrix name,
DafAnnData
exposes the
DataAxesFormats
data through the standard
AnnData
API so that existing code
written against
AnnData
can consume a
Daf
data set with minimal changes.
Key mappings ¶
-
X— the named matrix over(obs_axis, var_axis). -
obs/var— dict-like proxies over vector properties of each axis, behave likepandasDataFramefor the common[]get/set/delete,.columns,.index, and.to_df()operations. -
layers— dict-like proxy over additional(obs_axis, var_axis)matrices (all exceptX). -
uns— flat dict-like proxy over Daf scalars (strings and numbers only, nested dicts are not supported). -
obsp/varp— dict-like proxies over square(axis, axis)matrices. -
obsm/varm— dict-like proxies over(main_axis, other_axis)matrices addressed by the key"other_axis:matrix_name". Setting requiresother_axisto already exist in the Daf data set.
Slicing ¶
adata[obs_index,
var_index]
returns a read-only
DafAnnData
backed by a
DafView
. Each index may be a Boolean
numpy
array, a list of entry names
or integer positions, a single name or integer, or a
slice
.
The extension methods
DafAnnData.query_obs()
and
DafAnnData.query_var()
accept any Daf query fragment that would fit between the
[
and
]
in
@
axis
[
...
]
.
Limitations ¶
-
Categorical values assigned to
obsorvarcolumns are automatically converted to strings. -
unsonly supports flat scalar values (strings and numbers). Assigning a non-scalar raisesTypeError. -
obs_namesandvar_namesare read-only; axis entries cannot be renamed through this facade. -
Concatenation and other operations that create new
AnnDataobjects are not supported.
- class dafpy.anndata_facade. DafAnnData ( daf : DafReader , * , obs_axis : str , var_axis : str , x_matrix : str ) [source] ¶
-
Facade that presents a
DafReaderorDafWriteras anAnnData-like object.Parameters ¶
- daf:
-
The underlying Daf data set (reader or writer).
- obs_axis:
-
Name of the Daf axis that corresponds to AnnData’s observations (rows of
X). - var_axis:
-
Name of the Daf axis that corresponds to AnnData’s variables (columns of
X). - x_matrix:
-
Name of the
(obs_axis, var_axis)matrix that is exposed asX.
- property obs_names : Index ¶
-
Names of the observations as a
pd.Index.
- property var_names : Index ¶
-
Names of the variables as a
pd.Index.
- property n_obs : int ¶
-
Number of observations.
- property n_vars : int ¶
-
Number of variables.
- property shape : Tuple [ int , int ] ¶
-
Shape of the data matrix
(n_obs, n_vars).
- property X : ndarray | csc_matrix ¶
-
Primary data matrix of shape
(n_obs, n_vars).
- property obs : _DafAxisFrame ¶
-
Observation annotations — dict-like proxy over obs-axis vectors.
- property var : _DafAxisFrame ¶
-
Variable annotations — dict-like proxy over var-axis vectors.
- property layers : _DafLayersMapping ¶
-
Additional
(obs, var)matrices, excludingX.
- property uns : _DafUns ¶
-
Unstructured annotations as a flat dict of Daf scalars.
- property obsp : _DafPairwiseMapping ¶
-
Square
(obs × obs)pairwise matrices.
- property varp : _DafPairwiseMapping ¶
-
Square
(var × var)pairwise matrices.
- property obsm : _DafEmbeddingMapping ¶
-
Observation embeddings, keyed as
"other_axis:matrix_name".
- property varm : _DafEmbeddingMapping ¶
-
Variable embeddings, keyed as
"other_axis:matrix_name".
- to_df ( layer : str | None = None ) DataFrame [source] ¶
-
Return
X(or a namedlayer) as apandasDataFrame.The result has
obs_namesas the row index andvar_namesas columns. Sparse matrices are densified.
- query_obs ( query_fragment : str ) DafAnnData [source] ¶
-
Return a read-only view with observations filtered by a Daf query.
Parameters ¶
- query_fragment:
-
Anything that would fit between the
[and]of a Daf axis query, e.g.donor = D1 & age > 30.
Returns ¶
- DafAnnData
-
A read-only facade wrapping a
DafViewfiltered on the obs axis.
- query_var ( query_fragment : str ) DafAnnData [source] ¶
-
Return a read-only view with variables filtered by a Daf query.
Parameters ¶
- query_fragment:
-
Anything that would fit between the
[and]of a Daf axis query, e.g.highly_variable & ! is_lateral.
Returns ¶
- DafAnnData
-
A read-only facade wrapping a
DafViewfiltered on the var axis.