From c58c54edc126b73dd40636ea68974e54a62cd996 Mon Sep 17 00:00:00 2001 From: amnona Date: Thu, 2 Jul 2020 23:22:30 +0300 Subject: [PATCH 1/2] make database not installed warn instead of raise error --- calour/calour.config | 15 +++++++++++++++ calour/database.py | 12 +++++++++--- calour/heatmap/heatmap.py | 2 ++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/calour/calour.config b/calour/calour.config index 97d4e0d7..ad0975bb 100644 --- a/calour/calour.config +++ b/calour/calour.config @@ -1,12 +1,27 @@ [dbbact] module_name = dbbact_calour.dbbact class_name = DBBact +website = www.dbbact.org +installation = pip install git+git://github.com/amnona/dbbact-calour +description = manual annotations about bacterial amplicon sequences [sponge] module_name = spongeworld_calour class_name = SpongeWorld +website = www.spongeemp.com/main +installation = pip install git+git://github.com/amnona/spongeworld-calour +description = automatic annotations from the sea sponge EMP project [gnps] module_name = gnpscalour class_name = GNPS +website = gnps.ucsd.edu/ +installation = pip install git+git://github.com/amnona/gnps-calour +description = metabolomics analysis using GNPS output file as database +[phenodb] +module_name = phenocalour +class_name = Phenotype +website = github.com/amnona/pheno-calour +installation = pip install git+git://github.com/amnona/pheno-calour +description = phenotypes for cultured bacteria diff --git a/calour/database.py b/calour/database.py index e08774e2..b732d2f9 100644 --- a/calour/database.py +++ b/calour/database.py @@ -61,7 +61,12 @@ def _get_database_class(dbname, exp=None, config_file_name=None): # import the database module db_module = importlib.import_module(module_name) except ImportError: - raise ValueError('Database interface %s not installed. Did you do pip install for it?' % module_name) + module_website = get_config_value('website', section=dbname, config_file_name=config_file_name) + module_installation = get_config_value('installation', section=dbname, config_file_name=config_file_name) + logger.warning('Database interface %s not installed.\nSkipping.\n' + 'You can install the database using:\n%s\n' + 'For details see: %s' % (module_name, module_installation, module_website)) + return None # get the class DBClass = getattr(db_module, class_name) cdb = DBClass(exp) @@ -76,8 +81,9 @@ def _get_database_class(dbname, exp=None, config_file_name=None): databases.append(csection) if len(databases) == 0: raise ValueError('calour config file %s does not contain any database sections.' % get_config_file()) - raise ValueError('Database %s not found in config file (%s).\n' - 'Currently contains the databases: %s' % (dbname, get_config_file(), databases)) + logger.warning('Database %s not found in config file (%s).\nSkipping.\n' + 'Current databases in config file: %s' % (dbname, get_config_file(), databases)) + return None def add_terms_to_features(exp: Experiment, dbname, use_term_list=None, field_name='common_term', term_type=None, ignore_exp=None, **kwargs): diff --git a/calour/heatmap/heatmap.py b/calour/heatmap/heatmap.py index e8e20ec7..d0cac6ae 100644 --- a/calour/heatmap/heatmap.py +++ b/calour/heatmap/heatmap.py @@ -64,6 +64,8 @@ def _create_plot_gui(exp, gui='cli', databases=('dbbact',), tree_size=0): # link gui with the databases requested for cdatabase in databases: cdb = _get_database_class(cdatabase, exp=exp) + if cdb is None: + continue gui_obj.databases.append(cdb) # select the database for use with the annotate button if cdb.annotatable: From 00e6ca168dd8028a9b7eef566531d770564e3459 Mon Sep 17 00:00:00 2001 From: amnona Date: Fri, 3 Jul 2020 00:15:26 +0300 Subject: [PATCH 2/2] make database not installed warn instead of raise error --- calour/database.py | 3 ++- calour/tests/test_database.py | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/calour/database.py b/calour/database.py index b732d2f9..8adcf488 100644 --- a/calour/database.py +++ b/calour/database.py @@ -80,7 +80,8 @@ def _get_database_class(dbname, exp=None, config_file_name=None): if class_name is not None and module_name is not None: databases.append(csection) if len(databases) == 0: - raise ValueError('calour config file %s does not contain any database sections.' % get_config_file()) + logger.warning('calour config file %s does not contain any database sections. Skipping' % get_config_file()) + return None logger.warning('Database %s not found in config file (%s).\nSkipping.\n' 'Current databases in config file: %s' % (dbname, get_config_file(), databases)) return None diff --git a/calour/tests/test_database.py b/calour/tests/test_database.py index a20e93f1..6cac80fb 100644 --- a/calour/tests/test_database.py +++ b/calour/tests/test_database.py @@ -53,8 +53,11 @@ def test_get_database_class(self): calour.util.set_config_value('module_name', 'calour.tests.mock_database', section='testdb', config_file_name=f) db = _get_database_class('testdb', config_file_name=f) self.assertEqual(db.database_name, 'mock_db') - with self.assertRaises(ValueError): - _get_database_class('mock') + + # test None results if database does not exist in config file + res = _get_database_class('mock') + self.assertEqual(res, None) + shutil.rmtree(d)