scimilarity.anndata_data_models#

class scimilarity.anndata_data_models.MetricLearningDataModule(*args, **kwargs)[source]#

Bases: LightningDataModule

A class to encapsulate the anndata needed to train the model.

Parameters:
  • train_path (str) –

  • val_path (Optional[str]) –

  • obs_field (str) –

  • batch_size (int) –

  • num_workers (int) –

  • gene_order_file (Optional[str]) –

collate(batch)[source]#

Collate tensors.

Parameters:

batch – Batch to collate.

Returns:

A Tuple[torch.Tensor, torch.Tensor, list] containing information on the collated tensors.

Return type:

tuple

get_sampler_weights(labels, studies=None)[source]#

Get weighted random sampler.

Parameters:
  • dataset (scDataset) – Single cell dataset.

  • labels (list) –

  • studies (Optional[list]) –

Returns:

A WeightedRandomSampler object.

Return type:

WeightedRandomSampler

subset_valid_terms(data)[source]#

Keep cells whose celltype labels have valid ontology id.

Parameters:

data (anndata.AnnData) – Annotated data to subset by valid ontology id.

Returns:

An object containing the data whose celltype labels have valid ontology id.

Return type:

anndata.AnnData

test_dataloader()[source]#

Load the test dataset.

Returns:

A DataLoader object containing the test dataset.

Return type:

DataLoader

train_dataloader()[source]#

Load the training dataset.

Returns:

A DataLoader object containing the training dataset.

Return type:

DataLoader

val_dataloader()[source]#

Load the validation dataset.

Returns:

A DataLoader object containing the validation dataset.

Return type:

DataLoader

class scimilarity.anndata_data_models.scDataset(X, Y, study=None)[source]#

Bases: Dataset

A class that represent a single cell dataset.