Skip to content

fix(amr): apply GTDB species matching on the SQLite index path - #50

Merged
thanhleviet merged 1 commit into
mainfrom
fix/amr-index-gtdb-species
Sep 2, 2026
Merged

thanhleviet merged 1 commit into
mainfrom
fix/amr-index-gtdb-species

Conversation

@thanhleviet

Copy link
Copy Markdown
Collaborator

Summary

Fixes #49. atb amr --species "Enterococcus faecium" (an unsuffixed NCBI name) silently returned 0 results when a genus SQLite index was present.

v0.22.0 added GTDB-aware --species matching, but the AMR SQLite-index path (internal/amr/indexer.go buildSQL) matched the raw query with an exact LOWER(species) IN (...) clause and never applied the _[A-Z]+ suffix stripping that match.SpeciesMatches uses everywhere else. GTDB matching reached the parquet scan and atb query, but not the AMR index. --genus Enterococcus and the explicit --species "Enterococcus_B faecium" were unaffected.

Fix

QueryIndex now resolves the requested species against the index's distinct stored names in Go with match.SpeciesMatches (SQLite can't run the suffix regex), then feeds the concrete matched names into buildSQL's exact IN clause — the same pattern internal/index/query.go already uses. Empty resolution short-circuits to zero rows.

Tests

  • TestQueryAMRSpeciesGTDBSuffixIndexed — builds real .sqlite indexes via BuildIndexes, then queries the unsuffixed name across both clade partitions (RED before the fix, GREEN after).
  • TestQueryAMRSpeciesCladeSelectIndexed — an explicit clade name still selects only that clade.

The original v0.22.0 AMR tests missed this because they only wrote .parquet fixtures, so execution always fell to the (correct) parquet path.

Full suite, gofmt, and vet clean.

The AMR genus SQLite index matched --species with an exact
LOWER(species) IN (...) clause against the raw query string, so an
unsuffixed NCBI name such as "Enterococcus faecium" returned 0 results
when an index existed. v0.22.0's GTDB-suffix stripping reached the
parquet scan but not the index path.

QueryIndex now resolves the requested species against the stored names
with match.SpeciesMatches before building the IN clause, mirroring the
internal/index resolver. Explicit clade names still select one clade.

Closes #49
@thanhleviet
thanhleviet merged commit 434089b into main Sep 2, 2026
6 checks passed
@thanhleviet
thanhleviet deleted the fix/amr-index-gtdb-species branch September 2, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug in searching species due to a missing lower-case transformation

1 participant