Back to index

python-biopython  1.60
gen_results.py
Go to the documentation of this file.
00001 import os.path
00002 import sys
00003 
00004 
00005 VERSIONS = ["4_1", "4_3", "4_4", "4_4c", "4_5"]
00006 VERBOSE = True
00007     
00008 def codeml():
00009     from Bio.Phylo.PAML import codeml
00010     tests = [("aa_model0", "aa_alignment.phylip", "species.tree"),
00011             ("aa_pairwise", "aa_alignment.phylip", "species.tree"),
00012             ("all_NSsites", "alignment.phylip", "species.tree"),
00013             ("branchsiteA", "alignment.phylip", "species.tree"),
00014             ("clademodelC", "alignment.phylip", "species.tree"),
00015             ("freeratio", "alignment.phylip", "species.tree"),
00016             ("ngene2_mgene012", "lysinYangSwanson2002.nuc", "lysin.trees"),
00017             ("ngene2_mgene34", "lysinYangSwanson2002.nuc", "lysin.trees"),
00018             ("pairwise", "alignment.phylip", "species.tree"),
00019             ("SE", "alignment.phylip", "species.tree")]
00020 
00021     for test in tests:
00022         print test[0]
00023         cml = codeml.Codeml()
00024         cml.working_dir = "temp"
00025         ctl_file = os.path.join("Control_files",
00026                                 "codeml", 
00027                                 '.'.join([test[0], "ctl"]))
00028         alignment = os.path.join("Alignments", test[1])
00029         tree = os.path.join("Trees", test[2])                   
00030         cml.read_ctl_file(ctl_file)
00031         cml.alignment = alignment
00032         cml.tree = tree
00033         for version in VERSIONS:
00034             print "\t{0}".format(version.replace('_', '.'))
00035             out_file = '.'.join(['-'.join([test[0], version]), "out"])
00036             cml.out_file = os.path.join("Results", "codeml", test[0], out_file)
00037             bin = ''.join(["codeml", version])
00038             cml.run(command=bin, verbose=VERBOSE)
00039          
00040 
00041 def baseml():
00042     from Bio.Phylo.PAML import baseml
00043     
00044     tests = [("model", range(0, 9)), ("nhomo", [1, 3, 4]),
00045             ("nparK", range(1, 5)), ("alpha1rho1", None), ("SE", None)]
00046     alignment = os.path.join("Alignments", "alignment.phylip")
00047     tree = os.path.join("Trees", "species.tree")
00048     for test in tests:
00049         print test[0]
00050         bml = baseml.Baseml()
00051         for version in VERSIONS:
00052             print "\t{0}".format(version.replace('_', '.'))
00053             if test[1] is not None:
00054                 for n in test[1]:
00055                     if (version in ["4_3", "4_4", "4_4c", "4_5"] and 
00056                             test[0] == "nparK" and n in [3, 4]):
00057                         continue
00058                     print "\t\tn = {0}".format(n)
00059                     ctl_file = os.path.join("Control_files", "baseml", 
00060                         "{0}{1}.ctl".format(test[0], n))                   
00061                     bml.read_ctl_file(ctl_file)
00062                     bml.alignment = alignment
00063                     bml.tree = tree                
00064                     out_file = "{0}{1}-{2}.out".format(test[0], n, version)  
00065                     bml.out_file = os.path.join("Results", "baseml", test[0],
00066                         out_file)
00067                     bin = "baseml{0}".format(version)
00068                     bml.run(command=bin, verbose=VERBOSE)               
00069             else:
00070                 if (version in ["4_3", "4_4", "4_4c", "4_5"] and
00071                         test[0] == "alpha1rho1"):
00072                     continue
00073                 ctl_file = os.path.join("Control_files", "baseml",
00074                     "{0}.ctl".format(test[0]))
00075                 bml.read_ctl_file(ctl_file)
00076                 bml.alignment = alignment
00077                 bml.tree = tree                                  
00078                 out_file = "{0}-{1}.out".format(test[0], version)
00079                 bml.out_file = os.path.join("Results", "baseml", test[0],
00080                     out_file)
00081                 bin = "baseml{0}".format(version)
00082                 bml.run(command=bin, verbose=VERBOSE)
00083 
00084 def yn00():
00085     from Bio.Phylo.PAML import yn00
00086     
00087     tests = ["yn00"]
00088     alignment = os.path.join("Alignments", "alignment.phylip")
00089     for test in tests:
00090         print test[0]
00091         yn = yn00.Yn00()
00092         for version in VERSIONS:
00093             print "\t{0}".format(version.replace('_', '.'))
00094             ctl_file = os.path.join("Control_files", "yn00",
00095                 "{0}.ctl".format(test))
00096             yn.read_ctl_file(ctl_file)
00097             yn.alignment = alignment
00098             out_file = "{0}-{1}.out".format(test, version)
00099             yn.out_file = os.path.join("Results", "yn00", out_file)
00100             bin = "yn00{0}".format(version)
00101             yn.run(command=bin, verbose=VERBOSE)
00102 
00103 if __name__ == "__main__":
00104     if len(sys.argv) < 2:
00105         sys.exit("specify a paml program")
00106     if sys.argv[1] == "codeml":
00107         codeml()
00108     elif sys.argv[1] == "baseml":
00109         baseml()
00110     elif sys.argv[1] == "yn00":
00111         yn00()
00112     else:
00113         sys.exit("specify a paml program")