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/


In [1]:
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


In [2]:
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

In [3]:
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"


In [4]:
arg_dict = {"ot:ottTaxonName": "Apis mellifera"}

In [5]:
tree_list = ot_find_tree(arg_dict)

In [6]:
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!


In [7]:
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)


Out[7]:
Generated with ETE http://ete.cgenomics.org Generated with ETE http://ete.cgenomics.org 'Mengenilla sp' 'Halictophagidae sp' 'Tribolium castaneum' 'Strangalia bicolor' 'Kempynus sp' 'Platystoechotes sp' 'Austroneurothus brunneipennis' 'Mongoloraphidia martynovae' 'Nigronia sp' 'Microchorista philpotti' 'Nannochorista sp' 'Panorpa sp' 'Boreus sp' 'Boreus brumalis' 'Autralobittacus sp' 'Ctenocephalides felis' 'Neotyphloceras sp' 'Anopheles gambiae' 'Tipula abdominalis' 'Drosophila melanogaster' 'Musca domestica' 'Bombyx mori' 'Heliothis virescens' 'Hydropsyche phalerata' 'Apis mellifera' 'Ametastegia equiseti' 'Muscidifurax raptorellus' 'Blattella germanica' 'Frankliniella fusca' 'Blattella germanica' 'Frankliniella fusca' 'Mengenilla sp' 'Halictophagidae sp' 'Tribolium castaneum' 'Strangalia bicolor' 'Kempynus sp' 'Platystoechotes sp' 'Austroneurothus brunneipennis' 'Mongoloraphidia martynovae' 'Nigronia sp' 'Microchorista philpotti' 'Nannochorista sp' 'Panorpa sp' 'Boreus sp' 'Boreus brumalis' 'Autralobittacus sp' 'Ctenocephalides felis' 'Neotyphloceras sp' 'Anopheles gambiae' 'Tipula abdominalis' 'Drosophila melanogaster' 'Musca domestica' 'Bombyx mori' 'Heliothis virescens' 'Hydropsyche phalerata' 'Apis mellifera' 'Ametastegia equiseti' 'Muscidifurax raptorellus' 1.67 1.67

In [8]:
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)


Out[8]:
Generated with ETE http://ete.cgenomics.org Generated with ETE http://ete.cgenomics.org 'Mengenilla sp' 'Halictophagidae sp' 'Tribolium castaneum' 'Strangalia bicolor' 'Kempynus sp' 'Platystoechotes sp' 'Austroneurothus brunneipennis' 'Mongoloraphidia martynovae' 'Nigronia sp' 'Microchorista philpotti' 'Nannochorista sp' 'Panorpa sp' 'Boreus sp' 'Boreus brumalis' 'Autralobittacus sp' 'Ctenocephalides felis' 'Neotyphloceras sp' 'Anopheles gambiae' 'Tipula abdominalis' 'Drosophila melanogaster' 'Musca domestica' 'Bombyx mori' 'Heliothis virescens' 'Hydropsyche phalerata' 'Apis mellifera' 'Ametastegia equiseti' 'Muscidifurax raptorellus' 'Blattella germanica' 'Frankliniella fusca' 'Blattella germanica' 'Frankliniella fusca' 'Mengenilla sp' 'Halictophagidae sp' 'Tribolium castaneum' 'Strangalia bicolor' 'Kempynus sp' 'Platystoechotes sp' 'Austroneurothus brunneipennis' 'Mongoloraphidia martynovae' 'Nigronia sp' 'Microchorista philpotti' 'Nannochorista sp' 'Panorpa sp' 'Boreus sp' 'Boreus brumalis' 'Autralobittacus sp' 'Ctenocephalides felis' 'Neotyphloceras sp' 'Anopheles gambiae' 'Tipula abdominalis' 'Drosophila melanogaster' 'Musca domestica' 'Bombyx mori' 'Heliothis virescens' 'Hydropsyche phalerata' 'Apis mellifera' 'Ametastegia equiseti' 'Muscidifurax raptorellus' 1.25 1.25

In [ ]: