-
Notifications
You must be signed in to change notification settings - Fork 5
/
ribo.pm
executable file
·1633 lines (1475 loc) · 70.7 KB
/
ribo.pm
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
#!/usr/bin/perl
#
# version: 1.0.5
#
# ribo.pm
# Eric Nawrocki
# EPN, Fri May 12 09:48:21 2017
#
# Perl module used by riboaligner, ribodbmaker, ribosensor,
# ribotest and ribotyper, which contains subroutines called by
# those scripts.
use strict;
use warnings;
my $ribo_sequip_dir = $ENV{"RIBOSEQUIPDIR"};
if(! defined $ribo_sequip_dir) {
die "ERROR, the environment variable \$RIBOSEQUIPDIR is not set, see ribovore/documentation/install.md";
}
if(! -d $ribo_sequip_dir) {
die "ERROR, the directory specified by the environment variable \$RIBOSEQUIPDIR does not exist, see ribovore/documentation/install.md";
}
# require the specific sequip modules in RIBOSEQUIPDIR in case user has another
# package installed that uses a (potentially different version) of sequip (e.g. VADR)
require $ribo_sequip_dir . "/sqp_opts.pm";
require $ribo_sequip_dir . "/sqp_ofile.pm";
require $ribo_sequip_dir . "/sqp_seq.pm";
require $ribo_sequip_dir . "/sqp_seqfile.pm";
require $ribo_sequip_dir . "/sqp_utils.pm";
#
# List of subroutines:
#
# Parsing files:
# ribo_CountAmbiguousNucleotidesInSequenceFile
# ribo_ParseSeqstatFile
# ribo_ParseSeqstatCompTblFile
# ribo_ParseRAModelinfoFile
# ribo_ParseQsubFile
# ribo_ParseLogFileForParallelTime
# ribo_ParseCmsearchFileForTotalCpuTime
# ribo_ParseCmalignFileForCpuTime
# ribo_ParseUnixTimeOutput
# ribo_ProcessSequenceFile
#
# Infernal and rRNA_sensor related functions
# ribo_RunCmsearchOrCmalignOrRRnaSensor
# ribo_RunCmsearchOrCmalignOrRRnaSensorValidation
# ribo_RunCmsearchOrCmalignOrRRnaSensorWrapper
# ribo_MergeAlignmentsAndReorder
# ribo_WaitForFarmJobsToFinish
#
# Miscellaneous utility functions:
# ribo_ConvertFetchedNameToAccVersion
# ribo_SumSeqlenGivenArray
# ribo_InitializeHashToEmptyString
# ribo_InitializeHashToZero
# ribo_NseBreakdown
# ribo_WriteCommandScript
# ribo_RemoveListOfDirsWithRmrf
# ribo_WriteAcceptFile
# ribo_CheckForTimeExecutable
#
#################################################################
# Subroutine : ribo_CountAmbiguousNucleotidesInSequenceFile()
# Incept: EPN, Tue May 29 14:51:35 2018
#
# Purpose: Use esl-seqstat to determine the number of ambiguous
# nucleotides in each sequence in a sequence file.
#
# Arguments:
# $seqstat_exec: path to esl-seqstat executable
# $seq_file: sequence file to process
# $seqstat_file: path to esl-seqstat output to create
# $seqnambig_HR: ref to hash of number of ambiguous nucleotides per sequence, filled here
# $opt_HHR: reference to 2D hash of cmdline options
# $FH_HR: REF to hash of file handles, including "cmd"
#
# Returns: number of sequences with 1 or more ambiguous nucleotides
# fills %{$seqnambig_HR}.
#
# Dies: If esl-seqstat call fails
#
#################################################################
sub ribo_CountAmbiguousNucleotidesInSequenceFile {
my $nargs_expected = 6;
my $sub_name = "ribo_CountAmbiguousNucleotidesInSequenceFile()";
if(scalar(@_) != $nargs_expected) { printf STDERR ("ERROR, $sub_name entered with %d != %d input arguments.\n", scalar(@_), $nargs_expected); exit(1); }
my ($seqstat_exec, $seq_file, $seqstat_file, $seqnambig_HR, $opt_HHR, $FH_HR) = (@_);
utl_RunCommand($seqstat_exec . " --dna --comptbl $seq_file > $seqstat_file", opt_Get("-v", $opt_HHR), 0, $FH_HR);
# parse esl-seqstat file to get lengths
return ribo_ParseSeqstatCompTblFile($seqstat_file, $seqnambig_HR, $FH_HR);
}
#################################################################
# Subroutine : ribo_ParseSeqstatFile()
# Incept: EPN, Wed Dec 14 16:16:22 2016
#
# Purpose: Parse an esl-seqstat -a output file.
#
# Arguments:
# $seqstat_file: file to parse
# $max_targetname_length_R: REF to the maximum length of any target name, updated here, can be undef
# $max_length_length_R: REF to the maximum length of string-ized length of any target seq, updated here, can be undef
# $nseq_R: REF to the number of sequences read, updated here
# $seqorder_AR: REF to array of sequences in order to fill here
# $seqidx_HR: REF to hash of sequence indices to fill here
# $seqlen_HR: REF to hash of sequence lengths to fill here
# $FH_HR: REF to hash of file handles, including "cmd"
#
# Returns: Total number of nucleotides read (summed length of all sequences).
# Fills %{$seqidx_HR} and %{$seqlen_HR} and updates
# $$max_targetname_length_R, $$max_length_length_R, and $$nseq_R.
#
# Dies: If the sequence file has two sequences with identical names.
# Error message will list all duplicates.
# If no sequences were read.
#
#################################################################
sub ribo_ParseSeqstatFile {
my $nargs_expected = 8;
my $sub_name = "ribo_ParseSeqstatFile";
if(scalar(@_) != $nargs_expected) { printf STDERR ("ERROR, $sub_name entered with %d != %d input arguments.\n", scalar(@_), $nargs_expected); exit(1); }
my ($seqstat_file, $max_targetname_length_R, $max_length_length_R, $nseq_R, $seqorder_AR, $seqidx_HR, $seqlen_HR, $FH_HR) = @_;
open(IN, $seqstat_file) || ofile_FileOpenFailure($seqstat_file, $sub_name, $!, "reading", $FH_HR);
my $nread = 0; # number of sequences read
my $tot_length = 0; # summed length of all sequences
my $targetname_length; # length of a target name
my $seqlength_length; # length (number of digits) of a sequence length
my $targetname; # a target name
my $length; # length of a target
my %seqdups_H = (); # key is a sequence name that exists more than once in seq file, value is number of occurences
my $at_least_one_dup = 0; # set to 1 if we find any duplicate sequence names
# parse the seqstat -a output
# sequences must have non-empty names (else esl-seqstat call would have failed)
# lengths must be >= 0 (lengths of 0 are okay)
while(my $line = <IN>) {
# = lcl|dna_BP331_0.3k:467 1232
# = lcl|dna_BP331_0.3k:10 1397
# = lcl|dna_BP331_0.3k:1052 1414
chomp $line;
#print $line . "\n";
if($line =~ /^\=\s+(\S+)\s+(\d+)/) {
$nread++;
($targetname, $length) = ($1, $2);
if(exists($seqidx_HR->{$targetname})) {
if(exists($seqdups_H{$targetname})) {
$seqdups_H{$targetname}++;
}
else {
$seqdups_H{$targetname} = 2;
}
$at_least_one_dup = 1;
}
push(@{$seqorder_AR}, $targetname);
$seqidx_HR->{$targetname} = $nread;
$seqlen_HR->{$targetname} = $length;
$tot_length += $length;
$targetname_length = length($targetname);
if((defined $max_targetname_length_R) && ($targetname_length > $$max_targetname_length_R)) {
$$max_targetname_length_R = $targetname_length;
}
$seqlength_length = length($length);
if((defined $max_length_length_R) && ($seqlength_length > $$max_length_length_R)) {
$$max_length_length_R = $seqlength_length;
}
}
}
close(IN);
if($nread == 0) {
ofile_FAIL("ERROR in $sub_name, did not read any sequence lengths in esl-seqstat file $seqstat_file, did you use -a option with esl-seqstat", 1, $FH_HR);
}
if($at_least_one_dup) {
my $i = 1;
my $die_string = "\nERROR, not all sequences in input sequence file have a unique name. They must.\nList of sequences that occur more than once, with number of occurrences:\n";
foreach $targetname (sort keys %seqdups_H) {
$die_string .= "\t($i) $targetname $seqdups_H{$targetname}\n";
$i++;
}
$die_string .= "\n";
ofile_FAIL($die_string, 1, $FH_HR);
}
$$nseq_R = $nread;
return $tot_length;
}
#################################################################
# Subroutine : ribo_ParseSeqstatCompTblFile()
# Incept: EPN, Tue May 29 14:55:18 2018
#
# Purpose: Parse an esl-seqstat --comptbl output file.
#
# Arguments:
# $seqstat_file: file to parse
# $seqnambig_HR: REF to hash of number of ambiguities in each sequence, to fill here
#
# Returns: Total number of sequences with >= 1 ambiguous nucleotide.
#
# Dies: Never
#
#################################################################
sub ribo_ParseSeqstatCompTblFile {
my $nargs_expected = 3;
my $sub_name = "ribo_ParseSeqstatCompTblFile";
if(scalar(@_) != $nargs_expected) { printf STDERR ("ERROR, $sub_name entered with %d != %d input arguments.\n", scalar(@_), $nargs_expected); exit(1); }
my ($seqstat_file, $seqnambig_HR, $FH_HR) = @_;
open(IN, $seqstat_file) || ofile_FileOpenFailure($seqstat_file, $sub_name, $!, "reading", $FH_HR);
my $nread = 0; # number of sequences read
my $nread_w_ambig = 0; # summed length of all sequences
my $seqname = undef; # a sequence name
my $nA; # number of As
my $nC; # number of Cs
my $nG; # number of Gs
my $nT; # number of Ts
my $L; # length of the sequence
my $nambig; # number of ambiguities
my %seqdups_H = (); # key is a sequence name that exists more than once in seq file, value is number of occurences
my $at_least_one_dup = 0; # set to 1 if we find any duplicate sequence names
# parse the seqstat --comptbl output
while(my $line = <IN>) {
## Sequence name Length A C G T
##----------------------------- ------ ------ ------ ------ ------
#gi|675602128|gb|KJ925573.1| 500 148 98 112 142
#gi|219812015|gb|FJ552229.1| 796 193 209 244 150
#gi|675602352|gb|KJ925797.1| 500 149 103 126 122
chomp $line;
#print $line . "\n";
if($line =~ /^(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)$/) {
$nread++;
($seqname, $L, $nA, $nC, $nG, $nT) = ($1, $2, $3, $4, $5, $6);
$nambig = $L - ($nA + $nC + $nG + $nT);
if($nambig > 0) { $nread_w_ambig++; }
$seqnambig_HR->{$seqname} = $nambig;
}
elsif($line !~ m/^\#/) {
ofile_FAIL("ERROR in $sub_name, unable to parse esl-seqstat --comptbl line $line from file $seqstat_file", 1, $FH_HR);
}
}
close(IN);
return $nread_w_ambig;
}
#################################################################
# Subroutine : ribo_ParseRAModelinfoFile()
# Incept: EPN, Fri Oct 20 14:17:53 2017
#
# Purpose: Parse a riboaligner modelinfo file, and
# fill information in @{$family_order_AR}, %{$family_modelname_HR}.
#
#
# Arguments:
# $modelinfo_file: file to parse
# $env_ribo_dir: directory in which CM files should be found, if undef, should be full path
# $family_order_AR: reference to array of family names, in order read from file, FILLED HERE
# $family_modelfile_HR: reference to hash, key is family name, value is path to model, FILLED HERE
# $family_modellen_HR: reference to hash, key is family name, value is consensus model length, FILLED HERE
# $family_rtname_HAR reference to hash, key is family name, value is array of ribotyper model
# names to align with this model, FILLED HERE
# $FH_HR: ref to hash of file handles
#
# Returns: void;
#
#################################################################
sub ribo_ParseRAModelinfoFile {
my $nargs_expected = 7;
my $sub_name = "ribo_ParseRAModelinfoFile";
if(scalar(@_) != $nargs_expected) { printf STDERR ("ERROR, $sub_name entered with %d != %d input arguments.\n", scalar(@_), $nargs_expected); exit(1); }
my ($modelinfo_file, $env_ribo_dir, $family_order_AR, $family_modelfile_HR, $family_modellen_HR, $family_rtname_HAR, $FH_HR) = @_;
open(IN, $modelinfo_file) || ofile_FileOpenFailure($modelinfo_file, $sub_name, $!, "reading", $FH_HR);
my %family_exists_H = ();
while(my $line = <IN>) {
## each line has information on 1 family and at least 4 tokens:
## token 1: family.domain name in ribotyper output files, referred to as the 'family' below (e.g. SSU.Bacteria)
## token 2: CM file name for this family
## token 3: integer, consensus length for the CM for this family
## token 4 to N: names of ribotyper models (e.g. SSU_rRNA_archaea) for which we'll use this model to align
#SSU.Archaea RF01959.cm SSU_rRNA_archaea
#SSU.Bacteria RF00177.cm SSU_rRNA_bacteria SSU_rRNA_cyanobacteria
chomp $line;
if($line !~ /^\#/ && $line =~ m/\w/) {
$line =~ s/^\s+//; # remove leading whitespace
$line =~ s/\s+$//; # remove trailing whitespace
my @el_A = split(/\s+/, $line);
if(scalar(@el_A) < 4) {
ofile_FAIL("ERROR in $sub_name, less than 4 tokens found on line $line of $modelinfo_file", 1, $FH_HR);
}
my $family = $el_A[0];
my $modelfile = $el_A[1];
my $modellen = $el_A[2];
my @rtname_A = ();
for(my $i = 3; $i < scalar(@el_A); $i++) {
if($el_A[$i] =~ /[\)\(]/) {
ofile_FAIL("ERROR in $sub_name, ribotyper model name $el_A[$i] has '(' and/or ')', but these characters are not allowed in model names", 1, $FH_HR);
}
push(@rtname_A, $el_A[$i]);
}
if(defined $family_exists_H{$family}) {
ofile_FAIL("ERROR in $sub_name, family $family (first token) exists in more than one line in $modelinfo_file", 1, $FH_HR);
}
push(@{$family_order_AR}, $family);
$family_modelfile_HR->{$family} = $env_ribo_dir . "/" . $modelfile;
$family_modellen_HR->{$family} = $modellen;
@{$family_rtname_HAR->{$family}} = (@rtname_A);
$family_exists_H{$family} = 1;
}
}
close(IN);
return;
}
#################################################################
# Subroutine : ribo_ParseQsubFile()
# Incept: EPN, Mon Jul 9 10:30:41 2018
#
# Purpose: Parse a file that specifies the qsub command to use
# when submitting jobs to the farm. The file should
# have exactly 2 non-'#' prefixed lines. Chomp each
# and return them.
#
# Arguments:
# $qsub_file: file to parse
# $FH_HR: REF to hash of file handles
#
# Returns: 2 values:
# $qsub_prefix: string that is the qsub command prior to the
# actual cmsearch/cmalign command
# $qsub_suffix: string that is the qsub command after the
# actual cmsearch/cmalign command
#
# Dies: If we can't parse the qsub file because it is not
# in the correct format.
#
#################################################################
sub ribo_ParseQsubFile {
my $nargs_expected = 2;
my $sub_name = "ribo_ParseQsubFile";
if(scalar(@_) != $nargs_expected) { printf STDERR ("ERROR, $sub_name entered with %d != %d input arguments.\n", scalar(@_), $nargs_expected); exit(1); }
my ($qsub_file, $FH_HR) = @_;
open(IN, $qsub_file) || ofile_FileOpenFailure($qsub_file, $sub_name, $!, "reading", $FH_HR);
my $qsub_prefix_line = undef;
my $qsub_suffix_line = undef;
while(my $line = <IN>) {
if($line !~ m/^\#/) {
chomp $line;
if (! defined $qsub_prefix_line) { $qsub_prefix_line = $line; }
elsif(! defined $qsub_suffix_line) { $qsub_suffix_line = $line; }
else { # both $qsub_prefix_line and $qsub_suffix_line are defined, this shouldn't happen
ofile_FAIL("ERROR in $sub_name, read more than 2 non-# prefixed lines in file $qsub_file:\n$line\n", $?, $FH_HR);
}
}
}
close(IN);
if(! defined $qsub_prefix_line) {
ofile_FAIL("ERROR in $sub_name, read zero non-# prefixed lines in file $qsub_file, but expected 2", $?, $FH_HR);
}
if(! defined $qsub_suffix_line) {
ofile_FAIL("ERROR in $sub_name, read only one non-# prefixed lines in file $qsub_file, but expected 2", $?, $FH_HR);
}
return($qsub_prefix_line, $qsub_suffix_line);
}
#################################################################
# Subroutine : ribo_ParseLogFileForParallelTime()
# Incept: EPN, Tue Oct 9 10:24:09 2018
#
# Purpose: Parse a log file output from ribotyper or riboaligner
# to get CPU time.
#
# Arguments:
# $log_file: file to parse
# $FH_HR: REF to hash of file handles
#
# Returns: Number of seconds read from special lines showing
# time of multiple jobs due to -p option.
#
#################################################################
sub ribo_ParseLogFileForParallelTime {
my $nargs_expected = 2;
my $sub_name = "ribo_ParseQsubFileForParallelTime";
if(scalar(@_) != $nargs_expected) { printf STDERR ("ERROR, $sub_name entered with %d != %d input arguments.\n", scalar(@_), $nargs_expected); exit(1); }
my ($log_file, $FH_HR) = @_;
open(IN, $log_file) || ofile_FileOpenFailure($log_file, $sub_name, $!, "reading", $FH_HR);
my $tot_secs = 0.;
while(my $line = <IN>) {
# Elapsed time below does not include summed elapsed time of multiple jobs [-p], totalling 00:01:37.55 (hh:mm:ss) (does not include waiting time)
if($line =~ /summed elapsed time.+totalling\s+(\d+)\:(\d+)\:(\d+\.\d+)/) {
my ($hours, $minutes, $seconds) = ($1, $2, $3);
$tot_secs += (3600. * $hours) + (60. * $minutes) + $seconds;
}
}
close(IN);
return $tot_secs;
}
#################################################################
# Subroutine : ribo_ParseCmsearchFileForTotalCpuTime()
# Incept: EPN, Tue Oct 9 15:12:34 2018
#
# Purpose: Parse a cmsearch output file to get total number of
# CPU seconds elapsed in lines starting with
# "# Total CPU time" which are only printed if the
# --verbose option is used to cmsearch.
#
# Arguments:
# $out_file: file to parse
# $FH_HR: REF to hash of file handles
#
# Returns: Summed number of elapsed seconds read from >= 1 Total CPU time lines.
#
#################################################################
sub ribo_ParseCmsearchFileForTotalCpuTime {
my $nargs_expected = 2;
my $sub_name = "ribo_ParseCmsearchFileForTotalCpuTime";
if(scalar(@_) != $nargs_expected) { printf STDERR ("ERROR, $sub_name entered with %d != %d input arguments.\n", scalar(@_), $nargs_expected); exit(1); }
my ($out_file, $FH_HR) = @_;
open(IN, $out_file) || ofile_FileOpenFailure($out_file, $sub_name, $!, "reading", $FH_HR);
my $tot_secs = 0.;
while(my $line = <IN>) {
# Total CPU time:1.43u 0.19s 00:00:01.62 Elapsed: 00:00:01.70
if($line =~ /^# Total CPU time.+Elapsed\:\s+(\d+)\:(\d+)\:(\d+\.\d+)/) {
my ($hours, $minutes, $seconds) = ($1, $2, $3);
$tot_secs += (3600. * $hours) + (60. * $minutes) + $seconds;
}
}
close(IN);
return $tot_secs;
}
#################################################################
# Subroutine : ribo_ParseCmalignFileForCpuTime()
# Incept: EPN, Wed Oct 10 09:20:32 2018
#
# Purpose: Parse a cmalign output file to get total number of
# CPU seconds elapsed in lines starting with
# "# CPU time".
#
# Arguments:
# $out_file: file to parse
# $FH_HR: REF to hash of file handles
#
# Returns: Summed number of elapsed seconds read from >= 1 Total CPU time lines.
#
#################################################################
sub ribo_ParseCmalignFileForCpuTime {
my $nargs_expected = 2;
my $sub_name = "ribo_ParseCmalignFileForCpuTime";
if(scalar(@_) != $nargs_expected) { printf STDERR ("ERROR, $sub_name entered with %d != %d input arguments.\n", scalar(@_), $nargs_expected); exit(1); }
my ($out_file, $FH_HR) = @_;
open(IN, $out_file) || ofile_FileOpenFailure($out_file, $sub_name, $!, "reading", $FH_HR);
my $tot_secs = 0.;
while(my $line = <IN>) {
# CPU time: 6.72u 0.28s 00:00:07.00 Elapsed: 00:00:07.93
if($line =~ /^# CPU time.+Elapsed\:\s+(\d+)\:(\d+)\:(\d+\.\d+)/) {
my ($hours, $minutes, $seconds) = ($1, $2, $3);
$tot_secs += (3600. * $hours) + (60. * $minutes) + $seconds;
}
}
close(IN);
return $tot_secs;
}
#################################################################
# Subroutine : ribo_ParseUnixTimeOutput()
# Incept: EPN, Mon Oct 22 14:58:18 2018
#
# Purpose: Parse the output of 1 or more runs of Unix's 'time -p'
# (NOT THE 'time' SHELL BUILTIN, which has output
# that varies depending on the shell being run).
# With -p, 'time' is supposed to output in a portable
# format:
#
# From:
# http://man7.org/linux/man-pages/man1/time.1.html
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# -p When in the POSIX locale, use the precise traditional format
# "real %f\nuser %f\nsys %f\n"
#
# (with numbers in seconds) where the number of decimals in the
# output for %f is unspecified but is sufficient to express the
# clock tick accuracy, and at least one.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# So for example:
#
# real 0.52
# user 0.04
# sys 0.08
#
# Arguments:
# $out_file: file to parse
# $FH_HR: REF to hash of file handles
#
# Returns: Summed number of elapsed seconds read from all 'real' lines.
#
#################################################################
sub ribo_ParseUnixTimeOutput {
my $nargs_expected = 2;
my $sub_name = "ribo_ParseUnixTimeOutput";
if(scalar(@_) != $nargs_expected) { printf STDERR ("ERROR, $sub_name entered with %d != %d input arguments.\n", scalar(@_), $nargs_expected); exit(1); }
my ($out_file, $FH_HR) = @_;
open(IN, $out_file) || ofile_FileOpenFailure($out_file, $sub_name, $!, "reading", $FH_HR);
my $tot_secs = 0.;
while(my $line = <IN>) {
# Total CPU time:1.43u 0.19s 00:00:01.62 Elapsed: 00:00:01.70
if($line =~ /^real\s+(\d+\.\d+)/) {
my ($seconds) = ($1, $2);
$tot_secs += $seconds;
}
}
close(IN);
return $tot_secs;
}
#################################################################
# Subroutine : ribo_ProcessSequenceFile()
# Incept: EPN, Fri May 12 10:08:47 2017
#
# Purpose: Use esl-seqstat to get the lengths of all sequences in a
# FASTA or Stockholm formatted sequence file and fill
# %{$seqidx_HR} and %{$seqlen_HR} where key is sequence
# name, and value is index in file or sequence
# length. Also update %{$width_HR} with maximum length of
# sequence name (key: "target"), index (key: "index") and
# length (key: "length").
#
# Arguments:
# $seqstat_exec: path to esl-seqstat executable
# $seq_file: sequence file to process
# $seqstat_file: path to esl-seqstat output to create
# $seqorder_AR: ref to array of sequences in order to fill here
# $seqidx_HR: ref to hash of sequence indices to fill here
# $seqlen_HR: ref to hash of sequence lengths to fill here
# $width_HR: ref to hash to fill with max widths (see Purpose), can be undef
# $opt_HHR: reference to 2D hash of cmdline options
# $ofile_info_HHR: ref to the ofile info 2D hash
#
# Returns: total number of nucleotides in all sequences read,
# fills %{$seqidx_HR}, %{$seqlen_HR}, and
# %{$width_HR} (partially)
#
# Dies: If the sequence file has two sequences with identical names.
# Error message will list all duplicates.
# If no sequences were read.
#
#################################################################
sub ribo_ProcessSequenceFile {
my $nargs_expected = 9;
my $sub_name = "ribo_ProcessSequenceFile()";
if(scalar(@_) != $nargs_expected) { printf STDERR ("ERROR, $sub_name entered with %d != %d input arguments.\n", scalar(@_), $nargs_expected); exit(1); }
my ($seqstat_exec, $seq_file, $seqstat_file, $seqorder_AR, $seqidx_HR, $seqlen_HR, $width_HR, $opt_HHR, $ofile_info_HHR) = (@_);
my $FH_HR = $ofile_info_HHR->{"FH"}; # for convenience
utl_RunCommand($seqstat_exec . " --dna -a $seq_file > $seqstat_file", opt_Get("-v", $opt_HHR), 0, $FH_HR);
ofile_AddClosedFileToOutputInfo($ofile_info_HHR, "seqstat", $seqstat_file, 0, 1, "esl-seqstat -a output for $seq_file");
# parse esl-seqstat file to get lengths
my $max_targetname_length = length("target"); # maximum length of any target name
my $max_length_length = length("length"); # maximum length of the string-ized length of any target
my $nseq = 0; # number of sequences read
my $tot_length = ribo_ParseSeqstatFile($seqstat_file, \$max_targetname_length, \$max_length_length, \$nseq, $seqorder_AR, $seqidx_HR, $seqlen_HR, $FH_HR);
if(defined $width_HR) {
$width_HR->{"target"} = $max_targetname_length;
$width_HR->{"length"} = $max_length_length;
$width_HR->{"index"} = length($nseq);
if($width_HR->{"index"} < length("#idx")) { $width_HR->{"index"} = length("#idx"); }
}
return $tot_length;
}
#################################################################
# Subroutine: ribo_RunCmsearchOrCmalignOrRRnaSensor
# Incept: EPN, Thu Jul 5 15:05:53 2018
# EPN, Wed Oct 17 20:45:53 2018 [rRNA_sensor added]
#
# Purpose: Run cmsearch, cmalign or rRNA_sensor either locally
# or on the farm.
#
# Arguments:
# $executable: path to cmsearch or cmalign or rRNA_sensor executable
# $time_path: path to Unix time command (e.g. /usr/bin/time)
# $qsub_prefix: qsub command prefix to use when submitting to farm, undef to run locally
# $qsub_suffix: qsub command suffix to use when submitting to farm, undef to run locally
# $opts: options to provide to cmsearch or cmalign or rRNA_sensor arguments to use
# $info_HR: ref to hash with output files and arguments for running
# $program_choice (cmsearch/cmalign/rRNA_sensor_script).
# Validated by ribo_RunCmsearchOrCmalignOrRRnaSensorValidation()
# see comments for that subroutine for more details.
# $opt_HHR: ref to 2D hash of cmdline options
# $ofile_info_HHR: ref to the ofile info 2D hash
#
# Returns: void
#
# Dies: Never
#
#################################################################
sub ribo_RunCmsearchOrCmalignOrRRnaSensor {
my $sub_name = "ribo_RunCmsearchOrCmalignOrRRnaSensor()";
my $nargs_expected = 8;
if(scalar(@_) != $nargs_expected) { printf STDERR ("ERROR, $sub_name entered with %d != %d input arguments.\n", scalar(@_), $nargs_expected); exit(1); }
my ($executable, $time_path, $qsub_prefix, $qsub_suffix, $opts, $info_HR, $opt_HHR, $ofile_info_HHR) = @_;
# we can only pass $FH_HR to ofile_FAIL if that hash already exists
my $FH_HR = (defined $ofile_info_HHR->{"FH"}) ? $ofile_info_HHR->{"FH"} : undef;
# validate %{$info_HR}
my $program_choice = ofile_RemoveDirPath($executable);
ribo_RunCmsearchOrCmalignOrRRnaSensorValidation($program_choice, $info_HR, $opt_HHR, $ofile_info_HHR);
# IN:seqfile, OUT-NAME:stdout, OUT-NAME:time and OUT-NAME:stderr are required key for all programs (cmsearch, cmalign and rRNA_sensor_script)
my $seq_file = $info_HR->{"IN:seqfile"};
my $stdout_file = $info_HR->{"OUT-NAME:stdout"};
my $time_file = $info_HR->{"OUT-NAME:time"};
my $stderr_file = $info_HR->{"OUT-NAME:stderr"};
my $qcmdscript_file = $info_HR->{"OUT-NAME:qcmd"};
my $tmp_stderr_file = $stderr_file . ".tmp"; # necessary because we need to process $tmp_stderr_file to get $time_file and $stderr_file
my $tail_stderr_cmd = "tail -n 3 $tmp_stderr_file > $time_file"; # to create $time_file
my $awk_stderr_cmd = "awk 'n>=3 { print a[n%3] } { a[n%3]=\$0; n=n+1 }' $tmp_stderr_file > $stderr_file";
my $rm_tmp_cmd = "rm $tmp_stderr_file";
# determine if we are running on the farm or locally
my $cmd = ""; # the command that runs cmsearch, cmalign or rRNA_sensor
# determine if we have the appropriate paths defined in %{$info_HR}
# depending on if $executable is "cmalign" or "cmsearch" or "rRNA_sensor_script"
# and run the program
if($executable =~ /cmsearch$/) {
my $model_file = $info_HR->{"IN:modelfile"};
my $tblout_file = $info_HR->{"OUT-NAME:tblout"};
# Not all implementations of 'time' accept -o (Mac OS/X's sometimes doesn't)
#$cmd = "$time_path -p -o $time_file $executable $opts --verbose --tblout $tblout_file $model_file $seq_file > $stdout_file 2> $stderr_file";
if(defined $time_path) {
$cmd = "$time_path -p $executable $opts --verbose --tblout $tblout_file $model_file $seq_file > $stdout_file 2> $tmp_stderr_file;$tail_stderr_cmd;$awk_stderr_cmd;$rm_tmp_cmd;"
}
else {
$cmd = "$executable $opts --verbose --tblout $tblout_file $model_file $seq_file > $stdout_file 2> $stderr_file"
}
}
elsif($executable =~ /cmalign$/) {
my $model_file = $info_HR->{"IN:modelfile"};
my $i_file = $info_HR->{"OUT-NAME:ifile"};
my $stk_file = $info_HR->{"OUT-NAME:stk"};
my $el_file = (opt_IsUsed("--glocal", $opt_HHR)) ? undef : $info_HR->{"OUT-NAME:elfile"};
my $el_opt = (opt_IsUsed("--glocal", $opt_HHR)) ? "" : "--elfile $el_file ";
# Not all implementations of 'time' accept -o (Mac OS/X's sometimes doesn't)
#$cmd = "$time_path -p -o $time_file $executable $opts --ifile $i_file $el_opt -o $stk_file $model_file $seq_file > $stdout_file 2> $stderr_file";
if(defined $time_path) {
$cmd = "$time_path -p $executable $opts --ifile $i_file $el_opt -o $stk_file $model_file $seq_file > $stdout_file 2> $tmp_stderr_file;$tail_stderr_cmd;$awk_stderr_cmd;$rm_tmp_cmd;"
}
else {
$cmd = "$executable $opts --ifile $i_file $el_opt -o $stk_file $model_file $seq_file > $stdout_file 2> $stderr_file";
}
}
elsif($executable =~ /rRNA_sensor_script$/) {
my $minlen = $info_HR->{"minlen"};
my $maxlen = $info_HR->{"maxlen"};
my $classpath = $info_HR->{"OUT-DIR:classpath"};
my $classlocal = ofile_RemoveDirPath($classpath);
my $minid = $info_HR->{"minid"};
my $maxevalue = $info_HR->{"maxevalue"};
my $ncpu = $info_HR->{"ncpu"};
my $outdir = $info_HR->{"OUT-NAME:outdir"};
my $blastdb = $info_HR->{"blastdb"};
# Not all implementations of 'time' accept -o (Mac OS/X's sometimes doesn't)
#$cmd = "$time_path -p -o $time_file $executable $minlen $maxlen $seq_file $classlocal $minid $maxevalue $ncpu $outdir $blastdb > $stdout_file 2> $stderr_file";
if(defined $time_path) {
$cmd = "$time_path -p $executable $minlen $maxlen $seq_file $classlocal $minid $maxevalue $ncpu $outdir $blastdb > $stdout_file 2> $tmp_stderr_file;$tail_stderr_cmd;$awk_stderr_cmd;$rm_tmp_cmd"
}
else {
$cmd = "$executable $minlen $maxlen $seq_file $classlocal $minid $maxevalue $ncpu $outdir $blastdb > $stdout_file 2> $stderr_file"
}
}
if((defined $qsub_prefix) && (defined $qsub_suffix)) {
# write a script to execute on the cluster and execute it
# replace ![jobname]! with $jobname
my $jobname = "j" . ofile_RemoveDirPath($seq_file);
my $qsub_cmd = $qsub_prefix . "sh $qcmdscript_file" . $qsub_suffix;
$qsub_cmd =~ s/\!\[jobname\]\!/$jobname/g;
# create the shell script file with the cmsearch/cmalign/rRNA_sensor command $cmd
ribo_WriteCommandScript($qcmdscript_file, $cmd, $FH_HR);
utl_RunCommand($qsub_cmd, opt_Get("-v", $opt_HHR), 0, $FH_HR);
}
else {
# run command locally and wait for it to complete
utl_RunCommand($cmd, opt_Get("-v", $opt_HHR), 0, $FH_HR);
# Exit if an expected file does not exists or is empty, it should always exist and be non-empty.
# We had to add this shortly before the 1.0 release because if a cmsearch cmd fails, the 'time'
# command will not return a non-0 exit status so the program will not exit. By enforcing this
# file exists and is non-empty we catch this situation because cmsearch tblout will be empty.
my $expected_out_file = undef;
if(($executable =~ /cmsearch$/) || ($executable =~ /cmalign$/)) {
if($executable =~ /cmsearch$/) {
$expected_out_file = $info_HR->{"OUT-NAME:tblout"};
}
elsif($executable =~ /cmalign$/) {
$expected_out_file = $info_HR->{"OUT-NAME:stk"};
}
# we don't check for output file for rRNA_sensor because it may exist even if command failed
# we'll catch if it failed later when we try to parse the output (program should exit)
utl_FileValidateExistsAndNonEmpty($expected_out_file, "expected output file from command $cmd", $sub_name, 1, $FH_HR);
}
}
# else create the qsub cmd script file (the file with the actual cmsearch/cmalign/rRNA_sensor command)
# we will submit a job to the farm that will execute this qsub cmd script file (previously we just put the
# command
return;
}
#################################################################
# Subroutine: ribo_RunCmsearchOrCmalignOrRRnaSensorValidation()
# Incept: EPN, Thu Oct 18 12:32:18 2018
#
# Purpose: Validate that we can run cmsearch, cmalign or rRNA_sensor
# by checking that %{$info_HR} is valid.
#
# %{$info_HR} uses some key name conventions to include
# extra information that pertains to parallel mode only
# (-p).
#
# Keys beginning with 'IN:' are input files and we
# check to make sure they exist in this subroutine.
#
# Keys beginning with 'OUT-NAME:' and 'OUT-DIR:' are
# OUTput files that will have a integer (actually ".<d>")
# appended to their file NAMEs (if OUT-NAME) or DIRectory
# names (if OUT-DIR), one per job run in
# parallel. When all jobs are complete the individual
# files are concatenated into one file named as the value
# of $info_HR->{"OUT-{NAME,DIR}:<s>"}.
#
# Arguments:
# $program_choice: "cmalign" or "cmsearch" or "rRNA_sensor_script"
# $info_HR: ref to hash with output files and arguments for running
# $program_choice (cmsearch/cmalign/rRNA_sensor_script).
#
# if "cmsearch", keys must be:
# "IN:seqfile": name of input master sequence file
# "IN:modelfile": name of input model (CM) file
# "OUT-NAME:tblout": name of tblout output file (--tblout)
# "OUT-NAME:stdout": name of stdout output file
# "OUT-NAME:time": path to time output file
# "OUT-NAME:stderr": path to stderr output file
# "OUT-NAME:qcmd": path to cmd script file for the qsub cmd
#
# if "cmalign", keys must be:
# "IN:seqfile": name of input master sequence file
# "IN:modelfile": name of input model (CM) file
# "OUT-NAME:ifile": name of ifile output file (--ifile)
# "OUT-NAME:elfile": name of elfile output file (--elfile)
# "OUT-NAME:stk": name of alignment output file (-o)
# "IN:seqlist": name of file listing all sequences in "IN:seqfile";
# "OUT-NAME:stdout": name of stdout output file
# "OUT-NAME:time": path to time output file
# "OUT-NAME:stderr": path to stderr output file
# "OUT-NAME:qcmd": path to cmd script file for the qsub cmd
#
# if "rRNA_sensor_script", keys must be:
# "IN:seqfile": name of master sequence file
# "minlen": minimum length of sequence to allow (cmdline arg 1)
# "maxlen": maximum length of sequence to allow (cmdline arg 2)
# "OUT-DIR:classpath": path to output file with class definitions (file name (without path) will be cmdline arg 4)
# "OUT-DIR:lensum": path to length summary file
# "OUT-DIR:blastout": path to blast output file
# "minid": min blast %id to allow (cmdline arg 5)
# "maxevalue": max blast E-value to allow (cmdline arg 6)
# "ncpu": number of CPUs to use (cmdline arg 7)
# "OUT-NAME:outdir" name of output diretory (cmdline arg 8)
# "blastdb": name of blast db (cmdline arg 9)
# "OUT-NAME:stdout": name of stdout output file
# "OUT-NAME:time": path to time output file
# "OUT-NAME:stderr": path to stderr output file
# "OUT-NAME:qcmd": path to cmd script file for the qsub cmd
#
# $opt_HHR: REF to 2D hash of option values, see top of seqp_opts.pm for description
# $ofile_info_HHR: REF to 2D hash of output file information
#
# Returns: 2 values:
# $wait_key: key in $info_HR for which $info_HR->{$wait_key} is the file
# to look for $wait_str in to indicate the job is finished
# $wait_str: string in the final line of $info_HR->{$wait_key} that indicates
# a job is finished.
#
# Dies: If program_choice is invalid, a required info_key is not set, or an input file does not exist
#
#################################################################
sub ribo_RunCmsearchOrCmalignOrRRnaSensorValidation {
my $sub_name = "ribo_RunCmsearchOrCmalignOrRRnaSensorValidation";
my $nargs_expected = 4;
if(scalar(@_) != $nargs_expected) { printf STDERR ("ERROR, $sub_name entered with %d != %d input arguments.\n", scalar(@_), $nargs_expected); exit(1); }
my ($program_choice, $info_HR, $opt_HHR, $ofile_info_HHR) = @_;
my $wait_key = undef;
my $wait_str = undef;
my @reqd_keys_A = ();
my $FH_HR = $ofile_info_HHR->{"FH"}; # for convenience
# determine if we have the appropriate paths defined in %{$info_HR}
# depending on if $program_choice is "cmalign" or "cmsearch" or "rRNA_sensor_script"
if($program_choice eq "cmsearch") {
$wait_key = "OUT-NAME:tblout";
$wait_str = "[ok]";
@reqd_keys_A = ("IN:seqfile", "IN:modelfile", "OUT-NAME:tblout", "OUT-NAME:stdout", "OUT-NAME:time", "OUT-NAME:stderr", "OUT-NAME:qcmd");
}
elsif($program_choice eq "cmalign") {
$wait_key = "OUT-NAME:stdout";
$wait_str = "# CPU time:";
@reqd_keys_A = ("IN:seqfile", "IN:modelfile", "OUT-NAME:stk", "OUT-NAME:ifile", "IN:seqlist", "OUT-NAME:stdout", "OUT-NAME:time", "OUT-NAME:stderr", "OUT-NAME:qcmd");
if(! opt_Get("--glocal", $opt_HHR)) {
push(@reqd_keys_A, "OUT-NAME:elfile");
}
}
elsif($program_choice eq "rRNA_sensor_script") {
$wait_key = "OUT-NAME:stdout";
$wait_str = "Final output saved as";
@reqd_keys_A = ("IN:seqfile", "minlen", "maxlen", "OUT-DIR:classpath", "OUT-DIR:lensum", "OUT-DIR:blastout", "minid", "maxevalue", "ncpu", "OUT-NAME:outdir", "blastdb", "OUT-NAME:stdout", "OUT-NAME:time", "OUT-NAME:stderr", "OUT-NAME:qcmd");
}
else {
ofile_FAIL("ERROR in $sub_name, chosen executable $program_choice is not cmsearch, cmalign, or rRNA_sensor", 1, $FH_HR);
}
# verify all keys exists, and that input files exist
foreach my $key (@reqd_keys_A) {
if(! exists $info_HR->{$key}) {
ofile_FAIL("ERROR in $sub_name, executable is $program_choice but $key file not set", 1, $FH_HR);
}
# if it is an input file, make sure it exists
if($info_HR->{$key} =~ m/^IN:/) {
utl_FileValidateExistsAndNonEmpty($info_HR->{$key}, undef, $sub_name, 1, $FH_HR);
}
}
return($wait_key, $wait_str);
}
#################################################################
# Subroutine: ribo_RunCmsearchOrCmalignOrRRnaSensorWrapper()
# Incept: EPN, Thu Jul 5 15:24:19 2018
# EPN, Wed Oct 17 20:46:10 2018 [rRNA_sensor added]
#
# Purpose: Run one or more cmsearch, cmalign or rRNA_sensor jobs
# on the farm or locally, after possibly splitting up the input
# sequence file.
# The following must all be valid options in opt_HHR:
# -p, --nkb, -s, --wait, --errcheck, --keep, -v
# See ribotyper for examples of these options.
#
# Arguments:
# $execs_HR: ref to hash with paths to executables
# $program_choice: "cmalign" or "cmsearch" or "rRNA_sensor_script"
# $qsub_prefix: qsub command prefix to use when submitting to farm, if -p
# $qsub_suffix: qsub command suffix to use when submitting to farm, if -p
# $seqlen_HR: ref to hash of sequence lengths, key is sequence name, value is length
# $progress_w: width for outputProgressPrior output
# $out_root: output root for naming sequence files
# $tot_nseq: number of sequences in $seq_file
# $tot_len_nt: total length of all nucleotides in $seq_file
# $opts: string of cmsearch or cmalign options or rRNA_sensor arguments
# $info_HR: ref to hash with output files and arguments for running
# $program_choice (cmsearch/cmalign/rRNA_sensor_script).
# Validated by ribo_RunCmsearchOrCmalignOrRRnaSensorValidation()
# see comments for that subroutine for more details.
# $opt_HHR: REF to 2D hash of option values, see top of sqp_opts.pm for description
# $ofile_info_HHR: REF to 2D hash of output file information
#
# Returns: $sum_cpu_plus_wait_secs: '0' unless -p used.
# If -p used: this is an estimate on total number CPU
# seconds used required by all jobs summed together. This is
# more than actual CPU seconds, because, for example, if a
# job takes 1 seconds and we didn't check on until 10
# seconds elapsed, then it will contribute 10 seconds to this total.
#
# Dies: If an executable doesn't exist, or cmsearch command fails if we're running locally
#################################################################
sub ribo_RunCmsearchOrCmalignOrRRnaSensorWrapper {
my $sub_name = "ribo_RunCmsearchOrCmalignOrRRnaSensorWrapper";
my $nargs_expected = 13;
if(scalar(@_) != $nargs_expected) { printf STDERR ("ERROR, $sub_name entered with %d != %d input arguments.\n", scalar(@_), $nargs_expected); exit(1); }
my ($execs_HR, $program_choice, $qsub_prefix, $qsub_suffix, $seqlen_HR, $progress_w, $out_root, $tot_nseq, $tot_len_nt, $opts, $info_HR, $opt_HHR, $ofile_info_HHR) = @_;
my $FH_HR = $ofile_info_HHR->{"FH"}; # for convenience
my $log_FH = $ofile_info_HHR->{"FH"}{"log"}; # for convenience
my $out_dir = ribo_GetDirPath($out_root);
my $executable = undef; # path to the cmsearch or cmalign executable
my $info_key = undef; # a single info_HH 1D key
my $wait_str = undef; # string in output file that ribo_WaitForFarmJobsToFinish will check for to see if jobs are done
my $wait_key = undef; # outfile key that ribo_WaitForFarmJobsToFinish will use to check if jobs are done
my $sum_cpu_plus_wait_secs = 0; # will be returned as '0' unless -p used
my $njobs_finished = 0;
my $time_path = undef;
if(defined $execs_HR->{"time"}) {
$time_path = $execs_HR->{"time"};
}
# validate %{$info_HR}
($wait_key, $wait_str) = ribo_RunCmsearchOrCmalignOrRRnaSensorValidation($program_choice, $info_HR, $opt_HHR, $ofile_info_HHR);
$executable = $execs_HR->{$program_choice};
if(! opt_Get("-p", $opt_HHR)) {
# run job locally
ribo_RunCmsearchOrCmalignOrRRnaSensor($executable, $time_path, undef, undef, $opts, $info_HR, $opt_HHR, $ofile_info_HHR); # undefs: run locally
}
else {
my %wkr_outfiles_HA = (); # hash of arrays of output file names for all jobs,
# these are files to concatenate or otherwise combine after all jobs are finished
my %wkr_info_H = (); # hash of info for one worker's job
# we need to split up the sequence file, and submit a separate set of cmsearch/cmalign/rRNA_sensor jobs for each file
my $seq_file = $info_HR->{"IN:seqfile"};
my $nfasta_created = sqf_FastaFileSplitRandomly($seq_file, $seqlen_HR, $out_dir, $tot_nseq, $tot_len_nt, opt_Get("--nkb", $opt_HHR) * 1000, opt_Get("-s", $opt_HHR), $ofile_info_HHR->{"FH"});
# submit all jobs to the farm
my @info_keys_A = sort keys (%{$info_HR});
my $info_key;
for(my $f = 1; $f <= $nfasta_created; $f++) {
my %wkr_info_H = ();
my $seq_file_tail = ofile_RemoveDirPath($seq_file);
my $wkr_seq_file = $out_dir . "/" . $seq_file_tail . "." . $f;
foreach $info_key (@info_keys_A) {
if($info_key eq "IN:seqfile") { # special case
$wkr_info_H{$info_key} = $wkr_seq_file;
# keep a list of these files, we'll remove them later
push(@{$wkr_outfiles_HA{$info_key}}, $wkr_info_H{$info_key});
}
elsif($info_key =~ m/^OUT/) {
if($info_HR->{$info_key} eq "/dev/null") {
$wkr_info_H{$info_key} = "/dev/null";
}
elsif($info_key =~ m/^OUT-NAME/) {
$wkr_info_H{$info_key} = $info_HR->{$info_key} . "." . $f;
}
elsif($info_key =~ m/^OUT-DIR/) {
# need to put the .$f at end of dir path
my $tmpdir = ribo_GetDirPath($info_HR->{$info_key});
$tmpdir =~ s/\/$//;
my $tmpfile = ofile_RemoveDirPath($info_HR->{$info_key});
$wkr_info_H{$info_key} = $tmpdir . "." . $f . "/" . $tmpfile;
}
else {
ofile_FAIL("ERROR unrecognized special prefix beginning with OUT in info_H key: $info_key", 1, $FH_HR);
}
# and keep a list of these files, we will concatenate them later
push(@{$wkr_outfiles_HA{$info_key}}, $wkr_info_H{$info_key});
}
else { # value is not modified for each job
$wkr_info_H{$info_key} = $info_HR->{$info_key};
}