Skip to content

Commit

Permalink
Version 0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
apcamargo committed Aug 5, 2021
1 parent dc0c291 commit 0ab348e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

setup(
name="taxopy",
version="0.7.0",
version="0.8.0",
packages=find_packages(),
license="GNU General Public License v3.0",
description="A Python package for obtaining complete lineages and the lowest common ancestor (LCA) from a set of taxonomic identifiers.",
Expand Down
20 changes: 14 additions & 6 deletions taxopy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ class Taxon:
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_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.
Expand All @@ -187,14 +190,17 @@ class Taxon:
def __init__(self, taxid: int, taxdb: TaxDb):
self.taxid = taxid
if self.taxid not in taxdb.taxid2name:
raise TaxidError("The input integer is not a valid NCBI taxonomic identifier.")
raise TaxidError(
"The input integer is not a valid NCBI taxonomic identifier."
)
self.name = taxdb.taxid2name[self.taxid]
self.rank = taxdb.taxid2rank[self.taxid]
self.taxid_lineage = self._find_lineage(taxdb.taxid2parent)
self.name_lineage = self._convert_to_names(taxdb.taxid2rank, taxdb.taxid2name)
self.rank_name_dictionary = self._convert_to_rank_name_dictionary(
taxdb.taxid2rank, taxdb.taxid2name
)
(
self.rank_taxid_dictionary,
self.rank_name_dictionary,
) = self._convert_to_rank_dictionary(taxdb.taxid2rank, taxdb.taxid2name)

def __repr__(self):
return " > ".join(reversed(self.name_lineage))
Expand All @@ -211,13 +217,15 @@ def _find_lineage(self, taxid2parent):
def _convert_to_names(self, taxid2rank, taxid2name):
return [taxid2name[taxid] for taxid in self.taxid_lineage]

def _convert_to_rank_name_dictionary(self, taxid2rank, taxid2name):
def _convert_to_rank_dictionary(self, taxid2rank, taxid2name):
rank_taxid_dictionary = {}
rank_name_dictionary = {}
for taxid in self.taxid_lineage:
rank = taxid2rank[taxid]
if rank != "no rank":
rank_taxid_dictionary[rank] = taxid
rank_name_dictionary[rank] = taxid2name[taxid]
return rank_name_dictionary
return rank_taxid_dictionary, rank_name_dictionary


class _AggregatedTaxon(Taxon):
Expand Down

0 comments on commit 0ab348e

Please sign in to comment.