Coverage for denofo/utils/ncbiTaxDBcheck.py: 100%

1 from ete3 import NCBITaxa

2 from ete3.ncbi_taxonomy.ncbiquery import is_taxadb_up_to_date

3 import sqlite3

4 import warnings

5

6

7 class NCBITAXDBWarning(UserWarning):

8 """

9 Warning raised when NCBI Taxonomy Database is newly built or updated

10 """

11

12 pass

13

14

15 def check_NCBI_taxDB() -> NCBITaxa:

16 """

17 Check if NCBI Taxonomy Database exists and is valid or build it if not

18

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 )

35

36 ncbi = NCBITaxa()

37 return ncbi

38

39

40 def 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()