diff --git a/gga_load_data.py b/gga_load_data.py index 2c0016569c49cdba7e644ffb126c2b8d44c3fb42..0aadf59f8c08799a27d1c40b62164751bc04bd88 100755 --- a/gga_load_data.py +++ b/gga_load_data.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- import re -import bioblend import argparse import os import logging @@ -39,27 +38,6 @@ class LoadData(speciesData.SpeciesData): self.bam_metadata_cache = {} super().__init__(parameters_dictionary) - def get_history(self): - """ - Create or set the working history to the current species one - - :return: - """ - try: - histories = self.instance.histories.get_histories(name=str(self.genus_species)) - if len(histories) == 1: - self.history_id = histories[0]["id"] - logging.debug("History ID set for {0} {1}: {2}".format(self.genus, self.species, self.history_id)) - else: - logging.critical("Multiple histories exists for {0}: {1}".format(self.genus, self.species)) - except IndexError: - logging.info("Creating history for {0} {1}".format(self.genus, self.species)) - hist_dict = self.instance.histories.create_history(name=str(self.genus_species)) - self.history_id = hist_dict["id"] - logging.debug("History ID set for {0} {1}: {2}".format(self.genus, self.species, self.history_id)) - - return self.history_id - def remove_homo_sapiens_from_db(self): """ Run the GMOD tool to remove the "Homo sapiens" default organism from the original database @@ -304,6 +282,7 @@ if __name__ == "__main__": logging.basicConfig(level=logging.DEBUG) else: logging.basicConfig(level=logging.INFO) + logging.getLogger("urllib3").setLevel(logging.INFO) # Parsing the config file if provided, using the default config otherwise if args.config: @@ -360,7 +339,9 @@ if __name__ == "__main__": logging.debug("Successfully set up library in galaxy for {0} {1}".format(load_data_for_current_species.genus, load_data_for_current_species.species)) # Set or get the history for the current organism - load_data_for_current_species.get_history() + load_data_for_current_species.history_id = utilities_bioblend.get_history( + instance=load_data_for_current_species.instance, + history_name=load_data_for_current_species.history_name) # Remove H. sapiens from database if here # TODO: set a dedicated history for removing H. sapiens (instead of doing it into a species history) diff --git a/speciesData.py b/speciesData.py index 1e2a9f339cd099e19e75245f667a38c80199ff2a..3d41670c502a329fce16e62670c3ad78752a32de 100755 --- a/speciesData.py +++ b/speciesData.py @@ -139,4 +139,5 @@ class SpeciesData: self.instance_url = None self.instance = None self.history_id = None + self.history_name = str(self.genus_species) self.library_id = None diff --git a/utilities_bioblend.py b/utilities_bioblend.py index 3cfcc4857e6ae58ac51553e51c3e8438788adf60..0c959bc47249f6b920b591aaec24c1fa2b363503 100644 --- a/utilities_bioblend.py +++ b/utilities_bioblend.py @@ -34,21 +34,24 @@ def get_galaxy_instance(instance_url, email, password): return instance + def get_history(instance, history_name): """ Create or set the working history to the current species one :return: """ - try: - histories = instance.histories.get_histories(name=history_name) - history_id = histories[0]["id"] - logging.debug("History ID set for {0}: {1}".format(history_name, history_id)) - except IndexError: + histories = instance.histories.get_histories(name=str(history_name)) + if len(histories) == 0: logging.info("Creating history for %s" % history_name) - history = instance.histories.create_history(name=history_name) - history_id = history["id"] + hist_dict = instance.histories.create_history(name=str(history_name)) + history_id = hist_dict["id"] logging.debug("History ID set for {0}: {1}".format(history_name, history_id)) + if len(histories) == 1: + history_id = histories[0]["id"] + logging.debug("History ID set for {0}: {1}".format(history_name, history_id)) + else: + logging.critical("Multiple histories exists for {0}".format(history_name)) return history_id