forked from vikas0633/perl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatch_ltrseq.pl
1331 lines (1041 loc) · 38.8 KB
/
batch_ltrseq.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_ltrseq.pl - Run the LTR_seq program in batch mode |
# |
#-----------------------------------------------------------+
# |
# AUTHOR: James C. Estill |
# CONTACT: JamesEstill_@_gmail.com |
# STARTED: 09/06/2007 |
# UPDATED: 03/09/2010 |
# |
# 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
#-----------------------------+
# 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 $indir;
my $outdir;
my $file_config;
# This is the dir that will hold the config files
my $ltrseq_dir = $ENV{LTR_SEQ_DIR} || $ENV{HOME};
# Path to the LTRseq binary
my $ltrseq_bin = $ENV{LTR_SEQ_BIN} || "LTR_seq";
my $program="LTR_seq";
# Booleans
my $help = 0;
my $quiet = 0;
my $show_help = 0;
my $show_usage = 0;
my $show_man = 0;
my $show_version = 0;
my $verbose = 0;
my $do_test = 0;
#-----------------------------+
# COMMAND LINE OPTIONS |
#-----------------------------+
my $ok = GetOptions("i|indir=s" => \$indir,
"o|outdir=s" => \$outdir,
# OPTIONS
"program=s" => \$program,
"gff-ver=s" => \$gff_ver,
"c|config=s" => \$file_config,
"config-dir=s" => \$ltrseq_dir,
"ltrseq-bin=s" => \$ltrseq_bin,
"test" => \$do_test,
"usage" => \$show_usage,
"version" => \$show_version,
"man" => \$show_man,
"h|help" => \$show_help,
"verbose" => \$verbose,
"q|quiet" => \$quiet,);
#-----------------------------+
# 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 "\nbatch_ltrseq.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";
}
}
#-----------------------------+
# CHECK REQUIRED ARGS |
#-----------------------------+
if ( (!$indir) || (!$outdir) ) {
print "\a";
print STDERR "\n";
print STDERR "ERROR: An input directory was not specified at the".
" command line\n" if (!$indir);
print STDERR "ERROR: An output directory was specified at the".
" command line\n" if (!$outdir);
print_help ("usage", $0 );
}
#-----------------------------+
# 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."/";
}
unless ($ltrseq_dir =~ /\/$/ ) {
$ltrseq_dir = $ltrseq_dir."/";
}
#-----------------------------------------------------------+
# MAIN PROGRAM BODY |
#-----------------------------------------------------------+
#-----------------------------+
# Get the FASTA files from the|
# directory provided by the |
# var $indir |
#-----------------------------+
opendir( DIR, $indir ) ||
die "Can't open directory:\n$indir";
my @fasta_files = grep /\.fasta$|\.fa$/, readdir DIR ;
closedir( DIR );
my $count_files = @fasta_files;
#-----------------------------+
# SHOW ERROR IF NO FILES |
# WERE FOUND IN THE INPUT DIR |
#-----------------------------+
if ($count_files == 0) {
print STDERR "\a";
print STDERR "\nERROR: No fasta files were found in the input directory\n".
"$indir\n".
"Fasta files must have the fasta or fa extension.\n\n";
exit;
}
#-----------------------------+
# GET INFO FROM CONFIG FILE |
#-----------------------------+
my @config_opts;
if ($file_config) {
my $i;
# Load to the 2d config_opts array
open (CONFIG, $file_config) ||
die "Can't open the config file:\n$file_config";
$i = 0;
my $line_num = 0;
while (<CONFIG>) {
$line_num ++;
next if m/^\#/;
chomp;
my @tmpary = split (/\t/);
my $count_tmp = @tmpary;
if ($count_tmp == 2) {
$config_opts[$i][0] = $tmpary[0]; # Config name
# The following assumes the full path is in the config file
#$config_opts[$i][1] = $tmpary[1]; # Config file
$config_opts[$i][1] = $ltrseq_dir.$tmpary[1]; # Config file path
$i++;
}
elsif ($count_tmp == 1) {
# Problem, this may also happen if the config file has not
# been delimited by tabs.
# use default options for ltr_seq if only a name is given
$config_opts[$i][0] = $tmpary[0]; # Config name
$config_opts[$i][1] = "DEF"; # Tag as default config
$i++;
}
else {
print STDERR "ERROR: Config file line number $line_num\n";
print STDERR " $line_num columns of data were found\n";
print STDERR " Two columns were expected\n";
}
} # End of while CONFIG
close CONFIG;
}
#-----------------------------+
# If no config file use the |
# default options tag |
#-----------------------------+
else {
$config_opts[0][0] = "default"; # Config name
$config_opts[0][1] = "LTR.cfg"; # Set path to LTR.cfg
}
#-----------------------------+
# CHECK TO SEE IF THE LTRSEQ |
# CONFIG FILE EXISTS |
#-----------------------------+
for my $config_opt (@config_opts) {
my $ltrseq_cfg_file = $config_opt->[1];
unless ($ltrseq_cfg_file =~ "DEF") {
unless (-e $ltrseq_cfg_file) {
print "\a";
die "LTR_Seq config file not found at:\n$ltrseq_cfg_file\n";
} # End of check to see if the config files exists
} # End of unless we are using the defualt parameter set
} # For each option set
print STDERR "NUMBER OF FILES TO PROCESS: $count_files\n" if $verbose;
for my $ind_file (@fasta_files) {
my $name_root;
#-----------------------------+
# Get the root name of the |
# file to mask |
#-----------------------------+
if ($ind_file =~ m/(.*)\.masked\.fasta$/) {
# file ends in .masked.fasta
$name_root = "$1";
}
elsif ($ind_file =~ m/(.*)\.hard\.fasta$/) {
# file ends in .hard.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 "ERROR: Could not create root name dir:\n$name_root_dir\n";
}
#-----------------------------+
# CREATE THE LTRSEQ DIR |
#-----------------------------+
my $ltrseq_dir = $name_root_dir."ltrseq/";
unless (-e $ltrseq_dir) {
mkdir $ltrseq_dir ||
die "Could not create ltrseq out dir:\n$ltrseq_dir\n";
}
#-----------------------------+
# CREATE GFF OUTDIR |
#-----------------------------+
# This will hold the gff file modified from the
# original gff fine
my $gff_dir = $name_root_dir."gff/";
unless (-e $gff_dir) {
mkdir $gff_dir ||
die "ERROR: Could not create GFF out dir:\n$gff_dir\n";
}
#-----------------------------+
# RUN LTR SEQ |
#-----------------------------+
# Do this for every config set in the config file
# Note: LTR_seq usage
#LTR_seq {Fasta File} {#Sequences} [LTR.cfg file location optional]
for my $config_opt (@config_opts) {
my $config_name = $config_opt->[0];
my $ltrseq_cfg_file = $config_opt->[1];
my $seq_file = "$indir$ind_file";
# There should always be a single sequence in the input fasta file
# therefore there is a one in the command syntax
my $ltrseq_cmd = "$ltrseq_bin $seq_file 1";
# Append config file to command if given
unless ($ltrseq_cfg_file =~ "DEF") {
$ltrseq_cmd = $ltrseq_cmd." ".$ltrseq_cfg_file;
}
else {
$ltrseq_cmd = $ltrseq_cmd." LTR.cfg";
}
my $ltrseq_outfile = $ltrseq_dir.$name_root."_ltrseq_".
$config_name.".out";
my $gff_outfile = $gff_dir.$name_root."_ltrseq_".
$config_name.".gff";
$ltrseq_cmd = $ltrseq_cmd." > ".$ltrseq_outfile;
print STDERR "Processing: $ltrseq_cmd\n" if $verbose;
system ($ltrseq_cmd) unless $do_test;
#-----------------------------+
# CONVERT OUTPUT TO GFF |
#-----------------------------+
#ltrseq2gff ($ltrseq_in, $gff_out, $append_gff, $seqname);
if (-e $ltrseq_outfile) {
# OLD REF TO THE CONVERSION FUNCTION
# ltrseq2gff ($ltrseq_outfile, $gff_outfile, 0,
# $name_root, $config_name);
# NEW CONVERSION FUNCTION should look like
# differn is program variable
#ltrseq2gff ( $infile, $outfile, 0, $inseqname, $program, $parameter);
ltrseq2gff ($ltrseq_outfile, $gff_outfile, 0,
$name_root, $program, $config_name);
}
else {
# Report error, can not translate to gff
}
}
}
exit 0;
#-----------------------------------------------------------+
# SUBFUNCTIONS |
#-----------------------------------------------------------+
sub ltrseq2gff {
#-----------------------------+
# SUBFUNCTION VARS |
#-----------------------------+
# $source is the program
my ($ltrseq_in, $gff_out, $append_gff, $seqname,
$source, $param) = @_;
#-----------------------------+
# LTRSEQ VARS |
#-----------------------------+
my $ltrseq_infile; # Input file that was analyzed by LTR_seq
my $ltrseq_numseqs; # Number of seqs analyzed by LTR_seq
my $ltrseq_msrt; # Max Score Ration Threshold
my $ltrseq_ltrmin; # LTRmin
my $ltrseq_ltr_minexact; # LTR Min Exact Match
my $ltrseq_dmin; # Dmin
my $ltrseq_dmax; # Dmax
# Postion of the LTR Retrotransposon features
my $ltrseq_name; # Unique name assigned to the prediction
my $ltrspan_start; # Start of the entire LTR Retrotransposon
my $ltrspan_end; # End of the entire LTR Retrotransposon
my $ltrspan_len; # Length of the LTR span
my $ltr5_start; # Start of the 5' LTR
my $ltr5_end; # End of the 5' LTR
my $ltr3_start; # Start of the 3' LTR
my $ltr3_end; # End of the 3' LTR
my $ltr_len; # Length of the LTRs
my $mid_start; # Start of the LTR Mid region
my $mid_end; # End of the LTR Mid region
my $ltr_diff; # Percent Difference in the LTRs
my $ltr_conf; # Confidence score for the prediction
my $ltr_tsr; # Target site rep
my @in_split = (); # Split of the infile line
my $num_in; # Number of split vars in the infile
# Initialize Counters
my $ltrseq_num = 0; # ID Number of putatitve LTR retro (Incremented Number)
#-----------------------------+
# OPEN FILES |
#-----------------------------+
if ($ltrseq_in) {
open (INFILE, "<$ltrseq_in") ||
die "ERROR: Can not open input file:\n$ltrseq_in\n";
}
else {
print STDERR "Expecting input from STDIN\n";
open (INFILE, "<&STDIN") ||
die "Can not accept input from standard input.\n";
}
if ($gff_out) {
if ($append_gff) {
open (GFFOUT, ">>$gff_out") ||
die "ERROR: Can not open output file for appending\n$gff_out\n";
}
else {
open (GFFOUT, ">$gff_out") ||
die "ERROR: Can not open output file for output\n$gff_out\n";
if ($gff_ver =~ "GFF3") {
print GFFOUT "##gff-version 3\n";
}
} # End of if append_gff
}
else {
open (GFFOUT, ">&STDOUT") ||
die "Can not print to STDOUT\n";
if ($gff_ver =~ "GFF3") {
print GFFOUT "##gff-version 3\n";
}
}
if ($param) {
$source = $source.":".$param
}
#-----------------------------+
# PROCESS INFILE |
#-----------------------------+
while (<INFILE>) {
chomp;
# Print the INFILE
#print "$_\n";
if (m/^Report:/) {
# If this is a Report line, accepted or rejected can be
# determined by counting the line number
# 15 is a rejected line
# 19 is an accepted line
my @in_split = split;
my $num_in = @in_split;
#print "Report Line: $num_in parts\n";
#print "\t$_\n";
if ($num_in == 15) {
#print "\tREJECTED\n";
}
#-----------------------------+
# ACCEPTED LTR RETRO Parts |
#-----------------------------+
elsif ($num_in == 19) {
#print "\tACCEPTED\n";
print STDERR "\n".$_."\n" if $verbose;
$ltrseq_num++; # Increment the count
$ltr5_start = $in_split[4] || "0"; # Replaced with zero
$ltr5_end = $in_split[5] || "NULL";
$ltr3_start = $in_split[7] || "NULL";
$ltr3_end = $in_split[8] || "NULL";
$mid_start = $ltr5_end + 1;
$mid_end = $ltr3_start - 1;
$ltrspan_start = $ltr5_start;
$ltrspan_end = $ltr3_end;
$ltrspan_len = $in_split[12];
$ltr_len = $in_split[10];
$ltr_diff = $in_split[14];
$ltr_conf = $in_split[16];
$ltr_tsr = $in_split[18];
$ltrseq_name = "ltrseq_".$ltrseq_num;
if ($ltr_tsr =~ m/\#(.*)\#/) {
$ltr_tsr = $1;
}
# SHOW INFO IF VERBOSE
if ($verbose) {
print STDERR "$ltrseq_name\n";
print STDERR "\tSTART: $ltrspan_start\n";
print STDERR "\tEND: $ltrspan_end\n";
print STDERR "\tLTRLEN: $ltr_len\n";
print STDERR "\tSPAN_LEN: $ltrspan_len\n";
print STDERR "\tLTSR: $ltr_tsr\n";
print STDERR "\tLTRCON: $ltr_conf\n";
print STDERR "\tLTRDIF: $ltr_diff\n";
} # End of if verbose
#-----------------------------+
# PRINT TO GFF OUTPUT FILE |
#-----------------------------+
my $attribute = $ltrseq_name;
my $parent_id = $ltrseq_name;
#-----------------------------+
# LTR RETRO PREDICTION SPAN
#-----------------------------+
if ($gff_ver =~ "GFF3") {
$attribute = "ID=".$parent_id;
}
print GFFOUT "$seqname\t". # Name of sequence
"$source\t". # Source
"LTR_retrotransposon\t". # Feature, exon for Apollo
"$ltrspan_start\t". # Start of the ltr span
"$ltrspan_end\t". # End of the ltr span
"$ltr_conf\t". # Score, LTR Confidence Score
".\t". # Strand
".\t". # Frame
"$attribute\n"; # Features (Name)
#-----------------------------+
# 5' LTR |
#-----------------------------+
if ($gff_ver =~ "GFF3") {
$attribute = "ID=".$parent_id."_five_prime_LTR".
";Name=Five Prime LTR".
";Parent=".$parent_id;
}
print GFFOUT "$seqname\t". # Name of sequence
"$source\t". # Source
"five_prime_LTR\t". # Feature, exon for Apollo
"$ltr5_start\t". # Start of the 5'ltr
"$ltr5_end\t". # End of the 5' ltr span
"$ltr_conf\t". # Score, LTR Confidence Score
".\t". # Strand
".\t". # Frame
"$attribute\n"; # Features (Name)
#-----------------------------+
# 3' LTR |
#-----------------------------+
if ($gff_ver =~ "GFF3") {
$attribute = "ID=".$parent_id."_three_prime_LTR".
";Name=Three Prime LTR".
";Parent=".$parent_id;
}
print GFFOUT "$seqname\t". # Name of sequence
"$source\t". # Source
"three_prime_LTR\t". # Feature, exon for Apollo
"$ltr3_start\t". # Start of the 3'ltr
"$ltr3_end\t". # End of the 3' ltr span
"$ltr_conf\t". # Score, LTR Confidence Score
".\t". # Strand
".\t". # Frame
"$attribute\n"; # Features (Name)
}
# 15 Parts is Rejected
}
# HEADER INFORMATION
elsif (m/^Info:/) {
}
# The input string that was passed
elsif (m/^Input:/) {
}
} # End of while INFILE
}
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 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__
# OLD LTRSEQ 2 GFF CONVERSION
sub ltrseq2gff_old {
#-----------------------------+
# SUBFUNCTION VARS |
#-----------------------------+
my ($ltrseq_in, $gff_out, $append_gff, $seqname, $param_name) = @_;
#-----------------------------+
# LTRSEQ VARS |
#-----------------------------+
my $ltrseq_infile; # Input file that was analyzed by LTR_seq
my $ltrseq_numseqs; # Number of seqs analyzed by LTR_seq
my $ltrseq_msrt; # Max Score Ration Threshold
my $ltrseq_ltrmin; # LTRmin
my $ltrseq_ltr_minexact; # LTR Min Exact Match
my $ltrseq_dmin; # Dmin
my $ltrseq_dmax; # Dmax
# Postion of the LTR Retrotransposon features
my $ltrseq_name; # Unique name assigned to the prediction
my $ltrspan_start; # Start of the entire LTR Retrotransposon
my $ltrspan_end; # End of the entire LTR Retrotransposon
my $ltrspan_len; # Length of the LTR span
my $ltr5_start; # Start of the 5' LTR
my $ltr5_end; # End of the 5' LTR
my $ltr3_start; # Start of the 3' LTR
my $ltr3_end; # End of the 3' LTR
my $ltr_len; # Length of the LTRs
my $mid_start; # Start of the LTR Mid region
my $mid_end; # End of the LTR Mid region
my $ltr_diff; # Percent Difference in the LTRs
my $ltr_conf; # Confidence score for the prediction
my $ltr_tsr; # Target site rep
my @in_split = (); # Split of the infile line
my $num_in; # Number of split vars in the infile
# Initialize Counters
my $ltrseq_num = 0; # ID Number of putatitve LTR retro
# (Incremented Number)
#-----------------------------+
# OPEN FILES |
#-----------------------------+
open (INFILE, "<$ltrseq_in") ||
die "ERROR: Can not open input file:\n$ltrseq_in\n";
if ($append_gff) {
open (GFFOUT, ">>$gff_out") ||
die "ERROR: Can not open output file for appending\n$gff_out\n";
}
else {
open (GFFOUT, ">$gff_out") ||
die "ERROR: Can not open output file for output\n$gff_out\n";
} # End of if append_gff
#-----------------------------+
# PROCESS INFILE |
#-----------------------------+
while (<INFILE>) {
chomp;
# Print the INFILE
#print "$_\n";
if (m/^Report:/) {
# If this is a Report line, accepted or rejected can be
# determined by counting the line number
# 15 is a rejected line
# 19 is an accepted line
my @in_split = split;
my $num_in = @in_split;
#print "Report Line: $num_in parts\n";
#print "\t$_\n";
if ($num_in == 15) {
#print "\tREJECTED\n";
}
#-----------------------------+
# ACCEPTED LTR RETRO Parts |
#-----------------------------+
elsif ($num_in == 19) {
#print "\tACCEPTED\n";
#print "\n".$_."\n";
$ltrseq_num++; # Increment the count
$ltr5_start = $in_split[4] || "NULL";
$ltr5_end = $in_split[5] || "NULL";
$ltr3_start = $in_split[7] || "NULL";
$ltr3_end = $in_split[8] || "NULL";
$mid_start = $ltr5_end + 1;
$mid_end = $ltr3_start - 1;
$ltrspan_start = $ltr5_start;
$ltrspan_end = $ltr3_end;
$ltrspan_len = $in_split[12];
$ltr_len = $in_split[10];
$ltr_diff = $in_split[14];
$ltr_conf = $in_split[16];
$ltr_tsr = $in_split[18];
$ltrseq_name = $seqname."_ltrseq_".$ltrseq_num;
#-----------------------------+
# GET TSR LOCATIONS |
#-----------------------------+
# The location of the math to generate these will
# be strand dependent.
my $has_tsr = 0;
my $tsr5_start;
my $tsr5_end;
my $tsr3_start;
my $tsr3_end;
if ($ltr_tsr =~ m/\#(.*)\#/) {
$ltr_tsr = $1;
my $ltr_tsr_len = length($ltr_tsr);
if ($ltr_tsr_len > 0) {
$has_tsr = 1;
$tsr5_start = $ltr5_start - $ltr_tsr_len - 1;
$tsr5_end = $ltr5_start - 1;
$tsr3_start = $ltr3_end + 1;
$tsr3_end = $ltr3_end + $ltr_tsr_len + 1;
}
}
#-----------------------------+
# SHOW INFO IF VERBOSE
#-----------------------------+
if ($verbose) {
print STDERR "$ltrseq_name\n";
print STDERR "\tSTART: $ltrspan_start\n";
print STDERR "\tEND: $ltrspan_end\n";
print STDERR "\tLTRLEN: $ltr_len\n";
print STDERR "\tSPAN_LEN: $ltrspan_len\n";
print STDERR "\tLTSR: $ltr_tsr\n";
print STDERR "\tLTRCON: $ltr_conf\n";
print STDERR "\tLTRDIF: $ltr_diff\n";
} # End of if verbose
#-----------------------------+
# PRINT TO GFF OUTPUT FILE |
#-----------------------------+
# LTR_seq predicts everything in the positive strand
# SET THE PROGRAM SOURCE
my $prog_src;
if ($param_name) {
$prog_src = "LTR_seq:".$param_name;
}
else {
$prog_src = "LTR_seq";
}
# LTR RETRO PREDICTION SPAN
print GFFOUT "$seqname\t". # Name of sequence
"$prog_src\t". # Source name
"LTR_retrotransposon\t". # Feature, exon for Apollo
"$ltrspan_start\t". # Start of the ltr span
"$ltrspan_end\t". # End of the ltr span
"$ltr_conf\t". # Score, LTR Confidence Score
".\t". # Strand
".\t". # Frame
"$ltrseq_name\n"; # Features (Name)
# 5' LTR
print GFFOUT "$seqname\t". # Name of sequence
"$prog_src\t". # Source name
"five_prime_LTR\t". # Feature, exon for Apollo
"$ltr5_start\t". # Start of the 5'ltr
"$ltr5_end\t". # End of the 5' ltr span
"$ltr_conf\t". # Score, LTR Confidence Score
".\t". # Strand
".\t". # Frame
"$ltrseq_name\n"; # Features (Name)
# 3' LTR
print GFFOUT "$seqname\t". # Name of sequence
"$prog_src\t". # Source name
"three_prime_LTR\t". # Feature, exon for Apollo
"$ltr3_start\t". # Start of the 3'ltr
"$ltr3_end\t". # End of the 3' ltr span
"$ltr_conf\t". # LTR Confidence Score
".\t". # Strand
".\t". # Frame
"$ltrseq_name\n"; # Features (Name)
# REPORT TSRs IF PRESENT AND KNOWN
if ($has_tsr) {
# TSR 5 - 5' Target site duplication
print GFFOUT "$seqname\t". # Name of sequence
"$prog_src\t". # Source name
"target_site_duplication\t". # Feature
"$tsr5_start\t". # Start of the 3'ltr
"$tsr5_end\t". # End of the 3' ltr span
"$ltr_conf\t". # LTR Confidence Score
".\t". # Strand
".\t". # Frame
"$ltrseq_name\n"; # Features (Name)
# TSR - 5' Target site duplication
print GFFOUT "$seqname\t". # Name of sequence
"$prog_src\t". # Source name
"target_site_duplication\t". # Feature
"$tsr3_start\t". # Start of the 3'ltr
"$tsr3_end\t". # End of the 3' ltr span
"$ltr_conf\t". # LTR Confidence Score
".\t". # Strand
".\t". # Frame
"$ltrseq_name\n"; # Features (Name)
} # End has_tsr
} # end of num parts is 19
# 15 Parts are Rejected models
}
# HEADER INFORMATION
elsif (m/^Info:/) {
}
# The input string that was passed
elsif (m/^Input:/) {
}
} # End of while INFILE
}
=head1 NAME
batch_ltrseq.pl - Run the LTR_seq program in batch mode.
=head1 VERSION
This documentation refers to program version $Rev: 948 $
=head1 SYNOPSIS
=head2 Usage
batch_ltrseq.pl -i in_dir -o out_dir [-c config]
=head2 Required Options
-i # Intput directory of files to process
# These must be in fasta file format
-o # Base output directory
=head1 DESCRIPTION
This program runs the LTR_seq program for each file in the input directory.
An optional configuartion file can also be used to run the LTR_seq program
for multiple LTR_seq parameter combinations. If no configuration file is
provided, batch_ltrseq.pl will run LTR_seq using default parameters.
=head1 REQUIRED ARGUMENTS
=over 2
=item -i,--indir
Path of the directory containing the sequences to process.
=item -o,--outdir
Path of the directory to place the program output.
=back
=head1 OPTIONS
=over 2
=item -c,--config
Path to a configuration file. This config file will allow the
batch_ltrseq.pl program to run the LTR_seq program for multiple parameter
combinations for every fasta file in the input sequence directory.
If no configuartion file is used, the LTR_seq program will be run with
default parameters.
The configuration file will
be a two column, tab delimited text file with the following options:
=over
=item * Col. 1 Configuration Set Name
This is the name that will be used in the gff file to tag the configuration
set. For example def for default options or old for an optional set to
try to finder LTR retrotransposon insertions that are old.
=item * Col. 2 Config File
LTR_seq config file describing the parameter set to use. This file
should follow the format used for LTR_Seq config files. If this value is
set to DEF, then batch_ltrseq.p will run the LTR_seq program with
default parameters.
The directory that this config file is located in will be specified by