Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --keep-invalid Flag for LCA #35

Merged
merged 7 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 4 additions & 4 deletions .github/workflows/cibuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ jobs:
matrix:
include:
- os: ubuntu-latest
python-version: 3.7
python-version: "3.8"
- os: ubuntu-latest
python-version: 3.8
python-version: "3.9"
- os: ubuntu-latest
python-version: 3.9
python-version: "3.10"
- os: macos-latest
python-version: 3.8
python-version: "3.9"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub automatically disabled CI builds after several months of inactivity. So I re-enabled that, and bumped these version numbers.

steps:
- uses: actions/checkout@v1
- uses: conda-incubator/setup-miniconda@v2
Expand Down
2 changes: 1 addition & 1 deletion environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ dependencies:
- pytest>=5.4
- pytest-cov>=2.8
- pytest-xdist>=1.31
- taxonkit>=0.8
- taxonkit>=0.16.0
- wget>=1.20
36 changes: 32 additions & 4 deletions pytaxonkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,10 @@ def lineage(
>>> result.columns
Index(['TaxID', 'Code', 'Name', 'Lineage', 'LineageTaxIDs', 'Rank', 'FullLineage', 'FullLineageTaxIDs', 'FullLineageRanks'], dtype='object')
>>> result[["TaxID", "Lineage", "LineageTaxIDs"]]
TaxID Lineage LineageTaxIDs
0 1325911 Eukaryota;Arthropoda;Insecta;Hymenoptera;Eucharitidae;Pogonocharis; 2759;6656;50557;7399;216140;1325911;
1 1649473 Bacteria;Bacteroidota;Cytophagia;Cytophagales;Spirosomaceae;Nibrella; 2;976;768503;768507;2896860;1649473;
2 1401311 Eukaryota;Arthropoda;Insecta;Coleoptera;Staphylinidae;Styngetus; 2759;6656;50557;7041;29026;1401311;
TaxID Lineage LineageTaxIDs
0 1325911 Eukaryota;Arthropoda;Insecta;Hymenoptera;Eucharitidae;Pogonocharis; 2759;6656;50557;7399;216140;1325911;
1 1649473 Bacteria;Bacteroidota;Cytophagia;Cytophagales;Spirosomataceae;Nibrella; 2;976;768503;768507;2896860;1649473;
2 1401311 Eukaryota;Arthropoda;Insecta;Coleoptera;Staphylinidae;Styngetus; 2759;6656;50557;7041;29026;1401311;
Comment on lines -342 to +345
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better update your taxonomy DB 🙃

>>> result = pytaxonkit.lineage(["1382510", "929505", "390333"], formatstr="{f};{g};{s};{S}")
>>> result[["TaxID", "Lineage", "LineageTaxIDs"]]
TaxID Lineage LineageTaxIDs
Expand Down Expand Up @@ -1046,6 +1046,7 @@ def lca(
multi=False,
skip_deleted=False,
skip_unfound=False,
keep_invalid=False,
threads=None,
data_dir=None,
debug=False,
Expand All @@ -1063,6 +1064,8 @@ def lca(
Ignore deleted taxids and compute LCA with the remaining taxa
skip_unfound : bool, default False
Ignore taxids not found in the taxonomy database and compute LCA with the remaining taxa
keep_invalid: bool, default False
Returns 0 when all taxids have been skipped from `skip_deleted` or `skip_unfound`
threads : int
Override the default taxonkit threads setting
data_dir : str, default None
Expand Down Expand Up @@ -1096,6 +1099,8 @@ def lca(
arglist.append("--skip-deleted")
if skip_unfound:
arglist.append("--skip-unfound")
if keep_invalid:
arglist.append("--keep-invalid")
if threads:
arglist.extend(("--threads", validate_threads(threads)))
if data_dir:
Expand Down Expand Up @@ -1134,6 +1139,29 @@ def test_lca_unfound(capsys):
assert "taxonkit lca --skip-unfound" in terminal.err


def test_lca_keep_invalid_single(capsys):
assert lca([11111111], skip_deleted=True, skip_unfound=True) is None
assert lca([22222222], skip_deleted=True, skip_unfound=True) is None
assert lca([11111111], skip_deleted=True, skip_unfound=True, keep_invalid=True) == 0
assert lca([11111111, 22222222], skip_deleted=True, skip_unfound=True, keep_invalid=True, debug=True) == 0
terminal = capsys.readouterr()
assert "taxonkit lca --skip-deleted --skip-unfound --keep-invalid" in terminal.err


def test_lca_keep_invalid_multi():
query = [
[743375],
[123456789],
[987654321],
[743375, 123456789],
[743375, 987654321],
[123456789, 987654321]
]
observed = lca(query, skip_deleted=True, skip_unfound=True, keep_invalid=True, multi=True)
expected = [743375, 0, 0, 743375, 743375, 0]
assert expected == observed


@pytest.mark.parametrize(
"domulti, ids,result",
[
Expand Down
Loading