Skip to content

Commit

Permalink
refactor: normalize abstract interface and concrete service
Browse files Browse the repository at this point in the history
  • Loading branch information
Midnighter committed Aug 19, 2023
1 parent 3ec71bf commit 512731c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/taxpasta/domain/service/taxonomy_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def get_taxon_name_lineage(self, taxonomy_id: int) -> Optional[List[str]]:
def get_taxon_identifier_lineage(self, taxonomy_id: int) -> Optional[List[int]]:
"""Return the lineage of a given taxonomy identifier as identifiers."""

@abstractmethod
def get_taxon_rank_lineage(self, taxonomy_id: int) -> Optional[List[str]]:
"""Return the lineage of a given taxonomy identifier as ranks."""

@abstractmethod
def add_name(self, table: DataFrame[ResultTable]) -> DataFrame[ResultTable]:
"""Add a column for the taxon name to the given table."""
Expand All @@ -73,6 +77,10 @@ def add_identifier_lineage(
) -> DataFrame[ResultTable]:
"""Add a column for the taxon lineage as identifiers to the given table."""

@abstractmethod
def add_rank_lineage(self, table: DataFrame[ResultTable]) -> DataFrame[ResultTable]:
"""Add a column for the taxon lineage as ranks to the given table."""

@abstractmethod
def summarise_at(
self, profile: DataFrame[StandardProfile], rank: str
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def get_taxon_identifier_lineage(self, taxonomy_id: int) -> Optional[List[int]]:
return taxon.taxid_lineage

def get_taxon_rank_lineage(self, taxonomy_id: int) -> Optional[List[str]]:
"""Return the lineage of ranks of a given taxonomy identifier."""
"""Return the lineage of a given taxonomy identifier as ranks."""
try:
taxon = taxopy.Taxon(taxid=taxonomy_id, taxdb=self._tax_db)
except TaxidError:
Expand Down Expand Up @@ -150,7 +150,7 @@ def _taxid_lineage_as_str(self, taxonomy_id: int) -> Optional[str]:
return ";".join([str(tax_id) for tax_id in taxon.taxid_lineage])

def add_rank_lineage(self, table: DataFrame[ResultTable]) -> DataFrame[ResultTable]:
"""Add a column for the taxon rank lineage to the given table."""
"""Add a column for the taxon lineage as ranks to the given table."""
result = table.copy()
result.insert(
1,
Expand Down

0 comments on commit 512731c

Please sign in to comment.