2020def makeTree (ap , gene , wd , treefile , forward ):
2121 '''Calls PhyML to create a gene tree.'''
2222 # Call PhyML to make gene tree
23+ passed = True
2324 phy = Popen (split (ap + "PhyML/PhyML -q -i " + gene ), stdout = DEVNULL )
2425 phy .wait ()
2526 # Move PhyML output to temp directory
@@ -32,29 +33,31 @@ def makeTree(ap, gene, wd, treefile, forward):
3233 try :
3334 tree = genetree .readlines ()[0 ]
3435 except IndexError :
36+ passed = False
37+ if passed == True :
38+ # Remove branch lables introduced by PhyML
39+ tree = re .sub (r"\d+\.\d+:" , ":" , tree )
40+ # Add forward node to tree if specified
41+ if forward :
42+ if forward in tree :
43+ # Determine location and length of species name
44+ i = tree .index (forward ) + len (forward )
45+ if ":" in tree :
46+ # Find end of branch length
47+ comma = tree .find ("," , i )
48+ paren = tree .find (")" , i )
49+ i = min ([comma , paren ])
50+ # Insert space and node symbol after species name
51+ tree = (tree [:i ] + " #1" + tree [i :])
52+ elif forward not in tree :
3553 pass
36- # Remove branch lables introduced by PhyML
37- tree = re .sub (r"\d+\.\d+:" , ":" , tree )
38- # Add forward node to tree if specified
39- if forward :
40- if forward in tree :
41- # Determine location and length of species name
42- i = tree .index (forward ) + len (forward )
43- if ":" in tree :
44- # Find end of branch length
45- comma = tree .find ("," , i )
46- paren = tree .find (")" , i )
47- i = min ([comma , paren ])
48- # Insert space and node symbol after species name
49- tree = (tree [:i ] + " #1" + tree [i :])
50- elif forward not in tree :
51- pass
52- with open (treefile , "w" ) as outtree :
53- # Overwrite treefile
54- string = ""
55- for i in tree :
56- string += i
57- outtree .write (string )
54+ with open (treefile , "w" ) as outtree :
55+ # Overwrite treefile
56+ string = ""
57+ for i in tree :
58+ string += i
59+ outtree .write (string )
60+ return passed
5861
5962def makeCtl (gene , outfile , tempctl , treefile , ctl ):
6063 '''Creates unique control file'''
@@ -93,18 +96,20 @@ def parallelize(ap, outdir, finished, completed, multiple, cpu, ctl,
9396 rmtree (wd )
9497 pass
9598 else :
99+ passed = True
96100 if not treefile :
97101 # Run Phyml
98102 treefile = wd + filename + "_phyml_tree.txt"
99- makeTree (ap , gene , wd , treefile , forward )
100- # Make control file
101- makeCtl (gene , outfile , tempctl , treefile , ctl )
102- os .chdir (wd )
103- # Call CodeML
104- with open ("codemlLog.txt" , "w" ) as tmpout :
105- cm = Popen (split (ap + "paml/bin/codeml " + tempctl ),
106- shell = True , stdout = tmpout , stderr = tmpout )
107- cm .wait ()
103+ passed = makeTree (ap , gene , wd , treefile , forward )
104+ if passed == True :
105+ # Make control file
106+ makeCtl (gene , outfile , tempctl , treefile , ctl )
107+ os .chdir (wd )
108+ # Call CodeML
109+ with open ("codemlLog.txt" , "w" ) as tmpout :
110+ cm = Popen (split (ap + "paml/bin/codeml " + tempctl ),
111+ shell = True , stdout = tmpout , stderr = tmpout )
112+ cm .wait ()
108113 elif multiple == False :
109114 # Make control file
110115 treefile = wd + filename + ""
0 commit comments