import peyotl from ete2 import Tree, TreeStyle 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 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 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)