dataloader
_dataloader
This file is a base class for dataloader.
- class scalr.nn.dataloader._dataloader.DataLoaderBase(batch_size: int = 1, target: str | list[str] = None, mappings: dict = None)[source]
Bases:
object
- collate_fn(batch)[source]
Collate function for dataloader. Should be implemented in child classes.
Given an input anndata of batch_size, the collate function creates inputs and outputs. It can also be used to perform batch-wise operations.
- scalr.nn.dataloader._dataloader.build_dataloader(dataloader_config: dict, adata: AnnData | AnnCollection, target: str, mappings: dict) tuple[DataLoaderBase, dict] [source]
Builder object to get DataLoader, updated dataloader_config.
- Parameters:
dataloader_config (dict) – Config to build dataloader.
adata (Union[AnnData, AnnCollection]) – Data to load.
target (str) – Target column in data.obs.
mappings (dict) – Mappings of column labels to ids.
simple_dataloader
This file is the implementation of simpledataloader.
- class scalr.nn.dataloader.simple_dataloader.SimpleDataLoader(batch_size: int, target: str, mappings: dict, padding: int = None)[source]
Bases:
DataLoaderBase
Class for simple dataloader.
Simple DataLoader converts all adata values to inputs, and target columns in metadata to output labels.
- Returns:
Tensor [batch_size, features], y: Tensor [batch_size, ]).
- Return type:
PyTorch DataLoader object with (X
- collate_fn(adata_batch: AnnData | AnnCollection) tuple[Tensor, Tensor] [source]
Given an input anndata of batch_size, the collate function creates inputs and outputs.
- Parameters:
adata_batch (Union[AnnData, AnnCollection]) – Anndata view object with batch_size samples.
- Returns:
Input to model, output from data.
- Return type:
Tuple(x, y)
simple_metadataloader
This file is the implementation of simple metadataloader.
- class scalr.nn.dataloader.simple_metadataloader.SimpleMetaDataLoader(batch_size: int, target: str, mappings: dict, metadata_col: list[str], padding: int = None)[source]
Bases:
SimpleDataLoader
Class for simple metadataloader.
Simple MetaDataLoader converts all adata values to inputs, concat specified metadata columns as onehotencoded vector to feature data and map target columns in metadata to output labels.
- Returns:
Tensor [batch_size, features], y: Tensor [batch_size, ]).
- Return type:
PyTorch DataLoader object with (X
- collate_fn(adata_batch: AnnData | AnnCollection)[source]
Given an input anndata of batch_size, the collate function creates inputs and outputs.
- Parameters:
adata_batch (Union[AnnData, AnnCollection]) – Anndata view object with batch_size samples.
- Returns:
Input to model, output from data.
- Return type:
Tuple(x, y)
test_simple_dataloader
This is a test file for simpledataloader.
- scalr.nn.dataloader.test_simple_dataloader.test_metadataloader()[source]
This function tests features shape returned by simpledataloader for the below 2 cases. 1. #features are consistent with feature_subsetsize. No padding is required. 2. #features are less than feature_subsetsize. This case needs padding.
test_simple_metadataloader
This is a test file for simplemetadataloader.