def main(): option_parser, opts, args =\ parse_command_line_parameters(**script_info) # get options tree_fp = opts.input_tree tips_to_keep = opts.tips_to_keep.split(',') scoring_method = opts.scoring_method # load tree tree = DndParser(open(tree_fp, 'U'), constructor=PhyloNode) # decorate measurements onto tree (either by depth or by number of children) if scoring_method == 'depth': tree2 = decorate_depth(tree) elif scoring_method == 'numtips': tree2 = decorate_numtips(tree) # get the nodes for the inserted sequences nodes_dict = get_insert_dict(tree2, set(tips_to_keep)) # remove nodes accordingly final_tree = drop_duplicate_nodes(tree2, nodes_dict) #final_tree.nameUnnamedNodes() # write out the resulting tree open_outpath = open(opts.output_fp, 'w') open_outpath.write(final_tree.getNewick(with_distances=True)) open_outpath.close()
def main(): option_parser, opts, args =\ parse_command_line_parameters(**script_info) # get options tree_fp= opts.input_tree tips_to_keep=opts.tips_to_keep.split(',') scoring_method=opts.scoring_method # load tree tree=DndParser(open(tree_fp,'U'), constructor=PhyloNode) # decorate measurements onto tree (either by depth or by number of children) if scoring_method=='depth': tree2=decorate_depth(tree) elif scoring_method=='numtips': tree2=decorate_numtips(tree) # get the nodes for the inserted sequences nodes_dict = get_insert_dict(tree2, set(tips_to_keep)) # remove nodes accordingly final_tree=drop_duplicate_nodes(tree2, nodes_dict) #final_tree.nameUnnamedNodes() # write out the resulting tree open_outpath=open(opts.output_fp,'w') open_outpath.write(final_tree.getNewick(with_distances=True)) open_outpath.close()
def test_drop_duplicate_nodes(self): """drop_duplicate_nodes: remove duplicate tips from tree based on either the number of tips or depth.""" # pull out the tips for Species006 inserted_nodes = get_insert_dict(self.tree, "Species006") # decorate the depth of each node on the tree decorated_tree = decorate_depth(self.tree) # drop duplicate nodes based on depth (deterministic when equal depths) obs = drop_duplicate_nodes(decorated_tree, inserted_nodes) # verify the resulting tree is correct self.assertEqual(obs.getNewick(with_distances=True), EXPECTED_TREE)
def test_drop_duplicate_nodes(self): """drop_duplicate_nodes: remove duplicate tips from tree based on either the number of tips or depth.""" # pull out the tips for Species006 inserted_nodes = get_insert_dict(self.tree, 'Species006') # decorate the depth of each node on the tree decorated_tree = decorate_depth(self.tree) # drop duplicate nodes based on depth (deterministic when equal depths) obs = drop_duplicate_nodes(decorated_tree, inserted_nodes) # verify the resulting tree is correct self.assertEqual(obs.getNewick(with_distances=True), EXPECTED_TREE)
def test_decorate_depth(self): """decorate_depth: decorate the depth from the root each node is.""" # decorate the depth of each node on the tree obs = decorate_depth(self.tree) # make sure each tip depth is between 1 and 5 tips = obs.tips() tip_depth = [1, 2, 3, 4, 5] for obs_tips in tips: self.assertTrue(obs_tips.Score in tip_depth) # check that the node depth is 1 for nodes in obs: exp = 1 self.assertEqual(nodes.Score, exp)