Coverage for denofo/utils/ncbiTaxDBcheck.py: 100%
18 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-04-09 15:27 +0200
« prev ^ index » next coverage.py v7.6.12, created at 2025-04-09 15:27 +0200
1from ete3 import NCBITaxa
2from ete3.ncbi_taxonomy.ncbiquery import is_taxadb_up_to_date
3import sqlite3
4import warnings
7class NCBITAXDBWarning(UserWarning):
8 """
9 Warning raised when NCBI Taxonomy Database is newly built or updated
10 """
12 pass
15def check_NCBI_taxDB() -> NCBITaxa:
16 """
17 Check if NCBI Taxonomy Database exists and is valid or build it if not
19 :return: NCBI Taxonomy Database object
20 :rtype: NCBITaxa
21 """
22 try:
23 if not is_taxadb_up_to_date():
24 warnings.warn(
25 "No valid NCBI Taxonomy Database found. Building NCBI Taxonomy "
26 "Database. This might take a while...",
27 NCBITAXDBWarning,
28 )
29 except (sqlite3.OperationalError, ValueError, IndexError, TypeError):
30 warnings.warn(
31 "No valid NCBI Taxonomy Database found. Building NCBI Taxonomy "
32 "Database. This might take a while...",
33 NCBITAXDBWarning,
34 )
36 ncbi = NCBITaxa()
37 return ncbi
40def update_NCBI_taxDB():
41 """
42 Update NCBI Taxonomy Database
43 """
44 warnings.warn("Updating NCBI Taxonomy Database...", NCBITAXDBWarning)
45 ncbi = NCBITaxa()
46 ncbi.update_taxonomy_database()