Installing ete2 is not entirely straightforward, but it is described at http://etetoolkit.org/download/.
This tutorial requires installing th PyQT4 dependency for the tree vis steps.
Installing Peyotl is straightforward and is described here http://opentreeoflife.github.io/peyotl/installation/
import peyotl
from ete2 import Tree, TreeStyle
These functions use peyotl wrappers around OpenTree API calls, described at https://github.com/OpenTreeOfLife/opentree/wiki/Open-Tree-of-Life-APIs
def ot_find_tree(pair, exact=True, verbose=False, oti_wrapper=None):
'''Uses a peyotl wrapper around an Open Tree web service to get a list of trees including
values `value` for a given property to be searched on `property`.
The oti_wrapper can be None (in which case the default wrapper from peyotl.sugar will be used.
All other arguments correspond to the arguments of the web-service call.
'''
if oti_wrapper is None:
from peyotl.sugar import oti
oti_wrapper = oti
match_obj = oti_wrapper.find_trees(pair, exact=exact, verbose=verbose)
return match_obj
def ot_get_tree(study_id, tree_id,**kwargs):
from peyotl.api import APIWrapper
api_wrapper = APIWrapper()
if 'format' in kwargs:
match_obj = api_wrapper.study.get(study_id,tree=tree_id,format=kwargs['format'])
else:
match_obj = api_wrapper.study.get(study_id,tree=tree_id)
return match_obj
Changing the values here can allow you select trees with any values in trees' searchable properties.
Properties include: "is_deprecated", "ot:treebaseTreeId", "ot:branchLengthMode", "ot:comment", "ot:branchLengthDescription", "ot:nodeLabelMode", "ot:originalLabel", "ot:studyId", "ot:ottId", "ot:treeModified", "ot:treebaseOTUId", "ot:tag", "ot:treeLastEdited", "ot:inferenceMethod", "ot:ottTaxonName", "ot:branchLengthTimeUnits", "ot:nodeLabelDescription", "oti_tree_id"
arg_dict = {"ot:ottTaxonName": "Apis mellifera"}
tree_list = ot_find_tree(arg_dict)
for study in tree_list:
for tree in study['matched_trees']:
study_id=study['ot:studyId']
for tree in study['matched_trees']:
tnew=ot_get_tree(study_id, tree['oti_tree_id'],format='newick')
t = Tree(tnew, format=1)
if len(t) < 100:#this is just an aribitrary way to grab a tree isn't too hard to visualize
break
Using ETE you can visualize the trees pulled down from the OpenTree database in an ipython notebook!
circular_style = TreeStyle()
circular_style.mode = "c" # draw tree in circular mode
circular_style.scale = 30
t.render("%%inline", units="mm", tree_style=circular_style)
ts = TreeStyle()
ts.show_leaf_name = True
ts.mode = "c"
ts.arc_start = -180 # 0 degrees = 3 o'clock
ts.arc_span = 180
ts.scale = 40
t.render("%%inline", units='mm', tree_style=ts)