def extract_tree_nexson(nexson, tree_id, curr_version=None):
    """Returns a list of (id, tree, otus_group) tuples for the
    specified tree_id (all trees if tree_id is None)
    """
    if curr_version is None:
        curr_version = detect_nexson_version(nexson)
    if not _is_by_id_hbf(curr_version):
        nexson = convert_nexson_format(nexson, BY_ID_HONEY_BADGERFISH)

    nexml_el = get_nexml_el(nexson)
    tree_groups = nexml_el['treesById']
    tree_obj_otus_group_list = []
    for tree_group in tree_groups.values():
        if tree_id:
            tree_list = [(tree_id, tree_group['treeById'].get(tree_id))]
        else:
            tree_list = tree_group['treeById'].items()
        for tid, tree in tree_list:
            if tree is not None:
                otu_groups = nexml_el['otusById']
                ogi = tree_group['@otus']
                otu_group = otu_groups[ogi]['otuById']
                tree_obj_otus_group_list.append((tid, tree, otu_group))
                if tree_id is not None:
                    return tree_obj_otus_group_list
    return tree_obj_otus_group_list
def extract_tree_nexson ( nexson , tree_id , curr_version = None ) : if curr_version is None : curr_version = detect_nexson_version ( nexson ) if not _is_by_id_hbf ( curr_version ) : nexson = convert_nexson_format ( nexson , BY_ID_HONEY_BADGERFISH ) nexml_el = get_nexml_el ( nexson ) tree_groups = nexml_el [ 'treesById' ] tree_obj_otus_group_list = [ ] for tree_group in tree_groups . values ( ) : if tree_id : tree_list = [ ( tree_id , tree_group [ 'treeById' ] . get ( tree_id ) ) ] else : tree_list = tree_group [ 'treeById' ] . items ( ) for tid , tree in tree_list : if tree is not None : otu_groups = nexml_el [ 'otusById' ] ogi = tree_group [ '@otus' ] otu_group = otu_groups [ ogi ] [ 'otuById' ] tree_obj_otus_group_list . append ( ( tid , tree , otu_group ) ) if tree_id is not None : return tree_obj_otus_group_list return tree_obj_otus_group_list
Returns a list of (id, tree, otus_group) tuples for the
    specified tree_id (all trees if tree_id is None)