scvi.data.fields.BaseMuDataWrapperClass#

class scvi.data.fields.BaseMuDataWrapperClass(mod_key=None, mod_required=False)[source]#

A wrapper class that adds MuData support for an AnnDataField.

The wrapper class makes calls to the self.adata_field instance using the appropriate modality and allows for manipulation at the MuData object level.

Parameters:
mod_key : str | NoneOptional[str] (default: None)

Modality key where data is stored. If None, uses the top level MuData object attributes.

mod_required : bool (default: False)

If True, raises ValueError when mod_key is None.

Attributes table#

adata_field

AnnDataField instance that this class instance wraps.

attr_key

The key of the data field within the relevant AnnData/MuData attribute.

attr_name

The name of the AnnData/MuData attribute where the data is stored.

is_empty

Returns True if the field is empty as a function of its kwargs.

mod_key

The modality key of the data field within the MuData (if applicable).

registry_key

The key that is referenced by models via a data loader.

Methods table#

get_data_registry()

Returns a nested dictionary which describes the mapping to the data field.

get_field_data(adata)

Returns the requested data as determined by the field for a given AnnData/MuData object.

get_modality(mdata)

Fetches the appropriate modality from the MuData object using self.mod_key.

get_summary_stats(state_registry)

Returns a dictionary comprising of summary statistics relevant to the field.

preregister(mdata)

Function that is called prior to registering fields.

register_field(mdata)

Sets up the AnnData/MuData object and creates a mapping for scvi-tools models to use.

transfer_field(state_registry, mdata_target, ...)

Takes an existing scvi-tools setup dictionary and transfers the same setup to the target AnnData.

validate_field(mdata)

Validates whether an AnnData/MuData object is compatible with this field definition.

view_state_registry(state_registry)

Returns a rich.table.Table summarizing a state registry produced by this field.

Attributes#

adata_field#

BaseMuDataWrapperClass.adata_field#

AnnDataField instance that this class instance wraps.

Return type:

Type[BaseAnnDataField]

attr_key#

BaseMuDataWrapperClass.attr_key#

The key of the data field within the relevant AnnData/MuData attribute.

Return type:

str | NoneOptional[str]

attr_name#

BaseMuDataWrapperClass.attr_name#

The name of the AnnData/MuData attribute where the data is stored.

Return type:

str

is_empty#

BaseMuDataWrapperClass.is_empty#
Return type:

bool

mod_key#

BaseMuDataWrapperClass.mod_key#

The modality key of the data field within the MuData (if applicable).

Return type:

str | NoneOptional[str]

registry_key#

BaseMuDataWrapperClass.registry_key#

The key that is referenced by models via a data loader.

Return type:

str

Methods#

get_data_registry#

BaseMuDataWrapperClass.get_data_registry()#

Returns a nested dictionary which describes the mapping to the data field.

The dictionary is of the form {“mod_key”: mod_key, “attr_name”: attr_name, “attr_key”: attr_key}. This mapping is then combined with the mappings of other fields to make up the data registry.

Return type:

dict

get_field_data#

BaseMuDataWrapperClass.get_field_data(adata)#

Returns the requested data as determined by the field for a given AnnData/MuData object.

Return type:

ndarray | DataFrameUnion[ndarray, DataFrame]

get_modality#

BaseMuDataWrapperClass.get_modality(mdata)[source]#

Fetches the appropriate modality from the MuData object using self.mod_key.

Return type:

AnnData | MuDataUnion[AnnData, MuData]

get_summary_stats#

BaseMuDataWrapperClass.get_summary_stats(state_registry)[source]#

Returns a dictionary comprising of summary statistics relevant to the field.

Parameters:
state_registry : dict

Dictionary returned by register_field(). Summary stats should always be a function of information stored in this dictionary.

Return type:

dict

Returns:

summary_stats_dict The dictionary is of the form {summary_stat_name: summary_stat_value}. This mapping is then combined with the mappings of other fields to make up the summary stats mapping.

preregister#

BaseMuDataWrapperClass.preregister(mdata)[source]#

Function that is called prior to registering fields.

Function that is be called at the beginning of register_field() and transfer_field(). Used when data manipulation is necessary across modalities.

Return type:

None

register_field#

BaseMuDataWrapperClass.register_field(mdata)[source]#

Sets up the AnnData/MuData object and creates a mapping for scvi-tools models to use.

Return type:

dict

Returns:

dict A dictionary containing any additional state required for scvi-tools models not stored directly on the AnnData/MuData object.

transfer_field#

BaseMuDataWrapperClass.transfer_field(state_registry, mdata_target, **kwargs)[source]#

Takes an existing scvi-tools setup dictionary and transfers the same setup to the target AnnData.

Used when one is running a pretrained model on a new AnnData object, which requires the mapping from the original data to be applied to the new AnnData object.

Parameters:
state_registry : dict

state_registry dictionary created after registering an AnnData using an AnnDataManager object.

adata_target

AnnData/MuData object that is being registered.

**kwargs

Keyword arguments to modify transfer behavior.

Return type:

dict

Returns:

dict A dictionary containing any additional state required for scvi-tools models not stored directly on the AnnData object.

validate_field#

BaseMuDataWrapperClass.validate_field(mdata)[source]#

Validates whether an AnnData/MuData object is compatible with this field definition.

Return type:

None

view_state_registry#

BaseMuDataWrapperClass.view_state_registry(state_registry)[source]#

Returns a rich.table.Table summarizing a state registry produced by this field.

Parameters:
state_registry : dict

Dictionary returned by register_field(). Printed summary should always be a function of information stored in this dictionary.

Return type:

Table | NoneOptional[Table]

Returns:

state_registry_summary Optional rich.table.Table summarizing the state_registry.