Commit c356bed6 authored by Philippe Veber's avatar Philippe Veber
Browse files

scripts: don't check if tree is rooted when not necessary

parent a0c6b95c
......@@ -3,6 +3,7 @@
#===================================================================================================
######### output trees for simulation
t, nodeId = read_input_tree()
### tree.only_node_ids.nhx: a tree with numbered nodes
t.write(format=1, features=["ND"], outfile = "%s/tree.only_node_ids.nhx" %(OutDirName),format_root_node=True)
......
......@@ -92,52 +92,54 @@ elif OutDirName: # if OutDirName is not a empty string we create the directory
#===================================================================================================
# Read input tree
#===================================================================================================
try:
t=Tree(TreeFile.name)
except Exception as exc:
logger.error(str(exc))
sys.exit(1)
if t:
features = []
for n in t.traverse("postorder"): # get all features:
features.extend(list(set(dir(n)) - set(dir(Tree()))))
features = list(set(features)) # list(set(*)) = remove duplicates
logger.info("No detected tag" if not features else "Detected tags: "+", ".join([f for f in features]))
#check rooted tree
nb_root_children = len(t.get_children())
if nb_root_children > 2:
logger.error("Unrooted tree")
def read_input_tree(ensure_tree_is_rooted = True):
try:
t=Tree(TreeFile.name)
except Exception as exc:
logger.error(str(exc))
sys.exit(1)
if "ND" in features:
logger.warning("\"ND\" is in the detected tags but it will be removed by the programm")
features.remove("ND")
if not "Condition" in features:
logger.error("\"Condition\" must be in the detected tags. \"Condition:1\" must identify nodes under the convergent model under Ha")
if t:
features = []
for n in t.traverse("postorder"): # get all features:
features.extend(list(set(dir(n)) - set(dir(Tree()))))
features = list(set(features)) # list(set(*)) = remove duplicates
logger.info("No detected tag" if not features else "Detected tags: "+", ".join([f for f in features]))
#check rooted tree
nb_root_children = len(t.get_children())
if ensure_tree_is_rooted and nb_root_children > 2:
logger.error("Unrooted tree")
sys.exit(1)
if "ND" in features:
logger.warning("\"ND\" is in the detected tags but it will be removed by the programm")
features.remove("ND")
if not "Condition" in features:
logger.error("\"Condition\" must be in the detected tags. \"Condition:1\" must identify nodes under the convergent model under Ha")
sys.exit(1)
if not "Transition" in features:
logger.error("\"Transition\" must be in the detected tags. \"Transition:1\" must identify nodes where there are transitions")
sys.exit(1)
if "Transition" in features:
logger.info("\"Transition\" is in the detected tags. \"Transition:1\" will be use to indicate OneChange model on this node")
# Check existing bl
branch_lengths = []
nodeId = 0
for node in t.traverse("postorder"):
node.add_features(ND=nodeId)
branch_lengths.append(node.dist)
nodeId = nodeId + 1
logger.debug("Branch length %s", branch_lengths)
if set(branch_lengths) == set([1.0]):
logger.warning("No branch length in %s, all branch length will be put to 1",tree_filename)
if not (t and branch_lengths):
sys.exit(1)
if not "Transition" in features:
logger.error("\"Transition\" must be in the detected tags. \"Transition:1\" must identify nodes where there are transitions")
sys.exit(1)
if "Transition" in features:
logger.info("\"Transition\" is in the detected tags. \"Transition:1\" will be use to indicate OneChange model on this node")
# Check existing bl
branch_lengths = []
nodeId = 0
for node in t.traverse("postorder"):
node.add_features(ND=nodeId)
branch_lengths.append(node.dist)
nodeId = nodeId + 1
logger.debug("Branch length %s", branch_lengths)
if set(branch_lengths) == set([1.0]):
logger.warning("No branch length in %s, all branch length will be put to 1",tree_filename)
if not (t and branch_lengths):
sys.exit(1)
logger.info("Tree (%s) ok after checking", TreeFile.name)
logger.info("Tree (%s) ok after checking", TreeFile.name)
return(t, nodeId)
......@@ -2,6 +2,8 @@
# Create output files
#===================================================================================================
t, nodeId = read_input_tree(ensure_tree_is_rooted = False)
######### output trees for detection
all_node_ids = range(nodeId-1)
conv_node_ids = [n.ND for n in t.search_nodes(Condition = "1")]
......
######### output trees for detection
t, _ = read_input_tree()
### tree.only_convergent_tags.nhx: a tree with only Condition and Transition tags
t.write(format=1, features=["Condition","Transition"], outfile = "%s/tree.only_convergent_tags.nhx" %(OutDirName))
......@@ -67,5 +67,6 @@ def build_conv_topo(t):
return tconv
t, _ = read_input_tree()
tconv = build_conv_topo(t)
tconv.write(format=1, outfile = "%s/tree.topological" %(OutDirName))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment