-
Notifications
You must be signed in to change notification settings - Fork 5
/
batch_repmask.pl
1740 lines (1415 loc) · 52.1 KB
/
batch_repmask.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_repmask.pl - Run RepeatMasker in batch mode |
# |
#-----------------------------------------------------------+
# |
# AUTHOR: James C. Estill |
# CONTACT: JamesEstill_at_sourceforge.net |
# STARTED: 04/10/2006 |
# UPDATED: 03/05/2010 |
# |
# DESCRIPTION: |
# Runs the RepeatMasker program for a set of input |
# FASTA files against a set of repeat library files & |
# then converts the repeat masker *.out file into the |
# GFF format and then to the game XML format for |
# visualization by the Apollo genome anotation program. |
# |
# USAGE: |
# batch_repmask.pl -i InDir -o OutDir -c ConfigFile.txt |
# |
# batch_repmask.pl --man |
# |
# LICENSE: |
# GNU General Public License, Version 3 |
# http://www.gnu.org/licenses/gpl.html |
# |
#-----------------------------------------------------------+
package DAWGPAWS;
#-----------------------------+
# INCLUDES |
#-----------------------------+
use strict;
use File::Copy;
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";
#//////////////////////
my $file_num_max = 1;
#\\\\\\\\\\\\\\\\\\\\\\
#-----------------------------------------------------------+
# VARIABLE SCOPE |
#-----------------------------------------------------------+
# VARS WITH DEFAULT VALUES
my $engine = "crossmatch";
my $prog = "repeatmasker"; # The program used
# GENERAL PROGRAM VARS
my @inline; # Parse of an input line
my $msg; # Message printed to the log file
my $param; # Parameter name
# DIR PATHS
my $indir; # Directory containing the seq files to process
my $outdir; # Directory to hold the output
my $bac_out_dir; # Dir for each sequence being masked
my $bac_rep_out_dir; # Dir to hold BAC repeat masker output
# $bac_out_dir/rm
my $gff_out_dir; # Dir for the gff output
# $bac_out_dir/gff
# FILE PATHS
my $logfile; # Path to a logfile to log error info
# Full path to the repeatmasker binary
my $rm_path = $ENV{DP_RM_BIN} || "RepeatMasker";
# Dir containing the files to mask with
my $rm_dir = $ENV{DP_RM_DIR} || "0";
my $ap_path; # Full path to the apollo program
my $rm_opt; # Repmasker options
my $rep_db_path; # Path to an indivual repeat database
my $file_to_mask; # The fasta file to be masked
my $repmask_outfile; # Repeat masked outfile
my $repmask_catfile; # Concatenated repeat masked outfile
my $config_file; # Full path to the configuration file
# This includes the db names and paths
# of the fasta files to use for masking
my $repmask_cat_cp; # Path to the copy of the RepMask
my $search_name; # Name searched for in grep command
my $name_root; # Root name to be used for output etc
my $repmask_log;
my $repmask_log_cp;
my $repmask_tbl_file;
my $repmask_masked_file;
my $gff_alldb_out;
my $gff_el_out;
my $xml_alldb_out;
my $xml_el_out;
#my $repmask_cat_cp;
# FINAL FILE LOCATIONS
my $repmask_masked_cp; # Masked fasta file
my $repmask_local_cp; # Copy of masked in fasta file
my $repmask_tbl_cp; # Repmask Table
my $repmask_el_cp; # Individual
my $repmask_xml_el_cp;
my $repmask_out_cp; # Repmask out file copy
# REPEAT DB VARS
my $rep_db_name; # Name of the repeat database
my $ind_lib; # Vars for an individual library
# BOOLEANS
my $show_help = 0; # Show program help
my $show_version = 0; # Show program version
my $show_man = 0; # Show program manual page using peldoc
my $show_usage = 0; # Show program usage command
my $quiet = 0; # Boolean for reduced output to STOUT
my $apollo = 0; # Path to apollo and apollo variables
my $test = 0;
my $verbose = 0;
my $debug = 0; # Run the program in debug mode
my $pos_strand = 0; # Put all results in positive strand
# PROGRAM COMMAND STRINGS
my $cmd_repmask; # Command to run RepeatMasker
my $cmd_make_gff_db; # Make the gff file for an individual database
my $cmd_make_gff_el; # Appears to not be used
# COUNTERS AND INDEX VARS
my $num_proc = 1; # Number of processors to use
my $i; # Used to index the config file
my $proc_num = 0; # Counter for processes
my $file_num = 0; # Counter for fasta files being processed
# ARRAYS
my @mask_libs = ();
#-----------------------------+
# COMMAND LINE OPTIONS |
#-----------------------------+
my $ok = GetOptions(
# REQUIRED ARGUMENTS
"i|indir=s" => \$indir,
"o|outdir=s" => \$outdir,
"c|config=s", => \$config_file,
# ADDITIONAL OPTIONS
# BOOLEANS
"program=s" => \$prog,
"gff-ver=s" => \$gff_ver,
"rm-path=s" => \$rm_path,
"rm-dir=s" => \$rm_dir,
"ap-path=s", => \$ap_path,
"logfile=s" => \$logfile,
"p|num-proc=s" => \$num_proc,
"engine=s" => \$engine,
# BOOLEANS
"plus" => \$pos_strand,
"apollo" => \$apollo,
"verbose" => \$verbose,
"debug" => \$debug,
"test" => \$test,
"usage" => \$show_usage,
"version" => \$show_version,
"man" => \$show_man,
"h|help" => \$show_help,
"q|quiet" => \$quiet,);
my $bac_parent_dir = $outdir;
my ( @rep_libs );
#-----------------------------+
# 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_repmask.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 |
#-----------------------------+
# Show full help when required options
# are not present
if ( (!$indir) || (!$outdir) || (!$config_file) ) {
print "\a";
print "ERROR: An input directory was not specified with the -i flag\n"
if !$indir;
print "ERROR: An output directory was not specified with the -o flag\n"
if !$outdir;
print "ERROR: A config file was not specified with the -c flag\n"
if !$config_file;
print_help ("usage", $0 );
}
#-----------------------------+
# OPEN THE LOG FILE |
#-----------------------------+
if ($logfile) {
# Open file for appending
open ( LOG, ">>$logfile" ) ||
die "Can not open logfile:\n$logfile\n";
my $time_now = time;
print LOG "==================================\n";
print LOG " batch_repmask.pl\n";
print LOG " JOB: $time_now\n";
print LOG "==================================\n";
}
#-----------------------------+
# 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 ($rm_dir =~ /\/$/ ) {
$rm_dir = $rm_dir."/";
}
#-----------------------------+
# 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 );
#-----------------------------+
# REPEAT LIBRARY INFORMATION |
#-----------------------------+
open (CONFIGFILE, "<$config_file")
|| die "Could not open the config file:\n$config_file\n";
$i = 0;
my $config_line_num = 0;
print "Parsing config file...\n" if $verbose;
while (<CONFIGFILE>) {
chomp;
$config_line_num++;
unless (m/^\#/) {
# Split input by tab
my @in_line = split(/\t/, $_);
my $num_in_line = @in_line;
print "\tConfig line $config_line_num\t".
"$num_in_line sections\n" if $verbose;
# Only try to parse the inline if it has the
# expected number of componenets
if ($num_in_line == 2) {
$mask_libs[$i][0] = $in_line[0];
$mask_libs[$i][1] = $in_line[1];
# If a db dir path is given, prepend this
# to the location of the database
unless ($rm_dir =~ 0) {
$mask_libs[$i][1] = $rm_dir.$mask_libs[$i][1];
}
# Only print for debug runs
if ($debug) {
print STDERR "INLINE SPLIT, i:$i \n";
print STDERR "\t\t".$in_line[0]."\n";
print STDERR "\t\t".$in_line[1]."\n";
print STDERR "VAL1 IS:" if $verbose;
print STDERR $mask_libs[$i][0]."\n";
print STDERR "VAL2 IS:" if $verbose;
print STDERR $mask_libs[$i][1]."\n";
} # End of print for debug runs
$i++;
}
# If three cols then we have additional options
elsif ($num_in_line == 3) {
$mask_libs[$i][0] = $in_line[0];
$mask_libs[$i][1] = $in_line[1];
$mask_libs[$i][2] = $in_line[2];
# If a db dir path is given, prepend this
# to the location of the database
unless ($rm_dir =~ 0) {
$mask_libs[$i][1] = $rm_dir.$mask_libs[$i][1];
}
$i++;
}
} # End of unless comment line
} # End of while CONFIGFILE
close CONFIGFILE;
my $num_libs = @mask_libs;
my $num_files = @fasta_files;
my $num_proc_total = $num_libs * $num_files;
#-----------------------------+
# SHOW ERROR IF NO LIBS IN |
# THE CONFIG FILE |
#-----------------------------+
if ($num_libs == 0) {
print "\a";
print STDERR "\nERROR: No library files were indicated in the ".
"config file\n$config_file\n";
exit;
}
#-----------------------------+
# SHOW ERROR IF NO FILES |
# WERE FOUND IN THE INPUT DIR |
#-----------------------------+
if ($num_files == 0) {
print "\a";
print "\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;
}
if ($verbose) {
print STDERR "\n";
print STDERR "NUM FILES: $num_files\n";
print STDERR "NUM LIBS: $num_libs\n";
print STDERR "NUM PROC: $num_proc_total\n";
print STDERR "\n";
}
#-----------------------------+
# SHOW ERROR IF ONE OF THE |
# MASK LIBS DOES NOT EXIST |
#-----------------------------+
print STDERR "Checking mask libs ...\n" if $verbose;
for ($i=0; $i<$num_libs; $i++) {
print "i $i\n";
$rep_db_name = $mask_libs[$i][0];
$rep_db_path = $mask_libs[$i][1];
unless (-e $rep_db_path) {
print "\a";
print "\nERROR: The following masking library could not be found:\n".
$rep_db_path."\n";
exit;
}
}
#-----------------------------+
# CREATE THE OUT DIR |
# IF IT DOES NOT EXIST |
#-----------------------------+
print "Creating output dir ...\n" unless $quiet;
unless (-e $outdir) {
mkdir $outdir ||
die "\aERROR: Could not create the output directory:\n$outdir\n";
}
#-----------------------------+
# RUN REPEAT MASKER AND PARSE |
# RESULTS FOR EACH SEQ IN THE |
# fasta_files ARRAY FOR EACH |
# REPEAT LIBRARY IN THE |
# rep_libs ARRAY |
#-----------------------------+
for my $ind_file (@fasta_files)
{
$file_num++;
# Reset search name to null
$search_name = "";
if ($ind_file =~ m/(.*)\.masked\.fasta$/ ) {
$name_root = "$1";
}
elsif ($ind_file =~ m/(.*)\.fasta$/ ) {
$name_root = "$1";
}
else {
$name_root = $ind_file;
}
# The following names are the names as produced by
# RepeatMasker
$file_to_mask = $indir.$ind_file;
$repmask_outfile = $file_to_mask.".out";
$repmask_catfile = $file_to_mask.".cat";
$repmask_tbl_file = $file_to_mask.".tbl";
$repmask_masked_file = $file_to_mask.".masked";
$proc_num++;
# Print log file report
print LOG "\n\nProcess $proc_num of $num_proc_total.\n" if $logfile;
# Print process information to STDERR
print STDERR "\n\n+---------------------------------------------------+\n"
unless $quiet;
print STDERR "| Process $proc_num of $num_proc_total.\n" unless $quiet;
print STDERR "+---------------------------------------------------+\n"
unless $quiet;
#-----------------------------+
# SHOW BASIC RUN INFO
#-----------------------------+
print STDERR "\n";
print STDERR "\tINFILE: $ind_file\n";
print STDERR "\t ROOT: $name_root\n";
#-----------------------------+
# MAKE OUTPUT DIR |
#-----------------------------+
# The base output dir for the BAC
$bac_out_dir = $outdir.$name_root."/";
mkdir $bac_out_dir, 0777 unless (-e $bac_out_dir);
#-----------------------------+
# MAKE RM OUTPUT DIR |
#-----------------------------+
# dir for the repeat maske output
$bac_rep_out_dir = "$bac_out_dir"."rm/";
mkdir $bac_rep_out_dir, 0777 unless (-e $bac_rep_out_dir);
#-----------------------------+
# MAKE GFF OUTPUT DIR |
#-----------------------------+
$gff_out_dir = "$bac_out_dir"."gff/";
mkdir $gff_out_dir, 0777 unless (-e $gff_out_dir);
#-----------------------------+
# FOR EACH DB IN THE |
# mask_libs ARRAY |
#-----------------------------+
for ($i=0; $i<$num_libs; $i++) {
$rep_db_name = $mask_libs[$i][0];
$rep_db_path = $mask_libs[$i][1];
$rm_opt = $mask_libs[$i][2];
#-----------------------------+
# GET THE STRING TO SEARCH |
# FOR IN THE RM OUTPUT |
#-----------------------------+
# The name used by Repeat Masker is taken from the FASTA header
# Only the first twenty characters of the FASTA header are used
open (IN, $file_to_mask);
while (<IN>) {
chomp;
if (/^\>(.*)/) {
print STDERR "\tFASTA HEADER:\n\t$_\n" if $verbose;
print STDERR "\tSEQ_ID:\n\t$1\n" if $verbose;
$search_name = $1;
my $test_len = 20;
my $cur_len = length ($search_name);
if ( $cur_len > $test_len ) {
$search_name = substr ($_, 0, 20);
}
} # End of in fasta header file
}
close IN;
#$gff_el_out = $indir.$rep_db_name."_".$ind_file."_EL.gff";
#$xml_el_out = $indir.$rep_db_name."_".$ind_file."_EL.game.xml";
#$gff_alldb_out = $indir."ALLDB_".$ind_file.".gff";
#$xml_alldb_out = $indir."ALLDB_".$ind_file."game.xml";
# Renamed 09/11/2007
$gff_el_out = $gff_out_dir.$name_root."_".$rep_db_name.".gff";
#$gff_el_out = $indir.$name_root."_".$rep_db_name.".gff";
$xml_el_out = $indir.$name_root."_".$rep_db_name.".game.xml";
$gff_alldb_out = $indir.$name_root."_ALLDB.gff";
$xml_alldb_out = $indir.$name_root."_ALLDB.game.xml";
if ($rm_opt) {
$cmd_repmask = $rm_path.
" -lib ".$rep_db_path.
" -pa ".$num_proc.
" -engine ".$engine.
" -xsmall".
" $rm_opt ".
" $file_to_mask";
}
else {
$cmd_repmask = $rm_path.
" -lib ".$rep_db_path.
" -pa ".$num_proc.
" -engine ".$engine.
" -xsmall".
" $file_to_mask";
}
#-----------------------------+
# SHOW THE USER THE COMMANDS |
# THAT WILL BE USED |
#-----------------------------+
if ($verbose) {
print STDERR "\n";
print STDERR "+-----------------------------+\n";
print STDERR "| CONVERT COMMANDS |\n";
print STDERR "+-----------------------------+\n";
print STDERR "\tSEARCH: ".$search_name."\n";
print STDERR "\tOUTFILE: ".$repmask_outfile."\n";
print STDERR "\tDB-NAME: ".$rep_db_name."\n";
print STDERR "\tGFF-FILE: ".$gff_alldb_out."\n";
print STDERR "\n";
print STDERR "+-----------------------------+\n";
print STDERR "| REPEATMASKER COMMANDS |\n";
print STDERR "+-----------------------------+\n";
print STDERR "\tLIB-NAME: ".$rep_db_name."\n";
print STDERR "\tLIB-PATH: ".$rep_db_path."\n";
print STDERR "\tEL-OUT: ".$gff_el_out."\n";
print STDERR "\tREPCMD: ".$cmd_repmask."\n";
print STDERR "\n\n";
}
#-----------------------------+
# PRINT INFO TO LOG FILE |
#-----------------------------+
if ($logfile) {
print LOG "\tLib Name: ".$rep_db_name."\n";
print LOG "\tLib Path: ".$rep_db_path."\n";
print LOG "\tEL Out: ".$gff_el_out."\n";
print LOG "\tRepCmd: ".$cmd_repmask."\n";
print LOG "\n\n";
}
unless ( $test ) {
$msg = "\nERROR:\n".
"Could not complete system cmd\n$cmd_repmask\n";
system ( $cmd_repmask );
}
#-----------------------------------------------------------+
# CONVERT TO GFF
#-----------------------------------------------------------+
my $append;
$append = 0;
$param = $rep_db_name;
print STDERR "Out to $gff_el_out" if $test;
rmout2gff ($prog, $repmask_outfile, $gff_el_out,
$name_root, $param, $append, $pos_strand );
# append to existing file
$append = 1;
$param = $rep_db_name;
rmout2gff ($prog, $repmask_outfile, $gff_el_out,
$name_root, $param, $append, $pos_strand );
#-----------------------------+
# CONVERT THE FILES FROM GFF |
# FORMAT TO A MORE USABLE |
# FORMAT FOR APOLLO |
#-----------------------------+
if ($apollo) {
print "\n\n\n\nCONVERTING GFF TO GAME\n\n\n" if $verbose;
&apollo_convert ( $gff_el_out, "gff", $xml_el_out, "game",
$file_to_mask, "none" );
}
#-----------------------------+
# FILES MOVED TO HERE |
#-----------------------------+
$repmask_out_cp = $bac_rep_out_dir.$name_root."_".$rep_db_name.
".rm.out";
$repmask_cat_cp = $bac_rep_out_dir.$name_root."_".$rep_db_name.
".rm.cat";
$repmask_tbl_cp = $bac_rep_out_dir.$name_root."_".$rep_db_name.
".rm.tbl";
$repmask_masked_cp = $bac_rep_out_dir.$name_root."_".$rep_db_name.
".masked.fasta";
$repmask_el_cp = $gff_out_dir.$name_root."_rm_".$rep_db_name.
".gff";
$repmask_xml_el_cp = $bac_rep_out_dir.$name_root."_".$rep_db_name.
".game.xml";
#///////////////////////////////////////
# This is another copy of the masked file
# this will allow me to put all of the masked files in
# a single location and have a shorter name
# These will all be placed in the $outdir
$repmask_local_cp = $outdir.$name_root.".masked.fasta";
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
# THE FOLLOWING ADDED 09/28/2006
# REmoved 09/11/2007
# $repmask_log = $indir.$rep_db_name."_".$ind_file.".log";
# $repmask_log_cp = $bac_rep_out_dir.$rep_db_name."_".$ind_file.".log";
# $msg = "\nERRORCan not move\n\t".$repmask_log."\n\t".
# $repmask_log_cp."\n";
# move ( $repmask_log, $repmask_log_cp) ||
# print STDERR $msg;
#-----------------------------+
# MAKE A COPY OF THE MASKED |
# FASTA FILE TO A SINGLE DIR |
#-----------------------------+
$msg = "\nERROR: Can not copy ".$repmask_masked_file." to\n".
$repmask_local_cp."\n";
copy ( $repmask_masked_file, $repmask_local_cp ) ||
print STDERR $msg;
#-----------------------------+
# MOVE THE RM OUTPUT FILES TO |
# THE TARGET DIR |
#-----------------------------+
$msg = "\nERROR: Can not move ".$repmask_outfile.
" to\n ".$repmask_cat_cp."\n";
move ( $repmask_outfile, $repmask_cat_cp ) ||
print STDERR $msg;
$msg = "\nERROR: Can not move ".$repmask_catfile."\n";
move ( $repmask_catfile, $repmask_cat_cp ) ||
print STDERR $msg;
# $msg = "\nERROR: The table file could not be moved from".
# "$repmask_tbl_file to $repmask_tbl_cp";
# move ( $repmask_tbl_file, $repmask_tbl_cp ) ||
# print STDERR $msg;
$msg = "\nERROR: Can not move ".$repmask_masked_file."\n";
move ( $repmask_masked_file, $repmask_masked_cp ) ||
print STDERR $msg;
print STDERR "Moving GFF to $repmask_el_cp\n" if $test;
$msg = "\nERROR: Can not move ".$gff_el_out."\n";
move ( $gff_el_out , $repmask_el_cp ) ||
print STDERR $msg;
if ($apollo) {
$msg = "\nERROR: Can not move ".$xml_el_out."\n";
move ( $xml_el_out, $repmask_xml_el_cp ) ||
print STDERR $msg;
}
} # End of for LibData
#-----------------------------+
# THE APOLLO CONVERT FOR THE |
# ENTIRE SET OF REPEAT LIBS |
# FOR A GIVEN SEQUENCE FILE |
# THAT IS BEING MASKED. |
#-----------------------------+
if ($apollo) {
apollo_convert ( $gff_alldb_out, "gff", $xml_alldb_out , "game",
$file_to_mask, "none" );
}
my $repmask_all_gff_cp = $bac_rep_out_dir.$name_root."_ALLDB.rm.gff";
my $repmask_all_xml_cp = $bac_rep_out_dir.$name_root."_ALLDB.rm.game.xml";
$msg = "\nCan not move ".$gff_alldb_out."\n";
move ( $gff_alldb_out, $repmask_all_gff_cp ) ||
print STDERR $msg;
if ($apollo) {
$msg = "\nCan not move ".$xml_alldb_out."\n";
move ( $xml_alldb_out, $repmask_all_xml_cp ) ||
print STDERR $msg;
}
# TEMP EXIT FOR DEBUG, WIll JUST RUN FIRST FILE TO BE MASKED
if ($debug) {
if ($file_num > $file_num_max ) {
print "\nDebug run finished\n\n";
exit;
}
}
} # End of for each file in the input folder
close LOG if $logfile;
print STDOUT "\n";
exit;
#-----------------------------------------------------------+
# SUBFUNCTIONS |
#-----------------------------------------------------------+
sub rmout2gff {
# DO CONVERSION
# example use
#rmout2gff ($prog, $infile, $outfile, $seqname, $param, $append, $pos_strand );
# $source = program name source for the annotation
# $rm_file = path to the repeat masker file
# $gff_file = path to the gff output file
# $seq_id = identifier of the sequence being processed
# $src_suffix = parameter name/ db name suffix for source
# $do_append = append results to an existing gff file
# $all_plus = place all results on the plus strand
# the default will be to concatenate when the prefix
# variable can not be undertood
my ( $source, $rm_file, $gff_out, $seq_id, $src_suffix, $do_append,
$all_plus) = @_;
my $strand;
# Set the has_seq_id flag to true is a over ride sequence id was passed
my $has_seq_id;
if ($seq_id) {
$has_seq_id = 1;
}
else {
$has_seq_id = 0;
}
#-----------------------------+
# OPEN RM FILE |
#-----------------------------+
# Default is to expect intput from STDIN if infile path not given
if ($rm_file) {
open ( RM_IN, "<".$rm_file ) ||
die "Could not open the RM infile:\n $rm_file\n";
}
else {
print STDERR "Expecting input from STDIN";
open ( RM_IN, "<&STDIN" ) ||
die "Could not open STDIN for input\n";
}
#-----------------------------+
# OPEN THE GFF OUTFILE |
#-----------------------------+
# Default to STDOUT if no argument given
if ($gff_out) {
if ($do_append) {
open (GFFOUT, ">>$gff_out") ||
die "ERROR: Can not open gff outfile:\n $gff_out\n";
}
else {
open (GFFOUT,">$gff_out") ||
die "ERROR: Can not open gff outfile:\n $gff_out\n";
if ($gff_ver =~ "GFF3") {
print GFFOUT "##gff-version 3\n";
}
}
}
else {
open (GFFOUT, ">&STDOUT") ||
die "Can not print to STDOUT\n";
if ($gff_ver =~ "GFF3") {
print GFFOUT "##gff-version 3\n";
}
}
#-----------------------------+
# SET PROGRAM SOURCE |
#-----------------------------+
if ($src_suffix) {
$source = $source.":".$src_suffix;
}
#-----------------------------------------------------------+
# REPEATMASKER OUT FILE CONTAINS
#-----------------------------------------------------------+
# 0 Smith-Waterman score of the match
# 1 % substitutions in matching region compared to the consensus
# 2 % of bases opposite a gap in the query sequence (deleted bp)
# 3 % of bases opposite a gap in the repeat consensus (inserted bp)
# 4 name of query sequence
# 5 starting position of match in query sequence
# 6 ending position of match in query sequence
# 7 no. of bases in query sequence past the ending position of match
# in parenthesis
# 8 match is with the Complement of the consensus sequence in the database
# C
# 9 name of the matching interspersed repeat
#10 class of the repeat, in this case a DNA transposon
#11 no. of bases in (complement of) the repeat consensus sequence
# in parenthesis
#12 starting position of match in database sequence
# (using top-strand numbering)
#13 ending position of match in database sequence
my $lc_count = 0; # Count of low complexity
my $tr_count = 0; # Count of tandem repeats
my $m_count = 0; # Count of matches
my $unk_count = 0; # Count of unkonwn type
while (<RM_IN>) {
chomp;
my @rmout = split;
my $line_len = @rmout;
# Skip lines related to database used etc
next if ($line_len < 13);
my $cur_strand = $rmout[8];
#-----------------------------+
# GET STRAND AND HIT COORDS |
#-----------------------------+
my $hit_start; # Start position in hit
my $hit_end; # End position in alignment hit
if ($cur_strand =~ "C" ) {
$strand = "-";
$hit_start = $rmout[12];
$hit_end = $rmout[13];
}
else {
$strand = "+";
$hit_start = $rmout[11];
$hit_end = $rmout[12];
}
if ($all_plus) {
$strand = "+";
}
#-----------------------------+
# SET SEQUENCE ID |
#-----------------------------+
unless ($has_seq_id) {
if ($rmout[4]) {
$seq_id = $rmout[4];
}
else {
$seq_id = "seq";
}
}
if ($gff_ver =~ "GFF3") {
$seq_id = seqid_encode($seq_id);
}
# Since these are essentially parts of a match these will be
# set to be match part
my $rm_class = $rmout[10];
if ($gff_ver =~ "GFF3") {
$rm_class = gff3_encode($rm_class);
}
#-----------------------------+
# FORMAT FEATURE |
#-----------------------------+
# my $feature = "match_part";
# if ($rm_class =~ "Unknown") {
# $feature = "match_part";
# }
my $feature = "match";
if ($rm_class =~ "Unknown") {
$feature = "match";
}
elsif ($rm_class =~ "Simple_repeat") {
$tr_count++;
$feature = "tandem_repeat"
}
elsif ($rm_class =~ "Low_complexity") {
$lc_count++;
$feature = "low_complexity_region";
}
#-----------------------------+
# FORMAT ATTRIBUTE |
#-----------------------------+
my $hitname = $rmout[9];
if ($gff_ver =~ "GFF3") {
$hitname = gff3_encode($hitname);
}
my $attribute;
if ($gff_ver =~ "GFF3") {
if ($rm_class =~ "Simple_repeat") {
$attribute = "ID=".$hitname."_".$tr_count;
}
elsif ($rm_class =~ "Low_complexity") {
$attribute = "ID=".$hitname."_".$lc_count;
}
# elsif ($feature =~ "match_part") {
elsif ($feature =~ "match") {
$m_count++;
$attribute = "ID=match_".$m_count."_".$hitname.
"; ".
"Name=".$hitname."; ".
"Target=".$hitname." ".
$hit_start." ".$hit_end;
}
else {
$attribute="ID=".$hitname;
}
}
else {
$attribute = $hitname;
}
# If match part may want to express where thse
# match on the corresponging region in the dbase
#-----------------------------+
# PRINT GFF OUT |
#-----------------------------+
# TO DO: Allow for attribute name at cmd line
# May also want to place everything in positive strand
print GFFOUT "$seq_id\t". # qry sequence name
"$source\t". # software used
"$feature\t". # feature attribute name
"$rmout[5]\t". # start
"$rmout[6]\t". # stop
"$rmout[0]\t". # smith waterman score"
"$strand\t". # Postive strand
".\t". # frame
"$attribute". # attribute
"\n";
# Seeing if working
# print STDERR "$seq_id\t". # qry sequence name
# "$source\t". # software used
# "$feature\t". # feature attribute name
# "$rmout[5]\t". # start
# "$rmout[6]\t". # stop
# "$rmout[0]\t". # smith waterman score"