Skip to content

Commit

Permalink
Report error if species tree inference fails, resolves #919
Browse files Browse the repository at this point in the history
  • Loading branch information
davidemms committed Oct 20, 2024
1 parent 92d520d commit cd0ad51
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions scripts_of/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,9 @@ def BetweenCoreOrthogroupsWorkflow(continuationDir, speciesInfoObj, seqsInfo, op
core_rooted_species_tree = tree.Tree(files.FileHandler.GetCoreSpeciesTreeIDsRootedFN(), format=1)
species_to_speices_map = lambda x: x
rooted_species_tree_ids, qHaveSupport = trees2ologs_of.CheckAndRootTree(species_tree_unrooted_fn, core_rooted_species_tree, species_to_speices_map)
if rooted_species_tree_ids is None:
print("ERROR: Species tree inference failed. Please check for errors and check the species tree files: \n%s \n%s" % (species_tree_unrooted_fn, core_rooted_species_tree))
util.Fail()
rooted_species_tree_fn = files.FileHandler.GetSpeciesTreeIDsRootedFN()
rooted_species_tree_ids.write(outfile=rooted_species_tree_fn)

Expand Down
9 changes: 6 additions & 3 deletions scripts_of/trees2ologs_of.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,8 @@ def CheckAndRootTree(treeFN, species_tree_rooted, GeneToSpecies):
Root tree
Returns None if this fails, i.e. checks: exists, has more than one gene, can be rooted
"""
if (not os.path.exists(treeFN)) or os.stat(treeFN).st_size == 0: return None, False
if (not os.path.exists(treeFN)) or os.stat(treeFN).st_size == 0:
return None, False
qHaveSupport = False
try:
tree = tree_lib.Tree(treeFN, format=2)
Expand All @@ -724,9 +725,11 @@ def CheckAndRootTree(treeFN, species_tree_rooted, GeneToSpecies):
tree = tree_lib.Tree(treeFN)
except:
tree = tree_lib.Tree(treeFN, format=3)
if len(tree) == 1: return None, False
if len(tree) == 1:
return None, False
root = GetRoot(tree, species_tree_rooted, GeneToSpecies)
if root == None: return None, False
if root == None:
return None, False
# Pick the first root for now
if root != tree:
tree.set_outgroup(root)
Expand Down

0 comments on commit cd0ad51

Please sign in to comment.