-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtRNAscan-SE.src
More file actions
executable file
·1966 lines (1758 loc) · 69.2 KB
/
tRNAscan-SE.src
File metadata and controls
executable file
·1966 lines (1758 loc) · 69.2 KB
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
#! @PERL@
#
# --------------------------------------------------------------------
# tRNAscan-SE: a program for improved detection of transfer RNA
# genes in genomic sequence
#
# Version 2.0.12
#
# Copyright (C) 2022 Patricia Chan and Todd Lowe
#
# School of Engineering, University of California, Santa Cruz
# trna@soe.ucsc.edu
# http://trna.ucsc.edu/
# --------------------------------------------------------------------
#
# Usage:
# tRNAscan-SE [options] <FASTA file(s)>
#
use strict;
use lib "@libdir@/tRNAscan-SE";
use Getopt::Long;
use tRNAscanSE::Configuration;
use tRNAscanSE::tRNA;
use tRNAscanSE::SprinzlPos;
use tRNAscanSE::ArraytRNA;
use tRNAscanSE::Utils;
use tRNAscanSE::GeneticCode;
use tRNAscanSE::Options;
use tRNAscanSE::Eufind;
use tRNAscanSE::Tscan;
use tRNAscanSE::CM;
use tRNAscanSE::LogFile;
use tRNAscanSE::Stats;
use tRNAscanSE::Sequence;
use tRNAscanSE::FpScanResultFile;
use tRNAscanSE::ScanResult;
use tRNAscanSE::IntResultFile;
use tRNAscanSE::MultiResultFile;
use tRNAscanSE::SS;
our $version = "2.0.12";
our $release_date = "Nov 2022";
our $program_id = "tRNAscan-SE-".$version;
# modified by 'make'
our $default_conf = "@bindir@/tRNAscan-SE.conf";
# Signal handling
$SIG{'TERM'} = 'error_handler';
$SIG{'QUIT'} = 'error_handler';
$SIG{'INT'} = 'error_handler';
# Global variables
our @fp_start_time;
our $opts = tRNAscanSE::Options->new;
our $global_constants = tRNAscanSE::Configuration->new();
our $log = tRNAscanSE::LogFile->new("default");
our $sprinzl = tRNAscanSE::SprinzlPos->new;
our $fp_tRNAs = tRNAscanSE::ArraytRNA->new;
our $sp_tRNAs = tRNAscanSE::ArraytRNA->new;
our $fp_result_file = tRNAscanSE::FpScanResultFile->new("");
our $sp_int_results = tRNAscanSE::IntResultFile->new;
our $iso_int_results = tRNAscanSE::MultiResultFile->new;
our $gc = tRNAscanSE::GeneticCode->new;
our $stats = tRNAscan::Stats->new;
our $seq_file = tRNAscanSE::Sequence->new;
our $eufind = tRNAscanSE::Eufind->new;
our $tscan = tRNAscanSE::Tscan->new;
our $cm = tRNAscanSE::CM->new;
$global_constants->config_file($default_conf);
our %global_vars = (global_constants => $global_constants,
log_file => $log,
options => $opts,
sprinzl => $sprinzl,
fp_tRNAs => $fp_tRNAs,
sp_tRNAs => $sp_tRNAs,
fp_result_file => $fp_result_file,
sp_int_results => $sp_int_results,
iso_int_results => $iso_int_results,
sequence => $seq_file,
gc => $gc,
stats => $stats
);
# set user-selectable options
&set_options();
# set location of binaries & data files,
# plus, check to make sure they are there
$cm->set_file_paths(\%global_vars);
$cm->check_lib_files($opts);
$cm->set_bin($global_constants->get("bin_dir"));
$cm->set_infernal_bin($global_constants->get("infernal_dir"));
$eufind->set_bin($global_constants->get("bin_dir"));
$tscan->set_bin($global_constants->get("bin_dir"));
# initialize variables
$gc->read_transl_table($opts);
if ($opts->save_stats())
{
$stats->file_name($opts->stats_file());
}
# Start processing
&initialize_process();
# prescan with either tRNAscan/eufind or both
if ($opts->tscan_mode() || $opts->eufind_mode() || $opts->infernal_fp())
{
&first_pass_prescan();
}
# Check to see if no sequences were read from input file(s)
if (($stats->numscanned() == 0) && ($opts->eufind_mode() || $opts->tscan_mode() || $opts->infernal_fp()))
{
if ($opts->seq_key() ne '\S*')
{
die "\nNo FASTA sequences matching \'".$opts->raw_seq_key()."\' key found\n\n";
}
elsif ($opts->multiple_files())
{
die "\nFATAL: No sequences in FASTA format found in ", join(', ',@ARGV),"\n\n";
}
else
{
die "\nFATAL: No sequences in FASTA format found in file ".$opts->fasta_file()."\n\n";
}
}
# Run Cove or Infernal on candidate tRNAs picked in first pass,
# or by itself on seqs if no first pass searches
elsif ($opts->cove_mode() || $opts->infernal_mode())
{
$sp_int_results->file_name($opts->secondpass_int_result_file());
$iso_int_results->file_name($opts->isotype_int_result_file());
&run_cm_scan();
}
$stats->end_sp_timer();
if ($opts->save_stats())
{
$stats->open_file();
$stats->save_final_stats($opts, $gc, $fp_result_file->get_hit_count(), $cm->tab_results());
$stats->close_file();
}
$log->finish_process();
&cleanup(); # clean up temp files
exit(0);
# END main
sub initialize_process
{
# print program info header, credits, & selected run options
if (!$opts->quiet_mode())
{
print STDERR "\ntRNAscan-SE v.$version ($release_date) -",
" scan sequences for transfer RNAs\n";
&display_credits();
$opts->display_run_options($cm, $tscan, $eufind, $global_constants, *STDERR);
}
$stats->start_fp_timer(); # save starting time
# if statistics are being saved, write run options in stats file
if ($opts->save_stats())
{
my $host = `hostname`;
chomp($host);
$stats->open_file();
$stats->write_line("\ntRNAscan-SE v.$version ($release_date) scan results (on host $host)\nStarted: ".`date`);
$opts->display_run_options($cm, $tscan, $eufind, $global_constants, $stats->FILE_H());
$stats->close_file();
}
}
# Running tRNAscan and/or EufindtRNA
sub first_pass_prescan
{
if ($opts->infernal_fp())
{
$log->status("Phase I: Searching for tRNAs with HMM-enabled Infernal");
}
else
{
$log->status("Phase I: Searching for tRNAs with tRNAscan and/or EufindtRNA");
}
# open seq file to search
$seq_file->open_file($opts->fasta_file(), "read");
# Main loop for reading seqs & scanning with tRNAscan and/or EufindtRNA
my $targ_seq_id = 0; # Don't look for a specific Seq number
my $start_index = 1;
my $sequence_scanned = 0;
my $printed_header = 0;
my $eufind_output;
my @hit_list = ();
my $tmp_raw = $global_constants->get("tmp_raw");
my $tmp_fa = $global_constants->get("tmp_fa");
my $tmp_fa_file = tRNAscanSE::Sequence->new;
my $missing_fa_file = tRNAscanSE::Sequence->new;
while ($seq_file->read_fasta($opts, $targ_seq_id))
{
if ($opts->cove_mode() || $opts->infernal_mode())
{
$log->broadcast("Scanned seqs: ".$stats->numscanned()." (at ".$seq_file->seq_name().")");
}
$stats->increment_numscanned();
$stats->increment_first_pass_base_ct($seq_file->seq_length());
do
{
# Write one input sequence / seq buffer to tmp_fa file
$tmp_fa_file->open_file($tmp_fa, "write");
$tmp_fa_file->set_seq_info($seq_file->seq_name(), $seq_file->seq_description(),
$seq_file->seq_length(), $seq_file->sequence());
$tmp_fa_file->write_fasta();
$tmp_fa_file->close_file();
if ($opts->infernal_fp())
{
$cm->first_pass_scan(\%global_vars, $start_index, $seq_file->seq_name());
}
else
{
# Run tRNAscan on $tmp_fa file & write results to $tmp_raw output file
if ($opts->tscan_mode())
{
$tscan->run_tRNAscan($tmp_fa, $tmp_raw, $start_index, $global_constants->get("lib_dir"), $seq_file->seq_name());
if ($opts->save_verbose())
{
$tscan->append_verbfile($opts->verb_file(), $tmp_fa, $seq_file->seq_name());
}
$tscan->process_tRNAscan_hits(\%global_vars, $seq_file->seq_name());
}
# Run eufindtRNA program & save results in memory in $Eufind_output array
if ($opts->eufind_mode())
{
$eufind_output = $eufind->run_eufind($tmp_fa, $start_index, $opts->max_int_len(), $seq_file->seq_name());
if ($eufind_output ne "")
{
$eufind->process_Eufind_hits(\%global_vars, $eufind_output);
$eufind_output = "";
}
}
}
$sequence_scanned = 1; # Flag indicating current sequence has been scanned
# Check to see if all of sequence was read in last buffer-sized chunck
if ($seq_file->seq_buf_overrun())
{
$start_index = $seq_file->buffer_end_index() + 1;
if ($seq_file->read_more_fasta($opts))
{
$sequence_scanned = 0;
}
}
}
until ($sequence_scanned);
if ($fp_tRNAs->get_count() > 0)
{
$stats->increment_seqs_hit();
# save results in ACeDB format now if not using Cove analysis
if ($opts->ace_output() && (!$opts->CM_mode()))
{
&save_Acedb_from_firstpass($opts->output_codon(), $gc->one_let_trans_map(), $fp_tRNAs, $opts->out_file());
}
else
{
# save all hits for this seq
my $fpass_trna_base_ct = $stats->fpass_trna_base_ct();
if (!$opts->CM_mode())
{
if (!($opts->brief_output() || $printed_header))
{
&open_for_append(\*TABOUT, $opts->out_file());
&print_results_header(\*TABOUT, $opts, 0, 8, 8, 1);
close (TABOUT);
$printed_header = 1;
}
}
$fp_result_file->save_firstpass_output($opts, $fp_tRNAs, \$fpass_trna_base_ct, $seq_file->seq_length(), $seq_file->seq_id());
$stats->fpass_trna_base_ct($fpass_trna_base_ct);
}
# clear hit array
$fp_tRNAs->clear();
}
elsif ($opts->save_missed())
{
# save sequence that had no tRNA hits if -M param set
# NOTE: only writes last frame of seq buffer if seq length > max_seq_buffer
$missing_fa_file->open_file($opts->missed_seq_file(), "append");
$missing_fa_file->set_seq_info($seq_file->seq_name(), $seq_file->seq_description(), $seq_file->seq_length(), $seq_file->sequence());
$missing_fa_file->write_fasta();
$missing_fa_file->close_file();
}
$seq_file->reset_buffer_ct();
$start_index = 1;
} # while (read_fasta()) - still more seqs to scan
$seq_file->close_file();
# remove temporary files
system("rm -f $tmp_raw $tmp_fa");
$seq_file->release_memory(); # release memory
$log->broadcast("\n".$stats->numscanned()." seqs scanned, ".$stats->seqs_hit()." seqs had at ".
"least one hit.\n".$stats->trnatotal()." total tRNAs predicted in first pass scans");
if ((!$opts->CM_mode()) && ($stats->trnatotal() == 0) && (!$opts->quiet_mode()))
{
$log->status("No tRNAs found.");
}
$stats->end_fp_timer(); # save time first-pass scans are done
if ($opts->save_stats())
{
$stats->open_file();
$stats->save_firstpass_stats();
$stats->close_file();
}
}
# Run Cove or Infernal
sub run_cm_scan
{
$stats->start_sp_timer();
if ($opts->tscan_mode() || $opts->eufind_mode() || $opts->infernal_fp())
{
$log->status("Phase II: ".$opts->second_pass_label()." verification of candidate ".
"tRNAs detected with first-pass scan");
}
else
{
$log->status("Running ".$opts->second_pass_label()." analysis");
if (!$opts->use_prev_ts_run())
{
$fp_result_file->prep_for_secpass_only($opts, $stats, $seq_file);
}
}
# Name of tRNA sequence currently in memory
my $prev_seq_name = '';
# flag indicates if seqid and seqlen are saved in firstpass result file
my $seqinfo_flag = 0;
my $curseq_trnact = 0;
my $prescan_trna = tRNAscanSE::tRNA->new;
my $tRNAs_found = 0;
my $index = -1;
$seq_file->open_file($opts->fasta_file(), "read");
$fp_result_file->index_results(\$seqinfo_flag);
my @fp_result_file_indexes = $fp_result_file->get_indexes();
$fp_result_file->open_file();
for (my $seq_ct = 0; $seq_ct < scalar(@fp_result_file_indexes); $seq_ct++)
{
$sp_int_results->file_name($opts->secondpass_int_result_file());
$global_vars{sp_int_results} = $sp_int_results;
$sp_int_results->open_file("write");
$sp_tRNAs->clear();
$log->broadcast("Scanning ".$fp_result_file_indexes[$seq_ct]->[1]);
if ($opts->cove_mode())
{
$fp_result_file->reset_current_seq();
$fp_result_file->get_next_tRNA_candidate($opts, $seqinfo_flag, $seq_ct, $prescan_trna);
while ($prescan_trna->seqname() ne "")
{
# Retrieve tRNA sequence and write to tmp_trnaseq_file
if (!&prepare_tRNA_to_scan($seq_file, $prescan_trna))
{
next;
}
$tRNAs_found = $cm->analyze_with_cove(\%global_vars, $prescan_trna, \$curseq_trnact);
if (!$cm->CM_check_for_introns())
{
$stats->increment_total_secpass_ct($tRNAs_found);
}
$fp_result_file->get_next_tRNA_candidate($opts, $seqinfo_flag, $seq_ct, $prescan_trna);
}
}
else
{
# Retrieve tRNA sequences and write to tmp_trnaseq_file
if (!&prepare_multi_tRNAs_to_scan($seqinfo_flag, $seq_file, $seq_ct))
{
next;
}
if ($opts->mito_mode())
{
$tRNAs_found = $cm->analyze_mito(\%global_vars, $seqinfo_flag, $seq_ct, $fp_result_file_indexes[$seq_ct]->[1], \$curseq_trnact);
}
elsif($opts->alternate_mode())
{
$tRNAs_found = $cm->analyze_alternate(\%global_vars, $seqinfo_flag, $seq_ct, $fp_result_file_indexes[$seq_ct]->[1], \$curseq_trnact);
}
elsif ($opts->metagenome_mode())
{
}
elsif ($opts->numt_mode())
{
}
elsif ($opts->infernal_mode())
{
$tRNAs_found = $cm->analyze_with_cmsearch(\%global_vars, $seqinfo_flag, $seq_ct, $fp_result_file_indexes[$seq_ct]->[1], \$curseq_trnact);
}
$stats->increment_total_secpass_ct($tRNAs_found);
}
$sp_int_results->close_file();
if (($curseq_trnact > 0) and $cm->CM_check_for_introns())
{
if (&prepare_intron_scan($seq_file))
{
$cm->scan_noncanonical_introns(\%global_vars, $fp_result_file_indexes[$seq_ct]->[1]);
}
}
if ($curseq_trnact > 0)
{
if ($opts->euk_mode() or $opts->bact_mode() or $opts->arch_mode())
{
$cm->truncated_tRNA_search(\%global_vars, $fp_result_file_indexes[$seq_ct]->[1]);
if (!$opts->no_isotype())
{
$cm->isotype_cmsearch(\%global_vars);
}
}
&output_tRNA(\%global_vars, $cm, $cm->tab_results(), $cm->get_hmm_score(), $program_id);
}
if (($sp_int_results->get_count() > 0) and $cm->CM_check_for_split_halves())
{
my @sp_indexes = $sp_int_results->get_indexes();
if ($sp_int_results->open_file("read"))
{
for (my $i = 0; $i < scalar(@sp_indexes); $i++)
{
my $cm_tRNA = tRNAscanSE::tRNA->new;
$sp_int_results->get_tRNA($sp_indexes[$i]->[0], $cm_tRNA);
$sp_tRNAs->put($cm_tRNA);
}
$sp_int_results->close_file();
$cm->scan_split_tRNAs(\%global_vars);
}
}
if ($opts->bed_file() ne "")
{
if ($curseq_trnact > 0)
{
&write_bed(\%global_vars);
}
}
if ($opts->gff_file() ne "")
{
if ($curseq_trnact > 0)
{
&write_gff(\%global_vars);
}
}
$sp_int_results->clear_index();
$curseq_trnact = 0;
}
$fp_result_file->close_file();
$seq_file->close_file();
if (($stats->total_secpass_ct() == 0) && (!$opts->quiet_mode()))
{
print STDERR "No tRNAs found.\n\n";
}
}
# Extracts tRNA sequences with given coordinates, and writes to $tmp_
sub prepare_multi_tRNAs_to_scan
{
my ($seqinfo_flag, $seq_file, $seq_ct) = @_;
system("rm -f ".$global_constants->get("tmp_trnaseq_file"));
my $trna_file = tRNAscanSE::Sequence->new;
$trna_file->open_file($global_constants->get("tmp_trnaseq_file"), "write");
my $flanking = 0;
my $trna = tRNAscanSE::tRNA->new;
$fp_result_file->reset_current_seq();
$fp_result_file->get_next_tRNA_candidate($opts, $seqinfo_flag, $seq_ct, $trna);
if ($fp_result_file->open_flanking("write"))
{
$flanking = 1;
}
while ($trna->seqname() ne "")
{
$seq_file->get_tRNA_sequence(\%global_vars, $trna);
$stats->increment_secpass_base_ct($trna->len());
$trna_file->set_seq_info($trna->seqname().".t".&pad_num($trna->id(), 6), $seq_file->seq_description(), length($trna->seq()), $trna->seq());
$trna_file->write_fasta();
if ($flanking)
{
$fp_result_file->write_tRNA_flanking($trna);
}
$seq_file->release_memory();
$fp_result_file->get_next_tRNA_candidate($opts, $seqinfo_flag, $seq_ct, $trna);
}
$trna_file->close_file();
$fp_result_file->close_flanking();
return 1;
}
# Extracts tRNA sequence with given coordinates, and writes to $tmp_
sub prepare_tRNA_to_scan
{
my ($seq_file, $trna) = @_;
$seq_file->get_tRNA_sequence(\%global_vars, $trna);
$stats->increment_secpass_base_ct($trna->len());
&write_tRNA($global_constants->get("tmp_trnaseq_file"), $seq_file->seq_name(), $seq_file->seq_description(), $trna->seq(), 1);
$seq_file->release_memory();
return 1;
}
# Extracts tRNA sequences with given coordinates, and writes to $tmp_
sub prepare_intron_scan
{
my ($seq_file) = @_;
my $ret_value = 1;
system("rm -f ".$global_constants->get("tmp_trnaseq_file"));
my $trna_file = tRNAscanSE::Sequence->new;
my $cm_tRNA = undef;
$trna_file->open_file($global_constants->get("tmp_trnaseq_file"), "write");
my $trna = tRNAscanSE::tRNA->new;
my $padded_seq = "";
$sp_tRNAs->clear();
my @sp_indexes = $sp_int_results->get_indexes();
if ($sp_int_results->open_file("read"))
{
for (my $i = 0; $i < scalar(@sp_indexes); $i++)
{
$cm_tRNA = tRNAscanSE::tRNA->new;
$sp_int_results->get_tRNA($sp_indexes[$i]->[0], $cm_tRNA);
my $orig_seq = $cm_tRNA->seq();
$seq_file->get_tRNA_sequence(\%global_vars, $cm_tRNA);
if (uc($orig_seq) ne uc($cm_tRNA->seq()))
{
$ret_value = 0;
$log->error("tRNA sequence does not match for intron scan: ".$cm_tRNA->tRNAscan_id()." ".$cm_tRNA->seqname().":".$cm_tRNA->start()."-".$cm_tRNA->end());
}
$padded_seq = $cm_tRNA->upstream().$cm_tRNA->seq().$cm_tRNA->downstream();
$trna_file->set_seq_info($cm_tRNA->seqname().".trna".&pad_num($cm_tRNA->id(), 6), $cm_tRNA->tRNAscan_id(), length($padded_seq), $padded_seq);
$trna_file->write_fasta();
$sp_tRNAs->put($cm_tRNA);
$seq_file->release_memory();
}
$sp_int_results->close_file();
}
$trna_file->close_file();
return $ret_value;
}
# clean up temp files
sub cleanup
{
system("rm -f ".$global_constants->get("temp_dir")."/tscan$$"."_*");
system("rm -f ".$global_constants->get("temp_dir")."/tscan$$".".*");
system("rm -f ".$opts->fafile().".pid");
}
sub error_handler
{
print "\nAborting tRNAscan-SE\n\n";
my $ppid = $$;
my $psout = `ps -ef`;
my @ps_lines = split(/\n/,$psout);
foreach my $line (0..$#ps_lines)
{
if ($ps_lines[$line] =~/^\s+\S+\s+(\d+)\s+($ppid)\s/)
{
print STDERR "Killing process $1:\n",$ps_lines[$line],"\n";
my $killct = kill 'KILL', $1;
print STDERR "$killct jobs received the kill signal\n";
}
}
&cleanup();
exit(1);
}
sub display_credits
{
print STDERR "Copyright (C) 2022 Patricia Chan and Todd Lowe\n",
" University of California Santa Cruz\n",
"Freely distributed under the GNU General Public License (GPLv3)\n\n";
}
sub print_usage
{
print STDERR "\nUsage: tRNAscan-SE [-options] <FASTA file(s)>\n\n";
print STDERR " Scan a sequence file for tRNAs \n",
" -- default: use Infernal & tRNA covariance models\n",
" with eukaryotic sequences \n",
" (use -B, -A, -M, -O or -G to scan other types of sequences)\n\n",
"Basic Options\n",
" -E : search for eukaryotic tRNAs (default)\n",
" -B : search for bacterial tRNAs\n",
" -A : search for archaeal tRNAs\n",
" -M <model> : search for mitochondrial tRNAs\n",
" options: mammal, vert\n",
" -O : search for other organellar tRNAs\n",
" -G : use general tRNA model (cytoslic tRNAs from all 3 domains included)\n",
" -L : search using the legacy method (tRNAscan, EufindtRNA, and COVE)\n",
" use with -E, -B, -A, -O, or -G\n",
" -I : search using Infernal (default)\n",
" use with -E, -B, -A, -O, or -G\n",
# " -T : search for tRNAs in metagenome\n",
# " -N : search for tRNAs in nuclear mitochondrial DNA regions (NUMTs)\n",
" -o <file> : save final results in <file>\n",
" -f <file> : save tRNA secondary structures to <file>\n",
" -m <file> : save statistics summary for run in <file>\n",
" (speed, # tRNAs found in each part of search, etc)\n",
" -H : show both primary and secondary structure components to\n",
" covariance model bit scores\n",
" -q : quiet mode (credits & run option selections suppressed)\n\n",
" -h : print full list (long) of available options\n\n";
}
sub print_all_options
{
print "\nUsage: tRNAscan-SE [-options] <FASTA file(s)>\n\n";
print " Scan a sequence file for tRNAs \n",
" -- default: use Infernal & tRNA covariance models\n",
" with eukaryotic sequences \n",
" (use 'Search Mode Options' below to scan other types of sequences)\n\n",
"Search Mode Options:\n\n",
" -E : search for eukaryotic tRNAs (default)\n",
" -B : search for bacterial tRNAs\n",
" -A : search for archaeal tRNAs\n",
" -M <model> : search for mitochondrial tRNAs\n",
" options: mammal, vert\n",
" -O : search for other organellar tRNAs\n",
" -G : use general tRNA model (cytoslic tRNAs from all 3 domains included)\n",
" --mt <model> : use mito tRNA models for cytosolic/mito detemination\n",
" (if not specified, only cytosolic isotype-specific model scan will be performed)\n",
# " -T : search for tRNAs in metagenome\n",
# " -N : search for tRNAs in nuclear mitochondrial DNA regions (NUMTs)\n",
" -I : search using Infernal\n",
" default use with -E, -B, -A, or -G; optional for -O\n",
" --max : maximum sensitivity mode - search using Infernal without hmm filter (very slow)\n",
" -L : search using the legacy method (tRNAscan, EufindtRNA, and COVE)\n",
" use with -E, -B, -A or -G\n",
" -C --cove : search using COVE analysis only (legacy, extremely slow)\n",
" default use with -O\n",
" -H --breakdown : show breakdown of primary and secondary structure components to\n",
" covariance model bit scores\n",
" -D --nopseudo : disable pseudogene checking\n\n",
"Output options:\n\n",
" -o --output <file> : save final results in <file>\n",
" -f --struct <file> : save tRNA secondary structures to <file>\n",
" -s --isospecific <file> : save results using isotype-specific models in <file>\n",
" -m --stats <file> : save statistics summary for run in <file>\n",
" (speed, # tRNAs found in each part of search, etc)\n",
" -b --bed <file> : save results in BED file format of <file>\n",
" -j --gff <file> : save results in GFF3 file format of <file>\n",
" -a --fasta <file> : save predicted tRNA sequences in FASTA file format of <file>\n",
" -l --log <file> : save log of program progress in <file>\n",
" --detail : display prediction outputs in detailed view\n",
" --brief : brief output format (no column headers)\n\n",
" -? \# : '#' in place of <file> chooses default name for output files\n",
" -p --prefix <label> : use <label> prefix for all default output file names\n\n",
" -d --progress : display program progress messages\n",
" -q --quiet : quiet mode (credits & run option selections suppressed)\n",
" -y --hitsrc : show origin of hits (Ts=tRNAscan 1.4, Eu=EufindtRNA, \n",
" Bo=Both Ts and Eu, Inf=Infernal)\n\n",
"Specify Alternate Cutoffs / Data Files:\n\n",
" -X --score <score> : set cutoff score (in bits) for reporting tRNAs (default=20)\n",
" -g --gencode <file> : use alternate genetic codes specified in <file> for\n",
" determining tRNA type\n",
" -z --pad <number> : use <number> nucleotides padding when passing first-pass\n",
" tRNA bounds predictions to CM analysis (default=8)\n",
" --len <length> : set max length of tRNA intron+variable region for legacy search mode\n",
" (default=116bp)\n",
"Misc Options:\n\n",
" -h --help : print this help message\n",
" -c --conf <file> : tRNAscan-SE configuration file (default: tRNAscan-SE.conf)\n",
" -Q --forceow : do not prompt user before overwriting pre-existing\n",
" result files (for batch processing)\n\n",
" --match <EXPR> : search only sequences with names matching <EXPR> string\n",
" (<EXPR> may contain * or ? wildcard chars)\n",
" --search <EXPR> : start search at sequence with name matching <EXPR> string\n",
" and continue to end of input sequence file(s)\n",
"Special Advanced Options (for testing & special purposes)\n\n",
" -U : search for tRNAs with alternate models defined in configuration file\n\n",
" -t --tscan : search using tRNAscan only (defaults to strict params)\n",
" --tmode <mode> : explicitly set tRNAscan params, where <mode>=R or S\n",
" (R=relaxed, S=strict tRNAscan v1.3 params)\n\n",
" -v --verbose <file> : save verbose tRNAscan 1.3 output to <file>\n",
" --nomerge : Keep redundant tRNAscan 1.3 hits (don't filter out multiple\n",
" predictions per tRNA identification)\n",
" -e --eufind : search using Eukaryotic tRNA finder (EufindtRNA) only\n",
" (defaults to Normal seach parameters when run alone,\n",
" or to Relaxed search params when run with Cove)\n",
" --emode <mode> : explicitly set EufindtRNA params, where <mode>=R, N, or S\n",
" (relaxed, normal, or strict)\n\n",
" --iscore <score> : manually set \"intermediate\" cutoff score for EufindtRNA\n",
" -r --fsres <file> : save first-pass scan results from EufindtRNA, tRNAscan, or\n",
" Infernal hmm in <file> in tabular results format\n",
" --mid : fast scan mode - search using Infernal with mid-level strictness of hmm filter\n",
" -F --falsepos <file> : save first-pass candidate tRNAs in <file> that were then\n",
" found to be false positives by second-pass analysis\n",
" --missed <file> : save all seqs that do NOT have at least one\n",
" tRNA prediction in them (aka \"missed\" seqs)\n",
" --thread <number> : number of threads used for running infernal (default is to use available threads)\n",
"\n\n";
}
sub set_options
{
# clear option vars
our $opt_conf= '';
our $opt_acedb=0; our $opt_quiet=0; our $opt_progress=0; our $opt_log="";
our $opt_euk=1; our $opt_bact=0; our $opt_arch=0; our $opt_organ=0; our $opt_general=0; our $opt_mito='';
our $opt_legacy=0; our $opt_inf=0; our $opt_isocm=''; our $opt_mt = '';
our $opt_metagenome=0; our $opt_numt=0;
our $opt_alt=0;
our $opt_cove=0; our $opt_mid=0; our $opt_max=0; our $opt_eufind=0; our $opt_tscan=0;
our $opt_ncintron=0; our $opt_frag='';
our $opt_breakdown=0; our $opt_nopseudo=0; our $opt_nomerge=0; our $opt_hitsrc=0;
our $opt_output=''; our $opt_struct=''; our $opt_stats=''; our $opt_isospecific=''; our $opt_bed=''; our $opt_gff=''; our $opt_fasta=''; our $opt_brief=0;
our $opt_detail=0;
our $opt_prefix=''; our $opt_match=''; our $opt_search='';
our $opt_gencode=''; our $opt_codons=0;
our $opt_tmode=''; our $opt_emode=''; our $opt_fsres=''; our $opt_filter=''; our $opt_falsepos=''; our $opt_missed='';
our $opt_score=1000; our $opt_iscore=1000; our $opt_len=-1; our $opt_pad=1000;
our $opt_help=0; our $opt_verbose=''; our $opt_forceow=0;
our $opt_w=''; our $opt_U=0; our $opt_Y=0; our $opt_thread=999;
Getopt::Long::Configure("bundling", "no_ignore_case", "no_auto_abbrev");
my $result = &GetOptions(
# Configuration
"conf|c=s","log|l=s",
# Misc option switches
"help|h",
"quiet|q","hitsrc|y","breakdown|H",
"Y",
"progress|d","nopseudo|D","codons","forceow|Q","nomerge",
# Search mode switches
"euk|E", "bact|B", "arch|A", "organ|O", "general|G", "mito|M=s",
"legacy|L", "inf|I", "isocm|S=s",
# "metagenome|T", "numt|N",
"alt|U", "mt=s",
"eufind|e", "tscan|t", "cove|C", "mid", "max",
# file name input specifiers
"gencode|g=s",
# file name output specifiers
"output|o=s", "stats|m=s", "struct|f=s", "bed|b=s", "gff|j=s", "fasta|a=s", "isospecific|s=s", "acedb", "brief",
"fsres|r=s","verbose|v=s","w=s","falsepos|F=s","missed=s", "detail",
#string parameters
"prefix|p=s","match=s","search=s","emode=s","tmode=s",
#numerical parameters
"score|X=f","iscore=f","pad|z=i","len=i",
"thread=i");
if ($opt_help)
{
print STDERR "\ntRNAscan-SE $version ($release_date)\n";
&display_credits;
&print_all_options;
exit(0);
}
if ($#ARGV < 0)
{
print STDERR "\ntRNAscan-SE $version ($release_date)\n";
print STDERR "\nFATAL: No sequence file(s) specified.\n";
&print_usage();
exit(1);
}
# set location of temp and lib files
if ($ENV{TMPDIR})
{
$global_constants->set_temp_dir($ENV{TMPDIR});
}
# set defaults
if ($opt_conf ne "")
{
$global_constants->config_file($opt_conf);
}
$global_constants->read_configuration_file();
$cm->set_defaults(\%global_vars);
$eufind->set_defaults(\%global_vars);
$tscan->set_defaults(\%global_vars);
# use input seq file name as prefix for default output file names
my $fafile = $ARGV[0];
$fafile =~ s/\.fa|\.seq$//;
# use specified prefix for default output file names, take .seq or .fa extensions off
if ($opt_prefix ne '')
{
$fafile = $opt_prefix;
}
$opts->fafile($fafile);
$opts->secondpass_int_result_file($global_constants->get("temp_dir")."/tscan$$"."_sp.out");
$opts->isotype_int_result_file($global_constants->get("temp_dir")."/tscan$$"."_iso.out");
$opts->truncated_int_result_file($global_constants->get("temp_dir")."/tscan$$"."_sp_trunc.out");
if ($opt_detail)
{
$opts->detail(1);
}
# Do NOT prompt before overwriting pre-existing output files; good for use in batch-mode jobs
if ($opt_forceow != 0)
{
$opts->prompt_for_overwrite(0);
}
# set name of result file
if ($opt_output ne '')
{
$opts->results_to_stdout(0);
if ($opt_output eq "#")
{
$opts->out_file("$fafile.out");
}
else
{
$opts->out_file($opt_output);
}
&check_output_file($opts->out_file(), $opts->prompt_for_overwrite());
}
# save results in ACeDB output
if ($opt_acedb != 0)
{
$opts->ace_output(1);
}
# use brief output (suppress column header)
if ($opt_brief != 0)
{
$opts->brief_output(1);
}
# use quite mode (suppress credits & user-selected options)
if ($opt_quiet != 0)
{
$opts->quiet_mode(1);
$log->quiet_mode(1);
}
# save source of tRNA hit
if ($opt_hitsrc != 0)
{
if ($opt_mito ne "" || $opt_numt)
{
die "FATAL: Conflicting search options have been selected. -y cannot be combined with -M.\n";
}
$opts->save_source(1);
}
# disable pseudogene filtering
if ($opt_nopseudo != 0)
{
$cm->skip_pseudo_filter(1);
}
# translate anticodon to codon for output
if ($opt_codons != 0)
{
$opts->output_codon(1);
}
# search only sequences matching KEY name
# save original KEY expr
# turning KEY into regular expression notation
if ($opt_match ne '')
{
$opts->seq_key($opt_match);
$opts->raw_seq_key($opts->seq_key());
my $key = $opts->seq_key();
$key =~ s/(\W)/\\$1/g;
$key =~ s/\\\*/\\S\*/g;
$key =~ s/\\\?/\\S/g;
$key =~ s/[\"\']//g;
$opts->seq_key($key);
}
# search all sequences after matching KEY
# save original KEY expr
# turning KEY into regular expression notation
elsif ($opt_search ne '')
{
$opts->start_at_key(1);
$opts->seq_key($opt_search);
$opts->raw_seq_key($opts->seq_key());
my $key = $opts->seq_key();
$key =~ s/(\W)/\\$1/g;
$key =~ s/\\\*/\\S\*/g;
$key =~ s/\\\?/\\S/g;
$key =~ s/[\"\']//g;
$opts->seq_key($key);
}
else
{
$opts->seq_key('\S*');
}
if ($opt_isocm ne "" and $opt_isocm ne "on" and $opt_isocm ne "off")
{
die "FATAL: Invalid value for --isocm. Please use on or off or leave out the option for default setting\n";
}
if ($opt_alt != 0)
{
if ($opt_bact || $opt_arch || $opt_general || $opt_mito ne "" || $opt_metagenome || $opt_numt)
{
die "FATAL: Conflicting search options have been selected. -U cannot be combined with other sequence type search option.\n";
}
if ($opt_isocm eq "on")
{
die "FATAL: Conflicting search options have been selected. -U cannot be combined with --isocm.\n";
}
my $cms = $global_constants->get("alt_cm");
if (!defined $cms or scalar(keys %$cms) == 0)
{
die "FATAL: Alternate covariance models are not defined in the configuration file when using -U.\n";
}
$opt_inf = 1;
$opt_eufind = 0;
$opt_tscan = 0;
$opts->search_mode("alt");
$opt_euk = 0;
$opt_mid = 1;
$cm->skip_pseudo_filter(1);
$opts->no_isotype(1);
if ($opt_ncintron != 0)
{
die "FATAL: Conflicting search options have been selected. -U and --ncintron cannot be used simultaneously.\n";
}
if ($opt_frag ne '')
{
die "FATAL: Conflicting search options have been selected. -U and --frag cannot be used simultaneously.\n";
}
$opts->CM_mode("infernal");
}
if ($opt_bact != 0)
{
if ($opt_arch || $opt_general || $opt_mito ne "" || $opt_metagenome || $opt_numt)