Skip to content

Commit b5b843a

Browse files
committed
fix missing import in bactopia-prepare
1 parent a59d5fe commit b5b843a

File tree

5 files changed

+42
-35
lines changed

5 files changed

+42
-35
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[flake8]
22
max-line-length = 88
33
# the default ignores minus E704
4-
ignore = E121,E123,E126,E226,E203,E24,F401,E402,F403,E501,W503,W504
4+
ignore = E24,E121,E123,E126,E203,E221,E226,E231,E713,F401,E402,F403,E501,W503,W504

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 1.6.1
4+
5+
- shuffle ncbi related module out of `utils` and into `ncbi`
6+
- fixed missing import in `bactopia-prepare`
7+
8+
39
## 1.6.0
410

511
- `bactopia-search`

bactopia/cli/prepare.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
from rich.logging import RichHandler
1212

1313
import bactopia
14-
from bactopia.utils import get_ncbi_genome_size, get_taxid_from_species, validate_file
14+
from bactopia.databases.ncbi import get_ncbi_genome_size, get_taxid_from_species
15+
from bactopia.utils import validate_file
1516

1617
# Set up Rich
1718
stderr = rich.console.Console(stderr=True)

bactopia/databases/ncbi.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,38 @@ def is_biosample(accession: str) -> bool:
5757
)
5858

5959

60+
def get_taxid_from_species(species: str) -> str:
61+
"""
62+
Convert a species name into a tax_id
63+
64+
Args:
65+
species (str): A species name
66+
67+
Returns:
68+
str: The corresponding tax_id
69+
"""
70+
r = requests.get(
71+
f"https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=taxonomy&term={species}"
72+
)
73+
taxid = None
74+
if r.status_code == requests.codes.ok:
75+
for line in r.text.split("\n"):
76+
line = line.strip()
77+
if line.startswith("<Id>"):
78+
taxid = line.replace("<Id>", "").replace("</Id>", "")
79+
if taxid:
80+
logging.debug(f"Found taxon ID ({taxid}) for {species}")
81+
return taxid
82+
else:
83+
logging.error(
84+
f"Unable to determine taxon ID from {species}, please check spelling or try again later."
85+
)
86+
sys.exit(1)
87+
else:
88+
logging.error("Unexpected error querying NCBI, please try again later.")
89+
sys.exit(1)
90+
91+
6092
def taxid2name(taxids: list, ncbi_api_key: str, chunk_size: int) -> dict:
6193
"""
6294
Convert a list of NCBI TaxIDs to species names.

bactopia/utils.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def execute(
4040
check=True, # Raises CalledProcessError for non-zero exit codes
4141
)
4242
logging.debug(f"Exit code: {command.returncode}")
43-
logging.debug(f"STDOUT:\n{command.stdout}")
43+
logging.debug(f"STDOUT: \n{command.stdout}")
4444
logging.debug(f"STDERR:\n{command.stderr}")
4545

4646
if capture:
@@ -188,38 +188,6 @@ def remove_keys(results: dict, remove: list) -> dict:
188188
return removed
189189

190190

191-
def get_taxid_from_species(species: str) -> str:
192-
"""
193-
Convert a species name into a tax_id
194-
195-
Args:
196-
species (str): A species name
197-
198-
Returns:
199-
str: The corresponding tax_id
200-
"""
201-
r = requests.get(
202-
f"https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=taxonomy&term={species}"
203-
)
204-
taxid = None
205-
if r.status_code == requests.codes.ok:
206-
for line in r.text.split("\n"):
207-
line = line.strip()
208-
if line.startswith("<Id>"):
209-
taxid = line.replace("<Id>", "").replace("</Id>", "")
210-
if taxid:
211-
logging.debug(f"Found taxon ID ({taxid}) for {species}")
212-
return taxid
213-
else:
214-
logging.error(
215-
f"Unable to determine taxon ID from {species}, please check spelling or try again later."
216-
)
217-
sys.exit(1)
218-
else:
219-
logging.error("Unexpected error querying NCBI, please try again later.")
220-
sys.exit(1)
221-
222-
223191
def download_url(url: str, save_path: str, show_progress: bool) -> str:
224192
"""
225193
Download a file from a URL

0 commit comments

Comments
 (0)