예제 #1
0
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_decorate_numtips(self):
        """decorate_numtips: decorate the number of tips below each node."""

        obs = decorate_numtips(self.tree)

        # make sure each tip only has 1 tip
        tips = obs.tips()
        for obs_tips in tips:
            exp = 1
            self.assertEqual(obs_tips.Score, exp)

        # check that the node scores are correct
        node_numtips = [1, 2, 8]
        for nodes in obs:
            self.assertTrue(nodes.Score in node_numtips)
    def test_decorate_numtips(self):
        """decorate_numtips: decorate the number of tips below each node."""

        obs = decorate_numtips(self.tree)

        # make sure each tip only has 1 tip
        tips = obs.tips()
        for obs_tips in tips:
            exp = 1
            self.assertEqual(obs_tips.Score, exp)

        # check that the node scores are correct
        node_numtips = [1, 2, 8]
        for nodes in obs:
            self.assertTrue(nodes.Score in node_numtips)