CSData
A CSData object is a wrapper around a single-cell dataset, which tracks its path on disk. It’s main functionality is to keep the dataset stored on disk so that data need not be loaded in memory until it is used, either for inference or finetuning.
- csdata.CSData(vocab, data_path, dataset_backend='arrow')
Wrapper class to abstract different types of input data that can be passed in cell2sentence based workflows.
- csdata.CSData.__init__(self, vocab, data_path, dataset_backend='arrow')
Core constructor for CSData object that contains a data path to the C2S dataset. Helps manage data loading and buffering.
- Parameters:
vocab – ordered dictionary of feature names and their number of cells expressed
data_path – path to saved arrow dataset on disk
dataset_backend – backend implementation of C2S dataset (currently Huggingface supported)
The CSData.adata_to_arrow() function takes as input a single-cell dataset in the form
of a H5AD Scanpy object, and returns a pyarrow dataset which stores cell sentences
representing the dataset after C2S rank transformation.
- csdata.CSData.adata_to_arrow(adata, random_state: int = 42, sentence_delimiter: str = ' ', label_col_names: list = None)
Construct an arrow dataset of cell sentences from an AnnData object.
- Parameters:
adata – anndata.AnnData object to convert into a cell sentence dataset
random_state – random seed to control randomness
sentence_delimiter – separator for cell sentence strings (default: ‘ ‘)
label_col_names – optional list of column names in .obs to save into dataset along with cell sentences
- Returns:
Tuple of i) arrow dataset of cell sentences and ii) ordered dictionary of gene names and their number of expressed cells
- csdata.CSData.csdata_from_arrow(arrow_dataset, vocabulary, save_dir: str, save_name: str, dataset_backend: str = 'arrow')
Create new CSData object from a single arrow dataset.
This function expects the C2S arrow dataset to already be created (e.g. by using adata_to_arrow()), and will create a CSData() wrapper object which will manage loading the dataset in concert with other C2S classes.
- Parameters:
arrow_dataset – an arrow dataset to create the CSData wrapper around
vocabulary – ordered dictionary containing feature names and their number of cells expressed
save_dir – directory where cell sentence dataset will be saved to disk
save_name – name of folder to create storing cell sentence dataset (will be created)
dataset_backend – backend implementation for cell sentence dataset
- Returns:
CSData() object
- csdata.CSData.csdata_from_multiple_arrow_datasets(arrow_dataset_list, vocabulary_list, save_dir: str, save_name: str, dataset_backend: str = 'arrow')
Create new CSData object from multiple arrow datasets. Useful when creating a CSData() object to manage multiple chunks of a large single-cell dataset, or when combining multiple single-cell datasets into one large dataset.
- Parameters:
arrow_dataset_list – list of arrow datasets to create the CSData object around
vocabulary_list – list of ordered dictionaries containing feature names and their number of cells expressed
save_dir – directory where cell sentence dataset will be saved to disk
save_name – name of folder to create storing cell sentence dataset (will be created)
dataset_backend – backend implementation for cell sentence dataset
- Returns:
CSData() object
- csdata.CSData.get_sentence_strings(self)
Helper function to return cell sentences sotred in arrow dataset.
- csdata.CSData.__str__(self)
Summarize CSData object as string for debugging and logging.