forked from vikas0633/perl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcnv_ltrfinder2gff.pl
1211 lines (1005 loc) · 36.5 KB
/
cnv_ltrfinder2gff.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
#-----------------------------------------------------------+
# |
# cnv_ltrfinder2gff.pl - Converts ltr_finder to gff |
# |
#-----------------------------------------------------------+
# |
# AUTHOR: James C. Estill |
# CONTACT: JamesEstill_@_gmail.com |
# STARTED: 09/14/2007 |
# UPDATED: 01/29/2010 |
# |
# DESCRIPTION: |
# Converts the LTR_FINDER results to gff format. |
# |
# VERSION: $Rev: 948 $ |
# |
# LICENSE: |
# GNU General Public License, Version 3 |
# http://www.gnu.org/licenses/gpl.html |
# |
#-----------------------------------------------------------+
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
use Cwd; # Get the current working directory
use File::Copy; # Copy files
#-----------------------------+
# PROGRAM VARIABLES |
#-----------------------------+
my ($VERSION) = q$Rev: 948 $ =~ /(\d+)/;
# Get GFF version from environment, GFF2 is DEFAULT
my $gff_ver = uc($ENV{DP_GFF}) || "GFF2";
#-----------------------------+
# VARIABLE SCOPE |
#-----------------------------+
my $infile; # Infile. textfile result from LTR_FINDER
my $outfile; # Outfile.
# Booleans
my $quiet = 0;
my $verbose = 0;
my $show_help = 0;
my $show_usage = 0;
my $show_man = 0;
my $show_version = 0;
my $append = 0; # Append gff output to existing file
my $param; # Suffix appended to the end of the gff
my $seqname; #
my $program = "ltr_finder"; # The source program
#-----------------------------+
# COMMAND LINE OPTIONS |
#-----------------------------+
my $ok = GetOptions(# REQUIRED OPTIONS
"i|infile=s" => \$infile,
"o|outfile=s" => \$outfile,
# ADDITIONAL OPTIONS
"gff-ver=s" => \$gff_ver,
"p|param=s" => \$param,
"program=s" => \$program,
"s|seqname=s" => \$seqname,
"append" => \$append,
"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_man) {
# User perldoc to generate the man documentation.
system ("perldoc $0");
exit($ok ? 0 : 2);
}
if ($show_version) {
print "\ncnv_ltrfinder2gff.pl:\n".
"Version: $VERSION\n\n";
exit;
}
#-----------------------------+
# STANDARDIZE GFF VERSION |
#-----------------------------+
unless ($gff_ver =~ "GFF3" ||
$gff_ver =~ "GFF2") {
# Attempt to standardize GFF format names
if ($gff_ver =~ "3") {
$gff_ver = "GFF3";
}
elsif ($gff_ver =~ "2") {
$gff_ver = "GFF2";
}
else {
print "\a";
die "The gff-version \'$gff_ver\' is not recognized\n".
"The options GFF2 or GFF3 are supported\n";
}
}
#-----------------------------------------------------------+
# MAIN PROGRAM BODY |
#-----------------------------------------------------------+
ltrfinder2gff ($program, $seqname, $infile, $outfile, $append, $param);
exit 0;
#-----------------------------------------------------------+
# 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 ltr_struc differs from the way
# the user is referring to the assembly
# MAY WANT TO ALLOW FOR USING THE $ls_seq_id
my ($gff_src, $seq_id, $lf_infile, $gffout, $do_append, $gff_suffix) = @_;
#////////////////////////////////////////
#////////////////////////////////////////
#////////////////////////////////////////
# ltr finder results as an array
# new 01/28/2010
my @ltr_results;
# Starting i at -1 so that increments start at 0
my $i = -1;
my $j = -1;
#////////////////////////////////////////
#////////////////////////////////////////
#////////////////////////////////////////
# The gff src id
#my $gff_src = "ltr_finder";
if ($gff_suffix) {
$gff_src = $gff_src.":".$gff_suffix;
}
my $print_gff_out = 0; # Boolean to print out gff data
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;
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
# 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
#-----------------------------+
# OPEN GFF OUTFILE |
#-----------------------------+
# Default to STDOUT if no argument given
if ($gffout) {
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";
}
}
else {
open (GFFOUT, ">&STDOUT") ||
die "Can not print to STDOUT\n";
}
if ($gff_ver =~ "GFF3") {
print GFFOUT "##gff-version 3\n";
}
#-----------------------------+
# OPEN INPUT FILE |
#-----------------------------+
if ($lf_infile) {
open (INFILE, "<$lf_infile") ||
die "ERROR: Can not open LTR_FINDER result file\n $lf_infile\n";
}
else {
print STDERR "Expecting input from STDIN\n";
open (INFILE, "<&STDIN") ||
die "Can not accept input from standard input.\n";
}
while (<INFILE>) {
chomp;
#
if (m/Nothing Header(.*)/) {
}
# IN NEW REC, GET ID
elsif (m/^\[(.*)\]/) {
#-----------------------------+
# PRINT STORED GFF OUTPUT |
# IF VALUES ARE PRESENT |
#-----------------------------+
# Increment $I and initialize j for protein domains
$i++;
$j = -1;
# override seq id if one passed
if ($seqname) {
$lf_seq_id = $seqname;
}
# # FULL SPAN
# if ($lf_span_start) {
# $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;
# }
#
# if ($lf_5ltr_start) {
# $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;
# }
#
# if ($lf_3ltr_start) {
# $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;
# }
#
# 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;
# }
#
#
# 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;
# }
#
#
# 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;
#
# }
#
#
# # Integrase Core
# if ($has_in_core) {
# #/////////
# # NOT SONG
# #\\\\\\\\\
# $gff_str_out = "$lf_seq_id\t". # Seq ID
# "$gff_src\t". # Source
# "integrase_core_domain\t". # Data type
# "$lf_in_core_dom_start\t". # Start
# "$lf_in_core_dom_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;
#
# #/////////
# # NOT SONG
# #\\\\\\\\\
# $gff_str_out = "$lf_seq_id\t". # Seq ID
# "$gff_src\t". # Source
# "integrase_core_orf\t". # Data type
# "$lf_in_core_orf_start\t". # Start
# "$lf_in_core_orf_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;
#
# } # End of has in_core
#
#
# if ($has_in_cterm) {
#
# #/////////
# # NOT SONG
# #\\\\\\\\\
# $gff_str_out = "$lf_seq_id\t". # Seq ID
# "$gff_src\t". # Source
# "integrase_cterm_domain\t". # Data type
# "$lf_in_cterm_dom_start\t". # Start
# "$lf_in_cterm_dom_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
# "integrase_cterm_orf\t". # Data type
# "$lf_in_cterm_orf_start\t". # Start
# "$lf_in_cterm_orf_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;
#
# } # End of has_in_cterm
#
# if ($has_rh) {
#
# #/////////
# # NOT SONG
# #\\\\\\\\\
# $gff_str_out = "$lf_seq_id\t". # Seq ID
# "$gff_src\t". # Source
# "rnaseh_domain\t". # Data type
# "$lf_rh_dom_start\t". # Start
# "$lf_rh_dom_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
# "rnaseh_orf\t". # Data type
# "$lf_rh_orf_start\t". # Start
# "$lf_rh_orf_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;
#
# }
#
# if ($has_rt) {
#
# #/////////
# # NOT SONG
# #\\\\\\\\\
# $gff_str_out = "$lf_seq_id\t". # Seq ID
# "$gff_src\t". # Source
# "rt_domain\t". # Data type
# "$lf_rt_dom_start\t". # Start
# "$lf_rt_dom_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
# "rt_orf\t". # Data type
# "$lf_rt_orf_start\t". # Start
# "$lf_rt_orf_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;
#
# } # End of has_reverse_transcriptase
#-----------------------------+
# LOAD ID VAR |
#-----------------------------+
# $lf_ltr_id = $1;
$ltr_results[$i]{lf_ltr_id} = $1;
}
# SEQ ID AND LENGTH
elsif (m/>Sequence: (.*) Len:(.*)/){
# Incrmenting here would be the number of contigs that are being processed
$lf_seq_id = $1;
$lf_seq_len = $2;
}
# SPAN LOCATION, LENGTH, AND STRAND
elsif (m/^Location : (\d*) - (\d*) Len: (\d*) Strand:(.)/){
# $lf_span_start = $1;
# $lf_span_end = $2;
# $lf_length = $3;
# $lf_strand = $4;
$ltr_results[$i]{lf_span_start} = $1;
$ltr_results[$i]{lf_span_end} = $2;
$ltr_results[$i]{lf_length} = $3;
$ltr_results[$i]{lf_strand} = $4;
$ltr_results[$i]{lf_seq_id} = $lf_seq_id;
}
# SCORE SIMILARITY
elsif (m/^Score : (.*) \[LTR region similarity:(.*)\]/){
$ltr_results[$i]{lf_score} = $1; # Score
$ltr_results[$i]{lf_ltr_similarity} = $2; # Similarity of LTRs
}
# STATUS SET
elsif (m/^Status : (\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)/){
# Since this is a binary string, it can be split as digits
# and used to load the $has_* booleans
$has_5ltr_tg = $1;
$has_5ltr_ca = $2;
$has_3ltr_tg = $3;
$has_3ltr_ca = $4;
$has_tsr = $5;
$has_pbs = $6;
$has_ppt = $7;
$has_rt = $8;
$has_in_core = $9;
$has_in_cterm = $10;
$has_rh = $11;
}
# 5' LTR
elsif (m/^5\'-LTR : (\d*) - (\d*) Len: (\d*)/){
$ltr_results[$i]{lf_5ltr_start} = $1;
$ltr_results[$i]{lf_5ltr_end} = $2;
$ltr_results[$i]{lf_5ltr_len} = $3;
}
# 3' LTR
elsif (m/^3\'-LTR : (\d*) - (\d*) Len: (\d*)/){
$ltr_results[$i]{lf_3ltr_start} = $1;
$ltr_results[$i]{lf_3ltr_end} = $2;
$ltr_results[$i]{lf_3ltr_len} = $3;
}
# TARGET SITE REPLICATION
elsif (m/TSR : (\d*) - (\d*) , (\d*) - (\d*) \[(.*)\]/){
$ltr_results[$i]{lf_5tsr_start} = $1;
$ltr_results[$i]{lf_5tsr_end} = $2;
$ltr_results[$i]{lf_3tsr_start} = $3;
$ltr_results[$i]{lf_3tsr_end} = $4;
$ltr_results[$i]{lf_tsr_string} = $5;
}
# SHARPNESS METRIC
elsif (m/^Sharpness: (.*),(.*)/){
$ltr_results[$i]{lf_sharp5} = $1;
$ltr_results[$i]{lf_sharp_3} = $2;
}
# PBS
elsif (m/PBS : \[(\d*)\/(\d*)\] (\d*) - (\d*) \((.*)\)/) {
$ltr_results[$i]{lf_pbs_num_match} = $1; # Number of matching bases
$ltr_results[$i]{lf_pbs_aln_len} = $2; # PBS alignment length
$ltr_results[$i]{lf_pbs_start} = $3; # Start of PBS signal
$ltr_results[$i]{lf_pbs_end} = $4; # End of PBS signal
$ltr_results[$i]{lf_pbs_trna} = $5; # PBS tRNA type and anti-codon
}
# PPT
elsif (m/PPT : \[(\d*)\/(\d*)\] (\d*) - (\d*)/) {
$ltr_results[$i]{lf_ppt_num_match} = $1;
$ltr_results[$i]{lf_ppt_aln_len} = $2;
$ltr_results[$i]{lf_ppt_start} = $3;
$ltr_results[$i]{lf_ppt_end} = $4;
}
# PROTEIN DOMAINS
# This will need to be modified and checked after another run
# using ps_scan to get the additional domains
#
#Domain: 56796 - 57326 [possible ORF:56259-59144, (IN (core))]
elsif (m/Domain: (\d*) - (\d*) \[possible ORF:(\d*)-(\d*), \((.*)\)\]/) {
my $lf_domain_name = $5;
#///////////////////////////
# PUSH ALL DOMAIN DATA TO HREF
#//////////////////////////
# Increment j for index of protein domains
$j++;
$ltr_results[$i]{lf_dom}[$j]{lf_dom_start} = $1;
$ltr_results[$i]{lf_dom}[$j]{lf_dom_end} = $2;
# 3 and 5 are potential ORFS
$ltr_results[$i]{lf_dom}[$j]{lf_dom_name} = $5;
#-----------------------------+
# NORMALIZE DOMAIN NAME |
#-----------------------------+
if ($lf_domain_name =~ 'IN \(core\)') {
$ltr_results[$i]{lf_dom}[$j]{lf_dom_name_norm} = "Integrase";
$ltr_results[$i]{lf_dom}[$j]{lf_dom_name_short} = "int";
}
elsif ($lf_domain_name =~ 'IN \(c-term\)') {
$ltr_results[$i]{lf_dom}[$j]{lf_dom_name_norm} = "C-terminal";
$ltr_results[$i]{lf_dom}[$j]{lf_dom_name_short} = "cterm";
}
elsif ($lf_domain_name =~ 'RH') {
$ltr_results[$i]{lf_dom}[$j]{lf_dom_name_norm} = "RnaseH";
$ltr_results[$i]{lf_dom}[$j]{lf_dom_name_short} = "rh";
}
elsif ($lf_domain_name =~ 'RT') {
$ltr_results[$i]{lf_dom}[$j]{lf_dom_name_norm} = "Reverse Transcriptase";
$ltr_results[$i]{lf_dom}[$j]{lf_dom_name_short} = "rvt";
}
else {
# print "\a";
# print STDERR "Unknown domain type: $lf_domain_name\n";
$ltr_results[$i]{lf_dom}[$j]{lf_dom_name_norm} = $lf_domain_name;
$ltr_results[$i]{lf_dom}[$j]{lf_dom_name_short} = $lf_domain_name;
}
} # End of elsif Domain
#-----------------------------+
# FILE HEADER INFORMATION |
#-----------------------------+
# PROGRAM NAME
elsif (m/^Program : (.*)/) {
$lf_prog_name = $1;
# $ltr_results[$i]{program} = $1;
}
# PROGRAM VERSION
elsif (m/^Version : (.*)/) {
$lf_version = $1;
# $ltr_results[$i]{lf_version} = $1;
}
# MOD HERE
if ($print_gff_out) {
}
}
close INFILE;
#-----------------------------------------------------------+
# PRINT OUTPUT FROM THE ARRAY OF HASHES |
#-----------------------------------------------------------+
for my $href ( @ltr_results ) {
# For GFF2 format attribute is same for all parts
my $attribute = "ltr_finder_".$href->{lf_ltr_id};
my $model_num = $href->{lf_ltr_id};
$model_num = sprintf("%04d", $model_num);
# parent id
my $parent_id;
# If GFF3 format encode seq_ids to follow specifications
if ($gff_ver =~ "GFF3") {
$href->{lf_seq_id} = seqid_encode( $href->{lf_seq_id} );
if ($param) {
$parent_id = "ltr_finder".
"_par".$param.
"_model".$model_num;
}
else {
$parent_id = "ltr_finder".
"_model".$model_num;
}
}
#-----------------------------+
# LTR retrotransposon span |
#-----------------------------+
if ($gff_ver =~ "GFF3") {
$attribute = "ID=".$parent_id;
}
$gff_str_out = $href->{lf_seq_id}."\t". # Seq ID
"$gff_src\t". # Source
"LTR_retrotransposon\t". # Data type
$href->{lf_span_start}."\t". # Start
$href->{lf_span_end}."\t". # End
$href->{lf_score}."\t". # Score
$href->{lf_strand}."\t". # Strand
".\t". # Frame
$attribute.
"\n";
print GFFOUT $gff_str_out;
#-----------------------------+
# 5 Prime LTR |
#-----------------------------+
if ($gff_ver =~ "GFF3") {
$attribute = "ID=".$parent_id."_five_prime_LTR".
";Name=Five Prime LTR".
";Parent=".$parent_id;
}
$gff_str_out = $href->{lf_seq_id}."\t". # Seq ID
"$gff_src\t". # Source
"five_prime_LTR\t". # Data type
$href->{lf_5ltr_start}."\t". # Start
$href->{lf_5ltr_end}."\t". # End
$href->{lf_score}."\t". # Score
$href->{lf_strand}."\t". # Strand
".\t". # Frame
$attribute.
"\n";
print GFFOUT $gff_str_out;
#-----------------------------+
# 3 Prime LTR |
#-----------------------------+
if ($gff_ver =~ "GFF3") {
$attribute = "ID=".$parent_id."_three_prime_LTR".
";Name=Three Prime LTR".
";Parent=".$parent_id;
}
$gff_str_out = $href->{lf_seq_id}."\t". # Seq ID
"$gff_src\t". # Source
"three_prime_LTR\t". # Data type
$href->{lf_3ltr_start}."\t". # Start
$href->{lf_3ltr_end}."\t". # End
$href->{lf_score}."\t". # Score
$href->{lf_strand}."\t". # Strand
".\t". # Frame
$attribute.
"\n";
print GFFOUT $gff_str_out;
#-----------------------------+
# PRIMER BINDING SITE |
#-----------------------------+
if ($gff_ver =~ "GFF3") {
$attribute = "ID=".$parent_id."_primer_binding_site".
";Name=PBS".
";Parent=".$parent_id;
}
$gff_str_out = $href->{lf_seq_id}."\t". # Seq ID
"$gff_src\t". # Source
"primer_binding_site\t". # Data type
$href->{lf_pbs_start}."\t". # Start
$href->{lf_pbs_end}."\t". # End
$href->{lf_score}."\t". # Score
$href->{lf_strand}."\t". # Strand
".\t". # Frame
$attribute.
"\n";
print GFFOUT $gff_str_out;
#-----------------------------+
# RR_tract |
#-----------------------------+
if ($gff_ver =~ "GFF3") {
$attribute = "ID=".$parent_id."_RR_tract".
";Name=PPT".
";Parent=".$parent_id;
}
$gff_str_out = $href->{lf_seq_id}."\t". # Seq ID
"$gff_src\t". # Source
"RR_tract\t". # Data type
$href->{lf_ppt_start}."\t". # Start
$href->{lf_ppt_end}."\t". # End
$href->{lf_score}."\t". # Score
$href->{lf_strand}."\t". # Strand
".\t". # Frame
$attribute.
"\n";
print GFFOUT $gff_str_out;
#-----------------------------+
# 5' TSD |
#-----------------------------+
if ( $href->{lf_5tsr_start}) {
if ($gff_ver =~ "GFF3") {
$attribute = "ID=".$parent_id."_tsd5".
";Name=Target Site Duplication".
";Parent=".$parent_id;
}
$gff_str_out = $href->{lf_seq_id}."\t". # Seq ID
"$gff_src\t". # Source
"target_site_duplication\t". # Data type
$href->{lf_5tsr_start}."\t". # Start
$href->{lf_5tsr_end}."\t". # End
$href->{lf_score}."\t". # Score
$href->{lf_strand}."\t". # Strand
".\t". # Frame
$attribute.
"\n";
print GFFOUT $gff_str_out;
}
#-----------------------------+
# 3' TSD |
#-----------------------------+
if ( $href->{lf_3tsr_start}) {
if ($gff_ver =~ "GFF3") {
$attribute = "ID=".$parent_id."_tsd3".
";Name=Target Site Duplication".
";Parent=".$parent_id;
}
$gff_str_out = $href->{lf_seq_id}."\t". # Seq ID
"$gff_src\t". # Source
"target_site_duplication\t". # Data type
$href->{lf_3tsr_start}."\t". # Start
$href->{lf_3tsr_end}."\t". # End
$href->{lf_score}."\t". # Score
$href->{lf_strand}."\t". # Strand
".\t". # Frame
$attribute.
"\n";
print GFFOUT $gff_str_out;
}
#-----------------------------+
# PROTEIN DOMAINS |
#-----------------------------+
for my $dom ( @{ $href->{lf_dom} } ) {
# The following will just print the name
my $type = $dom->{lf_dom_name_norm};
if ($gff_ver =~ "GFF3") {
$attribute = "ID=".$parent_id.$dom->{lf_dom_name_short}.
";Name=".$dom->{lf_dom_name_norm}.
";Parent=".$parent_id;
#$type = "polypeptide_domain";
$type = "transposable_element_gene";
# It may be necessary to first define a "gene" and
# then set domains..
}
$gff_str_out = $href->{lf_seq_id}."\t". # Seq ID
"$gff_src\t". # Source
$type."\t".
$dom->{lf_dom_start}."\t". # Start
$dom->{lf_dom_end}."\t". # End
$href->{lf_score}."\t". # Score
$href->{lf_strand}."\t". # Strand
".\t". # Frame
$attribute.
"\n";
print GFFOUT $gff_str_out;
}
}
close GFFOUT;
} # End of ltrfinder2gff subfunction
sub seqid_encode {
# Following conventions for GFF3 v given at http://gmod.org/wiki/GFF3
# Modified from code for urlencode in the perl cookbook
# Ids must not contain unescaped white space, so spaces are not allowed
my ($value) = @_;
$value =~ s/([^[a-zA-Z0-9.:^*$@!+_?-|])/"%" . uc(sprintf "%lx" , unpack("C", $1))/eg;
return ($value);
}
sub gff3_encode {
# spaces are allowed in attribute, but tabs must be escaped
my ($value) = @_;
$value =~ s/([^[a-zA-Z0-9.:^*$@!+_?-| ])/"%" . uc(sprintf "%lx" , unpack("C", $1))/eg;
return ($value);
}
1;
__END__
=head1 NAME
cnv_ltrfinder2gff.pl - Converts LTR_Finder output to gff format
=head1 VERSION
This documentation refers to program version $Rev: 948 $
=head1 SYNOPSIS
=head2 Usage
cnv_ltrfinder2gff.pl -i lf_result.txt -o lf_result.gff
=head2 Required Arguments
--infile # Path to the input file
# Result from a single record fasta file
--outdir # Base output dir
=head1 DESCRIPTION
Convert the ltrfinder output to gff format. This assumes that the output
from ltr_finder correspons to a single BAC. A suffix can be passed with the
--suffix option to provide a suffix for the source column. For example
run default ltr_finder results with --suffix def to create
ltr_finder:def. T
=head1 REQUIRED ARGUMENTS
=over 2
=item -i,--infile
Path of the input file. If an input file is not provided, the program
will expect input from STDIN.
=item -o,--outfile
Path of the output file. If an output path is not provided,