scvi.dataloaders.TileDBDataModule#

class scvi.dataloaders.TileDBDataModule(query, *args, batch_column_names=None, batch_labels=None, label_keys=None, unlabeled_category='Unknown', sample_key=None, train_size=1.0, split_seed=None, dataloader_kwargs=None, accelerator='auto', device='auto', model_name='SCVI', categorical_covariate_keys=None, continuous_covariate_keys=None, **kwargs)[source]#

Bases: LightningDataModule

PyTorch Lightning DataModule for training scVI models from SOMA data

Wraps a tiledbsoma_ml.ExperimentDataset to stream the results of a SOMA ExperimentAxisQuery, exposing a DataLoader to generate tensors ready for scVI model training. Also handles deriving the scVI batch label as a tuple of obs columns.

Attributes table#

extra_categorical_covs

extra_continuous_covs

labels_mapping

n_batch

n_labels

n_obs

n_samples

n_vars

registry

samples_mapping

split_seed

Seed for data split.

train_size

Fraction of data to use for training.

unlabeled_category

String assigned to unlabeled cells.

validation_size

Fraction of data to use for validation.

Methods table#

inference_dataloader()

Dataloader for inference with on_before_batch_transfer applied.

on_before_batch_transfer(batch, dataloader_idx)

Convert a tiledbsoma batch to the dictionary scvi-tools expects.

setup([stage])

Called at the beginning of fit (train + validate), validate, test, or predict.

train_dataloader()

Create the train data loader.

val_dataloader()

Create the validation data loader.

Attributes#

TileDBDataModule.extra_categorical_covs[source]#
TileDBDataModule.extra_continuous_covs[source]#
TileDBDataModule.labels_mapping[source]#
TileDBDataModule.n_batch[source]#
TileDBDataModule.n_labels[source]#
TileDBDataModule.n_obs[source]#
TileDBDataModule.n_samples[source]#
TileDBDataModule.n_vars[source]#
TileDBDataModule.registry[source]#
TileDBDataModule.samples_mapping[source]#
TileDBDataModule.split_seed[source]#

Seed for data split.

TileDBDataModule.train_size[source]#

Fraction of data to use for training.

TileDBDataModule.unlabeled_category[source]#

String assigned to unlabeled cells.

TileDBDataModule.validation_size[source]#

Fraction of data to use for validation.

Methods#

TileDBDataModule.inference_dataloader()[source]#

Dataloader for inference with on_before_batch_transfer applied.

TileDBDataModule.on_before_batch_transfer(batch, dataloader_idx)[source]#

Convert a tiledbsoma batch to the dictionary scvi-tools expects.

Return type:

dict[str, Tensor | None]

TileDBDataModule.setup(stage=None)[source]#

Called at the beginning of fit (train + validate), validate, test, or predict. This is a good hook when you need to build models dynamically or adjust something about them. This hook is called on every process when using DDP.

Parameters:

stage (str | None (default: None)) – either 'fit', 'validate', 'test', or 'predict'

Return type:

None

Example:

class LitModel(...):
    def __init__(self):
        self.l1 = None

    def prepare_data(self):
        download_data()
        tokenize()

        # don't do this
        self.something = else

    def setup(self, stage):
        data = load_data(...)
        self.l1 = nn.Linear(28, data.num_classes)
TileDBDataModule.train_dataloader()[source]#

Create the train data loader.

Return type:

DataLoader

TileDBDataModule.val_dataloader()[source]#

Create the validation data loader.

Return type:

DataLoader