-
Notifications
You must be signed in to change notification settings - Fork 0
/
RAIDER_eval.py
executable file
·1656 lines (1374 loc) · 85 KB
/
RAIDER_eval.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import sys
import subprocess
import os
import os.path
import shutil
import argparse
import tempfile
import re
import perform_stats
import time
import pickle
from parse_pra_output import parse_pra_output
from checkpoint_jobs import *
try:
fp = open("locations.txt")
except:
sys.stderr.println("locations.txt file not present.")
exit(1);
location = fp.readline().strip()
if not (location.lower() in {'redhawk', 'oakley', 'osx'}):
sys.stderr.println("location.txt: Bad content")
exit(1)
wait_time = 100 # Amount of time to spin before checking job progress in a wait() call.
# Need to be higher on Oakley.
sleep_pause = 60
#################################################################
# The following global variables are related to debugging issues.
show_progress = False
stats_only = False
job_index = {}
default_time_limit = "4:00:00"
#default_time_limit = "00:20:00"
rm_time_limit = "25:00:00"
#rm_time_limit = "2:00:00"
time_limit = default_time_limit
timing = False
timing_jobs = False
start_time = None
quit_time = None
prog_walltime = None
safety_margin = None
continue_prev = False
check_fname = 'reval.dat'
log_fname = 'reval.log'
flist_start = "START_FILE_LIST"
flist_end = "END_FILE_LIST"
csjobs_start = "START_CHROM_SIM_JOBS"
csjobs_end = "END_CHROM_SIM_JOBS"
tjobs_start = "START_TOOL_JOBS"
tjobs_end = "END_TOOL_JOBS"
rmjobs_start = "START_REPMASK_JOBS"
rmjobs_end = "END_REPMASK_JOBS"
prajobs_start = "START_PRA_JOBS"
prajobs_end = "END_PRA_JOBS"
jobdic_start = "START_JOB_DICT"
jobdic_end = "END_JOB_DICT"
blast_db_start = "START_BLAST_DB"
blast_db_end = "END_BLAST_DB"
stats_start = "START_STATS_JOBS"
stats_end = "END_STATS_JOBS"
#################################################################
def print_time():
return time.strftime("%x %X", time.localtime())
#################################################################
# These global variables have to do with executable locations.
MacLocations = {'build_lmer_table':'/usr/local/RepeatScout/build_lmer_table',
'RptScout':'/usr/local/RepeatScout/RepeatScout',
'filter_stage-1':'/usr/local/RepeatScout/filter-stage-1.prl',
'filter_stage-2':'/usr/local/RepeatScout/filter-stage-2.prl',
'raider':'./raider',
'raider_pre':'./raider_pre',
'bigfoot':'./bigfoot',
'python':'python3.4',
'araider':'./araider',
'raider2': './phRAIDER',
'rm_modules': None,
'RepeatMasker' : 'RepeatMasker',
'proc_per_node' : 1,
'basic_arch_type' : None,
'high_mem_arch' : None}
RedhawkLocations = {'build_lmer_table':'./build_lmer_table',
'RptScout':'./RepeatScout',
'filter_stage-1':'./filter-stage-1.prl',
'filter_stage-2':'./filter-stage-2.prl',
'raider':'./raider',
'raider_pre':'./raider_pre',
'bigfoot':'./bigfoot',
'python':'python3.3',
'araider':'./araider',
'raider2': './phRAIDER',
'rm_modules' : ['RepeatMasker', 'python-3.3.3'],
'RepeatMasker' : 'RepeatMasker',
'proc_per_node' : 4,
'basic_arch_type' : ["n09","bigmem"],
'high_mem_arch' : 'redhawk'}
OakleyLocations = {'build_lmer_table':'./build_lmer_table',
'RptScout':'./RepeatScout',
'filter_stage-1':'./filter-stage-1.prl',
'filter_stage-2':'./filter-stage-2.prl',
'raider':'./raider',
'raider_pre':'./raider_pre',
'bigfoot':'./bigfoot',
'python':'python',
'araider':'./araider',
'raider2': './phRAIDER',
'rm_modules' : None,
'RepeatMasker' : 'RepeatMasker',
'proc_per_node' : 12,
'basic_arch_type' : None,
'high_mem_arch' : 'oakley'}
Locations = None; # This will be set to one of the above two, and references to find exectuable locations.
#########
# Utility functions
def sum_resources(T1, T2):
if T1[0] == -1 or T2[0] == -1:
return [-1]*4
return [T1[0] + T2[0], T1[1] + T2[1], max(T1[2], T2[2]), max(T1[3], T2[3])]
def get_job_index(s):
global job_index
if s not in job_index:
job_index[s] = 0
v = job_index[s]
job_index[s] += 1
return v
def file_base(file):
return os.path.basename(file)
def file_dir(file):
return file.rstrip(file_base(file)).rstrip("/")
def parse_redhawk_time(time_str):
"""Parse time limit string for redhawk (format HH:MM:SS) into seconds amount"""
secs = sum(int(x) * 60 ** i for i,x in enumerate(reversed(time_str.split(":"))))
#print(time_str, '/t', secs)
return secs
def convert_seed(seed):
"""Convert an abriviated seed to a full seed (e.g. "1{2}0{3}1{2}" => "1100011" """
i = 0
while (i < len(seed)-1):
if seed[i+1] == '^':
j = i+2
assert seed[j] == "{"
k = j+1
while seed[k] != '}':
k += 1
n = int(seed[j+1:k])
seed = seed[:i] + seed[i]*n + seed[k+1:]
i += 1
return seed
def parse_params(args):
"""Parse command line arguments using the argparse library"""
parser = argparse.ArgumentParser(description = "Evaluate RAIDER against RepeatScout")
# GENERAL ARGUMENTS
#parser2 = parser.add_mutually_exclusive_group()
#parser2.add_argument('--organize', action = "store_true", help = "Create directory for all Raider Eval output", default = False)
#parser2.add_argument('--no', '--named_organize', dest = "named_organize", help = "Organize under a named directory", default = None)
# TOOL SELECTION
parser_tools = parser.add_argument_group("tool selection (all on by default)")
parser_tools.add_argument('-R', '--raider_on', dest = 'run_raider', action = 'store_true', help = 'Turn RAIDER on', default = False)
parser_tools.add_argument('--R2', '--raider2_on', dest = 'run_raider2', action = 'store_true', help = 'Turn RAIDERV2 on', default = False)
parser_tools.add_argument('--AR', '--araider_on', dest = 'run_araider', action = 'store_true', help = 'Turn ARAIDER on', default = False)
parser_tools.add_argument('--RS', '--repscout_on', dest = 'run_repscout', action = 'store_true', help = 'Turn RAIDER on', default = False)
parser_tools.add_argument('-B', '--bigfoot_on', dest = 'run_bigfoot', action = 'store_true', help = 'Turn BIGFOOT on', default = False)
parser_tools.add_argument('-P', '--piler_on', dest = 'run_piler', action = 'store_true', help = 'Turn PILER on', default = False)
parser_tools.add_argument('-A', '--all_tools', dest = 'all_tools', action = 'store_true', help = 'Turn all tools on (overide all other tool arguments)', default = False)
parser_tools.add_argument('--A2', '--all_tools2', dest = 'all_tools2', action = 'store_true', help = 'Turn all tools on except araider (overide all other tool arguments)', default = False)
parser_tools.add_argument('--tl', '--time_limit', dest = 'time_limit', help = 'Redhawk time limit (max: 400:00:00 default: 4:00:00)', default = default_time_limit)
parser_tools.add_argument("--mn", '--max_nodes', dest = "max_nodes", action="store_true", help="Reserve all nodes of a processor for each tool (disabled by default).", default=False)
# Will later add: RepeatModeler, RECON, PILER (other?)
# I/O ARGUMENTs
parser_io = parser.add_argument_group("i/o arguments")
parser_io.add_argument('-r', '--results_dir', dest = "results_dir", help = "Directory containing all results", default = "EVAL")
parser_io.add_argument('--nuke', dest ='nuke', action = "store_true", help = "Nuke the results directory", default = False)
parser_io.add_argument('--rd', '--raider_dir', dest = "raider_dir", help = "Subdirectory containing raider results", default = "RAIDER")
parser_io.add_argument('--ard', '--araider_dir', dest = "araider_dir", help = "Subdirectory containing araider results", default = "ARAIDER")
parser_io.add_argument('--r2d', '--raider2_dir', dest = "raider2_dir", help = "Subdirectory containing araider results", default = "RAIDERV2")
parser_io.add_argument('--rsd', '--rptscout_dir', dest = 'rptscout_dir', help = "Subdirectory containing rpt scout results", default = "RPT_SCT")
parser_io.add_argument('--bfd', '--bigfoot_dir', dest = 'bigfoot_dir', help = "Subdirectory containing bigfoot results", default = "BIGFOOT")
parser_io.add_argument('--pd', '--pilder_dir', dest = 'piler_dir', help = "Subdirectory containing piler results", default = "PILER")
parser_io.add_argument('--dd', '--data_dir', dest = 'data_dir', help = "Directory containing the resulting simulated chromosome", default = "SOURCE_DATA")
parser_tools.add_argument('--hj', '--hooke_jeeves', dest = 'hooke_jeeves', action = 'store_true', help = 'Simply print the tp+tn statistics counts', default = False)
# RAIDER ARGUMENTS
raider_argument = parser.add_argument_group("RAIDER parameters")
raider_argument.add_argument('-f', type = int, help = "E.R. occurrence threshold", default = 5)
raider_argument.add_argument('-d', '--output_dir', help = "Raider output directory", default = None)
raider_argument.add_argument('-e', '--output_ext', help = "Output Extension", default = None)
raider_argument.add_argument('-C', '--cleanup_off', dest = "cleanup", action = "store_false", help = "Turn off file cleanup", default = True)
raider_argument.add_argument('--raider_min', '--raider_min', type = int, help = "Minimum repeat length. Defaults to pattern length.", default = None)
raider_argument.add_argument('--pre', '--pre_scan', action = 'store_true', help = "Use pre-scan version of raider", default = False)
raider_argument.add_argument('--mem', action = 'store_true', help = "Use large memory-nodes", default = False);
seed_group = raider_argument.add_mutually_exclusive_group(required = False)
seed_group.add_argument('-s', '--seed', dest = "seed", help = "Spaced seed string", default = "111111111111111111111111111111")
seed_group.add_argument('--sf', '--seed_file', dest = 'seed_file', help = 'File containing raider seeds', default = None)
# RAIDER2 ARGUMENTS
raider2_argument = parser.add_argument_group("RAIDER2 parameters")
raider2_argument.add_argument('--age', type = int, help="Use older version of raider2", default=1)
raider2_argument.add_argument('--aa', '--all_ages', dest="all_ages", action="store_true", help="Run all ages of raider2", default=False) # type = int, help="Use older version of raider", default=0)
#raider2_argument.add_argument('--multi', '--multi_seed', dest="multi_seed", action="store_true", help="Run all seeds in seed file concurrently",default=False)
raider2_argument.add_argument('--na', '--no_family_array', dest="family_array", action="store_false", help="Disable family array in Raider2", default=True)
raider2_argument.add_argument('--ex', '--excise', dest="excising", action="store_true", help="Enable excising in RAIDER2", default=False)
raider2_argument.add_argument('--no', '--no_overlaps', dest="overlaps", action="store_false", help="Do not require overlaps in RAIDER2", default=True)
raider2_argument.add_argument('--tu', '--tie_up', dest="tieup", action="store_true", help="Enable alternative tie ups", default=False)
raider2_argument.add_argument('--ps', '--prosplit', dest="prosplit", action="store_true", help="Enable proactive splitting(disabled by default).", default=False)
raider2_argument.add_argument("--pf", '--prevfam', dest="prevfam", action="store_true", help="Enable pointers to prev family (disabled by default).", default=False)
# REPSCOUT ARGUMENTS
repscout_argument = parser.add_argument_group("REPSCOUT parameters")
repscout_argument.add_argument('--repscout_min', type = int, help = "Minimum repeat length for repscout.", default = 10)
repscout_argument.add_argument('--rs_min_freq', type = int, help = "Minimum repeat length for repscout.", default = 3)
repscout_argument.add_argument('--rs_filters', type = int, dest = "rs_filters", help = "Specify how many RS filters to use {0,1,2}. 3 specifies to run all versions", default = 0)
#raider_argument.add_argument('--uff', '--use_first_filter', dest = "use_first_filter", action = "store_true", help = "Use the first RepScout filter", default = True)
#raider_argument.add_argument('--usf', '--use_second_filter', dest = "use_second_filter", action = "store_true", help = "Use the second RepScout filter", default = True)
# BIGFOOT ARGUMENTS
bigfoot_arguments = parser.add_argument_group("BIGFOOT parameters")
bigfoot_arguments.add_argument('-L', '--bigfoot_L', type = int, help = "Minimum repeat length. Defaults to 20.", default = 20)
bigfoot_arguments.add_argument('-min', '--bigfoot_min', type = int, help = "E.R. occurrence threshold", default = 2)
bigfoot_arguments.add_argument('-I', '--bigfoot_I', type = float, help = "Minimum percent frequency of more frequent Lmer a less frequent Lmer must have to be part of the same family", default = 0.75)
bigfoot_arguments.add_argument('-T', '--bigfoot_T', type = float, help = "Minimum percent of time a base must occur after an Lmer to be considered significant", default = 0.75)
# REPEAT MASKER ARGUMENTS
repeatmasker_arguments = parser.add_argument_group("RepeatMasker parameters")
repeatmasker_arguments.add_argument('--masker_dir', help = "Repeat masker output directory", default = None)
repeatmasker_arguments.add_argument('-p', '--pa', type = int, help = "Number of processors will be using", default = 1)
# STATISTICS ARGUMENT
stats_group = parser.add_argument_group(title = "Statistics argument")
stats_group.add_argument('--stats_dir', dest = 'stats_dir', help = "Statistics output directory", default = "STATS_OUTPUT")
stats_group.add_argument('--stats_file', dest = 'stats_file', help = "Statistics output file", default = "stats.txt")
stats_group.add_argument('--stats_only', dest = 'stats_only', action = 'store_true', help = 'Remove files not involved in stats analysis', default = False)
#stats_group.add_argument('--print_reps', action = "store_true", help = "Print out repeats in statistics file", default = False)
# DEBUGGING ARGUMENTS
debug_group = parser.add_argument_group(title = "debugging")
debug_group.add_argument('--sp', '--show_progress', dest = 'show_progress', action = 'store_true', help = "Print reports on program progress to stderr", default = False)
debug_group.add_argument('--so', '--simulate_only', dest = 'simulate_only', action = 'store_true', help = "Quit after creating simulated file", default = False)
# ANALYSIS
parser_analysis = parser.add_argument_group("Analysis options")
parser_analysis.add_argument('--PRA', '--pre_rm_analysis_off', dest = 'pra', action = 'store_false', help = 'Turn off pre-RM stats. analysis', default = True)
parser_analysis.add_argument('--RA', '--rm_analysis_off', dest = 'repmask', action = 'store_false', help = 'Turn off RM stats. analysis', default = True)
parser_analysis.add_argument('--ce', '--class_exclude', dest = 'exclude', action = 'store', help = 'File of family classes to exclude from PRA analysis', default = 'exclude.txt')
### KARRO END
# CONTINUE PREVIOUS RUN ARGUMENTS
cont_group = parser.add_argument_group(title = "continuing previous")
cont_group.add_argument('--timing_jobs', dest = 'timing_jobs', action = 'store_true', help = "Set up timed jobs", default = False)
cont_group.add_argument('--pwt', '--prog_walltime', dest = 'prog_walltime', help = 'Redhawk time limit for program', default = None)
cont_group.add_argument('--cp', '--continue_prev', dest = 'continue_prev', action = 'store_true', help = "Continue previously started job", default = False)
cont_group.add_argument('--sm', '--safe_marg', dest = 'safety_margin', help = "Amount of time left on clock (secs) when start to save run state", default = None)
subparsers = parser.add_subparsers(dest="subparser_name")
# SEQUENCE FILE OPTION ARGUMENTS
parser_seqs = subparsers.add_parser("seq_files")
parser_seqs.add_argument('seq_files', nargs = '+', help = "Use files directly (no simulation)", default = None)
# CHROMOSOME SIMULATION OPTION ARGUMENTS
parser_chrom = subparsers.add_parser("chrom_sim")
parser_chrom.add_argument('-k', type = int, help = "Order of markov chain", default = 5) # KARRO: Added this
parser_chrom.add_argument('--rng_seed', type = int, help = "RNG seed", default = None)
parser_chrom.add_argument('-n', '--negative_strand', action = "store_true", help = "Use repeats on negative string", default = False)
parser_chrom.add_argument('--family_file', help = "List of repeat families to use", default = None)
parser_chrom.add_argument('--mc', '--mc_file', dest = 'mc_file', help = "Markov Chain file", default = False)
parser_chrom.add_argument('--mi', '--max_interval', dest = "max_interval", type = int,
help = "Maximum allowed length of interval between repeats; -1 value (default) means no maximum", default = None)
parser_chrom.add_argument('--rn', '--retain_n', dest = "retain_n", action = 'store_true',
help = "If used, will use the whole chromosome. Otherwise, cuts of Ns at either end.", default = False)
parser_chrom.add_argument('--nr', '--num_repeats', dest = 'num_repeats', type = int,
help = "Specify the number of repeats. Simulation will terminate either 1000 bases or max interval bases past the nth instance of a repeat (excluding any other repeats in that range).", default = None)
parser_chrom.add_argument('-l', '--length', type = int, help = "Simulated sequence length", default = None)
parser_chrom.add_argument('-o', '--output', help = "Output file (Default: replace chromosome file \".fa\" with \".sim.fa\")")
parser_chrom.add_argument('-t', '--num_sims', type = int, dest = "num_sims", help ="Number of simulations", default = 1)
parser_chrom.add_argument('--lc', '--low_complexity', dest = 'low_complexity', action = 'store_false', help = "Toss low complexity and simple repeats (tossed by default)", default = True)
parser_chrom.add_argument('--st', '--sim_type', dest = 'sim_type', type = int, help = "0 = use mdern sequence exactly (default); 1 = use ancestor fragment; 2 = preserve mutations, but not indels; 3 = preserve indels, but not mutations", default = 0)
parser_chrom.add_argument('chromosome', help = "Template chromosome file")
arg_return = parser.parse_args(args)
global time_limit
time_limit = arg_return.time_limit
global show_progress
show_progress = arg_return.show_progress
global stats_only
stats_only = arg_return.stats_only
###
# Update global vars related to continuing previous jobs
global prog_walltime
prog_walltime = parse_redhawk_time(arg_return.prog_walltime) if arg_return.prog_walltime else None
global timing
timing = True if prog_walltime else False
global timing_jobs
timing_jobs = True if timing else arg_return.timing_jobs
global safety_margin
safety_margin = arg_return.safety_margin if arg_return.safety_margin else prog_walltime/10.0 if timing else None
global continue_prev
continue_prev = arg_return.continue_prev if timing else False
global check_fname
check_fname = arg_return.results_dir + "/" + check_fname
global log_fname
log_fname = arg_return.results_dir + "/" + log_fname
if arg_return.all_tools or arg_return.all_tools2:
arg_return.run_raider = True
arg_return.run_repscout = True
arg_return.run_piler = True
if arg_return.all_tools:
arg_return.run_araider = True
arg_return.run_raider2 = True
arg_return.run_bigfoot = True
#### The following is to set the global debugging variables
if arg_return.simulate_only: # Set to supress all tools
arg_return.run_raider = False
arg_return.run_araider = False
arg_return.run_raider2 = False
arg_return.run_repscout = False
arg_return.run_bigfoot = False
arg_return.run_piler = False
return arg_return
############################################################
# Main functions
def simulate_chromosome(chromosome_file, rng_seed, length, neg_strand, fam_file, data_dir, output_file, file_index, k, mc_file, mi, retain_n, num_repeats, low_complexity, sim_type):
"""Given chromosome file and repeat file and rng_seed, runs chromosome
simulator and then passes raider params (including path to new simulated chromosome
file) into run_raider"""
# Output file is either specified or replace .fa with .sim.#.fa
length_arg = "-l %d" % (length) if length else ""
k_arg = "-k %d" % (k)
seed_arg = "-s %d" % (rng_seed) if rng_seed else ""
neg_arg = "-n" if neg_strand else ""
fam_arg = "-f %s" % (fam_file) if fam_file else ""
mi = ("--mi %d" % (mi)) if mi else ""
retain_n = "--rn" if retain_n else ""
num_repeats = ("--nr %d" % (num_repeats)) if num_repeats else ""
low_complexity = "--lc" if low_complexity else ""
seq_arg = chromosome_file
repeat_arg = chromosome_file + ".out"
output_file = (output_file if output_file else re.sub(".fa$", ".sim.%d.fa" % (file_index), file_base(chromosome_file)))
output_path = "%s/%s" % (data_dir, output_file)
mc = "--mc %s" % mc_file if mc_file else ""
if k == 0: # Really only for debugging
cmd = "{python} chromosome_simulator3.py {mi} {length} {mc} {k} {seed} {neg} {fam} {retain_n} {num_repeats} {lc} {seq} {repeat} {output}".format(python = Locations['python'], mi=mi, mc=mc, length=length_arg, k=k_arg, seed=seed_arg, neg=neg_arg, fam=fam_arg, retain_n=retain_n, num_repeats=num_repeats, lc=low_complexity, seq = seq_arg, repeat=repeat_arg, output=output_path)
elif sim_type == 0 and os.path.isfile(repeat_arg):
cmd = "{python} chromosome_simulator.py {mi} {length} {mc} {k} {seed} {neg} {fam} {retain_n} {num_repeats} {lc} {seq} {repeat} {output}".format(python = Locations['python'], mi=mi, mc=mc, length=length_arg, k=k_arg, seed=seed_arg, neg=neg_arg, fam=fam_arg, retain_n=retain_n, num_repeats=num_repeats, lc=low_complexity, seq = seq_arg, repeat=repeat_arg, output=output_path)
else:
sim_type = "--st %d" % (sim_type)
cmd = "{python} chromosome_simulator2.py {sim_type} {mi} {length} {mc} {k} {seed} {neg} {fam} {retain_n} {num_repeats} {lc} {seq} {output}".format(python = Locations['python'], sim_type = sim_type, mi=mi, mc=mc, length=length_arg, k=k_arg, seed=seed_arg, neg=neg_arg, fam=fam_arg, retain_n=retain_n, num_repeats=num_repeats, lc=low_complexity, seq=seq_arg, output=output_path)
if show_progress:
sys.stderr.write("Creating simulation:\n%s\n" % (cmd))
sys.stderr.flush()
##progress_fp.write(print_time() + "\n")
progress_fp.write("Creating simulation:\n%s\n" % (cmd))
progress_fp.flush()
batch_name = data_dir + "/" + output_file + ".sim.batch"
job_name = "simulation.%d" % (get_job_index("simulation"))
p = pbsJobHandler(batch_file = batch_name, executable = cmd, job_name = job_name,
stdout_file = output_file + ".stdout", stderr_file = output_file + ".stderr",
output_location = data_dir, walltime = time_limit, arch_type = Locations['basic_arch_type'])
if not timing_jobs:
p.submit(preserve=True, delay = wait_time)
else:
p.submit_timed_job(preserve=True, delay = wait_time)
p.output_file = output_file
p.seq_file = file_base(output_file)
p.sim_output = output_path
p.index = file_index
return p
def run_raider(seed, seed_num, f, m, input_file, raider_dir, mem, max_nodes):
"""Given raider parameters and an input file, run RAIDER and put the output into
the directory specified in output_dir (creating a random name is none is
specified."""
input_base = file_base(input_file).rstrip(".fa")
output_dir = raider_dir + "/" + input_base.upper() + ".s" + str(seed_num)
if not os.path.exists(output_dir):
os.makedirs(output_dir)
min_arg = "-m %d" % (m) if m else ""
cmd1 = "{raider} -q -c {f} {min_arg} {seed} {input_file} {output_dir}".format(raider = Locations['raider'], f = f, min_arg = min_arg, seed = seed, input_file = input_file, output_dir = output_dir)
out_file = raider_dir + "/" + input_base + ".s" + str(seed_num) + ".raider_consensus.txt"
lib_file = raider_dir + "/" + input_base + ".s" + str(seed_num) + ".raider_consensus.fa"
cmd2 = "{python} consensus_seq.py -s {seq_file} -e {elements_dir}/elements {output_file} {fa_file}".format(python = Locations['python'], seq_file = input_file, elements_dir = output_dir, output_file = out_file, fa_file = lib_file)
if show_progress:
sys.stderr.write("\nLaunching raider:\n%s\n%s\n" % (cmd1, cmd2))
sys.stderr.flush()
##progress_fp.write(print_time() + "\n")
progress_fp.write("\nLaunching raider:\n%s\n%s\n" % (cmd1, cmd2))
progress_fp.flush()
batch_name = raider_dir + "/" + input_base + ".raider.batch"
job_name = "R.{input}.{seed}.{num}".format( num = get_job_index("raider") , input=re.sub("hg18.","",input_base), seed=seed_num)
p = pbsJobHandler(batch_file = batch_name, executable = cmd1 + "; " + cmd2, job_name = job_name,
stdout_file = input_base + ".raider.stdout", stderr_file = input_base + ".raider.stderr",
output_location = output_dir, walltime = time_limit, mem = Locations['high_mem_arch'] if mem else False, ppn = Locations['proc_per_node'] if max_nodes else 1,
arch_type = Locations['basic_arch_type'] if not mem else False)
if not timing_jobs:
p.submit(preserve=True, delay = wait_time)
else:
p.submit_timed_job(preserve=True, delay = wait_time)
p.tool_resources = [0]*4
p.description = "raider"
p.tools_resources = [0]*4
p.seed = seed
p.seed_num = seed_num
p.seq_file = input_file
p.lib_file = lib_file
return p
def run_composites_finder(elements_file, seq_file, compositesFinderDir):
input_base = file_base(elements_file)
output_dir = compositesFinderDir + "/" + input_base.upper()
if not os.path.exists(output_dir):
os.makedirs(output_dir)
compositesDiscover = compositesFinderDir + "/" + "CompositesDiscover"
slimComFinder = compositesFinderDir + "/" + "SlimComFinder.py"
cmd1 = "{compositesFinder} {input_file}".format(compositesFinder = compositesDiscover, input_file = elements_file)
cmd2 = "{python} {slim_composites_finder} {elements} {sequence_file} {output_file}".format(python = "python", slim_composites_finder = slimComFinder,
elements = elements_file, sequence_file = seq_file, output_file = output_dir + "/" + "ConsensusSequences")
if show_progress:
sys.stderr.write("\nLaunching composites finder:\n%s\n%s\n" % (cmd1, cmd2))
sys.stderr.flush()
##progress_fp.write(print_time() + "\n")
progress_fp.write("\nLaunching composites finder:\n%s\n%s\n" % (cmd1, cmd2))
progress_fp.flush()
batch_name = compositesFinderDir + "/" + input_base + ".composites finder.batch"
job_name = "composites finder.%d" % get_job_index("composites finder")
p = pbsJobHandler(batch_file = batch_name, executable = cmd1 + "; " + cmd2, job_name = job_name,
stdout_file = input_base + ".comFinder.stdout", stderr_file = input_base + ".comFinder.stderr",
output_location = output_dir, walltime = time_limit)
if not timing_jobs:
p.submit(preserve=True, delay = wait_time)
else:
p.submit_timed_job(preserve=True, delay = wait_time)
p.description = "composites.finder"
p.elementsFile = elements_file
p.seqFile = seq_file
return p
def run_raider2(seed, seed_num, f, m, input_file, raider2_dir, family_array, excise, overlaps, tieup, prosplit, prevfam, age, age_only, max_nodes, mem):
"""Given raider parameters and an input file, run RAIDER and put the output into
the directory specified in output_dir (creating a random name is none is
specified."""
input_base = file_base(input_file).rstrip(".fa")
#raider2_dir += "NO_FA." if not family_array else "FA."
#raider2_dir += "EXC." if excise else "NO_EXC."
#raider2_dir += "NO_OV." if not overlaps else "OV."
#raider2_dir += "TU." if tieup else "NO_TU."
#raider2_dir += "PS" if prosplit else "NO_PS."
#raider2_dir += "PF" if prevfam else "NO_PF"
output_dir = raider2_dir + "/" + input_base.upper() + ".s" + str(seed_num)
if not os.path.exists(output_dir):
os.makedirs(output_dir)
min_arg = "-m %d" % (m) if m else ""
if type(seed) is list:
seed_string = "-s " + " -s ".join(seed)
else:
seed_string = "-s {seed}".format(seed = seed)
opt_str = ""
if not age_only:
opt_str += "--na " if not family_array else ""
opt_str += "--e " if excise else ""
opt_str += "--no " if not overlaps else ""
opt_str += "--t " if tieup else ""
opt_str += "--ps " if prosplit else ""
opt_str += "--pf " if prevfam else ""
else:
opt_str += "--age " + str(age)
cmd1 = "{raider2} -q -c {f} {version} {min_arg} {seed} {input_file} {output_dir}".format(raider2 = Locations['raider2'], f = f, version = opt_str, min_arg = min_arg, seed = seed_string, input_file = input_file, output_dir = output_dir)
out_file = raider2_dir + "/" + input_base + ".s" + str(seed_num) + ".raider2_consensus.txt"
lib_file = raider2_dir + "/" + input_base + ".s" + str(seed_num) + ".raider2_consensus.fa"
cmd2 = "{python} consensus_seq.py -s {seq_file} -e {elements_dir}/elements {output_file} {fa_file}".format(python = Locations['python'], seq_file = input_file, elements_dir = output_dir, output_file = out_file, fa_file = lib_file)
element_file = output_dir + "/elements"
family_file = output_dir + "/families"
cmd3 = "rm {elements}; rm {family}".format(elements = element_file, family = family_file ) if stats_only else ""
if show_progress:
sys.stderr.write("\nLaunching raider2:\n%s\n%s\n\n" % (cmd1, cmd2))
sys.stderr.flush()
#progress_fp.write(print_time() + "\n")
progress_fp.write("Launching raider2:\n%s\n%s\n\n" % (cmd1, cmd2))
progress_fp.flush()
batch_name = raider2_dir + "/" + input_base + ".s" + str(seed_num) + ".raider2.batch"
job_name = "R2.{input}.{seed}.{num}".format( num = get_job_index("raider2") , input=re.sub("hg18.","",input_base), seed=seed_num)
p = pbsJobHandler(batch_file = batch_name, executable = cmd1 + "; " + cmd2 + "; " + cmd3, job_name = job_name,
stdout_file = input_base + ".raider2.stdout", stderr_file = input_base + ".raider2.stderr",
output_location = output_dir, walltime= time_limit, ppn = Locations['proc_per_node'] if max_nodes else 1, mem = Locations['high_mem_arch'] if mem else False)
if not timing_jobs:
p.submit(preserve=True, delay = wait_time)
else:
p.submit_timed_job(preserve=True, delay = wait_time)
p.tool_resources = [0]*4
p.description = "raider2"
p.tools_resources = [0]*4
p.seed = seed
p.seed_num = seed_num
p.seq_file = input_file
p.lib_file = lib_file
return p
def run_araider(seed, seed_num, f, m, input_file, araider_dir):
"""Given raider parameters and an input file, run RAIDER and put the output into
the directory specified in output_dir (creating a random name is none is
specified."""
input_base = file_base(input_file).rstrip(".fa")
output_dir = araider_dir + "/" + input_base.upper() + ".s" + str(seed_num)
if not os.path.exists(output_dir):
os.makedirs(output_dir)
min_arg = "-m %d" % (m) if m else ""
cmd1 = "{araider} -q -c {f} {min_arg} {seed} {input_file} {output_dir}".format(araider = Locations['araider'], f = f, min_arg = min_arg, seed = seed, input_file = input_file, output_dir = output_dir)
out_file = araider_dir + "/" + input_base + ".s" + str(seed_num) + ".araider_consensus.txt"
lib_file = araider_dir + "/" + input_base + ".s" + str(seed_num) + ".araider_consensus.fa"
cmd2 = "{python} consensus_seq.py -s {seq_file} -e {elements_dir}/elements {output_file} {fa_file}".format(python = Locations['python'], seq_file = input_file, elements_dir = output_dir, output_file = out_file, fa_file = lib_file)
element_file = output_dir + "/elements"
family_file = output_dir + "/families"
cmd3 = "rm {elements}; rm {family}".format(elements = element_file, family = family_file ) if stats_only else ""
if show_progress:
sys.stderr.write("\nLaunching araider:\n%s\n%s\n" % (cmd1, cmd2))
sys.stderr.flush()
#progress_fp.write(print_time() + "\n")
progress_fp.write("\nLaunching araider:\n%s\n%s\n" % (cmd1, cmd2))
progress_fp.flush()
batch_name = araider_dir + "/" + input_base + ".araider.batch"
job_name = "araider.%d" % get_job_index("araider")
p = pbsJobHandler(batch_file = batch_name, executable = cmd1 + "; " + cmd2 + "; " + cmd3, job_name = job_name,
stdout_file = input_base + ".araider.stdout", stderr_file = input_base + ".araider.stderr",
output_location = output_dir, walltime = time_limit)
if not timing_jobs:
p.submit(preserve=True, delay = wait_time)
else:
p.submit_timed_job(preserve=True, delay = wait_time)
p.tool_resources = [0]*4
p.description = "araider"
p.tools_resources = [0]*4
p.seed = seed
p.seed_num = seed_num
p.seq_file = input_file
p.lib_file = lib_file
return p
def run_bigfoot(input_file, bigfoot_dir, L, C, I, T):
"""Runs BIGFOOT and returns a submitted pbs object with specific attributes used to run RepeatMasker.
* input_file: The name of the .fa sequence file being searched.
* bigfoot_dir: The name of the directory that will contain all files from this run.
"""
input_base = file_base(input_file).rstrip(".fa") # The name of the inputfile -- which I've been using as a basis for all file names
output_dir = bigfoot_dir + "/" + input_base.upper() # If bigfoot creates its own directory for information, use this as the name of that directory.
if not os.path.exists(output_dir):
os.makedirs(output_dir)
cmd1 = "{bigfoot} -l {L} -c {C} --I {I} --T {T} {input_file} {output_dir}".format(bigfoot = Locations['bigfoot'], L = L, C = C, I = I, T = T, output_dir = output_dir, input_file = input_file) # Put the command-line executable for for bigfoot here. Use input_file for the input file name, and put any output into bigfoot_dir
cmd2 = "cp {output_dir}/seeds {bigfoot_dir}/{input_base}.seeds".format(output_dir=output_dir, bigfoot_dir=bigfoot_dir, input_base=input_base)
cmd = cmd1 + "; " + cmd2;
if show_progress:
sys.stderr.write("\nLaunching bigfoot:\n%s\n" % (cmd))
sys.stderr.flush()
#progress_fp.write(print_time() + "\n")
progress_fp.write("\nLaunching bigfoot:\n%s\n" % (cmd))
progress_fp.flush()
lib_file = bigfoot_dir + "/" + input_base + ".seeds"
batch_name = bigfoot_dir + "/" + input_base + ".bigfoot.batch" # This is the batch fils for the qsub command.
job_name = "bigfoot.%d" % get_job_index("bigfoot") # This is the redhawk jobname. get_job_index just assigned the next unused number (for then running multiple jobs)
stdout_file = input_base + ".bigfoot.stdout" # Anything bigfoot prints to stdout will be redirected here
stderr_file = input_base + ".bigfoot.stderr" # Anything bigfoot prints to stderr will be redirected here
p = pbsJobHandler(batch_file = batch_name, executable = cmd, job_name = job_name,
stdout_file = stdout_file, stderr_file = stderr_file,
output_location = output_dir, walltime = time_limit)
if not timing_jobs:
p.submit(preserve=True, delay = wait_time)
else:
p.submit_timed_job(preserve=True, delay = wait_time)
p.description = "bigfoot"
p.tool_resources = [0]*4
p.seq_file = input_file # Required by run_repeat_masker -- uses this as the source sequence.
p.lib_file = lib_file # This should be set to the file name that will be the library for the repeatmasker run
return p
def run_piler(input_file, piler_dir, max_nodes):
"""Runs Piler and returns a submitted pbs object with specific attributes used to run RepeatMasker."""
input_base = file_base(input_file).rstrip(".fa")
lib_file = input_base + ".lib"
if not os.path.exists(piler_dir):
os.makedirs(piler_dir)
cmd = "{python} run_piler.py {input_file} {piler_dir} {output_file}".format(python = Locations['python'], input_file = input_file, piler_dir = piler_dir, output_file = lib_file);
if show_progress:
sys.stderr.write("\nLaunching Piler:\n%s\n" % (cmd))
sys.stderr.flush()
#progress_fp.write(print_time() + "\n")
progress_fp.write("\nLaunching Piler:\n%s\n" % (cmd))
progress_fp.flush()
batch_name = piler_dir + "/" + input_base + ".piler.batch";
job_name = "piler%d" % get_job_index("piler")
stdout_file = input_base + ".piler.stdout";
stderr_file = input_base + ".piler.stderr";
p = pbsJobHandler(batch_file = batch_name, executable = cmd, job_name = job_name,
stdout_file = stdout_file, stderr_file = stderr_file,
output_location = piler_dir, walltime = time_limit, ppn = Locations['proc_per_node'] if max_nodes else 1)
if not timing_jobs:
p.submit(preserve=True, delay = wait_time)
else:
p.submit_timed_job(preserve=True, delay = wait_time)
p.description = "piler"
p.tool_resources = [0]*4
p.seq_file = input_file
p.lib_file = piler_dir + "/" + lib_file
return p
def run_scout(input_file, output_dir, min_freq, length, use_first_filter, use_second_filter, threshold, max_nodes, mem):
if not os.path.exists(output_dir):
os.makedirs(output_dir)
input_name= file_base(input_file)
# First: run build_lmer_table
lmer_output = output_dir + "/" + input_name.rstrip(".fa") + ".freq.fa"
cmd1 = "{build_lmer_table_exe} -min {min} -sequence {sequence} -freq {freq}".format(build_lmer_table_exe=Locations['build_lmer_table'], min=min_freq,
sequence = input_file, freq = lmer_output)
# Next: Run RepeatScout
rptscout_output = output_dir + "/" + input_name.rstrip(".fa") + ".repscout.fa"
cmd2 = "{RptScout_exe} -sequence {sequence} -freq {freq} -output {output}".format(RptScout_exe = Locations['RptScout'], sequence = input_file, freq = lmer_output, output = rptscout_output)
# Next: Run filter-stage-1
if use_first_filter:
filter_stage_output = output_dir + "/" + input_name.rstrip(".fa") + ".repscout.filtered.fa"
cmd3 = "{filter} {input} > {filter_output}".format(input=rptscout_output, filter = Locations['filter_stage-1'], filter_output = filter_stage_output)
else:
cmd3 = ""
if show_progress:
sys.stderr.write("\nRepeatScout:\n%s\n%s\n%s\n" % (cmd1, cmd2, cmd3))
sys.stderr.flush()
#progress_fp.write(print_time() + "\n")
progress_fp.write("\nRepeatScout:\n%s\n%s\n%s\n" % (cmd1, cmd2, cmd3))
progress_fp.flush()
batch_name = output_dir + "/" + file_base(input_file) + ".repscout1.batch"
job_name = "rptscout.{input}.{num}".format( num = get_job_index("repscout") , input=file_base(input_file))
p = pbsJobHandler(batch_file = batch_name, executable = cmd1 + "; " + cmd2 + "; " + cmd3, job_name = job_name, RHmodules = Locations['rm_modules'],
stdout_file = file_base(rptscout_output) + ".stdout", stderr_file = file_base(rptscout_output) + ".stderr",
output_location = output_dir, walltime = time_limit, arch_type = Locations['basic_arch_type'] if not mem else [], ppn = Locations['proc_per_node'] if max_nodes else 1,
mem = Locations['high_mem_arch'] if mem else False)
if not timing_jobs:
p.submit(preserve=True, delay = wait_time)
else:
p.submit_timed_job(preserve=True, delay = wait_time)
p.description = "rep_scout" if not use_first_filter else "rep_scout1" if not use_second_filter else "rep_scout12"
p.tool_resources = [0,0,0,0]
p.seq_file = input_file
p.should_filter_stage2 = use_second_filter
p.input_name= input_name
p.threshold = threshold
p.stage = "1"
p.lib_file = filter_stage_output if use_first_filter else rptscout_output
return p
def run_scout_second_filter_RM(p, num_processors):
if p.should_filter_stage2:
p2 = run_repeat_masker(p, num_processors)
p2.should_filter_stage2 = p.should_filter_stage2
p2.threshold = p.threshold
p2.input_name = p.input_name
p2.stage = "RM"
p2.description = p.description#"rep_scout"
#print("F1 resources : " + str(p2.tool_resources))
return p2
else:
return p
def run_scout_second_filter(p):
if p.should_filter_stage2:
filter_stage2_output = p.dir + "/" + p.input_name.rstrip(".fa") + ".repscout.filtered2.fa"
cmd = "cat {filtered} | {filter} --cat={rm_output} --thresh={thresh} > {filter_output}".format(filtered=p.lib_file, filter=Locations['filter_stage-2'],
filter_output= filter_stage2_output, thresh=p.threshold, rm_output = p.rm_output) #RM_output_dir + "/" + file_base(input_file) + ".out")
if show_progress:
sys.stderr.write("\nRepeatScout Filter2:\n%s\n" % cmd)
sys.stderr.flush()
#progress_fp.write(print_time() + "\n")
progress_fp.write("\nRepeatScout Filter2:\n%s\n" % cmd)
progress_fp.flush()
batch_name = file_dir(p.rm_output) + "/" + p.input_name.rstrip(".fa") + ".repscout2.fa"
job_name = "filter2.%d" % get_job_index("filter2")
p2 = pbsJobHandler(batch_file = batch_name, executable = cmd, job_name = job_name,
stdout_file = file_base(p.seq_file) + ".repscout2.stdout", stderr_file = file_base(p.seq_file) + ".repscout2.stderr",
output_location = file_dir(p.seq_file), walltime = time_limit)
if not timing_jobs:
p2.submit(preserve=True, delay = wait_time)
else:
p2.submit_timed_job(preserve=True, delay = wait_time)
p2.description = p.description#"rep_scout"
p2.stage = "2"
#print("RM resources : " + str(p.getResources(cleanup=False)))
p2.tool_resources = [x + y for x, y in zip(p.tool_resources, p.getResources(cleanup=False))]
#print("F1 + RM resources : " + str(p2.tool_resources))
p2.seq_file = p.seq_file
p2.lib_file = filter_stage2_output
p2.should_filter_stage2 = p.should_filter_stage2
return p2
else:
return p
def scout_second_filter(p, min_freq):
"""NOT CURRENTLY WORKING!!! Does not run correctly, and does not properly adjust time"""
p.wait(wait_time)
filter2_stage_output = p.seq_file.rstrip(".fa") + ".repscout.filtered2.fa"
cmd = "cat {output} | perl {filter} --cat={cat} --thresh={thresh} > {final}".format(output = p.lib_file, filter = Locations['filter_stage-2'], cat = p.rm_output, thresh = min_freq, final = filter2_stage_output)
if show_progress:
sys.stderr.write("\nRepeatScout Filter2:\n%s\n" % cmd)
sys.stderr.flush()
#progress_fp.write(print_time() + "\n")
progress_fp.write("\nRepeatScout Filter2:\n%s\n" % cmd)
progress_fp.flush()
batch_name = file_dir(p.rm_output) + "/" + file_base(p.seq_file).rstrip(".fa") + ".repscout2.fa"
job_name = "filter2%d" % get_job_index("filter2")
p2 = pbsJobHandler(batch_file = batch_name, executable = cmd, job_name = job_name,
stdout_file = file_base(p.seq_file) + ".repscout2.stdout", stderr_file = file_base(p.seq_file) + ".repscout2.stderr",
output_location = file_dir(p.seq_file), walltime = time_limit)
if not timing_jobs:
p2.submit(preserve=True, delay = wait_time)
else:
p2.submit_timed_job(preserve=True, delay = wait_time)
p2.description = "rep_scout"
p2.time_resources = p.time_resources + p.getResources(cleanup=False)
p2.lib_file = p.lib_file
p2.seq_file = p.seq_file
p2.lib_file = filter2_stage_output
return p2
def run_repeat_masker(p, num_processors):
"""Given the pbs object used to start a consensus sequence job as well as
repeatmasker arguments, wait until the job is done and then call repeatmasker
on the output and put results in masker_dir (current dir if unspecified)"""
p.wait(wait_time)
p.loadResources()
input_base = file_base(p.seq_file) # Base name of the file used for input
output_dir = file_dir(p.lib_file) + "/" + file_base(p.lib_file).upper() + ".RM"
if not os.path.exists(output_dir):
os.makedirs(output_dir)
cmd = "{RepeatMasker} -nolow -lib {library} -pa {pa} -dir {dir} {seq_file}".format(RepeatMasker = Locations['RepeatMasker'], library = p.lib_file, pa = num_processors, dir = output_dir, seq_file = p.seq_file)
if show_progress:
sys.stderr.write("\nLaunch repeatmasker (%s):\n%s\n" % (p.description, cmd))
sys.stderr.flush()
#progress_fp.write(print_time() + "\n")
progress_fp.write("\nLaunch repeatmasker (%s):\n%s\n" % (p.description, cmd))
progress_fp.flush()
batch_name = p.lib_file.rstrip(".fa") + ".rm.batch"
tool_name = p.description if not "raider" in p.description else "R" if p.description == "raider" else "R2"
job_name = "RM.{input}.{tool}.{num}".format( num = get_job_index("repmask") , input=re.sub("hg18.","",input_base), tool=tool_name)
ppn_arg = 4*num_processors if num_processors == 1 else num_processors
p2 = pbsJobHandler(batch_file = batch_name, executable = cmd, nodes = 1, ppn = ppn_arg, RHmodules = ["RepeatMasker", "python-3.3.3"],
job_name = job_name, stdout_file = input_base + ".repmask.stdout", stderr_file = input_base + ".repmask.stderr",
output_location = output_dir, walltime = rm_time_limit, always_outputs=False);
if not timing_jobs:
p2.submit(preserve=True, delay = wait_time)
else:
p2.submit_timed_job(preserve=True, delay = wait_time)
p2.description = "RptMasker"
p2.seed = p.seed if hasattr(p, "seed") else "NA"
p2.seed_num = p.seed_num if hasattr(p, "seed_num") else "NA"
p2.dir = output_dir
p2.lib_file = p.lib_file
p2.seq_file = p.seq_file
p2.rm_output = output_dir + "/" + file_base(p.seq_file) + ".out"
p2.tool_resources = [x + y for x, y in zip(p.tool_resources, p.getResources(cleanup=False))]
p2.tool_description = p.description
return p2
def run_perform_stats(p, exclusion_file = None):
"""Given the pbs object used to start a consensus sequence job as well as
repeatmasker arguments, wait until the job is done and then call repeatmasker
on the output and put results in masker_dir (current dir if unspecified)"""
p.wait(wait_time)
p.loadResources()
input_base = file_base(p.seq_file) # Base name of the file used for input
known_repeats = p.seq_file + ".out"
found_repeats = p.rm_output
output_dir = p.dir
output_path = output_dir + "/" + file_base(p.seq_file) + ".stats"
exclusion_part = "-e {exclude}".format(exclude = exclusion_file) if exclusion_file else ""
cmd = "python perform_stats.py {exclusions} {known} {found} {output}".format(exclusions=exclusion_part, known = known_repeats, found = found_repeats, output = output_path)
if show_progress:
sys.stderr.write("\nLaunch perform_stats: %s\n" % (cmd))
sys.stderr.flush()
#progress_fp.write(print_time() + "\n")
progress_fp.write("\nLaunch perform_stats: %s\n" % (cmd))
progress_fp.flush()
batch_name = p.lib_file.rstrip(".fa") + ".stats.batch"
job_name = "stats.%d" % get_job_index("stats")
p2 = pbsJobHandler(batch_file = batch_name, executable = cmd,
job_name = job_name, stdout_file = input_base + ".stats.stdout", stderr_file = input_base + ".stats.stderr",
output_location = output_dir, walltime = time_limit, arch_type = Locations['basic_arch_type'])
if not timing_jobs:
p2.submit(preserve=True, delay = wait_time)
else:
p2.submit_timed_job(preserve=True, delay = wait_time)
p2.description = "Stats"
p2.seed = p.seed if hasattr(p, "seed") else "NA"
p2.seed_num = p.seed_num if hasattr(p, "seed_num") else "NA"
p2.dir = p.dir
p2.lib_file = p.lib_file
p2.seq_file = p.seq_file
p2.rm_output = p.rm_output #output_dir + "/" + file_base(p.seq_file) + ".out"
p2.tool_resources = p.tool_resources
p2.tool_description = p.tool_description
return p2
#def performance_sum(job_dic, PRA_jobs):
# """Given a list of all of the statistics jobs, uses the statistics output files to
# generate a summary file indicative of overall performance. Put results in stats_dir
# (Current dir if unspecified)"""
# ######
# # Calculate statistics (not bothering with parallelization yet)
# print_str = "{:<12}" + "{:<5}" + "".join("{:<14}"*4) + "".join("{:<14}"*6) + "".join("{:<14}"*8) + "{:<14}" + "\n"
# stats_jobs = set()
# for key in test_tools:
# for p in job_dic[key]:
# stats_jobs.add(run_perform_stats(p))
#
#
# with open(args.results_dir + "/" + args.stats_file, "w") as fp:
# fp.write(print_str.format("#tool", "seed", "tp", "fp", "fn", "tn", "tpr", "tnr", "ppv", "npv", "fpr", "fdr","ToolCpuTime", "ToolWallTime", "ToolMem", "ToolVMem", "RMCpuTime", "RMWallTime", "RMMem", "RMVMem", "coverage"))
#
# for key in test_tools:
# for p in job_dic[key]:
# try:
#
# s = run_perform_stats(p)
#
# except Exception as E:
# progress_fp.write("performance Exception: " + str(E) + "\n");
# fp.write("\t".join([str(key), str(p.seed_num) if hasattr(p, "seed_num") else "NA", "INCOMPLETE\n"]))
#
# ### KARRO
# # Finally: we should not terminate until all the pra jobs are done. (If pra is off, this list will be empty.)
# for p in PRA_jobs:
# p.timed_wait() # KARRO: Is this the correct method to use to ensure resubmission of needed
# ### KARRO END
# regex = re.compile("(?<=\# Average consensus coverage: )\d+.\d+")
# >>> m = regex.findall(text)
# >>> m
# ['0.0063']
#
# tps = 0
# tns = 0
# fps = 0
# fns = 0
# for p in stats_jobs:
# sf = open(p.stats_output, "r")
# tps += int(re.split("\s+", sf.readline().rstrip())[1])
# fps += int(re.split("\s+", sf.readline().rstrip())[1])
# tns += int(re.split("\s+", sf.readline().rstrip())[1])
# fns += int(re.split("\s+", sf.readline().rstrip())[1])
# sf.close()