diff --git a/.github/workflows/test_ncbi.yml b/.github/workflows/test_ncbi.yml new file mode 100644 index 0000000..e7628f0 --- /dev/null +++ b/.github/workflows/test_ncbi.yml @@ -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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fd828fb..4687d93 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 diff --git a/src/rank.rs b/src/rank.rs index 2d9aee5..64d74f5 100644 --- a/src/rank.rs +++ b/src/rank.rs @@ -15,6 +15,8 @@ use crate::errors::{Error, ErrorKind, TaxonomyResult}; #[non_exhaustive] pub enum TaxRank { Domain, + AcellularRoot, + CellularRoot, Subdomain, Realm, Subrealm, @@ -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", @@ -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), @@ -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", @@ -357,6 +365,7 @@ mod test { static RANKS: &[super::TaxRank] = &[ Domain, + AcellularRoot, Subdomain, Realm, Subrealm, diff --git a/test_python.py b/test_python.py index 1902040..0d0bccc 100644 --- a/test_python.py +++ b/test_python.py @@ -2,6 +2,9 @@ import unittest from taxonomy import Taxonomy, TaxonomyError +from downloads import download +import os +import subprocess JSON_DATA = """ { @@ -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() diff --git a/tests/data/nodes.dmp b/tests/data/nodes.dmp index 0b0683e..ae2d0de 100644 --- a/tests/data/nodes.dmp +++ b/tests/data/nodes.dmp @@ -1,5 +1,5 @@ 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 | | @@ -7,4 +7,4 @@ 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 | |