Skip to content

Commit a5c6fda

Browse files
committed
Modified error checking function.
1 parent a9db769 commit a5c6fda

1 file changed

Lines changed: 45 additions & 39 deletions

File tree

AlignmentProcessor.py

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,43 @@
2222
def checkInput(axt, kaks, phylip, codeml, outdir):
2323
'''Makes sure necessary programs are installed and proper file conversion
2424
is run for optional analysis program.'''
25+
proceed = True
2526
if kaks == True:
2627
if codeml == True:
2728
print("\n\tError: Please specify only one analysis program.\n")
29+
proceed = False
2830
indir = os.path.isfile("bin/KaKs_Calculator")
2931
if indir == False:
30-
print("\n\tError: Please install KaKs_Clculator in the\
32+
print("\n\tError: Please install KaKs_Calculator in the\
3133
AlignmentProcessor bin.\n")
32-
quit()
34+
proceed = False
3335
if axt == False:
3436
print("\n\tError: Files must be converted into axt format for use\
3537
with KaKs_Clculator.\n")
36-
quit()
38+
proceed = False
3739
if codeml == True:
40+
control = glob(outdir + "*.ctl")
41+
if len(control) == 0:
42+
print("\n\tPlease supply a control file for CodeML.\n")
43+
proceed = False
44+
elif len(control) > 1:
45+
print("\n\tPlease supply only one CodeML control file.\n")
46+
proceed = False
3847
indir = os.path.isfile("paml/bin/codeml")
3948
phyml = os.path.isfile("PhyML/PhyML")
4049
if indir == False:
4150
print("\n\tError: Please install PAML in the\
4251
AlignmentProcessor folder.\n")
43-
quit()
52+
proceed = False
4453
if phyml == False:
4554
print("\n\tError: Please install and rename PhyML for use\
4655
with CodeML.\n")
47-
quit()
56+
proceed = False
4857
if phylip == False:
4958
print("\n\tError: Files must be converted into phylip format for use\
5059
with CodeML.\n")
51-
control = glob(outdir + "*.ctl")
52-
if len(control) == 0:
53-
print("\n\tPlease supply a control file for CodeML.\n")
54-
elif len(control) > 1:
55-
print("\n\tPlease supply only one CodeML control file.\n")
56-
quit()
60+
proceed = False
61+
return proceed
5762

5863

5964
def makeDir(path, outdir, axt, phylip, kaks, codeml):
@@ -202,34 +207,35 @@ def main():
202207
if axt == True and phylip == True:
203208
print("\n\tError: Please specify only one file type.\n")
204209
quit()
205-
checkInput(axt, kaks, phylip, codeml, outdir)
206-
# Set checkpoint variables to False:
207-
sf = False
208-
ff = False
209-
cf = False
210-
done = False
211-
# Save working directory to variable and call other scripts:
212-
path = os.getcwd()
213-
path = path + "/"
214-
makeDir(path, outdir, axt, phylip, kaks, codeml)
215-
sf = splitFasta(infile, outdir)
216-
if sf == True:
217-
ff = filterFasta(outdir, ref, percent, retainstops)
218-
if ff == True:
219-
cf = convert(outdir, axt, phylip)
220-
if cf == True:
221-
# Run KaKs_Calculator:
222-
if kaks == True:
223-
done = calculateKaKs(outdir, method)
224-
# Run codeml
225-
elif codeml == True:
226-
done = runcodeml(cpu, outdir, forward, cleanup)
227-
else:
228-
# Exit if neither program was called
229-
done = True
230-
# Print run time
231-
if done == True:
232-
print("\n\tTotal runtime: ", datetime.now() - starttime, "\n")
210+
proceed = checkInput(axt, kaks, phylip, codeml, outdir)
211+
if proceed == True:
212+
# Set checkpoint variables to False:
213+
sf = False
214+
ff = False
215+
cf = False
216+
done = False
217+
# Save working directory to variable and call other scripts:
218+
path = os.getcwd()
219+
path = path + "/"
220+
makeDir(path, outdir, axt, phylip, kaks, codeml)
221+
sf = splitFasta(infile, outdir)
222+
if sf == True:
223+
ff = filterFasta(outdir, ref, percent, retainstops)
224+
if ff == True:
225+
cf = convert(outdir, axt, phylip)
226+
if cf == True:
227+
# Run KaKs_Calculator:
228+
if kaks == True:
229+
done = calculateKaKs(outdir, method)
230+
# Run codeml
231+
elif codeml == True:
232+
done = runcodeml(cpu, outdir, forward, cleanup)
233+
else:
234+
# Exit if neither program was called
235+
done = True
236+
# Print run time
237+
if done == True:
238+
print("\n\tTotal runtime: ", datetime.now() - starttime, "\n")
233239

234240
if __name__ == "__main__":
235241
main()

0 commit comments

Comments
 (0)