Dataset
SingleCellDataset
Bases: Dataset
A dataset class for single-cell pre-training. These can be generated using the sc_memmap.py script. Future updates will contain more comprehensive workflows for generating a Sparse Memmap from scRNA-seq.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_path
|
str
|
Path where the single cell files are stored in SingleCell Memmap format. It should contain the following files:
- |
required |
tokenizer
|
Any
|
The tokenizer to use for tokenizing the input data. |
required |
median_dict
|
dict
|
A dictionary containing median values for each gene. Defaults to None. |
None
|
max_len
|
int
|
The maximum length of the input sequence. Defaults to 1024. |
1024
|
include_unrecognized_vocab_in_dataset
|
bool
|
If set to True, a hard-check is performed to verify all gene identifers are in the user supplied tokenizer vocab. Defaults to False which means any gene identifier not in the user supplied tokenizer vocab will be excluded. |
False
|
Attributes:
Name | Type | Description |
---|---|---|
data_path |
str
|
Path where the single cell files are stored in SCDL memmap format. |
max_len |
int
|
The maximum length of the input sequence. |
metadata |
dict
|
Metadata loaded from |
gene_medians |
dict
|
A dictionary containing median values for each gene. If None, a median of '1' is assumed for all genes. |
num_train |
int
|
The number of samples in the training split. |
num_val |
int
|
The number of samples in the validation split. |
num_test |
int
|
The number of samples in the test split. |
index_offset |
int
|
The offset to apply to the indices. |
length |
int
|
The total number of samples in the dataset. |
gene_data |
memmap
|
Gene expression values stored in CSR format. |
gene_data_indices |
memmap
|
Gene indices associated with gene values. |
gene_data_ptr |
memmap
|
Column indices for each sample. |
tokenizer |
The tokenizer used for tokenizing the input data. |
|
dataset_ccum |
ndarray
|
Cumulative sum of row counts to map row indices to dataset id. |
dataset_map |
dict
|
Mapping of dataset id to dataset name. |
Methods:
Name | Description |
---|---|
__len__ |
Returns the length of the dataset. |
__getitem__ |
Returns the item at the given index. |
See Also
bionemo/data/singlecell/sc_memmap.py - creates the artifacts required for instantiating a singlecell dataset from hdf5 files.
Source code in bionemo/geneformer/data/singlecell/dataset.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
|
__getitem__(index)
Performs a lookup and the required transformation for the model.
Source code in bionemo/geneformer/data/singlecell/dataset.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
|
process_item(gene_data, gene_idxs, feature_ids, tokenizer, gene_median, rng, max_len=1024, mask_prob=0.15, mask_token_prob=0.8, random_token_prob=0.1, target_sum=10000, normalize=True, prepend_cls_token=True, eos_token=None, include_unrecognized_vocab_in_dataset=False)
Process a single item in the dataset.
Optionally performs median normalization and rank ordering. The tokenizers CLS token is added to the beginning of every sample. Converts gene names to ensemble ids before tokenizing. Expects gene_medians to contain ensembl ids as keys.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gene_data
|
list
|
List of gene data, these are expression counts. |
required |
gene_idxs
|
list
|
List of gene indices, these are keys in 'metadata['feature_ids']' and corresponding the CSR entry. |
required |
feature_ids
|
list
|
Feature ids for the full dataset. |
required |
tokenizer
|
Tokenizer
|
Tokenizer object. |
required |
gene_median
|
optional(dict
|
Dictionary of gene medians. Defaults to None. Expects ensembl IDs to be keys. |
required |
rng
|
Generator
|
Random number generator to ensure deterministic results. |
required |
max_len
|
int
|
Maximum length of the item. Defaults to 1024. Applies padding to any sequence shorter than max_len and truncates any sequence longer than max_len. |
1024
|
mask_prob
|
float
|
Probability of masking a token. Defaults to 0.15. |
0.15
|
target_sum
|
int
|
Target sum for normalization. Defaults to 10000. |
10000
|
normalize
|
bool
|
Flag to normalize the gene data. Defaults to True. When set, this re-orders the gene tokens by their median expression value. |
True
|
probabilistic_dirichlet_sampling
|
bool
|
Flag to enable probabilistic dirichlet sampling. Defaults to False. |
required |
dirichlet_alpha
|
float
|
Alpha value for dirichlet sampling if set by |
required |
same_length
|
bool
|
when true, sample the same length of genes as you originally had before the dirichlet sampler. |
required |
recompute_globals
|
bool
|
when true, global arrays are always recomputed. this is only useful for testing. |
required |
include_unrecognized_vocab_in_dataset
|
bool
|
If set to True, a hard-check is performed to verify all gene identifers are in the user supplied tokenizer vocab. Defaults to False which means any gene identifier not in the user supplied tokenizer vocab will be excluded. |
False
|
Returns:
Name | Type | Description |
---|---|---|
dict |
BertSample
|
Processed item dictionary. |
this method is very important and very useful. To generalize thiswwe should add an abstraction for
Datasets that have some kind of functor transformation.
Source code in bionemo/geneformer/data/singlecell/dataset.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
|