diff --git a/ksrates/fc_configfile.py b/ksrates/fc_configfile.py index f73785624829f0274fff3ad3855e390e7cff0360..3e624c87c4e5b1b1f27a0f38e46b1df880efecbc 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 @@ -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 diff --git a/ksrates/setup_correction.py b/ksrates/setup_correction.py index fd76ba1b21a063ce892a7a6284791e1022b07310..e659cf264adb6d859bd74efd17702fd198da0f57 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