def baseml(vers=None, verbose=False): from Bio.Phylo.PAML import baseml if vers is not None: versions = [vers] else: versions = VERSIONS tests = [ ("model", list(range(0, 9))), ("nhomo", [1, 3, 4]), ("nparK", list(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(f"\t{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(f"\t\tn = {n}") ctl_file = os.path.join("Control_files", "baseml", f"{test[0]}{n}.ctl") bml.read_ctl_file(ctl_file) bml.alignment = alignment bml.tree = tree out_file = f"{test[0]}{n}-{version}.out" bml.out_file = os.path.join("Results", "baseml", test[0], out_file) bin = f"baseml{version}" bml.run(command=bin, verbose=verbose, parse=False) 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", f"{test[0]}.ctl") bml.read_ctl_file(ctl_file) bml.alignment = alignment bml.tree = tree out_file = f"{test[0]}-{version}.out" bml.out_file = os.path.join("Results", "baseml", test[0], out_file) bin = f"baseml{version}" bml.run(command=bin, verbose=verbose, parse=False)
def baseml(vers=None, verbose=False): from Bio.Phylo.PAML import baseml if vers is not None: versions = [vers] else: versions = VERSIONS tests = [("model", list(range(0, 9))), ("nhomo", [1, 3, 4]), ("nparK", list(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, parse=False) 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, parse=False)
def setUp(self): self.bml = baseml.Baseml()
searcher = NNITreeSearcher(scorer) constructor = ParsimonyTreeConstructor(searcher) pars_tree = constructor.build_tree(alignment) print(pars_tree) print('\n') from Bio import Phylo Phylo.write(pars_tree, aln + ".newick", 'newick') with open(aln, 'r') as original: allLines = original.readlines() allLines[0] = allLines[0].rstrip() + "I\n" modifyFile = open(aln, 'w') for i in allLines: modifyFile.write(i) modifyFile.close() bml = baseml.Baseml() bml.alignment = aln bml.tree = aln + ".newick" bml.out_file = out bml.working_dir = work_dir bml.set_options(runmode=2, model=6) bml.run() with open(out, 'r') as result: lines = result.readlines() print("Best tree found:") print(lines[-1]) last = lines[-1] newtree = open(out + ".newick", "w") newtree.write(last) newtree.close()