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 like pandas DataFrame for the common [] get/set/delete, .columns , .index , and .to_df() operations.

  • layers — dict-like proxy over additional (obs_axis, var_axis) matrices (all except X ).

  • 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 requires other_axis to 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 obs or var columns are automatically converted to strings.

  • uns only supports flat scalar values (strings and numbers). Assigning a non-scalar raises TypeError .

  • obs_names and var_names are read-only; axis entries cannot be renamed through this facade.

  • Concatenation and other operations that create new AnnData objects are not supported.

class dafpy.anndata_facade. DafAnnData ( daf : DafReader , * , obs_axis : str , var_axis : str , x_matrix : str ) [source]

Facade that presents a DafReader or DafWriter as an AnnData -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 as X .

property daf : DafReader

Access the wrapped Daf repository.

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, excluding X .

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 named layer ) as a pandas DataFrame .

The result has obs_names as the row index and var_names as 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 DafView filtered 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 DafView filtered on the var axis.