bkbit.utils.get_ncbi_taxonomy module

CLI for pre-fetching the full NCBI taxonomy cache.

bkbit does not require this step: a taxonomy subset covering every organism with a GenBank common name ships inside the wheel, and the full taxonomy is downloaded automatically the first time a lookup falls outside that subset. This command exists for the cases where you want the download to happen up front rather than mid-pipeline - air-gapped runs, container images, CI, or reproducible builds.

All of the download and cache logic lives in bkbit.utils.ncbi_taxonomy_cache; this module is a thin wrapper around it and re-exports the previous function names for backwards compatibility.

Usage:

bkbit download-ncbi-taxonomy [–reload] [–data-dir PATH]

bkbit.utils.get_ncbi_taxonomy.build_full_cache(url: str = 'https://ftp.ncbi.nih.gov/pub/taxonomy/taxdmp.zip', cache_dir: Path | None = None) Dict[str, Path][source]

Downloads the NCBI taxdump and writes the full cache to disk.

Parameters:
  • url – The URL of the taxdump zip to download and process.

  • cache_dir – Destination directory. Defaults to data_dir().

Returns:

The written cache paths, as returned by full_cache_paths().

Return type:

dict

bkbit.utils.get_ncbi_taxonomy.download_and_extract_zip_in_memory(url: str = 'https://ftp.ncbi.nih.gov/pub/taxonomy/taxdmp.zip') str[source]

Downloads the taxdump zip from the given URL and returns ‘names.dmp’.

Parameters:

url – The URL of the zip file to download.

Returns:

The content of the ‘names.dmp’ file as a string.

Return type:

str

Raises:

requests.exceptions.HTTPError – If the download fails.

bkbit.utils.get_ncbi_taxonomy.parse_dmp_content(dmp_content: str) Tuple[dict, dict, dict][source]

Parses the content of a names.dmp file into taxonomy name lookups.

Parameters:

dmp_content – The content of the DMP file.

Returns:

(taxid_to_scientific_name, taxid_to_common_name, scientific_name_to_taxid).

Return type:

tuple

bkbit.utils.get_ncbi_taxonomy.process_and_save_taxdmp_in_memory(url='https://ftp.ncbi.nih.gov/pub/taxonomy/taxdmp.zip', output_dir=None)[source]

Downloads and processes the taxdump file, saving the parsed data as JSON.

Deprecated alias for bkbit.utils.ncbi_taxonomy_cache.build_full_cache().

Parameters:
  • url – The URL of the taxdump file to download and process.

  • output_dir – Destination directory. Defaults to the bkbit cache directory.