-
Notifications
You must be signed in to change notification settings - Fork 5
/
batch_ltrfinder.pl
2553 lines (2090 loc) · 73.8 KB
/
batch_ltrfinder.pl
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 -w
#-----------------------------------------------------------+
# |
# batch_ltrfinder.pl - Run ltr_finder in batch mode |
# |
#-----------------------------------------------------------+
# |
# AUTHOR: James C. Estill |
# CONTACT: JamesEstill_@_gmail.com |
# STARTED: 10/03/2007 |
# UPDATED: 03/24/2009 |
# |
# DESCRIPTION: |
# Run the LTR_FINDER program in batch mode and extract |
# output to gff files, summary text files, fasta files and |
# a tab delimited summary sequence file. |
# |
# VERSION: $Rev: 948 $ |
# |
# LICENSE: |
# GNU General Public License, Version 3 |
# http://www.gnu.org/licenses/gpl.html |
# |
#-----------------------------------------------------------+
# TO DO: -Reset vals to null and only print output when expected vals
# are not null
# -No gff output if no hits in ltr_finder
# -Add possiblity to extract sequence data
package DAWGPAWS;
#-----------------------------+
# INCLUDES |
#-----------------------------+
use strict;
use Getopt::Long;
# The following needed for printing help
use Pod::Select; # Print subsections of POD documentation
use Pod::Text; # Print POD doc as formatted text file
use IO::Scalar; # For print_help subfunction
use IO::Pipe; # Pipe for STDIN, STDOUT for POD docs
use File::Spec; # Convert a relative path to an abosolute path
#-----------------------------+
# PROGRAM VARIABLES |
#-----------------------------+
my ($VERSION) = q$Rev: 948 $ =~ /(\d+)/;
#-----------------------------+
# VARIABLE SCOPE |
#-----------------------------+
my $indir; # Input dir of fasta files
my $outdir; # Base output dir
my $config_file; # Configuration file
# GLOBAL SEQUENCE STRING OBJECTS
my $seq_in; # Full fasta file input object
my $qry_seq; # The full query sequence object
# LTR Finder Parameters
my @lf_params = (); # 2d Array to hold the find_ltr parameters
# Booleans
my $quiet = 0;
my $verbose = 0;
my $show_help = 0;
my $show_usage = 0;
my $show_man = 0;
my $show_version = 0;
my $do_gff_convert = 1;
my $do_feat_seq = 0; # Extract feature sequence data
# Counters/Index Vals
my $i = 0; # Array index val
my $file_num = 0; # File number
my $proc_num = 0; # Process number
# Vars needing
my $name_root;
my $gff_dir;
my $ls_out;
my $fl_gff_outpath;
#-----------------------------+
# USER ENV OPTIONS |
#-----------------------------+
# If variable not defined in the ENV then
# assume it is in the user's path and that the Oryza tRNA database
# is the preferred database
my $trna_db = $ENV{TRNA_DB} ||
"Os-tRNAs.fa";
my $prosite_dir = $ENV{PROSITE_DIR} ||
"ps_scan";
my $lf_path = $ENV{LTR_FINDER} ||
"ltr_finder";
#-----------------------------+
# COMMAND LINE OPTIONS |
#-----------------------------+
my $ok = GetOptions(# REQUIRED ARGUMENTS
"i|indir=s" => \$indir,
"o|outdir=s" => \$outdir,
"c|config=s" => \$config_file,
# ADDITIONAL OPTIONS
"ltr-finder=s" => \$lf_path, # LTR Finder Path
"s|trna-db=s" => \$trna_db, # s as per program
"a|prosite=s" => \$prosite_dir, # a as per program
"f|feat-seq" => \$do_feat_seq,
"g|gff" => \$do_gff_convert,
"q|quiet" => \$quiet,
"verbose" => \$verbose,
# ADDITIONAL INFORMATION
"usage" => \$show_usage,
"version" => \$show_version,
"man" => \$show_man,
"h|help" => \$show_help,);
#-----------------------------+
# SHOW REQUESTED HELP |
#-----------------------------+
if ( ($show_usage) ) {
# print_help ("usage", File::Spec->rel2abs($0) );
print_help ("usage", $0 );
}
if ( ($show_help) || (!$ok) ) {
# print_help ("help", File::Spec->rel2abs($0) );
print_help ("help", $0 );
}
if ($show_version) {
print "\nbatch_ltrfinder.pl:\nVersion: $VERSION\n\n";
exit;
}
if ($show_man) {
# User perldoc to generate the man documentation.
system("perldoc $0");
exit($ok ? 0 : 2);
}
#-----------------------------+
# CHECK REQUIRED ARGS |
#-----------------------------+
if ( (!$indir) || (!$outdir) || (!$config_file) ) {
print "\a";
print STDERR "\n";
print STDERR "ERROR: An input directory must be specified".
" at the command line.\n" if (!$indir);
print STDERR "ERROR: An output directory must be specified".
" at the command line.\n" if (!$outdir);
print STDERR "ERROR: A config file must be specified".
" at the command line.\n" if (!$config_file);
print_help ("usage", $0 );
exit;
}
#-----------------------------------------------------------+
# IF SEQ FEATURE STRINGS REQUESTED LOAD REQUIRED MODULES |
#-----------------------------------------------------------+
# This will only attempt to use these objects when they are needed for parsing
# sequence strings.
if ($do_feat_seq) {
use Bio::Location::Simple; # Used to get revcom of substrings
use Bio::Seq; # Fetch seq and do substrings
use Bio::SeqIO; # Seq IO
use Bio::Location::Simple; # Used to get reverse complement when needed
}
#-----------------------------------------------------------+
# MAIN PROGRAM BODY |
#-----------------------------------------------------------+
#-----------------------------+
# CHECK FOR SLASH IN DIR |
# VARIABLES |
#-----------------------------+
# If the indir does not end in a slash then append one
# TO DO: Allow for backslash
unless ($indir =~ /\/$/ ) {
$indir = $indir."/";
}
unless ($outdir =~ /\/$/ ) {
$outdir = $outdir."/";
}
#-----------------------------+
# CREATE THE OUT DIR |
# IF IT DOES NOT EXIST |
#-----------------------------+
unless (-e $outdir) {
print "Creating output dir ...\n" if $verbose;
mkdir $outdir ||
die "Could not create the output directory:\n$outdir";
}
#-----------------------------+
# LOAD THE CONFIG FILE |
#-----------------------------+
$i=0;
my $config_line_num=0;
open (CONFIG, "<$config_file") ||
die "ERROR Can not open the config file:\n $config_file";
while (<CONFIG>) {
chomp;
$config_line_num++;
unless (m/^\#/) {
my @in_line = split (/\t/); # Implicit split of $_ by tab
my $num_in_line = @in_line;
# Can have just a name to run LTR_Finder with default settings
# or can have two columns with additional parameter options
# parameter options in the second columns.
# I will currently stick with the two column config file
# since there are so many options availabe with LTR_FINDER
# that a multiple column config file would get messy.
if ($num_in_line < 3) {
$lf_params[$i][0] = $in_line[0] || "NULL"; # Name
$lf_params[$i][1] = $in_line[1] || ""; # Suffix
$i++;
} # End of if $num_in_line is 10
else {
print "\a";
print STDERR "WARNING: Unexpected number of line in config".
" file line $config_line_num\n$config_file\n";
}
} # End of unless comment line
} # End of while CONFIG file
close CONFIG;
# Number of parameter sets specified in the config file
my $num_par_sets = $i;
if ($num_par_sets == 0) {
print "\a";
print STDERR "ERROR: No parameter sets were found in the config file:\n".
"$config_file\n";
exit;
}
#-----------------------------+
# GET THE FASTA FILES FROM THE|
# DIRECTORY PROVIDED BY THE |
#$indir VARIABLE |
#-----------------------------+
opendir( DIR, $indir ) ||
die "Can't open directory:\n$indir";
my @fasta_files = grep /\.fasta$|\.fa$/, readdir DIR ;
closedir( DIR );
my $num_files = @fasta_files;
if ($num_files == 0) {
print "\a";
print "ERROR: No input fasta files were found in the directroy:\n$indir\n";
print "Fasta files must end with the fasta or fa extension\n";
exit;
}
my $num_proc_total = $num_files * $num_par_sets;
print STDERR "$num_proc_total find_ltr runs to process\n\n" if $verbose;
for my $ind_file (@fasta_files) {
$file_num++;
# Get root file name
if ($ind_file =~ m/(.*)\.masked\.fasta$/) {
# file ends in .masked.fasta
$name_root = "$1";
}
elsif ($ind_file =~ m/(.*)\.fasta$/ ) {
# file ends in .fasta
$name_root = "$1";
}
elsif ($ind_file =~ m/(.*)\.fa$/ ) {
# file ends in .fa
$name_root = "$1";
}
else {
$name_root = $ind_file;
}
#-----------------------------+
# CREATE ROOT NAME DIR |
#-----------------------------+
my $name_root_dir = $outdir.$name_root."/";
unless (-e $name_root_dir) {
mkdir $name_root_dir ||
die "Could not create dir:\n$name_root_dir\n"
}
#-----------------------------+
# CREATE LTR_FINDER OUTDIR |
#-----------------------------+
# Dir to hold gene prediction output from local software
my $ltrfinder_dir = $name_root_dir."ltr_finder/";
unless (-e $ltrfinder_dir) {
mkdir $ltrfinder_dir ||
die "Could not create ltr_finder out dir:\n$ltrfinder_dir\n";
}
#-----------------------------+
# CREATE GFF OUTDIR |
#-----------------------------+
if ($do_gff_convert) {
$gff_dir = $name_root_dir."gff/";
unless (-e $gff_dir) {
mkdir $gff_dir ||
die "Could not create gff out dir:\n$gff_dir\n";
}
}
#-----------------------------------------------------------+
# LOAD SEQUENCE TO STRING IF WE WANT TO EXTRACT FEATURES |
#-----------------------------------------------------------+
# TODO: This should also do the test to make sure that this is a fasta file
# with a single record
if ($do_feat_seq) {
my $lf_qryseqpath = $indir.$ind_file;
$seq_in = Bio::SeqIO->new ( '-format' => 'fasta',
'-file' => "<$lf_qryseqpath")
|| die "Can not open sequence file $lf_qryseqpath";
# THE FOLLOWING ERROR CHECK WOULD BE HELPFUL
# If number of seqs in object is one move forward
# otherwise throw error.
# Try using next_seq outside of a while statement
# This appears to work.
$qry_seq = $seq_in->next_seq();
}
#-----------------------------------------------------------+
# RUN LTR_FINDER FOR EACH SET OF PARAM VALS IN CONFIG FILE |
#-----------------------------------------------------------+
for ($i=0; $i<$num_par_sets; $i++) {
$proc_num++;
# Load parameters from array refs to name vars
my $lf_gff_suffix = $lf_params[$i][0]; # Name of the parameter set
my $lf_cmd_suffix = $lf_params[$i][1]; # Name of the parameter set
# Status proces number
my $stat_par_num = $i+1;
print STDERR "\n#------------------------------------\n" if $verbose;
print STDERR "# Processing $name_root $lf_gff_suffix\n" if $verbose;
print STDERR "# Seq $file_num of $num_files\n" if $verbose;
print STDERR "# Par $stat_par_num of $num_par_sets\n" if $verbose;
print STDERR "# PROCESS $proc_num of $num_proc_total\n" if $verbose;
print STDERR "#------------------------------------\n\n" if $verbose;
# lf_out is path of the ltrfinder output file
my $lf_inseqpath = $indir.$ind_file;
my $lf_out = $ltrfinder_dir.$name_root."_".$lf_gff_suffix.
"_ltr_finder.txt";
my $lf_gff_outpath = $gff_dir.$name_root."_".$lf_gff_suffix.
"_ltr_finder.gff";
my $lf_summary_outpath = $gff_dir.$name_root."_".$lf_gff_suffix.
"_lf_summary";
my $lf_cmd = "$lf_path $lf_inseqpath".
" -s $trna_db".
" -a $prosite_dir".
" $lf_cmd_suffix".
" > $lf_out";
print STDERR "\tCMD:$lf_cmd\n" if $verbose;
system ($lf_cmd);
#-----------------------------+
# CONVERT OUTPUT TO GFF |
#-----------------------------+
if ( (-e $lf_out) && ($do_gff_convert) ) {
ltrfinder2gff ( $name_root, $lf_out, $lf_gff_outpath,
0, $lf_gff_suffix, $do_feat_seq,$ltrfinder_dir,
$lf_summary_outpath);
}
# Check the global aspect of the seq record
#print STDERR "SEQ LEN: ".$qry_seq->length()."\n" if $verbose;
}
} # End of for each individual fasta file
exit;
#-----------------------------------------------------------+
# SUBFUNCTIONS |
#-----------------------------------------------------------+
sub print_help {
my ($help_msg, $podfile) = @_;
# help_msg is the type of help msg to use (ie. help vs. usage)
print "\n";
#-----------------------------+
# PIPE WITHIN PERL |
#-----------------------------+
# This code made possible by:
# http://www.perlmonks.org/index.pl?node_id=76409
# Tie info developed on:
# http://www.perlmonks.org/index.pl?node=perltie
#
#my $podfile = $0;
my $scalar = '';
tie *STDOUT, 'IO::Scalar', \$scalar;
if ($help_msg =~ "usage") {
podselect({-sections => ["SYNOPSIS|MORE"]}, $0);
}
else {
podselect({-sections => ["SYNOPSIS|ARGUMENTS|OPTIONS|MORE"]}, $0);
}
untie *STDOUT;
# now $scalar contains the pod from $podfile you can see this below
#print $scalar;
my $pipe = IO::Pipe->new()
or die "failed to create pipe: $!";
my ($pid,$fd);
if ( $pid = fork() ) { #parent
open(TMPSTDIN, "<&STDIN")
or die "failed to dup stdin to tmp: $!";
$pipe->reader();
$fd = $pipe->fileno;
open(STDIN, "<&=$fd")
or die "failed to dup \$fd to STDIN: $!";
my $pod_txt = Pod::Text->new (sentence => 0, width => 78);
$pod_txt->parse_from_filehandle;
# END AT WORK HERE
open(STDIN, "<&TMPSTDIN")
or die "failed to restore dup'ed stdin: $!";
}
else { #child
$pipe->writer();
$pipe->print($scalar);
$pipe->close();
exit 0;
}
$pipe->close();
close TMPSTDIN;
print "\n";
exit 0;
}
sub ltrfinder2gff {
# seq_id could be extracted from the ltrfinder result
# but passing it to the subfunction directly allows for cases
# where the id assigned by ltrfinder differs from the way
# the user is referring to the assembly
# The gff outfile path is passed to the function
my ($seq_id, $lf_infile, $gffout, $do_append, $gff_suffix,
$do_feat_seq, $ltrfinder_dir,$sumout_root) = @_;
# FILE PATHS
my $sumout_file = $sumout_root."_short.txt";
my $sumout_seq_file = $sumout_root."_seq.txt";
# The gff src id
my $gff_src = "ltr_finder:".$gff_suffix;
my $gff_str_out; # A single out string line of gff out
# LTF FINDER COUTNERS/INDICES
my $lf_id_num = 0; # Incremented for every predicted model
# LTR_FINDER BOOLEANS
my $in_emp_details = 0; # Exact match pairs details
my $in_ltr_align = 0; # Details of the LTR alignment
my $in_pbs_align = 0;
my $in_ppt;
# By default assume ltr_retro found
my $has_ltr_retro = 1; # Does the sequence have an LTR retrotransposon
#
my $lf_prog_name; # LTR Finder program name
my $lf_seq_id; # Seq id
my $lf_seq_len; # Sequence length
my $lf_version; # Version of LTR finder being parsed
my $lf_trna_db; # tRNA database used
# Genearl LTR Retrotransposon Span variables
my $lf_strand; # Strand of the LTR Retro
my $lf_span_start; # Location start
my $lf_span_end; # Location end
my $lf_length; # Length
my $lf_score; # Score
my $lf_ltr_similarity; # Similarity of the LTRs
# Status strings
my $has_5ltr_tg; # TG in 5' END of 5' LTR
my $has_5ltr_ca; # CA in 3' END of 5' LTR
my $has_3ltr_tg; # TG in 5' END of 3' LTR
my $has_3ltr_ca; # CA in 3' END of 3' LTR
my $has_tsr; # Has Target Site Replication
my $has_pbs; # Has Primer Binding Site
my $has_ppt; # Has Poly Purine Tract
my $has_rt; # Has Reverse Transcriptase
my $has_in_core; # Has Integrase Core
my $has_in_cterm; # Has Integrase C-term
my $has_rh; # Has RNAseH
my $lf_ltr_id; # LTR Retro Id number
# LTR COORDINATES
my $lf_5ltr_start;
my $lf_5ltr_end;
my $lf_5ltr_len;
my $lf_3ltr_start;
my $lf_3ltr_end;
my $lf_3ltr_len;
# TSR COORDINATES
my $lf_5tsr_start; # Start of the 5' TSR
my $lf_5tsr_end; # End of the 5' TSR
my $lf_3tsr_start; # Start of the 3' TSR
my $lf_3tsr_end; # End of the 3' TSR
my $lf_tsr_string; # String of bases in the TSR
# BOUNDARY SHARPNESS
my $lf_sharp_5; # Sharpness of 5' Boundary
my $lf_sharp_3; # Sharpness of 3' Boundary
# PBS
my $lf_pbs_num_match; # Number of matched bases in the PBS
my $lf_pbs_aln_len; # PBS alignment length
my $lf_pbs_start; # Start of the PBS signal
my $lf_pbs_end; # End of the PBS signal
my $lf_pbs_trna; # PBS tRNA type and anti-codon
# PPT
my $lf_ppt_num_match; # Number of matched based in the PPT
my $lf_ppt_aln_len; # PPT alignment length
my $lf_ppt_start; # Start of the PPT
my $lf_ppt_end; # End of the PPT
#-----------------------------+
# DOMAIN DATA |
#-----------------------------+
# GENERAL DOMAIN VARS
my $lf_domain_dom_start;
my $lf_domain_dom_end;
my $lf_domain_orf_start;
my $lf_domain_orf_end;
my $lf_domain_name; # Type of the domain
# INTEGRASE CORE
#my $has_in_core = 0; # Boolean for has integrase core
my $lf_in_core_dom_start;
my $lf_in_core_dom_end;
my $lf_in_core_orf_start;
my $lf_in_core_orf_end;
# INTEGRASE C-TERM
#my $has_in_cterm = 0;
my $lf_in_cterm_dom_start;
my $lf_in_cterm_dom_end;
my $lf_in_cterm_orf_start;
my $lf_in_cterm_orf_end;
# RNASEH
#my $has_rh = 0;
my $lf_rh_dom_start;
my $lf_rh_dom_end;
my $lf_rh_orf_start;
my $lf_rh_orf_end;
# RT
#my $has_rt = 0;
my $lf_rt_dom_start;
my $lf_rt_dom_end;
my $lf_rt_orf_start;
my $lf_rt_orf_end;
#-----------------------------+
# OPEN SUMMARY OUTFILE |
#-----------------------------+
open (SUMOUT, ">$sumout_file" ) ||
die "ERROR: Can not open summary outfile:n\ $sumout_file\n";
open (SUMSEQ, ">$sumout_seq_file" ) ||
die "ERROR Can not open summary seq outfile:\n $sumout_seq_file\n";
#-----------------------------+
# OPEN GFF OUTFILE |
#-----------------------------+
if ($do_append) {
open (GFFOUT, ">>$gffout") ||
die "ERROR: Can not open gff outfile:\n $gffout\n";
}
else {
open (GFFOUT,">$gffout") ||
die "ERROR: Can not open gff outfile:\n $gffout\n";
}
# Test of squence in the subfunction
if ($do_feat_seq) {
print "SEQ NAME: ".$qry_seq->primary_id()."\n" if $verbose;
}
#-----------------------------+
# OPEN INPUT FILE |
#-----------------------------+
open (INFILE, "<$lf_infile") ||
die "ERROR: Can not open LTR_FINDER result file\n $lf_infile\n";
while (<INFILE>) {
chomp;
# The following can be used to print LTR Finder output as
# it is parsed
# print STDERR $_."\n";
# CHECK BOOLEANS
#
if (m/Nothing Header(.*)/) {
}
elsif (m/No LTR Retrotransposons Found/) {
# No LTR Retrotransposons Found
# Set has_ltr_retro to false
$has_ltr_retro = 0;
print STDERR "\n\n\n\nHAS NO LTR RETROS\n\n\n\n" if $verbose;
}
#///////////////////////////////////////
# PAY ATTENTION BELOW THIS MAY BE THE
# PLACE TO PRINT OUT SAVED GFF DATA
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
# IN NEW REC, GET ID
elsif (m/^\[(.*)\]/) {
#-----------------------------------------------------------+
# PRINT STORED GFF OUTPUT AND SUMMARY OUT |
#-----------------------------------------------------------+
unless ($1 == 1 ) {
#-----------------------------+
# SUMMARY OUTPUT |
#-----------------------------+
print SUMOUT $seq_id."_LTRFinder_".$gff_suffix.$lf_ltr_id."\t".
$lf_span_start."\t". # 2
$lf_span_end."\t". # 3
$lf_length."\t". # 4
$lf_score."\t". # 5
# LTR INFO
$lf_ltr_similarity."\t". # 6
$lf_5ltr_len."\t". # 7
$lf_3ltr_len."\t". # 8
$lf_sharp_5."\t". # 9
$lf_sharp_3."\t". # 10
# BOOLEANS
$has_5ltr_tg."\t". # 11
$has_5ltr_ca."\t". # 12
$has_3ltr_tg."\t". # 13
$has_3ltr_ca."\t". # 14
$has_tsr."\t". # 15
$has_pbs."\t". # 16
$has_ppt."\t". # 17
$has_rt."\t". # 18
$has_in_core."\t". # 19
$has_in_cterm."\t". # 20
$has_rh. # 21
"\n"; # NEWLINE
print SUMSEQ $seq_id."_LTRFinder_".$gff_suffix.$lf_ltr_id."\t";
# Two alternatives here
# keep appending to gff_lout or LTR Retro object
# variable and then print set
# or print line at a time .. currently printing
# a line at a time. JCE 10/02/2007
# Advantage to this approach is that it is not memory
# limited. Extracted LTR sequences for entire chromosomes
# could run into mememory limites using an object
# oriented approach.
#-----------------------------+
# FULL SPAN OF LTR RETRO |
#-----------------------------+
$gff_str_out = "$lf_seq_id\t". # Seq ID
"$gff_src\t". # Source
"LTR_retrotransposon\t". # Data type
"$lf_span_start\t". # Start
"$lf_span_end\t". # End
"$lf_score\t". # Score
"$lf_strand\t". # Strand
".\t". # Frame
"ltr_finder_$lf_ltr_id\n"; # Retro ID
print GFFOUT $gff_str_out;
# Extract sequence
if ($do_feat_seq) {
my $feat_strand;
my $seq_header = $seq_id."_LTRFinder_".$gff_suffix.
$lf_ltr_id."_LTR_retrotransposon";
my $out_seq_path = $ltrfinder_dir.$seq_header.".fasta";
print ">$seq_header\n";
if ($lf_strand =~ "-") {
$feat_strand="-1";
}
else {
$feat_strand="1";
}
# TEMP PRINT OF FEATURE STRAND
print STDERR "STRAND: $feat_strand\n" if $verbose;
my $loc = Bio::Location::Simple->
new(-start => $lf_span_start,
-end => $lf_span_end,
-strand => $feat_strand);
# Sequene of the feature
my $feat_seq = $qry_seq->subseq($loc);
open (SEQOUT,">$out_seq_path") ||
die "Can not open\n:$out_seq_path\n";
print SEQOUT ">$seq_header\n";
print SEQOUT "$feat_seq\n";
close SEQOUT;
print SUMSEQ "$feat_seq\t";
}
# END EXTRACT SEQUENCE
#-----------------------------+
# PRIMER BINDING SITE |
#-----------------------------+
if ($has_pbs) {
$gff_str_out = "$lf_seq_id\t". # Seq ID
"$gff_src\t". # Source
"primer_binding_site\t". # Data type
"$lf_pbs_start\t" . # Start
"$lf_pbs_end\t". # End
"$lf_score\t". # Score
"$lf_strand\t". # Strand
".\t". # Frame
"ltr_finder_$lf_ltr_id\n"; # Retro ID
print GFFOUT $gff_str_out;
# Extract sequence
if ($do_feat_seq) {
my $feat_strand;
my $seq_header = $seq_id."_LTRFinder_".$gff_suffix.
$lf_ltr_id."_primer_binding_site";
my $out_seq_path = $ltrfinder_dir.
$seq_header.".fasta";
print ">$seq_header\n";
if ($lf_strand =~ "-") {
$feat_strand="-1";
}
else {
$feat_strand="1";
}
my $loc = Bio::Location::Simple->
new(-start => $lf_pbs_start,
-end => $lf_pbs_end,
-strand => $feat_strand);
# Sequene of the feature
my $feat_seq = $qry_seq->subseq($loc);
open (SEQOUT,">$out_seq_path") ||
die "Can not open\n:$out_seq_path\n";
print SEQOUT ">$seq_header\n";
print SEQOUT "$feat_seq\n";
close SEQOUT;
print SUMSEQ "$feat_seq\t";
}
# END EXTRACT SEQUENCE
} #
else {
# Case where we want to extract seq features but
# PBS is not present
if ($do_feat_seq) {
print SUMSEQ ".\t";
}
}
#-----------------------------+
# POLYPURINE TRACT |
#-----------------------------+
if ($has_ppt) {
$gff_str_out = "$lf_seq_id\t". # Seq ID
"$gff_src\t". # Source
"RR_tract\t". # Data type
"$lf_ppt_start\t". # Start
"$lf_ppt_end\t". # End
"$lf_score\t". # Score
"$lf_strand\t". # Strand
".\t". # Frame
"ltr_finder_$lf_ltr_id\n"; # Retro ID
print GFFOUT $gff_str_out;
# Extract sequence
if ($do_feat_seq) {
my $feat_strand;
my $seq_header = $seq_id."_LTRFinder_".$gff_suffix.
$lf_ltr_id."_RR_tract";
my $out_seq_path = $ltrfinder_dir.
$seq_header.".fasta";
print ">$seq_header\n";
if ($lf_strand =~ "-") {
$feat_strand="-1";
}
else {
$feat_strand="1";
}
my $loc = Bio::Location::Simple->
new(-start => $lf_ppt_start,
-end => $lf_ppt_end,
-strand => $feat_strand);
# Sequene of the feature
my $feat_seq = $qry_seq->subseq($loc);
open (SEQOUT,">$out_seq_path") ||
die "Can not open :\n$out_seq_path\n";
print SEQOUT ">$seq_header\n";
print SEQOUT "$feat_seq\n";
close SEQOUT;
}
# END EXTRACT SEQUENCE
}
else {
# Case where we want to extract seq features but
# PPT is not present
if ($do_feat_seq) {
print SUMSEQ ".\t";
}
}
#-----------------------------+
# 5' LTR |
#-----------------------------+
$gff_str_out = "$lf_seq_id\t". # Seq ID
"$gff_src\t". # Source
"five_prime_LTR\t". # Data type
"$lf_5ltr_start\t". # Start
"$lf_5ltr_end\t". # End
"$lf_score\t". # Score
"$lf_strand\t". # Strand
".\t". # Frame
"ltr_finder_$lf_ltr_id\n"; # Retro ID
print GFFOUT $gff_str_out;
# Extract sequence
if ($do_feat_seq) {
my $feat_strand;
my $seq_header = $seq_id."_LTRFinder_".$gff_suffix.
$lf_ltr_id."_five_prime_LTR";
my $out_seq_path = $ltrfinder_dir.$seq_header.".fasta";
print ">$seq_header\n";
if ($lf_strand =~ "-") {
$feat_strand="-1";
}
else {
$feat_strand="1";
}
my $loc = Bio::Location::Simple->new
(-start => $lf_5ltr_start,
-end => $lf_5ltr_end,
-strand => $feat_strand);
# Sequene of the feature
my $feat_seq = $qry_seq->subseq($loc);
open (SEQOUT,">$out_seq_path") ||
die "Can not open :\n$out_seq_path\n";
print SEQOUT ">$seq_header\n";
print SEQOUT "$feat_seq\n";
close SEQOUT;
# PRINT TO SUMMARY SEQUENCE FILE
print SUMSEQ "$feat_seq\t";
}
# END EXTRACT SEQUENCE
#-----------------------------+
# 3' LTR |
#-----------------------------+
$gff_str_out = "$lf_seq_id\t". # Seq ID
"$gff_src\t". # Source
"three_prime_LTR\t". # Data type
"$lf_3ltr_start\t". # Start
"$lf_3ltr_end\t". # End
"$lf_score\t". # Score
"$lf_strand\t". # Strand
".\t". # Frame
"ltr_finder_$lf_ltr_id\n"; # Retro ID
print GFFOUT $gff_str_out;
# Extract sequence
if ($do_feat_seq) {
my $feat_strand;
my $seq_header = $seq_id."_LTRFinder_".$gff_suffix.
$lf_ltr_id."_three_prime_LTR";
my $out_seq_path = $ltrfinder_dir.$seq_header.".fasta";
print ">$seq_header\n";
if ($lf_strand =~ "-") {
$feat_strand="-1";
}
else {
$feat_strand="1";
}
my $loc = Bio::Location::Simple->
new(-start => $lf_3ltr_start,
-end => $lf_3ltr_end,
-strand => $feat_strand);
# Sequene of the feature
my $feat_seq = $qry_seq->subseq($loc);
open (SEQOUT,">$out_seq_path") ||
die "Can not open:\n$out_seq_path\n";
print SEQOUT ">$seq_header\n";
print SEQOUT "$feat_seq\n";
close SEQOUT;
# PRINT TO SUMMARY SEQUENCE FILE
print SUMSEQ "$feat_seq\t";
}
# END EXTRACT SEQUENCE
#-----------------------------+
# TARGET SITE DUPLICATION |
#-----------------------------+
if ($has_tsr) {
$gff_str_out = "$lf_seq_id\t". # Seq ID
"$gff_src\t". # Source
"target_site_duplication\t". # Data type
"$lf_5tsr_start\t". # Start
"$lf_5tsr_end\t". # End
"$lf_score\t". # Score
"$lf_strand\t". # Strand
".\t". # Frame
"ltr_finder_$lf_ltr_id\n"; # Retro ID
print GFFOUT $gff_str_out;
$gff_str_out = "$lf_seq_id\t". # Seq ID
"$gff_src\t". # Source
"target_site_duplication\t". # Data type
"$lf_3tsr_start\t". # Start
"$lf_3tsr_end\t". # End
"$lf_score\t". # Score
"$lf_strand\t". # Strand
".\t". # Frame
"ltr_finder_$lf_ltr_id\n"; # Retro ID
print GFFOUT $gff_str_out;
# Extract sequence