def labelForPaml(unlabelledTreeAsString,listOfNodes, tree):
    t = EvolTree(unlabelledTreeAsString)
    marks = []
    count = 1
    for i in listOfNodes:
        marks.append("#"+str(count))
        count+=1
    t.mark_tree(listOfNodes, marks=marks)
    print(t.write())
    outfile = tree+"."+"_".join(listOfNodes)
    with open(outfile, 'w') as out:
        out.write(t.write())
def showAlignmentWithTree(unlabelledTreeAsString,alignment):
    t = EvolTree(unlabelledTreeAsString, alignment,alg_format="paml")
    t.link_to_alignment(alignment, alg_format="paml")
    for node in t.traverse():
        print(node)
        print(node.node_id, node.name)
    print(t.write())
    #print(t)
    t.show() #layout=evol_clean_layout)
示例#3
0
def labelForPamlRegex(unlabelledTreeAsString, regex, tree):
    pattern = re.compile(regex)
    t = EvolTree(unlabelledTreeAsString)
    marks = []
    count = 1
    outfiles = []
    #nsFG=TreeStyle()
    nsMatch = NodeStyle() #match
    nsMatch["fgcolor"] = "blue"
    nsMatch["size"] = 10
    nsBG = NodeStyle()
    nsBG["fgcolor"] = "black"
    nsBG["size"] = 0
    nsFG = []

    tolabelreg = []
    for i in range(0,MAX_PARENT):
        nsFG.append( NodeStyle())
        nsFG[i]["size"] = 10
        nsFG[i]["fgcolor"] = NODE_COLORS[i]

    isroot=True
    for node in t.traverse():
        node.set_style(nsBG)
        if node.is_root():
            print("root")
            node.unroot()
            node._support = None

    for node in t.get_descendants():
        node.add_face(TextFace(node.node_id), column=0)

    #traverse and match
    for node in t.traverse():
        if re.match(pattern, node.name):
            print("MATCH", node.name, node.node_id)
            node.set_style(nsMatch)
            n = node
            try:
                for i in range(0,MAX_PARENT):

                    n = n.up
                    n.set_style(nsFG[i])
                    marks.append("#"+str(count))
                    print(count)
                    t.mark_tree([str(count)], marks=marks)
                    #just label everything with #1
                    print(t.write())

                    tolabelreg.append(str(n.node_id))

                    outfile = tree+"."+"_".join([str(n.node_id)])
                    with open(outfile, 'w') as out:
                        out.write(t.write())
                    outfiles.append(outfile)

            except AttributeError:
                pass

            marks.append("#"+str(count))
            print(count)
            t.mark_tree([str(count)], marks=marks)
            #just label everything with #1
            print(t.write())

            outfile = tree+"."+"_".join([str(node.node_id)])
            with open(outfile, 'w') as out:
                out.write(t.write())
                outfiles.append(outfile)
    #t.show()
    t.render(tree+".png")
    return(outfiles, tolabelreg)
示例#4
0
from ete2 import EvolTree
from ete2 import NodeStyle

tree = EvolTree ("data/S_example/measuring_S_tree.nw")
tree.link_to_alignment ('data/S_example/alignment_S_measuring_evol.fasta')

print tree

print 'Tree and alignment loaded.'
raw_input ('Tree will be mark in order to contrast Gorilla and Chimpanzee as foreground \nspecies.')

marks = ['1', 3, '7']

tree.mark_tree (marks, ['#1'] * 3)
print tree.write ()

# display marked branches in orange
for node in tree.traverse ():
    if not hasattr (node, 'mark'):
        continue
    if node.mark == '':
        continue
    node.img_style = NodeStyle()
    node.img_style ['bgcolor'] = '#ffaa00'
tree.show()


print '''now running branch-site models C and D that represents
the addition of one class of sites in on specific branch.
These models must be compared to null models M1 and M3.
示例#5
0
def label_regex(unlabeled_tree, regex, treefile, depth=4,
                model_list=None, paml_msa=None, outfile=None):
    pattern = re.compile(regex)
    t = EvolTree(unlabeled_tree)
    marks = []
    count = 1
    outfiles = []
    ts = TreeStyle()
    ts.mode = "c"
    nsMatch = NodeStyle()  # match
    nsMatch["fgcolor"] = "blue"
    nsMatch["size"] = 10
    nsBG = NodeStyle()
    nsBG["fgcolor"] = "black"
    nsBG["size"] = 0
    nsFG = []

    tolabelreg = []
    for i in range(0, depth):
        nsFG.append(NodeStyle())
        nsFG[i]["size"] = 10
        nsFG[i]["fgcolor"] = "blue"

    #isroot = True
    #for node in t.traverse():
    #    node.set_style(nsBG)
    #    if node.is_root():
    #        print("root")
    #       node.unroot()
    #       node._support = None

    for node in t.get_descendants():
        node.add_face(TextFace(node.node_id), column=0)

    # traverse and match
    for node in t.traverse():
        if re.match(pattern, node.name):
            node.set_style(nsMatch)
            n = node
            try:
                for i in range(0, depth):
                    n = n.up
                    n.set_style(nsFG[i])
                    marks.append("#" + str(count))
                    #print(count)
                    t.mark_tree([str(count)], marks=marks)
                    #just label everything with #1
                    tolabelreg.append(str(n.node_id))

                    outfile = treefile + "." + "_".join([str(n.node_id)])
                    with open(outfile, 'w') as out:
                        out.write(t.write())
                    outfiles.append(outfile)

            except AttributeError:
                pass
        else:
            node.set_style(nsBG)
    for f in tolabelreg:
        print(f,"FFF")
        for m in model_list:
            generateCtl(model=m, treefile=treefile+"."+f, seqfile=paml_msa, outfile=treefile+"."+f,
                                            generateOther=False)

    t = fakeUnroot(t)
    t.render(treefile+".png", tree_style=ts)
    return outfiles, tolabelreg