scdynomics.utils.data.corpus

Dataset corpus for scDynOmics

author: jy

Classes

Multimodal_Corpus(*args, **kwargs)

A PyTorch Dataset designed for loading and handling multimodal single-cell data.

Repr_Corpus(*args, **kwargs)

Representation data corpus

Tensor_Corpus(*args, **kwargs)

Dummy dataset for tensor data

class scdynomics.utils.data.corpus.Multimodal_Corpus(*args: Any, **kwargs: Any)

Bases: Dataset

A PyTorch Dataset designed for loading and handling multimodal single-cell data.

This dataset integrates with AnnData objects to extract specified modalities (layers) and labels, preparing the raw data to be tokenized and ingested by the model.

__init__(adata_path: str = None, adata: anndata.AnnData = None, backed: bool = True, monomodal: str = None, layers: list = ['X'], label_key: str = None, squeeze_multimodal: bool = False, dtype=numpy.float32)
Parameters:
adata_path: str (default: None)

The file path to the .h5ad file containing the dataset.

adata: ad.AnnData (default: None)

An existing AnnData object. If provided, overrides adata_path.

backed: bool (default: True)

If True, loads the AnnData file in backed mode to minimize memory usage.

monomodal: str (default: None)

Restricts the output to a single specified modality.

layers: list (default: [‘X’])

A list of layers to extract and concatenate from the AnnData object.

label_key: str (default: None)

The column name in adata.obs containing categorical target labels for supervised tasks.

squeeze_multimodal: bool (default: False)

If True, reshapes the output tensor to (1, -1, 1).

dtype: type (default: np.float32)

The numpy data type for the returned arrays.

stratify(class_label: int = None, actual_label: str = None, label_key: str = None) Multimodal_Corpus

Stratify the dataset by the label

Parameters:
class_label: int (default: None)

The integer label to stratify by. If provided, overrides actual_label.

actual_label: str (default: None)

The categorical label to stratify by. If provided, overrides class_label.

label_key: str (default: None)

The column name in adata.obs to use for stratification. If not provided, uses the dataset’s default label_key.

Returns: scdynomics.Multimodal_Corpus

An instance of Multimodal_Corpus containing only the samples corresponding to the specified label.

class scdynomics.utils.data.corpus.Repr_Corpus(*args: Any, **kwargs: Any)

Bases: Multimodal_Corpus

Representation data corpus

__init__(adata_path: str = None, adata: anndata.AnnData = None, rep_key: str = 'X_pca', label_key: str = None, dtype=numpy.float32)
Parameters:
adata_path: str (default: None)

The file path to the .h5ad file containing the dataset.

adata: ad.AnnData (default: None)

An existing AnnData object. If provided, overrides adata_path.

backed: bool (default: True)

If True, loads the AnnData file in backed mode to minimize memory usage.

monomodal: str (default: None)

Restricts the output to a single specified modality.

layers: list (default: [‘X’])

A list of layers to extract and concatenate from the AnnData object.

label_key: str (default: None)

The column name in adata.obs containing categorical target labels for supervised tasks.

squeeze_multimodal: bool (default: False)

If True, reshapes the output tensor to (1, -1, 1).

dtype: type (default: np.float32)

The numpy data type for the returned arrays.

class scdynomics.utils.data.corpus.Tensor_Corpus(*args: Any, **kwargs: Any)

Bases: Dataset

Dummy dataset for tensor data

__init__(data: torch.Tensor, labels: torch.Tensor = None, parent: torch.utils.data.Dataset = None)
get_class_distribution(translate_label: bool = True)

Get the class distribution

stratify(class_label: int = None)

Stratify the dataset by the label