@@ -98,23 +98,23 @@ def check_required_files(runmode):
98
98
for f in outfile_dict [runmode ]:
99
99
if not os .path .isfile (f ):
100
100
if debug :
101
- print (now (),"DEBUG, check_required_files: File not found:" , f )
101
+ print (now (),"DEBUG: check_required_files: File not found:" , f )
102
102
return f
103
103
return
104
104
105
105
def check_directories (mode ):
106
106
for directory in outdir_dict [mode ]:
107
107
if not os .path .isdir (directory ):
108
108
if debug :
109
- print (now (), "DEBUG, check_directories: Directory not found:" , directory )
109
+ print (now (), "DEBUG: check_directories: Directory not found:" , directory )
110
110
return directory
111
111
return
112
112
113
113
def check_hasrun (mode ):
114
114
f = checkpoint_file_dict [mode ]
115
115
if not os .path .isfile (f ):
116
116
if debug :
117
- print (now (), "DEBUG, check_hasrun: Not found:" , f )
117
+ print (now (), "DEBUG: check_hasrun: Not found:" , f )
118
118
return f
119
119
else :
120
120
return
@@ -128,15 +128,15 @@ def check_config_file(f):
128
128
129
129
def check_for_errors (result ):
130
130
if result .startswith ("WorkflowError" ):
131
- return now ()+ " ERROR: phylociraptor encountered an error. You may try to run with --verbose to diagnose what has gone wrong .\n "
131
+ return now ()+ " ERROR: phylociraptor encountered an error. Use --debug and --verbose to diagnose.\n "
132
132
if result .startswith ("The singularity command" ):
133
133
return result
134
134
if result .startswith ("Error" ) or result .startswith ("error" ):
135
- return now ()+ " ERROR: There was an error. Maybe run with --verbose to diagnose. The error occurred here: %s " % result
135
+ return now ()+ " ERROR: There was an error. Use --debug and --verbose to diagnose. The error occurred here: %s " % result
136
136
if result .startswith ("Directory cannot be locked." ):
137
137
return now ()+ " ERROR: " + result
138
138
if result .startswith ("IncompleteFilesException" ):
139
- return now ()+ " ERROR: There seems to be a problem with incomplete output files from a previous run.\n You can run --verbose to see which files are incomplete and how to resolve the problem .\n "
139
+ return now ()+ " ERROR: There seems to be a problem with incomplete output files from a previous run. You can use --rerun-incomplete to force a rerun of incomplete tasks .\n "
140
140
if result .startswith ("KeyError" ):
141
141
return now ()+ " ERROR: " + result
142
142
return ""
@@ -174,9 +174,11 @@ def execute_command(cmd, verbose, isutil=False):
174
174
print (now (), "INFO: --dry specified, will only perform a dry run of the analysis" )
175
175
for line in io .TextIOWrapper (popen .stdout , encoding = "utf-8" ):
176
176
nline += 1
177
- if verbose :
178
- if debug :
179
- yield line
177
+ if debug :
178
+ yield line
179
+ elif verbose :
180
+ if check_for_errors (line ):
181
+ yield check_for_errors (line )
180
182
else :
181
183
if line .startswith ("rule" ) and not debug :
182
184
yield now ()+ " Task: %s\n " % line .strip ().split (" " )[1 ].rstrip (":" )
@@ -192,7 +194,7 @@ def execute_command(cmd, verbose, isutil=False):
192
194
jobcounts = True
193
195
elif jobcounts and result != "" and nline <= 30 : #only keep jobcount info from the beginning of the output
194
196
if len (result .split ("\t " )) == 2 : # the line with the total number of jobs has two elements
195
- yield now ()+ " Total number of tasks to run/submit : %s\n " % result .split ("\t " )[1 ].strip ()
197
+ yield now ()+ " Total number of tasks for this step : %s\n " % result .split ("\t " )[1 ].strip ()
196
198
elif jobcounts and result == "" :
197
199
jobcounts = False
198
200
line = ""
@@ -204,9 +206,11 @@ def execute_command(cmd, verbose, isutil=False):
204
206
for line in io .TextIOWrapper (popen .stdout , encoding = "utf-8" ):
205
207
nline += 1
206
208
logging .debug (line .strip ())
207
- if verbose :
208
- if debug :
209
- yield line
209
+ if debug :
210
+ yield line
211
+ elif verbose :
212
+ if check_for_errors (line ):
213
+ yield check_for_errors (line )
210
214
else :
211
215
if line .startswith ("Pulling singularity" ):
212
216
container = line .rstrip ().split (" " )[- 1 ].strip ("." )
@@ -246,17 +250,16 @@ def execute_command(cmd, verbose, isutil=False):
246
250
for line in io .TextIOWrapper (popen .stdout , encoding = "utf-8" ):
247
251
nline += 1
248
252
logging .debug (line .strip ())
249
- if verbose :
250
- if debug :
251
- yield line
252
- else :
253
- if line .startswith ("Pulling singularity" ):
254
- container = line .rstrip ().split (" " )[- 1 ].strip ("." )
255
- yield now () + " Please be patient as singularity container " + container + " is downloaded. This can take several minutes.\n "
256
- if line .startswith ("rule" ) and not debug :
257
- yield now ()+ " Will run task: %s\n " % line .strip ().split (" " )[1 ].rstrip (":" )
258
- if line .lstrip ().startswith ("wildcards:" ):
259
- yield "\t Parameters: %s\n " % line .split (":" )[1 ]
253
+ if debug :
254
+ yield line
255
+ elif verbose :
256
+ if line .startswith ("Pulling singularity" ):
257
+ container = line .rstrip ().split (" " )[- 1 ].strip ("." )
258
+ yield now () + " Please be patient as singularity container " + container + " is downloaded. This can take several minutes.\n "
259
+ if line .startswith ("rule" ) and not debug :
260
+ yield now ()+ " Will run task: %s\n " % line .strip ().split (" " )[1 ].rstrip (":" )
261
+ if line .lstrip ().startswith ("wildcards:" ):
262
+ yield "\t Parameters: %s\n " % line .split (":" )[1 ]
260
263
else :
261
264
result = line
262
265
if check_for_errors (result ):
@@ -298,20 +301,21 @@ def get_additional_snakemake_flags(flags, rerun, unlock):
298
301
else :
299
302
flags += "-p"
300
303
if flags :
301
- print (now (), "INFO: Additional flags will be passed on to snakemake: " , flags )
304
+ if debug :
305
+ print (now (), "DEBUG: Additional flags will be passed on to snakemake: " , flags )
302
306
return flags .split (" " )
303
307
else :
304
308
return []
305
309
306
310
def get_additional_singularity_flags (flags ):
307
311
if flags :
308
- print (now (), "INFO: Additional flags will be passed on to singularity: " , flags )
312
+ if debug :
313
+ print (now (), "DEBUG: Additional flags will be passed on to singularity: " , flags )
309
314
return ["--singularity-args" ]+ [singularity_bindpoints + " " + flags ]
310
315
else :
311
316
return ["--singularity-args" ]+ [singularity_bindpoints ]
312
317
313
318
pars = argparse .ArgumentParser (usage = help_message (default_help ))
314
- pars .add_argument ('--debug' , action = 'store_true' , dest = "debug" , required = False )
315
319
pars .add_argument ('-v' , '--version' , action = 'store_true' , dest = 'version' , required = False )
316
320
pars .add_argument ('command' , action = 'store' , nargs = "?" )
317
321
pars .add_argument ('arguments' , action = 'store' , nargs = argparse .REMAINDER )
@@ -326,9 +330,6 @@ if args.version == True:
326
330
print ("Git commit:" , commit )
327
331
sys .exit (0 )
328
332
329
- if args .debug == True :
330
- print (now (), "DEBUG: Addditional debugging output enabled." )
331
- debug = True
332
333
333
334
if not args .command :
334
335
print (default_help )
@@ -349,12 +350,21 @@ class PhyloParser(argparse.ArgumentParser):
349
350
self .add_argument ("--snakemake" , action = "store" ,dest = "sm_args" , default = "" )
350
351
self .add_argument ("--rerun-incomplete" , action = "store_true" , dest = "rerun" , default = False )
351
352
self .add_argument ("--unlock" , action = "store_true" , dest = "unlock" , default = False )
353
+ self .add_argument ('--debug' , action = 'store_true' , dest = "debug" , required = False )
354
+
355
+ def check_debug (debug ):
356
+ if debug :
357
+ #print(now(), "DEBUG: Addditional debugging output enabled.")
358
+ return True
359
+ else :
360
+ return False
352
361
353
362
class UtilParser (argparse .ArgumentParser ):
354
363
def __init__ (self , ** kwargs ):
355
364
super ().__init__ (** kwargs )
356
365
self .add_argument ("-h" , "--help" , action = "store_true" )
357
366
self .add_argument ("--verbose" , action = "store_true" , default = False )
367
+ self .add_argument ('--debug' , action = 'store_true' , dest = "debug" , required = False )
358
368
359
369
360
370
if args .command == "setup" :
@@ -366,6 +376,7 @@ if args.command == "setup":
366
376
setup_parser .add_argument ("--add_genomes" , action = "store_true" ,default = False , dest = "add_genomes" )
367
377
368
378
setup_args = setup_parser .parse_args (args .arguments )
379
+ debug = check_debug (setup_args .debug ) #check if debug is enabled
369
380
if setup_args .help or len (sys .argv ) <= 2 :
370
381
print (help_message (setup_help ))
371
382
sys .exit (0 )
@@ -407,6 +418,7 @@ elif args.command=="orthology":
407
418
orthology_parser .add_argument ("--augustus_species" , action = "store" )
408
419
orthology_parser .add_argument ("--additional_params" , action = "store" )
409
420
orthology_args = orthology_parser .parse_args (args .arguments )
421
+ debug = check_debug (orthology_args .debug ) #check if debug is enabled
410
422
if orthology_args .help or len (sys .argv ) <= 2 : # help is specified
411
423
print (help_message (orthology_help ))
412
424
sys .exit (0 )
@@ -451,6 +463,7 @@ elif args.command=="filter-orthology":
451
463
forthology_parser .add_argument ("--seqtype" , action = "store" )
452
464
453
465
forthology_args = forthology_parser .parse_args (args .arguments )
466
+ debug = check_debug (forthology_args .debug ) #check if debug is enabled
454
467
if forthology_args .help or len (sys .argv ) <= 2 : # help is specified
455
468
print (help_message (forthology_help ))
456
469
sys .exit (0 )
@@ -506,6 +519,7 @@ elif args.command=="align":
506
519
align_parser .add_argument ("--threads" , action = "store" )
507
520
align_parser .add_argument ("--parameters" , action = "store" )
508
521
align_args = align_parser .parse_args (args .arguments )
522
+ debug = check_debug (align_args .debug ) #check if debug is enabled
509
523
if align_args .help or len (sys .argv ) <= 2 : # help is specified
510
524
print (help_message (align_help ))
511
525
sys .exit (0 )
@@ -553,6 +567,7 @@ elif args.command=="filter-align":
553
567
falign_parser .add_argument ("--min_parsimony_sites" , action = "store" )
554
568
555
569
falign_args = falign_parser .parse_args (args .arguments )
570
+ debug = check_debug (falign_args .debug ) #check if debug is enabled
556
571
if falign_args .help or len (sys .argv ) <= 2 : # help is specified
557
572
print (help_message (falign_help ))
558
573
sys .exit (0 )
@@ -592,6 +607,7 @@ elif args.command=="speciestree":
592
607
sptree_parser = PhyloParser (add_help = False )
593
608
sptree_parser .add_argument ("--config-file" , action = "store" , dest = "config_file" , default = "data/config.yaml" )
594
609
sptree_args = sptree_parser .parse_args (args .arguments )
610
+ debug = check_debug (sptree_args .debug ) #check if debug is enabled
595
611
if sptree_args .help or len (sys .argv ) <= 2 : # help is specified
596
612
print (help_message (sptree_help ))
597
613
sys .exit (0 )
@@ -620,6 +636,8 @@ elif args.command=="njtree":
620
636
njtree_parser = PhyloParser (add_help = False )
621
637
njtree_parser .add_argument ("--config-file" , action = "store" , dest = "config_file" , default = "data/config.yaml" )
622
638
njtree_args = njtree_parser .parse_args (args .arguments )
639
+ debug = check_debug (njtree_args .debug ) #check if debug is enabled
640
+
623
641
if njtree_args .help or len (sys .argv ) <= 2 : # help is specified
624
642
print (help_message (njtree_help ))
625
643
sys .exit (0 )
@@ -648,6 +666,7 @@ elif args.command=="mltree":
648
666
tree_parser = PhyloParser (add_help = False )
649
667
tree_parser .add_argument ("--config-file" , action = "store" , dest = "config_file" , default = "data/config.yaml" )
650
668
tree_args = tree_parser .parse_args (args .arguments )
669
+ debug = check_debug (tree_args .debug ) #check if debug is enabled
651
670
if tree_args .help or len (sys .argv ) <= 2 : # help is specified
652
671
print (help_message (tree_help ))
653
672
sys .exit (0 )
@@ -677,6 +696,7 @@ elif args.command=="modeltest":
677
696
model_parser = PhyloParser (add_help = False )
678
697
model_parser .add_argument ("--config-file" , action = "store" , dest = "config_file" , default = "data/config.yaml" )
679
698
model_args = model_parser .parse_args (args .arguments )
699
+ debug = check_debug (model_args .debug ) #check if debug is enabled
680
700
if model_args .help or len (sys .argv ) <= 2 : # help is specified
681
701
print (help_message (model_help ))
682
702
sys .exit (0 )
@@ -708,6 +728,7 @@ elif args.command=="report":
708
728
report_parser .add_argument ("--figure" , action = "store_true" , default = False )
709
729
report_parser .add_argument ("--config-file" , action = "store" , dest = "config_file" , default = "data/config.yaml" )
710
730
report_args = report_parser .parse_args (args .arguments )
731
+ debug = check_debug (report_args .debug ) #check if debug is enabled
711
732
print (now (), "Will create a phylociraptor report..." )
712
733
713
734
if report_args .help : # help is specified
@@ -745,6 +766,7 @@ elif args.command == "check":
745
766
check_parser .add_argument ("-h" , "--help" , action = "store_true" )
746
767
check_parser .add_argument ("--verbose" , action = "store_true" , default = False )
747
768
check_args = check_parser .parse_args (args .arguments )
769
+ debug = check_debug (check_args .debug ) #check if debug is enabled
748
770
749
771
if check_args .help :
750
772
print (help_message (check_help ))
@@ -992,7 +1014,7 @@ elif args.command == "util":
992
1014
sys .exit (0 )
993
1015
else :
994
1016
which_util = args .arguments .pop (0 )
995
-
1017
+ debug = check_debug ( True ) #for util debugging output is enabled by default
996
1018
if which_util == "get-lineage" :
997
1019
gl_parser = UtilParser (add_help = False )
998
1020
gl_parser .add_argument ("-d" ,"--datafile" , action = "store" , default = "data/data.csv" )
@@ -1024,7 +1046,7 @@ elif args.command == "util":
1024
1046
print (line , end = "\r " )
1025
1047
print (now (), "Will now reformat lineage information for downstream applications like phylociraptor util plot-tree" )
1026
1048
cmd = ["singularity" , "exec" , "-B" , os .getcwd (), "docker://reslp/biopython_plus:1.77" , "python" , "bin/reformat_lineage.py" , "data/lineage_information/lineage_information.csv" , gl_args .outfile ]
1027
- if debug :
1049
+ if debug and gl_args . verbose :
1028
1050
print (cmd )
1029
1051
for line in execute_command (cmd , not gl_args .quiet ):
1030
1052
print (line , end = "\r " )
@@ -1074,7 +1096,7 @@ elif args.command == "util":
1074
1096
sys .exit (1 )
1075
1097
1076
1098
1077
- if debug :
1099
+ if debug and qs_args . verbose :
1078
1100
print (cmd )
1079
1101
for line in execute_command (cmd , not qs_args .quiet ):
1080
1102
print (line , end = "\r " )
@@ -1112,7 +1134,7 @@ elif args.command == "util":
1112
1134
cmd = ["singularity" , "exec" , "-B" , os .getcwd (), rphylocontainer , "Rscript" , "bin/plot-tree.R" ]
1113
1135
cmd += [os .getcwd (), qs_args .seed , all_trees , qs_args .outgroup , qs_args .lineagefile , qs_args .level , qs_args .outprefix , single ]
1114
1136
1115
- if debug :
1137
+ if debug and qs_args . verbose :
1116
1138
print (cmd )
1117
1139
for line in execute_command (cmd , not qs_args .quiet ):
1118
1140
print (line , end = "\r " )
@@ -1149,7 +1171,7 @@ elif args.command == "util":
1149
1171
cmd = ["singularity" , "exec" , "-B" , os .getcwd (), rphylocontainer , "Rscript" , "bin/plot-conflict.R" ]
1150
1172
cmd += [os .getcwd (), qs_args .seed , all_trees , qs_args .outgroup , qs_args .lineagefile , qs_args .level , qs_args .quartetfile , qs_args .treelist ]
1151
1173
1152
- if debug :
1174
+ if debug and qs_args . verbose :
1153
1175
print (cmd )
1154
1176
for line in execute_command (cmd , not qs_args .quiet ):
1155
1177
print (line , end = "\r " )
@@ -1187,7 +1209,7 @@ elif args.command == "util":
1187
1209
print (help_message (util_plot_pca_help ))
1188
1210
sys .exit (1 )
1189
1211
cmd = ["singularity" , "exec" , "-B" , os .getcwd (), rphylocontainer , "Rscript" , "bin/plot-t2t-pca.R" , os .getcwd (), qs_args .treelist , qs_args .threads , qs_args .ndistances , qs_args .seed ]
1190
- if debug :
1212
+ if debug and qs_args . verbose :
1191
1213
print (cmd )
1192
1214
for line in execute_command (cmd , not qs_args .quiet ):
1193
1215
print (line , end = "\r " )
@@ -1217,7 +1239,7 @@ elif args.command == "util":
1217
1239
if qs_args .genes and qs_args .genes != "none" :
1218
1240
first_arg = "genes=" + qs_args .genes
1219
1241
cmd = ["bash" , "bin/modify-busco.sh" , first_arg , qs_args .buscoset , qs_args .seed ]
1220
- if debug :
1242
+ if debug and qs_args . verbose :
1221
1243
print (cmd )
1222
1244
for line in execute_command (cmd , not qs_args .quiet ):
1223
1245
print (line , end = "\r " )
@@ -1240,7 +1262,7 @@ elif args.command == "util":
1240
1262
cmd += ["--cancel" ]
1241
1263
if qs_args .verbose :
1242
1264
cmd += ["--verbose" ]
1243
- if debug :
1265
+ if debug and qs_args . verbose :
1244
1266
print (cmd )
1245
1267
for line in execute_command (cmd , not qs_args .quiet , True ):
1246
1268
print (line , end = "\r " )
0 commit comments