From c07778fc279eca8c6ab337f97d55e3ac93558c7d Mon Sep 17 00:00:00 2001 From: cesen Date: Wed, 2 Feb 2022 11:39:01 +0100 Subject: [PATCH 1/3] Check if divergence colors are sufficient - setup_correction.py now checks whether the amount of colors provided in config file field "divergence_colors" is at least equal to the number of divergence nodes in the lineage that goes from the focal species to the second-to-last divergence node before the root. This way, we are sure that there are enough colors to depict all of the divergence lines in the mixed plot. --- ksrates/setup_correction.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ksrates/setup_correction.py b/ksrates/setup_correction.py index fd76ba1..e659cf2 100644 --- a/ksrates/setup_correction.py +++ b/ksrates/setup_correction.py @@ -24,6 +24,7 @@ def setup_correction(config_file, nextflow_flag): paranome = config.get_paranome() colinearity = config.get_colinearity() reciprocal_retention = config.get_reciprocal_retention() + divergence_colors = config.get_color_list() if not paranome and not colinearity and not reciprocal_retention: logging.error('At least one of the "paranome" or "collinearity" parameters in the configuration file needs to be set to "yes".') @@ -104,15 +105,25 @@ def setup_correction(config_file, nextflow_flag): logging.error(f"Please add at least one outgroup species or change the focal species.") sys.exit(1) + # Obtaining the numeric labels for internal nodes relevant in the species analysis + fcTree.labeling_internal_nodes(species_of_interest_node) + # If the amount of colors provided for the divergence lines in the config file + # is insufficient for the number of divergence nodes in the tree, exit + num_required_colors = sp_history[-2].name + if len(divergence_colors) < num_required_colors: + logging.error("") + logging.error(f'Configuration file field "divergence_colors" is missing {num_required_colors - len(divergence_colors)} color(s) ' + + f"out of {num_required_colors} required for the analysis on focal species [{species_of_interest}]") + logging.error("Please add the missing color(s) and rerun the analysis") + logging.error("Exiting.") + sys.exit(1) + trios_array = [] # list of trios outfile_drawing_path = os.path.join("rate_adjustment", f"{species_of_interest}", f"tree_{species_of_interest}.txt") with open(outfile_drawing_path, "w+") as outfile_drawing: outfile_drawing.write(f"Focal species: {species_of_interest}\n\n") - # Obtaining the numeric labels for internal nodes relevant in the species analysis - fcTree.labeling_internal_nodes(species_of_interest_node) - node = 0 while node < len(sp_history)-2: # the name label to be shown in the ASCII tree will start from 1 and not from 0 -- GitLab From 5d56af0791ac929eb5618625044485665a77600b Mon Sep 17 00:00:00 2001 From: cesen Date: Wed, 2 Feb 2022 11:42:19 +0100 Subject: [PATCH 2/3] Exit if divergence_colors is empty - Early checkpoint in setup_correction.py warns and exits if configuration file field "divergence_colors" was left empty --- ksrates/fc_configfile.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ksrates/fc_configfile.py b/ksrates/fc_configfile.py index f737856..2b7f81d 100644 --- a/ksrates/fc_configfile.py +++ b/ksrates/fc_configfile.py @@ -466,6 +466,10 @@ class Configuration: """ color_list_string = self.config.get("PARAMETERS", "divergence_colors") colors = [c.strip() for c in color_list_string.split(',')] + if len(colors) == 1 and colors[0] == "": + logging.error('Parameter "divergence_colors" in configuration file is empty, please fill in') + logging.error("Exiting.") + sys.exit(1) return colors -- GitLab From 98221a676f18340fed5b65145c2e3cdd00f3e6dc Mon Sep 17 00:00:00 2001 From: cesen Date: Wed, 2 Feb 2022 11:47:31 +0100 Subject: [PATCH 3/3] Minor (use same format in logging) --- ksrates/fc_configfile.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ksrates/fc_configfile.py b/ksrates/fc_configfile.py index 2b7f81d..3e624c8 100644 --- a/ksrates/fc_configfile.py +++ b/ksrates/fc_configfile.py @@ -106,10 +106,10 @@ class Configuration: """ species = self.config.get("SPECIES", "focal_species") if species == "": - logging.error("Parameter focal_species in configuration file is empty, please fill in") + logging.error('Parameter "focal_species" in configuration file is empty, please fill in') sys.exit(1) elif len(species.split()) != 1: - logging.error(f"Parameter focal_species [{species}] should be a short name and must not contain any spaces, please change accordingly") + logging.error(f'Parameter "focal_species" [{species}] should be a short name and must not contain any spaces, please change accordingly') sys.exit(1) return species @@ -123,13 +123,13 @@ class Configuration: if not (tree_string.endswith(';')): tree_string += ";" if tree_string == "();": - logging.error("Parameter newick_tree in configuration file is empty, please fill in") + logging.error('Field "newick_tree" in configuration file is empty, please fill in') sys.exit(1) try: tree = Tree(tree_string) return tree except Exception: - logging.error("Unrecognized format for parameter newick_tree in configuration file (for example, parentheses do not match)") + logging.error('Unrecognized format for field "newick_tree" in configuration file (for example, parentheses do not match)') sys.exit(1) def check_complete_latin_names_dict(self, dictionary): @@ -145,9 +145,9 @@ class Configuration: missing_species = list(set.difference(set(all_leaves), set(dictionary.keys()))) if len(missing_species) != 0: if len(missing_species) == 1: - logging.error(f"The following species is missing from the [latin_names] configuration file field:") + logging.error(f'The following species is missing from the "latin_names" configuration file field:') else: - logging.error(f"The following species are missing from the [latin_names] configuration file field:") + logging.error(f'The following species are missing from the "latin_names" configuration file field:') for missing_name in missing_species: logging.error(f" - {missing_name}") @@ -165,7 +165,7 @@ class Configuration: if latin_names != "": latin_names_dict = self._get_clean_dict_stringent(latin_names, "latin_names") else: - logging.error("Configuration file field [latin_names] is empty, please fill in and restart the analysis.") + logging.error('Configuration file field "latin_names" is empty, please fill in and restart the analysis.') logging.error("Exiting.") sys.exit(1) # Check if latin_names contains all the species present in the Newick tree; if not, exits -- GitLab