Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/test_ncbi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Test Latest NCBI Taxonomy
on:
push:
branches:
- master
pull_request:
schedule:
- cron: '0 0 1 * *' # runs at 00:00 on the 1st of every month (UTC)

jobs:
test-ncbi-python-bindings:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Install python headers
run: sudo apt-get update && sudo apt-get install python3-dev python3-pip python3-venv

- name: Install python dependencies
run: |
python3 -m venv venv
. venv/bin/activate
pip3 install maturin downloads
pip3 show maturin

- name: Add library to venv
run: |
. venv/bin/activate
maturin develop --features=python

- name: Test Python bindings with latest NCBI taxonomy
run: |
. venv/bin/activate
TAXONOMY_TEST_NCBI=true python -m unittest test_python.LatestNCBITestCase.test_load_latest_ncbi_taxonomy
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
run: |
python3 -m venv venv
. venv/bin/activate
pip3 install maturin
pip3 install maturin downloads
pip3 show maturin

- name: add library to venv
Expand Down
9 changes: 9 additions & 0 deletions src/rank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use crate::errors::{Error, ErrorKind, TaxonomyResult};
#[non_exhaustive]
pub enum TaxRank {
Domain,
AcellularRoot,
CellularRoot,
Subdomain,
Realm,
Subrealm,
Expand Down Expand Up @@ -113,6 +115,8 @@ impl TaxRank {
pub fn to_ncbi_rank(self) -> &'static str {
match self {
TaxRank::Superkingdom => "superkingdom",
TaxRank::AcellularRoot => "acellular root",
TaxRank::CellularRoot => "cellular root",
TaxRank::Kingdom => "kingdom",
TaxRank::Subkingdom => "subkingdom",
TaxRank::Superphylum => "superphylum",
Expand Down Expand Up @@ -170,6 +174,8 @@ impl FromStr for TaxRank {
"domain" | "regio" => Ok(TaxRank::Domain),
"subdomain" => Ok(TaxRank::Subdomain),
"realm" => Ok(TaxRank::Realm),
"acellular root" => Ok(TaxRank::AcellularRoot),
"cellular root" => Ok(TaxRank::CellularRoot),
"subrealm" => Ok(TaxRank::Subrealm),
"hyperkingdom" | "hyperregnum" => Ok(TaxRank::Hyperkingdom),
"superkingdom" | "superregnum" => Ok(TaxRank::Superkingdom),
Expand Down Expand Up @@ -257,6 +263,8 @@ impl fmt::Display for TaxRank {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let rank_str = match self {
TaxRank::Domain => "domain",
TaxRank::AcellularRoot => "acellular root",
TaxRank::CellularRoot => "cellular root",
TaxRank::Subdomain => "subdomain",
TaxRank::Realm => "realm",
TaxRank::Subrealm => "subrealm",
Expand Down Expand Up @@ -357,6 +365,7 @@ mod test {

static RANKS: &[super::TaxRank] = &[
Domain,
AcellularRoot,
Subdomain,
Realm,
Subrealm,
Expand Down
13 changes: 13 additions & 0 deletions test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import unittest

from taxonomy import Taxonomy, TaxonomyError
from downloads import download
import os
import subprocess

JSON_DATA = """
{
Expand Down Expand Up @@ -487,5 +490,15 @@ def test_invalid_format(self):
Taxonomy.from_gtdb(file.read())


class LatestNCBITestCase(unittest.TestCase):
@unittest.skipUnless(
os.getenv("TAXONOMY_TEST_NCBI"), "Define TAXONOMY_TEST_NCBI to run NCBI test"
)
def test_load_latest_ncbi_taxonomy(self):
download("https://ftp.ncbi.nih.gov/pub/taxonomy/taxdump.tar.gz")
subprocess.check_output(["tar", "-zxvf", "taxdump.tar.gz"])
Taxonomy.from_ncbi(".")


if __name__ == "__main__":
unittest.main()
4 changes: 2 additions & 2 deletions tests/data/nodes.dmp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
1 | 1 | no rank | | 8 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | |
10239 | 1 | no_rank | | 9 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | |
10239 | 1 | acellular root | | 9 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | |
2 | 131567 | superkingdom | | 0 | 0 | 11 | 0 | 0 | 0 | 0 | 0 | |
543 | 91347 | family | | 0 | 1 | 11 | 1 | 0 | 1 | 0 | 0 | |
561 | 543 | genus | | 0 | 1 | 11 | 1 | 0 | 1 | 0 | 0 | |
562 | 561 | species | EC | 0 | 1 | 11 | 1 | 0 | 1 | 1 | 0 | |
1224 | 2 | phylum | | 0 | 1 | 11 | 1 | 0 | 1 | 0 | 0 | |
1236 | 1224 | class | | 0 | 1 | 11 | 1 | 0 | 1 | 0 | 0 | |
91347 | 1236 | order | | 0 | 1 | 11 | 1 | 0 | 1 | 0 | 0 | |
131567 | 1 | no rank | | 8 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | |
131567 | 1 | cellular root | | 8 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | |
Loading