当前位置: 首页>>代码示例>>Python>>正文


Python Tree.read_from_string方法代码示例

本文整理汇总了Python中dendropy.Tree.read_from_string方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.read_from_string方法的具体用法?Python Tree.read_from_string怎么用?Python Tree.read_from_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dendropy.Tree的用法示例。


在下文中一共展示了Tree.read_from_string方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_sum_of_branches

# 需要导入模块: from dendropy import Tree [as 别名]
# 或者: from dendropy.Tree import read_from_string [as 别名]
def get_sum_of_branches(treepath):
    fin = open(treepath, "r")
    newick = fin.readline().strip()
    t = Tree()
    t.read_from_string(newick.__str__(), "newick")
    fin.close()
    return t.length()
开发者ID:cxhernandez,项目名称:asr-pipeline,代码行数:9,代码来源:phyloasr.py

示例2: reroot_tree

# 需要导入模块: from dendropy import Tree [as 别名]
# 或者: from dendropy.Tree import read_from_string [as 别名]
def reroot_tree(tstr):
    """Input: a tree path to a Newick tree.  Output: a re-rooted version of the tree, based on the outgroup defined in configuration.py"""
    t = Tree()
    t.read_from_string(tstr.__str__(), "newick")
    og = ap.params["outgroup"]
    og = re.sub("\[", "", og)
    og = re.sub("\]", "", og)
    og = re.sub("\"", "", og)
    ogs = og.split(",")
    mrca = t.mrca(taxon_labels=ogs)
    t.reroot_at_edge(mrca.edge, update_splits=False)
    ret = t.as_string("newick")
    ret = re.sub("\[\&\R\] ", "", ret)
    ret = ret.strip()
    return ret
开发者ID:bkacar,项目名称:asr-pipeline,代码行数:17,代码来源:tools.py

示例3: index_mutations

# 需要导入模块: from dendropy import Tree [as 别名]
# 或者: from dendropy.Tree import read_from_string [as 别名]
def index_mutations(con):
    """Builds an index of all mutations"""
    cur = con.cursor()
    
    for msaid in get_alignment_method_ids(con):
        for modelid in get_phylo_modelids(con):
            newick = get_anc_cladogram(con, msaid, modelid)
            t = Tree()
            t.read_from_string(newick, "newick")
            for edge in t.preorder_edge_iter():
                if edge.head_node == None or edge.tail_node == None:
                    continue
                if edge.head_node.label == None or edge.tail_node.label == None:
                    continue 
                print msaid, modelid, edge.head_node.label, edge.tail_node.label
                anc1name = "Node" + edge.head_node.label.__str__()
                anc2name = "Node" + edge.tail_node.label.__str__()
                index_mutations_helper(con, msaid, modelid, anc1name, anc2name)
开发者ID:bkacar,项目名称:asr-pipeline,代码行数:20,代码来源:index_mutations.py

示例4: return_trees_from_trace

# 需要导入模块: from dendropy import Tree [as 别名]
# 或者: from dendropy.Tree import read_from_string [as 别名]
def return_trees_from_trace(path):
    print "Parsing trace:", path
    trees = []
    lnls = []
    fin = open(path, "r")
    last_tree = None
    last_lnl = 0.0
    count_unique_trees = 0
    for line in fin.xreadlines():
        treestring = ""
        lnlstring = ""
        found_tree = False
        for c in line:
            if found_tree == False and c != "]" and c != "[" and c != "(":
                lnlstring += c
            if c == "(":
                found_tree = True
            if found_tree == True:
                treestring += c
        lnl = float(lnlstring)
        t = Tree()
        t.read_from_string(line, "newick")
        if last_tree != None: #2nd->nth trees in the list
            #sd = last_tree.symmetric_difference(t)
            #sd = t.symmetric_difference(last_tree)
            if last_lnl < lnl:
                trees.append(t)
                lnls.append("%.2f"%lnl)
                count_unique_trees += 1
            else:
                trees[trees.__len__()-1] = t
                lnls[lnls.__len__()-1] = "%.2f"%lnl
        else: #first tree in the list
            trees.append(t)
            lnls.append("%.2f"%lnl)
            count_unique_trees += 1
        last_tree = t
        last_lnl = lnl
        print count_unique_trees, lnl
    trees.append(last_tree)
    lnls.append("%.2f"%lnl)
    fin.close()
    return [trees, lnls]
开发者ID:vhsvhs,项目名称:phylowidgets,代码行数:45,代码来源:compare_phyml_tree_traces.py

示例5: reroot_newick

# 需要导入模块: from dendropy import Tree [as 别名]
# 或者: from dendropy.Tree import read_from_string [as 别名]
def reroot_newick(con, newick):
    """Provide a newick string, this method will re-root the tree
        based on the 'outgroup' setting."""
    cur = con.cursor()
    dendrotree = Tree()
    dendrotree.read_from_string(newick, "newick")
    sql = "select shortname from Taxa where id in (select taxonid from GroupsTaxa where groupid in (select id from TaxaGroups where name='outgroup'))"
    cur.execute(sql)
    rrr = cur.fetchall()
    outgroup_labels = []
    for iii in rrr:
        label = re.sub("_", " ", iii[0])
        outgroup_labels.append( label.__str__() )
    
    mrca = dendrotree.mrca(taxon_labels=outgroup_labels)
    if mrca.edge.tail_node != None and mrca.edge.head_node != None:
        dendrotree.reroot_at_edge(mrca.edge, update_splits=True)
    newick = dendrotree.as_string("newick")
    return newick
开发者ID:bkacar,项目名称:asr-pipeline,代码行数:21,代码来源:tools.py

示例6: compute_tree_distances

# 需要导入模块: from dendropy import Tree [as 别名]
# 或者: from dendropy.Tree import read_from_string [as 别名]
def compute_tree_distances(con):
    cur = con.cursor()
    cur.execute("insert or replace into TreeDistanceMetrics(metricid, name) values(1, 'symmetric')")
    cur.execute("insert or replace into TreeDistanceMetrics(metricid, name) values(2, 'euclidean')")
    con.commit()
    
    treeid_dendropytree = {}
    sql = "select id, almethod, phylomodelid, newick from UnsupportedMlPhylogenies"
    con.execute(sql)
    x = cur.fetchall()
    for ii in x:
        treeid = ii[0]
        t = Tree()
        t.read_from_string(newick, "newick")
        treeid_dendropytree[treeid] = t
        
    for ii in treeid_dendropytree:
        treeii = treeid_dendropytree[ii]
        this_row = []
        for jj in treeid_dendropytree:
            treejj = treeid_dendropytree[jj]
            
            """Symmetric Distance"""
            distance = treeii.symmetric_difference(treejj)
            """Store the computed distance in the database."""
            sql = "insert into TreeDistances(metricid, treeida, treeidb, distance) values("
            sql += "1," + ii.__str__() + "," + jj.__str__() + "," + distance.__str__() + ")"
            cur.execute(sql)

            """Euclidean Distance"""
            distance = treeii.euclidean_distance(treejj)
            """Store the computed distance in the database."""
            sql = "insert into TreeDistances(metricid, treeida, treeidb, distance) values("
            sql += "2," + ii.__str__() + "," + jj.__str__() + "," + distance.__str__() + ")"
            cur.execute(sql)
    
    con.commit()
                        
                        
            
    
开发者ID:bkacar,项目名称:asr-pipeline,代码行数:39,代码来源:phyloasr.py

示例7: match_ancestors_across_models

# 需要导入模块: from dendropy import Tree [as 别名]
# 或者: from dendropy.Tree import read_from_string [as 别名]
def match_ancestors_across_models(con):
    """This method fills data in the table AncestorsAcrossModels"""
    cur = con.cursor()

    modelids = get_phylo_modelids(con)
    msaids = get_alignment_method_ids(con)

    ancid_childrenids = {}  # key = Ancestor ID, value = list of Taxa IDs

    """Pull the map of taxon names to IDs from the database.
        We'll access this information a lot, so let's save it in a separate hashtable
        rather than repeatedly querying the databse."""
    taxonname_id = {}
    sql = "select id, shortname from Taxa"
    cur.execute(sql)
    for ii in cur.fetchall():
        id = ii[0]
        name = ii[1]
        taxonname_id[name] = id

    for modelid in modelids:
        for msaid in msaids:
            sql = "select newick from AncestralCladogram where unsupportedmltreeid in (select id from UnsupportedMlPhylogenies where almethod=" + msaid.__str__(
            ) + " and phylomodelid=" + modelid.__str__() + ")"
            cur.execute(sql)
            xx = cur.fetchone()
            if xx is None:
                write_error(con, "I cannot find the ancestral Newick cladogram for almethod=" +
                            msaid.__str__() + " and phylomodelid=" + modelid.__str__())
            cladonewick = xx[0].__str__()

            t = Tree()
            t.read_from_string(cladonewick, "newick")

            for node in t.nodes():
                if node.is_leaf() == False and node.level() > 0:
                    sql = "select id from Ancestors where name='Node" + node.label + \
                        "' and almethod=" + msaid.__str__() + " and phylomodel=" + modelid.__str__()
                    cur.execute(sql)
                    ancid = cur.fetchone()[0]
                    ancid_childrenids[ancid] = []

                    for l in node.leaf_iter():
                        # print "978:", l
                        taxonname = l.as_newick_string()
                        # print "980:", taxonname
                        taxonname = re.sub("'", "", taxonname)
                        ancid_childrenids[ancid].append(
                            taxonname_id[taxonname])

    # key = Ancestor ID, value = list of other ancestor IDs with the same
    # children.
    ancid_matches = {}
    for anc1 in ancid_childrenids:
        ancid_matches[anc1] = []
        mychildren = ancid_childrenids[anc1]
        mychildren.sort()
        for anc2 in ancid_childrenids:
            if anc1 == anc2:
                """Skip the self comparison."""
                continue
            theirchildren = ancid_childrenids[anc2]
            theirchildren.sort()
            if mychildren == theirchildren:
                ancid_matches[anc1].append(anc2)

    sql = "delete from AncestorsAcrossModels"
    cur.execute(sql)
    con.commit()

    for anc1 in ancid_matches:
        for anc2 in ancid_matches[anc1]:
            sql = "insert into AncestorsAcrossModels (ancid, same_ancid) values(" + anc1.__str__(
            ) + "," + anc2.__str__() + ")"
            cur.execute(sql)
    con.commit()
开发者ID:cxhernandez,项目名称:asr-pipeline,代码行数:78,代码来源:phyloasr.py


注:本文中的dendropy.Tree.read_from_string方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。