forked from vikas0633/perl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatch_findltr.pl
1135 lines (879 loc) · 33.2 KB
/
batch_findltr.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_findltr.pl - Run the findltr program in batch mode |
# |
#-----------------------------------------------------------+
# |
# AUTHOR: James C. Estill |
# CONTACT: JamesEstill_@_gmail.com |
# STARTED: 09/13/2007 |
# UPDATED: 03/10/2010 |
# |
# DESCRIPTION: |
# Run the find_ltr.pl LTR finding program in batch mode. |
# |
# LICENSE: |
# GNU General Public License, Version 3 |
# http://www.gnu.org/licenses/gpl.html |
# |
# VERSION: $Rev: 948 $ |
# |
#-----------------------------------------------------------+
package DAWGPAWS;
#-----------------------------+
# INCLUDES |
#-----------------------------+
use strict;
use Getopt::Long;
use File::Copy;
# 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 $param;
my $program = "FindLTR";
my $indir; # Base intput dir
my $outdir; # Base output dir
my $config_file; # Configuration file
my $name_root; # Root name of the file being analyzed
my $errmsg; # Var to hold error message strings
my $fl_gff_outpath; # Full output path of the gff output file
# Array of find_ltr parameters
my @fl_params = (); # 2d Array to hold the find_ltr parameters
# Path vars
my $fl_path = $ENV{FIND_LTR_PATH}; # Path to the find_ltr.pl program
my $gff_dir; # Dir to hold the gff output
# Counters/Index Vals
my $i = 0; # Array index val
my $file_num = 0; # File number
my $proc_num = 0; # Process number
# 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_test = 0;
my $do_gff_append = 0;
#-----------------------------+
# COMMAND LINE OPTIONS |
#-----------------------------+
my $ok = GetOptions(# REQUIRED OPTIONS
"i|indir=s" => \$indir,
"o|outdir=s" => \$outdir,
"c|config=s" => \$config_file,
# ADDITIONAL OPTIONS
"gff-ver=s" => \$gff_ver,
"program=s" => \$program,
"fl-path=s" => \$fl_path,
"q|quiet" => \$quiet,
"verbose" => \$verbose,
"gff" => \$do_gff_convert,
"test" => \$do_test,
# ADDITIONAL INFORMATION
"usage" => \$show_usage,
"version" => \$show_version,
"man" => \$show_man,
"h|help" => \$show_help,);
#-----------------------------+
# 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";
}
}
#-----------------------------+
# 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_findltr.pl:\nVersion: $VERSION\n\n";
exit;
}
if ($show_man) {
# User perldoc to generate the man documentation.
system("perldoc $0");
exit($ok ? 0 : 2);
}
# Throw error if required arguments not present
if ( (!$indir) || (!$outdir) || (!$config_file) ) {
print "\a";
print STDERR "ERROR: An input directory must be specified" if !$indir;
print STDERR "ERROR: An output directory must be specified" if !$outdir;
print STDERR "ERROR: A config file must be specified" if !$config_file;
print_help ("help", $0 );
exit;
}
# If not path for find_ltr.pl exists as an ENV option, and the
# the path is not given at the command line, assume that find_ltr.pl
# exists somewhere that the user has included in their PATH var.
if ( !$fl_path ) {
$fl_path = "find_ltr.pl";
}
#-----------------------------------------------------------+
# 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; # Implicit split of $_ by whitespace
my $num_in_line = @in_line;
if ($num_in_line == 10) {
$fl_params[$i][0] = $in_line[0] || "NULL"; # Name
$fl_params[$i][1] = $in_line[1] || "NULL"; # MIN-MEM
$fl_params[$i][2] = $in_line[2] || "NULL"; # MIN-MEM-DIST
$fl_params[$i][3] = $in_line[3] || "NULL"; # MAX-MEM-DIST
$fl_params[$i][4] = $in_line[4] || "NULL"; # MAX-MEM-GAP
$fl_params[$i][5] = $in_line[5] || "NULL"; # MIN-LEN-LTR
$fl_params[$i][6] = $in_line[6] || "NULL"; # MAX-LEN-LTR
$fl_params[$i][7] = $in_line[7] || "NULL"; # RANGE-BIN
$fl_params[$i][8] = $in_line[8] || "NULL"; # MIN LEN ORF
$fl_params[$i][9] = $in_line[9] || "NULL"; # MAX E Value HMM
$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;
#-----------------------------+
# 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 $num_files = @fasta_files;
my $num_proc_total = $num_files * $num_par_sets;
print STDERR "$num_proc_total find_ltr runs to process\n";
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;
}
# The following added for temp work with gff output
# 09/28/2007
# if ($file_num == 5) {exit;}
# print "Processing: $name_root\n";
#-----------------------------+
# 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 FIND_LTR OUTDIR |
#-----------------------------+
# Dir to hold gene prediction output from local software
my $findltr_dir = $name_root_dir."find_ltr/";
unless (-e $findltr_dir) {
mkdir $findltr_dir ||
die "Could not create genscan out dir:\n$findltr_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 genscan out dir:\n$gff_dir\n";
}
}
#-----------------------------------------------------------+
# RUN find_ltr.pl FOR EACH SET OF PARAM VALS IN CONFIG FILE |
#-----------------------------------------------------------+
for ($i=0; $i<$num_par_sets; $i++) {
# ASSUME THAT A CONFIG FILE IS USED
# OTHERWISE COULD JUST USE DEFAULT VALS
$proc_num++;
# Load array vals to usefull short names
my $fl_suffix = $fl_params[$i][0]; # Name of the parameter set
my $fl_min_mem = $fl_params[$i][1];
my $fl_min_mem_dist = $fl_params[$i][2];
my $fl_max_mem_dist = $fl_params[$i][3];
my $fl_max_mem_gap = $fl_params[$i][4];
my $fl_min_ltr = $fl_params[$i][5];
my $fl_max_ltr = $fl_params[$i][6];
my $fl_range_bin = $fl_params[$i][7];
my $fl_min_orf = $fl_params[$i][8];
my $fl_e_val = $fl_params[$i][9];
# Show processing information
print "Processing: $name_root $fl_suffix\n";
# The following name will need to be copied from the default
# named output from find_ltr
my $fl_inseqpath = $indir.$ind_file;
my $fl_ltrpos_out = $fl_inseqpath.".ltrpos";
my $fl_out_copy = $findltr_dir.$name_root."_findltr_".$fl_suffix.".txt";
my $fl_ltrseq_out = $fl_inseqpath.".ltrseq";
my $fl_ltrseq_out_cp = $findltr_dir.$name_root."_findltr_".
$fl_suffix.".ltrseq";
if ($do_gff_convert) {
$fl_gff_outpath = $gff_dir.$name_root."_findltr_".$fl_suffix.".gff";
}
#-----------------------------+
# RUN THE find_ltr.pl program |
#-----------------------------+
my $fl_cmd = $fl_path.
" --seq ".$fl_inseqpath.
" --min-mem ".$fl_min_mem.
" --min-dist ".$fl_min_mem_dist.
" --max-dist ".$fl_max_mem_dist.
" --max-gap ".$fl_max_mem_gap.
" --min-ltr ".$fl_min_ltr.
" --max-ltr ".$fl_max_ltr.
" --min-ltr ".$fl_min_ltr.
" --range-bin ".$fl_range_bin.
" --min-orf ".$fl_min_orf.
" --e-val ".$fl_e_val;
if ($verbose) {
$fl_cmd = $fl_cmd." --verbose";
}
print "\n---------------------------------------+\n" if $verbose;
print " Process $proc_num of $num_proc_total\n" if $verbose;
print "---------------------------------------+\n" if $verbose;
print STDERR "FL CMD: $fl_cmd\n\n" if $verbose;
system ($fl_cmd) unless $do_test;
#-----------------------------+
# CONVERT OUTPUT TO GFF |
#-----------------------------+
print STDERR "Searching for $fl_ltrpos_out\n";
if ( (-e $fl_ltrpos_out) && ($do_gff_convert)) {
if ($do_gff_append) {
findltr2gff ( $program, $fl_ltrpos_out, $fl_gff_outpath,
1, $name_root, $fl_suffix);
}
else {
print STDERR "Converting ".$fl_ltrpos_out." to ".$fl_gff_outpath."\n";
findltr2gff ( $program, $fl_ltrpos_out, $fl_gff_outpath,
0, $name_root, $fl_suffix);
}
# # OLD SUBFUNCTION
# findltr2gff ( $fl_ltrpos_out, $fl_gff_outpath,
# 0, $name_root, $fl_suffix);
}
#-----------------------------+
# MOVE RESULTS FILES |
#-----------------------------+
if (-e $fl_ltrpos_out) {
$errmsg = "Could not move\n $fl_ltrpos_out to\n $fl_out_copy\n";
move ($fl_ltrpos_out, $fl_out_copy)
|| print STDERR "\a$errmsg";
}
if ($fl_ltrseq_out) {
$errmsg = "Could not move\n $fl_ltrseq_out to \n $fl_ltrseq_out_cp\n";
move ($fl_ltrseq_out, $fl_ltrseq_out_cp )
|| print STDERR "\a$errmsg";
}
}
} # End of for each ind_file in @fasta_files
exit;
#-----------------------------------------------------------+
# SUBFUNCTIONS |
#-----------------------------------------------------------+
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);
}
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 findltr2gff {
#-----------------------------+
# SUBFUNCTION VARS |
#-----------------------------+
# gff_suffix is the name appended to the end of the gff_source
my ($gff_source,
$findltr_in, $gff_out, $append_gff, $seqname, $gff_suffix) = @_;
# find_ltr
#my $gff_source; #
my $findltr_id; # Id as assigned from find_ltr.pl
my $findltr_name; # Full name for the find_ltr prediction
my $ltr5_start; # Start of the 5' LTR
my $ltr5_end; # End of the 5' LTR
my $ltr5_len; # Length of the 5' LTR
my $ltr3_start; # Start of the 3' LTR
my $ltr3_end; # End of the 3' LTR
my $ltr3_len; # Length of the 3' LTR
my $el_len; # Length of the entire element
my $mid_start; # Start of the LTR Mid region
my $mid_end; # End of the LTR Mid region
my $ltr_similarity; # Percent similarity between LTRs
my $ltr_strand; # Strand of the LTR
my @in_split = (); # Split of the infile line
my $num_in; # Number of split vars in the infile
# Initialize Counters
my $findltr_num = 0; # ID Number of putatitve LTR retro
#-----------------------------+
# OPEN FILES |
#-----------------------------+
if ($findltr_in) {
open (INFILE, "<$findltr_in") ||
die "Can not open input file:\n$findltr_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 "Could not open output file for appending\n$gff_out\n";
}
else {
open (GFFOUT, ">$gff_out") ||
die "Could 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";
}
}
# Append parameter name if passed
if ($gff_suffix) {
$gff_source = $gff_source.":".$gff_suffix;
}
#-----------------------------+
# PROCESS INFILE |
#-----------------------------+
while (<INFILE>) {
chomp;
my @in_split = split;
my $num_in = @in_split;
# Load split data to vars if expected number of columns found
if ($num_in == 10) {
$findltr_num++;
my $model_num = sprintf("%04d", $findltr_num);
$findltr_id = $in_split[0];
$ltr5_start = $in_split[1];
$ltr5_end = $in_split[2];
$ltr3_start = $in_split[3];
$ltr3_end = $in_split[4];
$ltr_strand = $in_split[5];
$ltr5_len = $in_split[6];
$ltr3_len = $in_split[7];
$el_len = $in_split[8];
$ltr_similarity = $in_split[9];
$mid_start = $ltr5_end + 1;
$mid_end = $ltr3_start - 1;
$findltr_name = "findltr";
my $attribute = $findltr_name."_".$findltr_id;
# FULL LTR Retrotransposon Span
if ($gff_ver =~ "GFF3") {
if ($param) {
$attribute = "findltr".
"_par".$param.
"_model".$model_num;
}
else {
$attribute = "findltr".
"_model".$model_num;
}
$seqname = seqid_encode( $seqname );
}
my $parent_id = $attribute;
# LTR Retrotransposon
if ($gff_ver =~ "GFF3") {
$attribute = "ID=".$parent_id;
}
print GFFOUT "$seqname\t". # Name of sequence
"$gff_source\t". # Source
"LTR_retrotransposon\t".
"$ltr5_start\t". # Feature start
"$ltr5_end\t". # Feature end
".\t". # Score, Could use $ltr_similarity
"$ltr_strand\t". # Strand
".\t". # Frame
$attribute.
"\n";
# 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
"$gff_source\t". # Source
"five_prime_LTR\t".
"$ltr5_start\t". # Feature start
"$ltr5_end\t". # Feature end
".\t". # Score, Could use $ltr_similarity
"$ltr_strand\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
"$gff_source\t". # Source
"three_prime_LTR\t".
"$ltr3_start\t". # Feature start
"$ltr3_end\t". # Feature end
".\t". # Score, Could use $ltr_similarity
"$ltr_strand\t". # Strand
".\t". # Frame
$attribute.
"\n"; # Features (name)
} # End of if num_in is 10
} # End of while INFILE
} # End of findltr2gff
1;
__END__
sub findltr2gff_old {
#-----------------------------+
# SUBFUNCTION VARS |
#-----------------------------+
# gff_suffix is the name appended to the end of the gff_source
my ($findltr_in, $gff_out, $append_gff, $seqname, $gff_suffix) = @_;
# find_ltr
my $gff_source; #
my $findltr_id; # Id as assigned from find_ltr.pl
my $findltr_name; # Full name for the find_ltr prediction
my $ltr5_start; # Start of the 5' LTR
my $ltr5_end; # End of the 5' LTR
my $ltr5_len; # Length of the 5' LTR
my $ltr3_start; # Start of the 3' LTR
my $ltr3_end; # End of the 3' LTR
my $ltr3_len; # Length of the 3' LTR
my $el_len; # Length of the entire element
my $mid_start; # Start of the LTR Mid region
my $mid_end; # End of the LTR Mid region
my $ltr_similarity; # Percent similarity between LTRs
my $ltr_strand; # Strand of the LTR
my @in_split = (); # Split of the infile line
my $num_in; # Number of split vars in the infile
# Initialize Counters
my $findltr_num = 0; # ID Number of putatitve LTR retro
#-----------------------------+
# OPEN FILES |
#-----------------------------+
open (INFILE, "<$findltr_in") ||
die "Can not open input file:\n$findltr_in\n";
if ($append_gff) {
open (GFFOUT, ">>$gff_out") ||
die "Could not open output file for appending\n$gff_out\n";
}
else {
open (GFFOUT, ">$gff_out") ||
die "Could not open output file for output\n$gff_out\n";
} # End of if append_gff
#-----------------------------+
# PROCESS INFILE |
#-----------------------------+
while (<INFILE>) {
chomp;
my @in_split = split;
my $num_in = @in_split;
# Load split data to vars if expected number of columns found
if ($num_in == 10) {
$findltr_num++;
$findltr_id = $in_split[0];
$ltr5_start = $in_split[1];
$ltr5_end = $in_split[2];
$ltr3_start = $in_split[3];
$ltr3_end = $in_split[4];
$ltr_strand = $in_split[5];
$ltr5_len = $in_split[6];
$ltr3_len = $in_split[7];
$el_len = $in_split[8];
$ltr_similarity = $in_split[9];
$mid_start = $ltr5_end + 1;
$mid_end = $ltr3_start - 1;
$findltr_name = $seqname."_findltr_"."".$findltr_id;
$gff_source = "find_ltr:".$gff_suffix;
#-----------------------------+
# PRINT GFF OUTPUT |
#-----------------------------+
# Data type follows SONG
# http://song.cvs.sourceforge.net/*checkout*/song/ontology/so.obo
# Full span of LTR Retrotransposon
print GFFOUT "$seqname\t". # Name of sequence
"$gff_source\t". # Source
"LTR_retrotransposon\t".# Features, exon for Apollo
"$ltr5_start\t". # Feature start
"$ltr3_end\t". # Feature end
".\t". # Score, Could use $ltr_similarity
"$ltr_strand\t". # Strand
".\t". # Frame
"$findltr_name\n"; # Features (name)
# 5'LTR
print GFFOUT "$seqname\t". # Name of sequence
"$gff_source\t". # Source
"five_prime_LTR\t". # Features, exon for Apollo
"$ltr5_start\t". # Feature start
"$ltr5_end\t". # Feature end
".\t". # Score, Could use $ltr_similarity
"$ltr_strand\t". # Strand
".\t". # Frame
"$findltr_name\n"; # Features (name)
# # MID
# # This is not a SONG complient feature type name
# print GFFOUT "$seqname\t". # Name of sequence
# "$gff_source\t". # Source
# "mid\t". # Features, exon for Apollo
# "$mid_start\t". # Feature start
# "$mid_end\t". # Feature end
# ".\t". # Score, Could use $ltr_similarity
# "$ltr_strand\t". # Strand
# ".\t". # Frame
# "$findltr_name\n"; # Features (name)
# 3'LTR
print GFFOUT "$seqname\t". # Name of sequence
"$gff_source\t". # Source
"three_prime_LTR\t". # Features, exon for Apollo
"$ltr3_start\t". # Feature start
"$ltr3_end\t". # Feature end
".\t". # Score, Could use $ltr_similarity
"$ltr_strand\t". # Strand
".\t". # Frame
"$findltr_name\n"; # Features (name)
} # End of if num_in is 10
} # End of while INFILE
} # End of findltr2gff
=head1 NAME
batch_findltr.pl - Run the find_ltr.pl program in batch mode.
=head1 VERSION
This documentation refers to program version $Rev: 948 $
=head1 SYNOPSIS
=head2 Usage
batch_findltr.pl -i InDir -o OutDir -c Config.cfg [--gff]
=head2 Required Arguments
--indir # Path to the input directory of fasta files
--outdir # Path to the base output directory
--config # Config file containg batch_findltr.pl paramaters
--gff # Produce GFF formatted output
=head1 DESCRIPTION
Runs the program find_ltr.pl in batch mode. This makes use of a modified
version of the find_ltr.pl program that takes changes to the LTR finding
parameters at the command line.
=head1 REQUIRED ARGUMENTS
=over 2
=item -i,--indir
Path of the input directory. This is the directory that contains all
of the fasta files to anlayze. The fasta files should all end with
the I<fasta> extension to recognized.
=item -o,--outdir
Path of the output directory. This is the base directory that will
hold all of the batch_findltr.pl output
=item -c, --config
Path of the config file that contains the model options for running
find_ltr. This config file is a white space delimited text file that
should be in the following format.
#---------------------------------------------------------------+
#1 2 3 4 5 6 7 8 9 10 |
#---------------------------------------------------------------+
Def 40 1100 16000 40 100 1000 500 700 0.0000000001
Alt 40 1100 1800 40 100 1000 500 400 0.00001
More information about this file is available under configuration and
environment heading below.
=back
=head1 OPTIONS
=over 2
=item --gff-ver
The GFF version for the output. This will accept either gff2 or gff3 as the
options. By default the GFF version will be GFF2 unless specified otherwise.
The default GFF version for output can also be set in the user environment
with the DP_GFF option. The command line option will always override the option
defined in the user environment.
=item --fl-path
Location of the find_ltr.pl program. This option can also be set in the
users envrionment. See Configuration and Environment below.
=item -q,--quiet
Run the program with minimal output.
=item -v, --verbose
Run the program in verbose mode.
=item --gff
Produce gff formatted output of the results.
=item --test
Run the program in test mode. The find_ltr.pl program will not be run, but
the location of source files, binaries, will be checked and the
outupt directories will be created.
=item --usage
Short overview of how to use program from command line.
=item --help
Show program usage with summary of options.
=item --version
Show program version.
=item --man
Show the full program manual. This uses the perldoc command to print the
POD documentation for the program.
=back
=head1 DIAGNOSTICS
Error messages generated by this program and possible solutions are listed
below.
=over 2
=item ERROR: No fasta files were found in the input directory
The input directory does not contain fasta files in the expected format.
This could happen because you gave an incorrect path or because your sequence
files do not have the expected *.fasta extension in the file name.
=item ERROR: Could not create the output directory
The output directory could not be created at the path you specified.
This could be do to the fact that the directory that you are trying
to place your base directory in does not exist, or because you do not
have write permission to the directory you want to place your file in.
=back
=head1 CONFIGURATION AND ENVIRONMENT
=head2 Configuration File
The configuration file in batch_findltr.pl specifies the options for
running the find_ltr.pl program. This is a white space delimited text
file. All lines starting with the # symbol will be treated as comments.
An example of a config file is below:
#---------------------------------------------------------------+
#1 2 3 4 5 6 7 8 9 10 |
#---------------------------------------------------------------+
Def 40 1100 16000 40 100 1000 500 700 0.0000000001
Alt 40 1100 1800 40 100 1000 500 400 0.00001
These 10 columns represents the following information:
=over 2
=item Col 1.
Base_name for the parameter set. This set name will be used to
name the output file, and will be added to the output of
the gff output file. B<DO NOT INCLUDE SPACES IN NAMES>
=item Col 2.
Minimum Length MEM
=item Col 3.
Mimimum distance between MEMs
=item Col 4.
Maximum distance between MEMs
=item Col 5.
Maximu gap between MEMs
=item Col 6.
Minimum length of the LTR
=item Col 7.
Maximum length of the LTR
=item Col 8.