File: gen_results.py

package info (click to toggle)
python-biopython 1.59-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 32,800 kB
  • sloc: python: 116,625; xml: 39,183; ansic: 8,824; sql: 1,488; makefile: 151
file content (113 lines) | stat: -rw-r--r-- 4,702 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import os.path
import sys


VERSIONS = ["4_1", "4_3", "4_4", "4_4c", "4_5"]
VERBOSE = True
    
def codeml():
    from Bio.Phylo.PAML import codeml
    tests = [("aa_model0", "aa_alignment.phylip", "species.tree"),
            ("aa_pairwise", "aa_alignment.phylip", "species.tree"),
            ("all_NSsites", "alignment.phylip", "species.tree"),
            ("branchsiteA", "alignment.phylip", "species.tree"),
            ("clademodelC", "alignment.phylip", "species.tree"),
            ("freeratio", "alignment.phylip", "species.tree"),
            ("ngene2_mgene012", "lysinYangSwanson2002.nuc", "lysin.trees"),
            ("ngene2_mgene34", "lysinYangSwanson2002.nuc", "lysin.trees"),
            ("pairwise", "alignment.phylip", "species.tree"),
            ("SE", "alignment.phylip", "species.tree")]

    for test in tests:
        print test[0]
        cml = codeml.Codeml()
        cml.working_dir = "temp"
        ctl_file = os.path.join("Control_files",
                                "codeml", 
                                '.'.join([test[0], "ctl"]))
        alignment = os.path.join("Alignments", test[1])
        tree = os.path.join("Trees", test[2])                   
        cml.read_ctl_file(ctl_file)
        cml.alignment = alignment
        cml.tree = tree
        for version in VERSIONS:
            print "\t{0}".format(version.replace('_', '.'))
            out_file = '.'.join(['-'.join([test[0], version]), "out"])
            cml.out_file = os.path.join("Results", "codeml", test[0], out_file)
            bin = ''.join(["codeml", version])
            cml.run(command=bin, verbose=VERBOSE)
         

def baseml():
    from Bio.Phylo.PAML import baseml
    
    tests = [("model", range(0, 9)), ("nhomo", [1, 3, 4]),
            ("nparK", range(1, 5)), ("alpha1rho1", None), ("SE", None)]
    alignment = os.path.join("Alignments", "alignment.phylip")
    tree = os.path.join("Trees", "species.tree")
    for test in tests:
        print test[0]
        bml = baseml.Baseml()
        for version in VERSIONS:
            print "\t{0}".format(version.replace('_', '.'))
            if test[1] is not None:
                for n in test[1]:
                    if (version in ["4_3", "4_4", "4_4c", "4_5"] and 
                            test[0] == "nparK" and n in [3, 4]):
                        continue
                    print "\t\tn = {0}".format(n)
                    ctl_file = os.path.join("Control_files", "baseml", 
                        "{0}{1}.ctl".format(test[0], n))                   
                    bml.read_ctl_file(ctl_file)
                    bml.alignment = alignment
                    bml.tree = tree                
                    out_file = "{0}{1}-{2}.out".format(test[0], n, version)  
                    bml.out_file = os.path.join("Results", "baseml", test[0],
                        out_file)
                    bin = "baseml{0}".format(version)
                    bml.run(command=bin, verbose=VERBOSE)               
            else:
                if (version in ["4_3", "4_4", "4_4c", "4_5"] and
                        test[0] == "alpha1rho1"):
                    continue
                ctl_file = os.path.join("Control_files", "baseml",
                    "{0}.ctl".format(test[0]))
                bml.read_ctl_file(ctl_file)
                bml.alignment = alignment
                bml.tree = tree                                  
                out_file = "{0}-{1}.out".format(test[0], version)
                bml.out_file = os.path.join("Results", "baseml", test[0],
                    out_file)
                bin = "baseml{0}".format(version)
                bml.run(command=bin, verbose=VERBOSE)

def yn00():
    from Bio.Phylo.PAML import yn00
    
    tests = ["yn00"]
    alignment = os.path.join("Alignments", "alignment.phylip")
    for test in tests:
        print test[0]
        yn = yn00.Yn00()
        for version in VERSIONS:
            print "\t{0}".format(version.replace('_', '.'))
            ctl_file = os.path.join("Control_files", "yn00",
                "{0}.ctl".format(test))
            yn.read_ctl_file(ctl_file)
            yn.alignment = alignment
            out_file = "{0}-{1}.out".format(test, version)
            yn.out_file = os.path.join("Results", "yn00", out_file)
            bin = "yn00{0}".format(version)
            yn.run(command=bin, verbose=VERBOSE)

if __name__ == "__main__":
    if len(sys.argv) < 2:
        sys.exit("specify a paml program")
    if sys.argv[1] == "codeml":
        codeml()
    elif sys.argv[1] == "baseml":
        baseml()
    elif sys.argv[1] == "yn00":
        yn00()
    else:
        sys.exit("specify a paml program")