Ejemplo n.º 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()
Ejemplo n.º 2
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 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_get_insert_dict(self):
        """get_insert_dict: get the location of each inserted tip."""

        # pull out the tips for Species006
        obs = get_insert_dict(self.tree, "Species006")

        # verify the dict is properly refrenced
        self.assertTrue("Species006" in obs)

        # if Species006 in dict, verify there are 3 tips
        if "Species006" in obs:
            exp_len = 3
            obs_len = len(obs["Species006"])
            self.assertEqual(obs_len, exp_len)
    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_get_insert_dict(self):
        """get_insert_dict: get the location of each inserted tip."""

        # pull out the tips for Species006
        obs = get_insert_dict(self.tree, 'Species006')

        # verify the dict is properly refrenced
        self.assertTrue('Species006' in obs)

        # if Species006 in dict, verify there are 3 tips
        if 'Species006' in obs:
            exp_len = 3
            obs_len = len(obs['Species006'])
            self.assertEqual(obs_len, exp_len)