Reference#
taxopy.TaxDb
#
Create an object of the TaxDb class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
taxdb_dir
|
str
|
A directory to download NCBI's taxonomy database files to. If the directory does not exist it will be created. |
None
|
nodes_dmp
|
str
|
The path for a pre-downloaded |
None
|
names_dmp
|
str
|
The path for a pre-downloaded |
None
|
merged_dmp
|
str
|
The path for a pre-downloaded |
None
|
taxdump_url
|
str
|
The URL of the taxdump file (in .tar.gz) to be downloaded. By default, the latest version of NCBI's taxdump will be fetched. |
None
|
keep_files
|
bool
|
Keep the |
False
|
Attributes:
Name | Type | Description |
---|---|---|
taxid2name |
dict
|
A dictionary where the keys are taxonomic identifiers and the values are their corresponding names. |
taxid2parent |
dict
|
A dictionary where the keys are taxonomic identifiers and the values are the taxonomic identifiers of their corresponding parent taxon. |
taxid2rank |
dict
|
A dictionary where the keys are taxonomic identifiers and the values are their corresponding ranks. |
oldtaxid2newtaxid |
dict
|
A dictionary where the keys are legacy taxonomic identifiers and the
values are their corresponding new identifiers. If pre-downloaded
|
Raises:
Type | Description |
---|---|
DownloadError
|
If the download of the taxonomy database fails. |
ExtractionError
|
If the decompression of the taxonomy database fails. |
Source code in taxopy/core.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 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 |
|
taxopy.Taxon
#
Create an object of the Taxon class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
taxid
|
int
|
A NCBI taxonomic identifier. |
required |
taxdb
|
TaxDb
|
A TaxDb object. |
required |
Attributes:
Name | Type | Description |
---|---|---|
taxid |
int
|
The NCBI taxonomic identifier the object represents (e.g., 9606). |
name |
str
|
The name of the taxon (e.g., 'Homo sapiens'). |
rank |
str
|
The rank of the taxon (e.g., 'species'). |
legacy_taxid |
bool
|
A boolean that represents whether the NCBI taxonomic identifier was
merged to another identifier ( |
taxid_lineage |
list
|
An ordered list containing the taxonomic identifiers of the whole lineage of the taxon, from the most specific to the most general. |
name_lineage |
list
|
An ordered list containing the names of the whole lineage of the taxon, from the most specific to the most general. |
rank_lineage |
list
|
An ordered list containing the rank names of the whole lineage of the taxon, from the most specific to the most general. |
ranked_name_lineage |
list
|
An ordered list of tuples, where each tuple represents a rank in the lineage, with the first element denoting the rank name and the second indicating the taxon's name. |
ranked_taxid_lineage |
list
|
An ordered list of tuples, where each tuple represents a rank in the lineage, with the first element denoting the rank name and the second indicating the taxon's taxonomic identifier. |
rank_taxid_dictionary |
dict
|
A dictionary where the keys are named ranks and the values are the taxids of the taxa that correspond to each of the named ranks in the lineage. |
rank_name_dictionary |
dict
|
A dictionary where the keys are named ranks and the values are the names of the taxa that correspond to each of the named ranks in the lineage. |
Methods:
Name | Description |
---|---|
parent |
Returns a Taxon object of the parent node. |
Raises:
Type | Description |
---|---|
TaxidError
|
If the input integer is not a valid NCBI taxonomic identifier. |
Source code in taxopy/core.py
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 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
|
taxopy.find_lca
#
Takes a list of multiple Taxon objects and returns their lowest common ancestor (LCA).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
taxon_list
|
list
|
A list containing at least two Taxon objects. |
required |
taxdb
|
TaxDb
|
A TaxDb object. |
required |
Returns:
Type | Description |
---|---|
_AggregatedTaxon
|
The _AggregatedTaxon object of the lowest common ancestor (LCA) of the inputs. |
Raises:
Type | Description |
---|---|
LCAError
|
If the input list has less than two Taxon objects. |
Source code in taxopy/utilities.py
taxopy.find_majority_vote
#
find_majority_vote(taxon_list: List[Taxon], taxdb: TaxDb, fraction: float = 0.5, weights: Optional[List[float]] = None) -> Taxon
Takes a list of multiple Taxon objects and returns the most specific taxon that is shared by more than the chosen fraction of the input lineages.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
taxon_list
|
list
|
A list containing at least two Taxon objects. |
required |
taxdb
|
TaxDb
|
A TaxDb object. |
required |
fraction
|
float
|
The returned taxon will be shared by more than |
0.5
|
weights
|
Optional[List[float]]
|
A list of weights associated with the taxa lineages in |
None
|
Returns:
Type | Description |
---|---|
_AggregatedTaxon
|
The _AggregatedTaxon object of the most specific taxon that is shared by more than a specified fraction of the input lineages. |
Raises:
Type | Description |
---|---|
MajorityVoteError
|
If the input taxon list has less than two Taxon objects or if the
|
Source code in taxopy/utilities.py
taxopy.taxid_from_name
#
taxid_from_name(names: Union[str, List[str]], taxdb: TaxDb, fuzzy: bool = False, score_cutoff: float = 0.9) -> Union[List[int], List[List[int]]]
Takes one (or more) taxon name and returns a list (or list of lists) containing the taxonomic identifiers associated with it (or them).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
names
|
str or list of str
|
The name of the taxon whose taxonomic identifier will be returned. A list of names can also be provided. |
required |
taxdb
|
TaxDb
|
A TaxDb object. |
required |
fuzzy
|
bool
|
If True, the input name will be matched to the taxa names in the database using fuzzy string matching. |
False
|
score_cutoff
|
float
|
The minimum score required for a match to be considered valid when fuzzy string matching is used. This value must be between 0.0 and 1.0. |
0.9
|
Returns:
Type | Description |
---|---|
list or list of list
|
A list of all the taxonomic identifiers associated with the input taxon name. If a list of names is provided, a list of lists is returned. |