Skip to content

Getting sections of synth tree or taxonomy

Stephen Smith edited this page Oct 11, 2015 · 4 revisions

Hopefully you have peyotl installed and if not check this out. So I assume that you have a working peyotl and you understand virtualenv (if you use it).

##Getting a section of the synthetic tree## To get a section of the synthetic tree as a newick is quite simple. If you have the ott_id (see this tutorial to get that), then you can just use this procedure

def get_synth_tree_bit(ott_id):
    tm = APIWrapper().treemachine
    x = tm.get_synthetic_tree(format='newick',ott_id=ott_id,max_depth=1)
    return x

You may need to change the max_depth to get more of the tree.

If you want to get a section of the tree that only includes the ott_ids you want, we can use the function

def get_synth_tree_bit_pruned(ott_id):
    tm = APIWrapper().treemachine
    y=tm.induced_subtree(ott_ids=[355135,3892211])
    return y["newick"]

If you want to get an MRCA and the node id of this MRCA in the tree, you can run the command

y=tm.mrca(ott_ids=[355135,3892211])

The results of y will be a dictionary

{u'node_ids_not_in_tree': [], u'ott_ids_not_in_tree': [], u'mrca_rank': u'genus', u'nearest_taxon_mrca_ott_id': 649885, u'nearest_taxon_mrca_unique_name': u'Lonicera (genus in order Dipsacales)', u'mrca_name': u'Lonicera', u'mrca_node_id': 538009, u'ott_id': 649885, u'nearest_taxon_mrca_node_id': 538009, u'invalid_node_ids': [], u'tree_id': u'opentree3.0', u'invalid_ott_ids': [], u'mrca_unique_name': u'Lonicera (genus in order Dipsacales)', u'nearest_taxon_mrca_name': u'Lonicera', u'nearest_taxon_mrca_rank': u'genus'}

You can then use the node_id in this dictionary for your get_synthetic_tree function like this

x = tm.get_synthetic_tree(format='newick',node_id=538009,max_depth=1)

We will use this information for further analyses.

back to Tutorials

Clone this wiki locally