diff --git a/circhemy/cli/cli.py b/circhemy/cli/cli.py index f76ac2f..e3e0736 100755 --- a/circhemy/cli/cli.py +++ b/circhemy/cli/cli.py @@ -392,7 +392,9 @@ def main(): # close db connection util.db_connection.close() + elif args.command == "download": + util.setup_database(util, util.database_location, from_cli=True) + else: print("Unknown command:", args.command) exit(-1) - diff --git a/circhemy/common/util.py b/circhemy/common/util.py index eaee774..a45765a 100644 --- a/circhemy/common/util.py +++ b/circhemy/common/util.py @@ -270,7 +270,7 @@ def database_stats(self): return chart_dict, dbsize, chart2_dict - def setup_database(self, database): + def setup_database(self, database, from_cli=False): # check if there is a .bz2 version of the database # if yes, this is the first time circhemy runs @@ -323,6 +323,9 @@ def setup_database(self, database): "https://github.com/jakobilab/circhemy/issues/new") exit(-1) + if os.path.isfile(database) and from_cli: + print("Database already downloaded.") + self.db_connection = sqlite3.connect(database) # SQLite optimizations from @@ -341,6 +344,8 @@ def setup_database(self, database): # getting db cursor self.db_cursor = self.db_connection.cursor() + + @staticmethod def process_sql_output(sql_output, seperator="\t", empty_char="NA"):