예제 #1
0
def pamlSite(alnFile, treeFile, lModels, pamlParams, outDir, baseName, logger):

    tree = EvolTree(treeFile)
    os.mkdir(outDir + "paml_site/")
    tree.workdir = outDir + "paml_site/"
    tree.link_to_alignment(alnFile, "Fasta")
    logger.info("PAML codeml")

    dModelRun = {}
    for model in lModels:
        if model in ["M0", "M1", "M2", "M7", "M8"]:
            logger.info("Running {:s}".format(model))
            dModelRun[model] = tree.run_model(model)

    if "M1" and "M2" in dModelRun:
        p12 = tree.get_most_likely("M2", "M1")
        logger.info("LRT of M1 vs M2 = {}".format(p12))
    if "M7" and "M8" in dModelRun:
        p78 = tree.get_most_likely("M8", "M7")
        logger.info("LRT of M7 vs M8 = {}".format(p78))
    """
예제 #2
0
def main():
    """
    main function
    """
    tree = EvolTree(WRKDIR + 'tree.nw')
    tree.workdir = 'data/protamine/PRM1/paml/'

    random_swap(tree)
    tree.link_to_evol_model(WRKDIR + 'paml/fb/fb.out', 'fb')
    check_annotation(tree)
    tree.link_to_evol_model(WRKDIR + 'paml/M1/M1.out', 'M1')
    tree.link_to_evol_model(WRKDIR + 'paml/M2/M2.out', 'M2')
    tree.link_to_evol_model(WRKDIR + 'paml/M7/M7.out', 'M7')
    tree.link_to_evol_model(WRKDIR + 'paml/M8/M8.out', 'M8')
    tree.link_to_alignment(WRKDIR + 'alignments.fasta_ali')
    print 'pv of LRT M2 vs M1: ',
    print tree.get_most_likely('M2', 'M1')
    print 'pv of LRT M8 vs M7: ',
    print tree.get_most_likely('M8', 'M7')

    tree.show(histfaces=['M2'])

    print 'The End.'
def run_codeml(mark_id, aln_file, tree_file, sleep):
    logger.info('sub-process: {0}'.format(str(mark_id)))
    time.sleep(round(sleep / args.threads, 2))
    run_dir = os.path.join(output_dir, str(mark_id))
    os.makedirs(run_dir)
    tree = EvolTree(tree_file, format=0)
    tree.link_to_alignment(aln_file)
    tree.run_model('M0')
    tree.workdir = run_dir
    tree.mark_tree([mark_id], marks=['#1'])
    tree.run_model('bsA.' + str(mark_id))
    tree.run_model('bsA1.' + str(mark_id))
    ps = tree.get_most_likely('bsA.' + str(mark_id), 'bsA1.' + str(mark_id))
    rx = tree.get_most_likely('bsA1.' + str(mark_id), 'M0')
    bsA = tree.get_evol_model('bsA.' + str(mark_id))
    p_bsA = bsA.classes['proportions'][2]
    wfrg2a = bsA.classes['foreground w'][2]
    if ps < 0.05 and float(wfrg2a) > 1:
        result = [mark_id, ps, rx, p_bsA, 'positive selection']
    elif rx < 0.05 and ps >= 0.05:
        result = [mark_id, ps, rx, p_bsA, 'relaxation']
    else:
        result = [mark_id, ps, rx, p_bsA, 'no signal']
    return result
예제 #4
0
def main():
    """
    main function
    """
    tree = EvolTree (WRKDIR + 'tree.nw')
    tree.workdir = 'data/protamine/PRM1/paml/'

    random_swap(tree)
    tree.link_to_evol_model (WRKDIR + 'paml/fb/fb.out', 'fb')
    check_annotation (tree)
    tree.link_to_evol_model (WRKDIR + 'paml/M1/M1.out', 'M1')
    tree.link_to_evol_model (WRKDIR + 'paml/M2/M2.out', 'M2')
    tree.link_to_evol_model (WRKDIR + 'paml/M7/M7.out', 'M7')
    tree.link_to_evol_model (WRKDIR + 'paml/M8/M8.out', 'M8')
    tree.link_to_alignment  (WRKDIR + 'alignments.fasta_ali')
    print 'pv of LRT M2 vs M1: ',
    print tree.get_most_likely ('M2','M1')
    print 'pv of LRT M8 vs M7: ',
    print tree.get_most_likely ('M8','M7')


    tree.show (histfaces=['M2'])

    print 'The End.'
예제 #5
0
# each node/leaf has two kind of identifiers node_id and paml_id, to mark nodes we have to specify
# the node_id of the nodes we want to mark, and the kind of mark in this way:

for leaf in tree:
    leaf.node_id
    print '\n---------\nNow working with leaf ' + leaf.name
    tree.mark_tree([leaf.node_id], marks=['#1'])
    print tree.write()
    # to organize a bit, we name model with the name of the marked node
    # any character after the dot, in model name, is not taken into account
    # for computation. (have a look in /tmp/ete3.../bsA.. directory)
    print 'running model bsA and bsA1'
    tree.run_model('bsA.'+ leaf.name)
    tree.run_model('bsA1.' + leaf.name)
    print 'p-value of positive selection for sites on this branch is: '
    ps = tree.get_most_likely('bsA.' + leaf.name, 'bsA1.'+ leaf.name)
    rx = tree.get_most_likely('bsA1.'+ leaf.name, 'M0')
    print str(ps)
    print 'p-value of relaxation for sites on this branch is: '
    print str(rx)
    if ps < 0.05 and float(bsA.wfrg2a) > 1:
        print 'we have positive selection on sites on this branch'
    elif rx<0.05 and ps>=0.05:
        print 'we have relaxation on sites on this branch'
    else:
        print 'no signal detected on this branch, best fit for M0'
    print '\nclean tree, remove marks'
    tree.mark_tree(map(lambda x: x.node_id, tree.get_descendants()),
                    marks=[''] * len(tree.get_descendants()), verbose=True)

# nothing working yet to get which sites are under positive selection/relaxation,
예제 #6
0
print (tree)

try:
    input = raw_input
except NameError:
    pass

input ('\n   tree and alignment loaded\n Hit some key, to start computation of site models M1 and M2.\n')

print ('running model M1')
tree.run_model ('M1')
print ('running model M2')
tree.run_model ('M2')

print ('\n\n comparison of models M1 and M2, p-value: ' + str(tree.get_most_likely ('M2','M1')))

#tree.show()

print ('by default the hist represented is this one:')

tree.show (histfaces=['M2'])

print ('but we can choose between many others...')

model2 = tree.get_evol_model ('M2')

col2 = {'NS' : 'black', 'RX' : 'black',
        'RX+': 'black', 'CN' : 'black',
        'CN+': 'black', 'PS' : 'black', 'PS+': 'black'}
예제 #7
0
print ('''now running branch models
free branch models, 2 groups of branches, one with Gorilla and
chimp, the other with the rest of the phylogeny
''')
print ('running branch free...')
tree.run_model ('b_free.137')
print ('running branch neut...')
tree.run_model ('b_neut.137')
print ('running M0 (all branches have the save value of omega)...')
tree.run_model ('M0')

input ('''Now we can do comparisons...
Compare first if we have one or 2 rates of evolution among phylogeny.
LRT between b_free and M0 (that is one or two rates of omega value)
p-value ofthis comparison is:''')
print (tree.get_most_likely ('b_free.137', 'M0'))

input ('''
Now test if foreground rate is significantly different of 1.
(b_free with significantly better likelihood than b_neut)
if significantly different, and higher than one, we will be under
positive selection, if different and lower than 1 we will be under
negative selection. And finally if models are not significantly different
we should accept null hypothesis that omega value on marked branches is
equal to 1, what would be a signal of relaxation.
p-value for difference in rates between marked branches and the rest:''')
print (tree.get_most_likely ('b_free.137', 'M0'))
print ('p-value representing significance that omega is different of 1:')
print (tree.get_most_likely ('b_free.137', 'b_neut.137'))

print ('value of omega in marked branch (frg branch):')
예제 #8
0
    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.
if branch-site models are detected to be significantly better,
than, one class of site is evolving at different rate in the marked
clade.
''')

# TODO: re-enable model M3

print('running branch-site C...')
tree.run_model('bsC.137')
#print ('running branch-site D...')
#tree.run_model ('bsD.137')
print('running M1 (all branches have the save value of omega)...')
tree.run_model('M1')
#print ('running M3 (all branches have the save value of omega)...')
#tree.run_model ('M3')

print('''p-value that, in marked clade, we have one class of site
specifically evolving at a different rate:''')
print(tree.get_most_likely('bsC.137', 'M1'))
#print ('p-value representing significance that omega is different of 1:')
#print (tree.get_most_likely ('bsD.137', 'M3'))

print('The End.')
예제 #9
0
print '''now running branch models
free branch models, 2 groups of branches, one with Gorilla and
chimp, the other with the rest of the phylogeny
'''
print 'running branch free...'
tree.run_model('b_free.137')
print 'running branch neut...'
tree.run_model('b_neut.137')
print 'running M0 (all branches have the save value of omega)...'
tree.run_model('M0')

raw_input('''Now we can do comparisons...
Compare first if we have one or 2 rates of evolution among phylogeny.
LRT between b_free and M0 (that is one or two rates of omega value)
p-value ofthis comparison is:''')
print tree.get_most_likely('b_free.137', 'M0')

raw_input('''
Now test if foreground rate is significantly different of 1.
(b_free with significantly better likelihood than b_neut)
if significantly different, and higher than one, we will be under
positive selection, if different and lower than 1 we will be under
negative selection. And finally if models are not significantly different
we should accept null hypothesis that omega value on marked branches is
equal to 1, what would be a signal of relaxation.
p-value for difference in rates between marked branches and the rest:''')
print tree.get_most_likely('b_free.137', 'M0')
print 'p-value representing significance that omega is different of 1:'
print tree.get_most_likely('b_free.137', 'b_neut.137')

print 'value of omega in marked branch (frg branch):'
예제 #10
0
    """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.
if branch-site models are detected to be significantly better,
than, one class of site is evolving at different rate in the marked
clade.
"""
)

# TODO: re-enable model M3

print("running branch-site C...")
tree.run_model("bsC.137")
# print ('running branch-site D...')
# tree.run_model ('bsD.137')
print("running M1 (all branches have the save value of omega)...")
tree.run_model("M1")
# print ('running M3 (all branches have the save value of omega)...')
# tree.run_model ('M3')

print(
    """p-value that, in marked clade, we have one class of site
specifically evolving at a different rate:"""
)
print(tree.get_most_likely("bsC.137", "M1"))
# print ('p-value representing significance that omega is different of 1:')
# print (tree.get_most_likely ('bsD.137', 'M3'))


print("The End.")
예제 #11
0
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.
if branch-site models are detected to be significantly better,
than, one class of site is evolving at different rate in the marked
clade.
'''

# TODO: re-enable model M3

print 'running branch-site C...'
tree.run_model ('bsC.137')
#print 'running branch-site D...'
#tree.run_model ('bsD.137')
print 'running M1 (all branches have the save value of omega)...'
tree.run_model ('M1')
#print 'running M3 (all branches have the save value of omega)...'
#tree.run_model ('M3')

print '''p-value that, in marked clade, we have one class of site
specifically evolving at a different rate:'''
print tree.get_most_likely ('bsC.137', 'M1')
#print 'p-value representing significance that omega is different of 1:'
#print tree.get_most_likely ('bsD.137', 'M3')


print 'The End.'
예제 #12
0
tree.run_model('M0', keep=True)
#tree.link_to_evol_model("/home/edu/Desktop/Bioinformatica/Mitogenomics/Chondrichthyes/Phylogenetic_Tree","M0")
chimaeriformes = tree.get_common_ancestor("HM147138.1", "HM147135.1")
#chimaeriformes =tree.get_common_ancestor("Human_ECP","Goril_ECP")

for leaf in chimaeriformes:
    tree.mark_tree([leaf.node_id], marks=["#1"])
#tree.run_model("bsA." + chimaeriformes)
#tree.mark_tree([leaf.node_id], marks = ["#1"])
print("Running")
print(tree.write())
tree.run_model('bsA.Chimaeriformes')
tree.run_model("bsA1.Chimaeriformes")

print('p-value of positive selection for sites on this branch is: ')
ps = tree.get_most_likely('bsA.Chimaeriformes', 'bsA1.Chimaeriformes')
print(str(ps))
rx = tree.get_most_likely('bsA1.Chimaeriformes', 'M0')
print(str(rx))
model = tree.get_evol_model("bsA.Chimaeriformes")
if ps < 0.05 and float(model.classes['foreground w'][2]) > 1:
    print('we have positive selection on sites on this branch')
    tree.show(histfaces=['bsA1.Chimaeriformes'])
elif rx < 0.05 and ps >= 0.05:
    print('we have relaxation on sites on this branch')
else:
    print('no signal detected on this branch, best fit for M0')
#tree.show(histfaces=['bsA1.'])

for models in tree._models:
    print(tree.get_evol_model(models))