scvi.data.AnnDataManager#

class scvi.data.AnnDataManager(fields=None, setup_method_args=None)[source]#

Provides an interface to validate and process an AnnData object for use in scvi-tools.

A class which wraps a collection of AnnDataField instances and provides an interface to validate and process an AnnData object with respect to the fields.

Parameters:
fields : Sequence[Type[BaseAnnDataField]] | NoneOptional[Sequence[Type[BaseAnnDataField]]] (default: None)

List of AnnDataFields to intialize with.

setup_method_args : dict | NoneOptional[dict] (default: None)

Dictionary describing the model and arguments passed in by the user to setup this AnnDataManager.

Examples

>>> fields = [LayerField("counts", "raw_counts")]
>>> adata_manager = AnnDataManager(fields=fields)
>>> adata_manager.register_fields(adata)

Notes

This class is not initialized with a specific AnnData object, but later sets self.adata via register_fields(). This decouples the generalized definition of the scvi-tools interface with the registration of an instance of data.

Attributes table#

adata_uuid

Returns the UUID for the AnnData object registered with this instance.

data_registry

Returns the data registry for the AnnData object registered with this instance.

registry

Returns the top-level registry dictionary for the AnnData object registered with this instance as an attrdict.

summary_stats

Returns the summary stats for the AnnData object registered with this instance.

Methods table#

get_from_registry(registry_key)

Returns the object in AnnData associated with the key in the data registry.

get_state_registry(registry_key)

Returns the state registry for the AnnDataField registered with this instance.

register_fields(adata[, source_registry])

Registers each field associated with this instance with the AnnData object.

transfer_fields(adata_target, **kwargs)

Transfers an existing setup to each field associated with this instance with the target AnnData object.

validate()

Checks if AnnData was last setup with this AnnDataManager instance and reregisters it if not.

view_registry([hide_state_registries])

Prints summary of the registry.

view_setup_method_args(registry)

Prints setup kwargs used to produce a given registry.

Attributes#

adata_uuid#

AnnDataManager.adata_uuid[source]#

Returns the UUID for the AnnData object registered with this instance.

Return type:

str

data_registry#

AnnDataManager.data_registry[source]#

Returns the data registry for the AnnData object registered with this instance.

Return type:

attrdict

registry#

AnnDataManager.registry[source]#

Returns the top-level registry dictionary for the AnnData object registered with this instance as an attrdict.

Return type:

dict

summary_stats#

AnnDataManager.summary_stats[source]#

Returns the summary stats for the AnnData object registered with this instance.

Return type:

attrdict

Methods#

get_from_registry#

AnnDataManager.get_from_registry(registry_key)[source]#

Returns the object in AnnData associated with the key in the data registry.

Parameters:
registry_key : str

key of object to get from self.data_registry

Return type:

ndarray | DataFrameUnion[ndarray, DataFrame]

Returns:

The requested data.

get_state_registry#

AnnDataManager.get_state_registry(registry_key)[source]#

Returns the state registry for the AnnDataField registered with this instance.

Return type:

attrdict

register_fields#

AnnDataManager.register_fields(adata, source_registry=None, **transfer_kwargs)[source]#

Registers each field associated with this instance with the AnnData object.

Either registers or transfers the setup from source_setup_dict if passed in. Sets self.adata.

Parameters:
adata : AnnData | MuDataUnion[AnnData, MuData]

AnnData object to be registered.

source_registry : dict | NoneOptional[dict] (default: None)

Registry created after registering an AnnData using an AnnDataManager object.

transfer_kwargs

Additional keywords which modify transfer behavior. Only applicable if source_registry is set.

transfer_fields#

AnnDataManager.transfer_fields(adata_target, **kwargs)[source]#

Transfers an existing setup to each field associated with this instance with the target AnnData object.

Creates a new AnnDataManager instance with the same set of fields. Then, registers the fields with a target AnnData object, incorporating details of the source registry where necessary (e.g. for validation or modified data setup).

Parameters:
adata_target : AnnData | MuDataUnion[AnnData, MuData]

AnnData object to be registered.

kwargs

Additional keywords which modify transfer behavior.

Return type:

AnnDataManager

validate#

AnnDataManager.validate()[source]#

Checks if AnnData was last setup with this AnnDataManager instance and reregisters it if not.

Return type:

None

view_registry#

AnnDataManager.view_registry(hide_state_registries=False)[source]#

Prints summary of the registry.

Parameters:
hide_state_registries : bool (default: False)

If True, prints a shortened summary without details of each state registry.

Return type:

None

view_setup_method_args#

static AnnDataManager.view_setup_method_args(registry)[source]#

Prints setup kwargs used to produce a given registry.

Parameters:
registry : dict

Registry produced by an AnnDataManager.

Return type:

None