Gene tokenizer
GeneTokenizer
Bases: Label2IDTokenizer
, IOMixin
Initializes the GeneTokenizer object.
Source code in bionemo/geneformer/tokenizer/gene_tokenizer.py
32 33 34 35 36 37 38 39 40 41 42 43 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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
ens_tok_to_gene(ens)
Converts an Ensembl token to a gene name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ens
|
str
|
The Ensembl token to be converted. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The corresponding gene name. |
Source code in bionemo/geneformer/tokenizer/gene_tokenizer.py
140 141 142 143 144 145 146 147 148 149 |
|
enss_to_genes(ensemble_ids)
Converts a list of ensemble IDs to gene names.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ensemble_ids
|
List[str]
|
A list of ensemble IDs. |
required |
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: A list of gene names corresponding to the ensemble IDs. |
Raises:
Type | Description |
---|---|
ValueError
|
If an ensemble ID is not found in the mapping. |
Source code in bionemo/geneformer/tokenizer/gene_tokenizer.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
from_medians_and_genes_dicts(median_dict, gene_to_ens)
classmethod
Creates a tokenizer from a median dictionary.
Source code in bionemo/geneformer/tokenizer/gene_tokenizer.py
53 54 55 56 57 58 |
|
from_vocab_file(vocab_file)
classmethod
This method adds a layer on the constructor in the case we are working from a filename instead of a dictionary.
Source code in bionemo/geneformer/tokenizer/gene_tokenizer.py
115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
gene_tok_to_ens(gene)
Converts a gene token to its corresponding Ensembl ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gene
|
str
|
The gene token to be converted. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The Ensembl ID corresponding to the gene token. |
Source code in bionemo/geneformer/tokenizer/gene_tokenizer.py
129 130 131 132 133 134 135 136 137 138 |
|
genes_to_enss(genes)
Converts a list of gene names to Ensembl IDs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
genes
|
List[str]
|
A list of gene names. |
required |
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: A list of corresponding Ensembl IDs. |
Raises:
Type | Description |
---|---|
ValueError
|
If a gene name is not found in the gene_to_ens dictionary. |
Source code in bionemo/geneformer/tokenizer/gene_tokenizer.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
save_vocab(vocab_file)
Saves the vocabulary as a newline delimieted vocabulary file, each line represents an int -> token mapping. line number is assumed to be the integer.
Source code in bionemo/geneformer/tokenizer/gene_tokenizer.py
102 103 104 105 106 107 108 109 110 111 112 113 |
|
token_to_id(token)
Converts a token to its corresponding ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token
|
str
|
The token to be converted. |
required |
Returns:
Type | Description |
---|---|
int
|
The ID corresponding to the token. |
Source code in bionemo/geneformer/tokenizer/gene_tokenizer.py
72 73 74 75 76 77 78 79 80 81 |
|