scdynomics.utils.data.corpus
Dataset corpus for scDynOmics
author: jy
Classes
|
A PyTorch Dataset designed for loading and handling multimodal single-cell data. |
|
Representation data corpus |
|
Dummy dataset for tensor data |
- class scdynomics.utils.data.corpus.Multimodal_Corpus(*args: Any, **kwargs: Any)
Bases:
DatasetA 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
.h5adfile 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.obscontaining 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.
- adata_path:
- 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.obsto use for stratification. If not provided, uses the dataset’s defaultlabel_key.
- class_label:
- Returns:
scdynomics.Multimodal_Corpus An instance of
Multimodal_Corpuscontaining only the samples corresponding to the specified label.
- class scdynomics.utils.data.corpus.Repr_Corpus(*args: Any, **kwargs: Any)
Bases:
Multimodal_CorpusRepresentation 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
.h5adfile 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.obscontaining 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.
- adata_path:
- class scdynomics.utils.data.corpus.Tensor_Corpus(*args: Any, **kwargs: Any)
Bases:
DatasetDummy 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