Skip to content

Commit df000ad

Browse files
authored
feat(taxonomy): Indexed, case-insensitive scientific_name queries of NCBI taxonomy DB (#6170)
Updating the index on scientific_name in the NCBI taxonomy database to allow for indexed, case-insensitive queries using user-supplied scientific host names. This will be a slightly nicer user-experience once we implement host name validation in prepro. Current implementation: -> user gives us `hostNameScientific: aedes aegypti` -> DB stores `scientific_name: Aesdes aegypti` -> error: hostNameScienitific not found New implementation allows for: -> user gives us `hostNameScientific: aedes aegypti` -> DB stores `scientific_name: Aesdes aegypti` -> {"tax_id":7159,"common_name":"yellow fever mosquito","scientific_name":"Aedes aegypti","parent_id":53541,"depth":28} ## Manual tests: I reran the DB creation script, connected using `sqlite3`, and ran: ```sql sqlite> SELECT * FROM taxonomy WHERE scientific_name = 'aedes aegypti' COLLATE NOCASE; tax_id|common_name|scientific_name|parent_id|depth 7159|yellow fever mosquito|Aedes aegypti|53541|28 ``` ### PR Checklist - [x] All necessary documentation has been adapted. - [x] The implemented feature is covered by appropriate, automated tests. - [x] Any manual testing that has been done is documented (i.e. what exactly was tested?) 🚀 Preview: Add `preview` label to enable
1 parent 1a5aca3 commit df000ad

3 files changed

Lines changed: 4 additions & 3 deletions

File tree

ncbi_tax_download/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ CREATE TABLE IF NOT EXISTS "taxonomy" (
3636
);
3737
CREATE UNIQUE INDEX idx_tax_id ON taxonomy(tax_id);
3838
CREATE INDEX idx_parent_id ON taxonomy(parent_id);
39-
CREATE INDEX idx_scientific_name ON taxonomy(scientific_name);
39+
CREATE INDEX idx_scientific_name ON taxonomy(scientific_name COLLATE NOCASE);
4040
CREATE TABLE sqlite_stat1(tbl,idx,stat);
4141
CREATE TABLE sqlite_stat4(tbl,idx,neq,nlt,ndlt,sample);
4242
```

ncbi_tax_download/src/ncbi_tax_download/ncbi.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ def write_to_sqlite(df: pd.DataFrame, output_db: Path) -> None:
139139

140140
conn.execute("CREATE UNIQUE INDEX IF NOT EXISTS idx_tax_id ON taxonomy(tax_id);")
141141
conn.execute("CREATE INDEX IF NOT EXISTS idx_parent_id ON taxonomy(parent_id);")
142-
conn.execute("CREATE INDEX IF NOT EXISTS idx_scientific_name ON taxonomy(scientific_name);")
142+
conn.execute(
143+
"CREATE INDEX IF NOT EXISTS idx_scientific_name ON taxonomy(scientific_name COLLATE NOCASE);"
144+
)
143145

144146
conn.execute("ANALYZE;")
145147

ncbi_tax_download/tests/test_db_creation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
import shutil
32
from io import BytesIO
43
from pathlib import Path

0 commit comments

Comments
 (0)