From 9468ac92d5d56f6c7027a4819ebc76d34f9cbb35 Mon Sep 17 00:00:00 2001 From: Loraine Gueguen <loraine.gueguen@sb-roscoff.fr> Date: Sun, 30 May 2021 22:18:54 +0200 Subject: [PATCH] fix get_history(). Change verbosity --- gga_load_data.py | 79 ++++++++++++++++++++++++------------------- utilities_bioblend.py | 2 +- 2 files changed, 45 insertions(+), 36 deletions(-) diff --git a/gga_load_data.py b/gga_load_data.py index d664c70..f4e0818 100755 --- a/gga_load_data.py +++ b/gga_load_data.py @@ -38,33 +38,6 @@ class LoadData(speciesData.SpeciesData): self.bam_metadata_cache = {} super().__init__(parameters_dictionary) - def remove_homo_sapiens_from_db(self): - """ - Run the GMOD tool to remove the "Homo sapiens" default organism from the original database - Will do nothing if H. sapiens isn't in the database - - """ - - logging.debug("Getting 'Homo sapiens' ID in chado database") - get_sapiens_id_json_output = utilities_bioblend.run_tool_and_download_single_output_dataset( - self.instance, - tool_id=constants.GET_ORGANISMS_TOOL, # If this version if not found, Galaxy will use the one that is found - history_id=self.history_id, - tool_inputs={"genus": "Homo", "species": "sapiens"}) - - logging.info("Deleting Homo 'sapiens' in the instance's chado database") - try: - get_sapiens_id_final_output = json.loads(get_sapiens_id_json_output)[0] - sapiens_id = str(get_sapiens_id_final_output["organism_id"]) # needs to be str to be recognized by the chado tool - utilities_bioblend.run_tool( - self.instance, - tool_id=constants.DELETE_ORGANISMS_TOOL, - history_id=self.history_id, - tool_inputs={"organism": sapiens_id}) - except IndexError: - logging.error("Homo sapiens isn't in the instance's chado database (IndexError)") - pass - def purge_histories(self): """ Delete all histories in the instance @@ -256,7 +229,33 @@ class LoadData(speciesData.SpeciesData): logging.info("Did not find metadata in %s " % meta_file) return self.get_bam_label(dirname, bam_file) - +def remove_homo_sapiens_from_db(instance, history_id): + """ + Run the GMOD tool to remove the "Homo sapiens" default organism from the original database + Will do nothing if H. sapiens isn't in the database + + """ + + logging.debug("Getting 'Homo sapiens' ID in chado database") + get_sapiens_id_json_output = utilities_bioblend.run_tool_and_download_single_output_dataset( + instance, + tool_id=constants.GET_ORGANISMS_TOOL, # If this version if not found, Galaxy will use the one that is found + history_id=history_id, + tool_inputs={"genus": "Homo", "species": "sapiens"}) + + logging.info("Deleting Homo 'sapiens' in the instance's chado database") + try: + get_sapiens_id_final_output = json.loads(get_sapiens_id_json_output)[0] + sapiens_id = str(get_sapiens_id_final_output["organism_id"]) # needs to be str to be recognized by the chado tool + utilities_bioblend.run_tool( + instance, + tool_id=constants.DELETE_ORGANISMS_TOOL, + history_id=history_id, + tool_inputs={"organism": sapiens_id}) + except IndexError: + logging.error("Homo sapiens isn't in the instance's chado database (IndexError)") + pass + if __name__ == "__main__": parser = argparse.ArgumentParser(description="Load data into Galaxy library") @@ -268,6 +267,10 @@ if __name__ == "__main__": help="Increase output verbosity", action="store_true") + parser.add_argument("-vv", "--very_verbose", + help="Increase output verbosity", + action="store_true") + parser.add_argument("--config", type=str, help="Config path, default to 'examples/config.yml'") @@ -278,11 +281,14 @@ if __name__ == "__main__": args = parser.parse_args() - if args.verbose: + if args.verbose or args.very_verbose: logging.basicConfig(level=logging.DEBUG) else: logging.basicConfig(level=logging.INFO) - logging.getLogger("urllib3").setLevel(logging.INFO) + + if not args.very_verbose: + logging.getLogger("urllib3").setLevel(logging.INFO) + logging.getLogger("bioblend").setLevel(logging.INFO) # Parsing the config file if provided, using the default config otherwise if args.config: @@ -338,14 +344,17 @@ if __name__ == "__main__": load_data_for_current_species.setup_library() 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.history_id = utilities_bioblend.get_history( + # Get default history + history_id = utilities_bioblend.get_history( instance=load_data_for_current_species.instance, - history_name=load_data_for_current_species.history_name) - + history_name="Unnamed history") + # Remove H. sapiens from database if here # TODO: set a dedicated history for removing H. sapiens (instead of doing it into a species history) - load_data_for_current_species.remove_homo_sapiens_from_db() + remove_homo_sapiens_from_db( + instance=load_data_for_current_species.instance, + history_id=history_id + ) # logging.info("Importing datasets into history for %s" % load_data_for_current_species.full_name) # load_data_for_current_species.import_datasets_into_history() # Option "--load-history" diff --git a/utilities_bioblend.py b/utilities_bioblend.py index 0c959bc..08bb1bd 100644 --- a/utilities_bioblend.py +++ b/utilities_bioblend.py @@ -47,7 +47,7 @@ def get_history(instance, history_name): 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: + elif len(histories) == 1: history_id = histories[0]["id"] logging.debug("History ID set for {0}: {1}".format(history_name, history_id)) else: -- GitLab