-
Notifications
You must be signed in to change notification settings - Fork 5
/
batch_findmite.pl
1505 lines (1221 loc) · 42 KB
/
batch_findmite.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_findmite.pl - Batch run the findmite program |
# |
#-----------------------------------------------------------+
# |
# AUTHOR: James C. Estill |
# CONTACT: JamesEstill_@_gmail.com |
# STARTED: 08/30/2007 |
# UPDATED: 03/08/2010 |
# |
# DESCRIPTION: |
# Run the FINDMITE program in batch mode using a config |
# file to allow the program to run in a high-throughput |
# batch mode. |
# |
# LICENSE: |
# GNU General Public License, Version 3 |
# http://www.gnu.org/licenses/gpl.html |
# |
#-----------------------------------------------------------+
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
# Array to hold the findmite parameters
my @fm_params = ();
#-----------------------------+
# 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; # Input directory
my $outdir; # Output directory
my $parfile; # Parameters file
my $name_root; # Root name of the input file
my $gff_dir; # Dir to hold the gff output file
my $param; # Name of the parameter set used
my $prog = "findmite"; # Name of program
my $fasta_out_path;
# Counters/Index Vals
my $i = 0; # Array index val
my $file_num = 0; # File number
my $proc_num = 0; # Process number
# Booleans
my $verbose = 0;
my $help = 0;
my $quiet = 0;
my $show_help = 0;
my $show_usage = 0;
my $show_man = 0;
my $show_version = 0;
my $do_gff_convert = 1;
my $do_fasta_out = 0; # Create a fasta file with all predicted MITEs
my $do_test = 0;
my $fasta_append = 0;
my $findmite_bin = $ENV{FINDMITE_BIN} || "FINDMITE1New.bin";
#-----------------------------+
# COMMAND LINE OPTIONS |
#-----------------------------+
my $ok = GetOptions(# Required Arguments
"i|indir=s" => \$indir,
"o|outdir=s" => \$outdir,
"c|config=s" => \$parfile,
# Additional options
"program=s" => \$prog,
"p|param=s" => \$param,
"gff-ver=s" => \$gff_ver,
"f|fasta" => \$do_fasta_out,
"q|quiet" => \$quiet,
"verbose" => \$verbose,
"gff" => \$do_gff_convert,
"test" => \$do_test,
"append-fasta" => \$fasta_append,
# Additional information
"usage" => \$show_usage,
"version" => \$show_version,
"man" => \$show_man,
"h|help" => \$show_help,);
#-----------------------------+
# SHOW REQUESTED HELP |
#-----------------------------+
if ( ($show_usage) ) {
# print_help ("usage", File::Spec->rel2abs($0) );
print_help ("usage", $0 );
}
if ( ($show_help) || (!$ok) ) {
# print_help ("help", File::Spec->rel2abs($0) );
print_help ("help", $0 );
}
if ($show_version) {
print "\nbatch_findmite.pl:\nVersion: $VERSION\n\n";
exit;
}
if ($show_man) {
# User perldoc to generate the man documentation.
system("perldoc $0");
exit($ok ? 0 : 2);
}
#-----------------------------+
# 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) || (!$parfile) ) {
print "ERROR: Input directory path required\n" if (!$indir);
print "ERROR: Output directory path required\n" if (!$outdir);
print "ERROR: Config file required\n" if (!$parfile);
print_help ("usage", $0 );
}
#-----------------------------------------------------------+
# 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 FINDMITE PARAMATERS |
#-----------------------------+
open (PARFILE, "<$parfile")
|| die "Can not open the paramter file:\n$parfile\n";
while (<PARFILE>) {
chomp;
# # Use the following if an error crops up later
# print "IN: $_\n";
# Ignores comment lines starting with #
unless (m/^\#/) {
#my @in_line = split(/\t/, $_);
my @in_line = split; # Implicit split of $_ by whitespace
my $num_in_line = @in_line;
$fm_params[$i][0] = $in_line[0] || "NULL";
$fm_params[$i][1] = $in_line[1] || "NULL";
$fm_params[$i][2] = $in_line[2] || "NULL";
$fm_params[$i][3] = $in_line[3] || "NULL";
$fm_params[$i][4] = $in_line[4] || "NULL";
$fm_params[$i][5] = $in_line[5] || "NULL";
$fm_params[$i][6] = $in_line[6] || "NULL";
$fm_params[$i][7] = $in_line[7] || "NULL";
$fm_params[$i][8] = $in_line[8] || "NULL";
$fm_params[$i][9] = $in_line[9] || "NULL";
# # Use the following if a error crops up later
# if ($verbose) {
# print STDERR "\tProcessed as:\n";
# print STDERR "\t".$fm_params[$i][0]."\n";
# print STDERR "\t".$fm_params[$i][1]."\n";
# print STDERR "\t".$fm_params[$i][2]."\n";
# print STDERR "\t".$fm_params[$i][3]."\n";
# print STDERR "\t".$fm_params[$i][4]."\n";
# print STDERR "\t".$fm_params[$i][5]."\n";
# print STDERR "\t".$fm_params[$i][6]."\n";
# print STDERR "\t".$fm_params[$i][7]."\n";
# print STDERR "\t".$fm_params[$i][8]."\n";
# print STDERR "\t".$fm_params[$i][9]."\n";
# }
$i++;
}
} # End of while INFILE
my $num_par_sets = $i;
my $max_i = $i-1;
close PARFILE;
# TO DO: CHECK PARAM FILE VALIDITY
#-----------------------------+
# 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 findmite runs to process\n";
for my $ind_file (@fasta_files) {
$file_num++;
# Get root file name
if ($ind_file =~ m/(.*)\.masked\.fasta$/ ) {
$name_root = "$1";
}
elsif ($ind_file =~ m/(.*)\.fasta$/ ) {
$name_root = "$1";
}
elsif ($ind_file =~ m/(.*)\.fa$/ ) {
$name_root = "$1";
}
else {
# default to full file name
$name_root = $ind_file;
}
#-----------------------------+
# CREATE ROOT NAME DIR |
#-----------------------------+
my $name_root_dir = $outdir.$name_root."/";
unless (-e $name_root_dir) {
mkdir $name_root_dir ||
die "Could not create dir:\n$name_root_dir\n"
}
#-----------------------------+
# CREATE FINDMITE OUTDIR |
#-----------------------------+
# Dir to hold gene prediction output from local software
my $findmite_dir = $name_root_dir."findmite/";
unless (-e $findmite_dir) {
mkdir $findmite_dir ||
die "Could not create genscan out dir:\n$findmite_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 FINDMITE FOR EACH SET OF PARAM VALUES |
#-----------------------------------------------------------+
for ($i=0; $i<$num_par_sets; $i++) {
$proc_num++;
# Load array vals to usefull short names
my $mite_name = $fm_params[$i][0];
my $rep = $fm_params[$i][1];
my $tir_len = $fm_params[$i][2];
my $num_mismatch = $fm_params[$i][3];
my $filt_at = $fm_params[$i][4];
my $filt_cg = $fm_params[$i][5];
my $filt_atta = $fm_params[$i][6];
my $filt_2_base = $fm_params[$i][7];
my $min_dist = $fm_params[$i][8];
my $max_dist = $fm_params[$i][9];
if ($verbose) {
print STDERR "\n\n========================================\n";
print STDERR " FindMITE Process $proc_num of $num_proc_total\n";
print STDERR " ".$name_root."_".$mite_name."\n";
print STDERR "========================================\n";
}
#-----------------------------+
# RUN THE FINDMITE PROGRAM |
#-----------------------------+
# Then should be made a subfunction that can return true
my $fm_in = $indir.$ind_file;
my $fm_out = $findmite_dir.$name_root."_".$mite_name.".mite.txt";
my $fm_cmd = "$findmite_bin $fm_in $fm_out";
print STDERR "CMD: $fm_cmd\n" if $verbose;
unless ($do_test) {
# It seems like FINDMTE is closing
# Some j
open(FINDMITE,"|$fm_cmd") ||
die "Could not open findmite\n";
#sleep 1;
print FINDMITE "150000\n" ||
die "Could not set length";
print FINDMITE "$rep\n";
#sleep 1;
print FINDMITE "$tir_len\n";
#sleep 1;
print FINDMITE "$num_mismatch\n";
#sleep 1;
print FINDMITE "$filt_at\n";
#sleep 1;
print FINDMITE "$filt_cg\n";
#sleep 1;
print FINDMITE "$filt_atta\n";
#sleep 1;
print FINDMITE "$filt_2_base\n";
#sleep 1;
print FINDMITE "$min_dist\n";
#sleep 1;
print FINDMITE "$max_dist\n";
#sleep 10;
close FINDMITE;
}
#-----------------------------+
# CONVERT OUTPUT TO GFF |
#-----------------------------+
if ($do_gff_convert) {
my $findmite_gff = $findmite_dir.$name_root.
"_".$mite_name."mite.gff";
my $findmite_fasta = $outdir."FINDMITE_".
$mite_name."mite.fasta";
if (-e $fm_out) {
# Currently will do_fasta_file creation if requested
# This last boolean set to 1 will append to any existing
# fasta file that is present
# OLD GFF2 CONVERSION REQUIRED:
# my ($findmite_in, $gff_out, $append_gff, $seqname,
# $fasta_out, $append_fasta, $fasta_out_path) = @_;
# findmite2gff ($fm_out, $findmite_gff, 0, $name_root,
# $do_fasta_out, 1, $findmite_fasta);
#NEW GFF3 CONVERSION REQUIRES:
# my ( $source, $findmite_in, $gff_out, $src_suffix,
# $append_gff,
# $fm_seqname, $fasta_out, $append_fasta) = @_;
my $param = $mite_name;
my $do_append_gff = 1;
if ($fasta_out_path) {
findmite2gff ($prog, $fm_out, $findmite_gff, $param,
$do_append_gff, $name_root,
$fasta_out_path, $fasta_append);
} else {
findmite2gff ($prog, $fm_out, $findmite_gff, $param,
$do_append_gff, $name_root,
0, 0);
}
# Copy the gff file file
my $gff_copy_path = $gff_dir.$name_root.
"_".$mite_name."mite.gff";
my $cp_err_msg = "Can not copy from:\n".
" $findmite_gff TO $gff_copy_path\n";
copy ($findmite_gff, $gff_copy_path) ||
die "$cp_err_msg\n";
}
else {
print STDERR "\nERROR: Could not find the findmite out file\n".
"$fm_out\nto convert to gff\n";
}
}
# print return to clean up the command line
print "\n";
} # End of run find mite for each set of param vals
} # End of for each $ind_file
exit;
#-----------------------------------------------------------+
# SUBFUNCTIONS |
#-----------------------------------------------------------+
sub findmite2gff {
#-----------------------------+
# SUBFUNCTION VARS |
#-----------------------------+
my ( $source, $findmite_in, $gff_out, $src_suffix, $append_gff,
$fm_seqname, $fasta_out, $append_fasta) = @_;
# GFF OUT VARS
my $gff_seq_id; # Seq id for use in gff
my $gff_start; # Start of the feature
my $gff_end; # End of the feature
my $gff_source; # Source ie findmite_at_11
my $gff_name; # Name of the feature
# FINDMITE HEADER VARS
my $fm_dir_repeats; # Direct repeats
my $fm_tir_len; # Lenght of the TIR
my $fm_mismatch_max; # Max number of mistmatches
my $fm_filter_at; # Were A/T strings filtered
my $fm_filter_cg; # Were C/G strings filtered
my $fm_filter_atta; # Were AT/TA strings filtered
my $fm_filter_2_base; # Percent (0 to 100)
my $fm_min_dist; # Minimum distance used
my $fm_max_dist; # Maximum distance used
my $fm_file_an; # Name of the file analyzed
# FINDMATE INDIVIDUAL MITE VARS
my $fm_pattern; # Pattern
my $fm_seq_id; # Id of the query sequence
my $fm_num_mismatch; # Num of mismatches
my $fm_seq = ""; # Sequence string as parsed from findmite
my $mite_seq_string; # Sequence string of the putatitve mite
my $mite_context_5; # 5' Context of the mite (40bp)
my $mite_context_3; # 3' Context of the mite (40bp)
my $mite_start; # Start of the mite as parsed from FM
my $mite_end; # End of the mite as parsed from FM
# Counter
my $mite_num = 0; # Incremented ID number for the mite
# BOOLEANS
my $in_seq = 0; # Boolean, in seq data (past header info)
#-----------------------------+
# OPEN INFILE |
#-----------------------------+
if ($findmite_in) {
open (INFILE, "<$findmite_in") ||
die "Can not open input file:\n$findmite_in\n";
}
else {
print STDERR "Expecting input from STDIN\n";
open (INFILE, "<&STDIN") ||
die "Could not open STDIN for input.\n"
}
#-----------------------------+
# OPEN THE GFF OUTFILE |
#-----------------------------+
if ($gff_out) {
if ($append_gff) {
open (GFFOUT, ">>$gff_out") ||
die "Can not open output file:\n$gff_out\n";
}
else {
open (GFFOUT, ">$gff_out") ||
die "Can not open gff output file:\n$gff_out\n";
}
}
else {
open (GFFOUT, ">&STDOUT") ||
die "Can not print to STDOUT\n";
}
#-----------------------------+
# FASTA OUTPUT FILE |
#-----------------------------+
if ($fasta_out) {
if ($append_fasta) {
open (FASTAOUT, ">>$fasta_out") ||
die "Can not FASTA output file:\n$fasta_out\n";
}
else {
open (FASTAOUT, ">$fasta_out") ||
die "Can not FASTA output file:\n$fasta_out\n";
}
}
#-----------------------------+
# PROCESS FINDMITE FILE |
#-----------------------------+
while (<INFILE>) {
chomp;
#print $_."\n";
if(m/^Pattern : (.*)/) {
# If we have previously loaded seq data then
# futher parse the sequence string and and
# print the results to the gff output
if ($in_seq) {
if ($fm_seq =~ m/(.*)\((.*)\)\-{5}(.*)\-{5}\((.*)\)(.*)/) {
$mite_context_5 = $1;
$mite_start = $2;
$mite_seq_string = $3;
$mite_end = $4;
$mite_context_3 = $5;
if ($verbose) {
print STDERR "\t5CON: $mite_context_5\n";
print STDERR "\tSTAR: $mite_start\n";
print STDERR "\tMITE: $mite_seq_string\n";
print STDERR "\tEND : $mite_end\n";
print STDERR "\t3CON: $mite_context_3\n";
print STDERR "\n\n";
}
#-----------------------------+
# SET SEQUENCE ID |
#-----------------------------+
if ($fm_seqname) {
$gff_seq_id = $fm_seqname;
}
else {
if ($fm_seq_id =~ m/^>(\S*)\s./) {
$gff_seq_id = $1;
}
elsif ($fm_seq_id =~ m/^>(.*)/) {
$gff_seq_id = $1;
}
else {
$gff_seq_id = $fm_seq_id;
}
}
#-----------------------------+
# SET PROGRAM SOURCE |
#-----------------------------+
$gff_source = $source;
if ($src_suffix) {
$gff_source = $gff_source.":".$src_suffix;
}
# else {
# $gff_source = $gff_source.":".
# $fm_dir_repeats."_".$fm_tir_len;
# }
#-----------------------------+
# SET FEATURE NAME |
#-----------------------------+
if ($src_suffix) {
$gff_name = "findmite_".$src_suffix.
"_".$mite_num;
}
else {
$gff_name = "findmite_".$mite_num;
}
$gff_start = $mite_start;
$gff_end = $mite_end;
#-----------------------------+
# PRINT TO GFF FILE |
#-----------------------------+
my $attribute;
if ($gff_ver =~ "GFF3") {
$attribute = "ID=".$gff_name;
}
else {
$attribute = $gff_name
}
print GFFOUT "$gff_seq_id\t". # Seq name
"$gff_source\t". # Source
"MITE\t". # Feature type
"$gff_start\t". # Start
"$gff_end\t". # End
".\t". # Score
"+\t". # Strand
".\t". # Frame
"$attribute\n"; # Feature name
#-----------------------------+
# PRINT MITE TO FASTA FILE |
#-----------------------------+
if ($fasta_out) {
print FASTAOUT ">$gff_name\n";
print FASTAOUT "$mite_seq_string\n";
}
}
# Reset vals to null
$fm_seq = "";
}
$in_seq = 1;
$mite_num++;
$fm_pattern = $1;
print STDERR "$fm_pattern\n" if $verbose;
}
elsif(m/^Sequence : (.*)/) {
$fm_seq_id = $1;
print STDERR "\t$fm_seq_id\n" if $verbose;
}
elsif(m/^Mismatch : (.*)/){
$fm_num_mismatch = $1;
print STDERR "\t$fm_num_mismatch\n" if $verbose;
}
elsif($in_seq) {
$fm_seq = $fm_seq.$_;
}
#-----------------------------+
# HEADER INFORMATION |
#-----------------------------+
elsif(m/Direct repeats.{17}(.*)/) {
$fm_dir_repeats = $1;
}
elsif(m/Length of TIR.{18}(.*)/) {
$fm_tir_len = $1;
}
elsif(m/Number of mis.{18}(.*)/) {
$fm_num_mismatch = $1;
}
elsif(m/Filtering A\/T.{18}(.*)/) {
$fm_filter_at = $1;
}
elsif(m/Filtering C\/G.{18}(.*)/) {
$fm_filter_cg = $1;
}
elsif(m/Filtering AT\/.{18}(.*)/) {
$fm_filter_atta = $1;
}
elsif(m/Filtering 2.{20}(.*)/) {
$fm_filter_2_base = $1;
}
elsif(m/Minimum dist.{19}(.*)/) {
$fm_min_dist = $1;
}
elsif(m/Maximum dist.{19}(.*)/) {
$fm_max_dist = $1;
}
elsif(m/The results from the input.{17}(.*)/) {
$fm_file_an = $1;
}
}
#-----------------------------+
# PRINT OUT OF DATA IN VARS |
#-----------------------------+
if ($fm_seq =~ m/(.*)\((.*)\)\-{5}(.*)\-{5}\((.*)\)(.*)/) {
#if ($fm_seq =~ m/(.*)\((.*)\)\-\-\-\-\-(.*)\-\-\-\-\-\((.*)\)(.*)/) {
$mite_context_5 = $1;
$mite_start = $2;
$mite_seq_string = $3;
$mite_end = $4;
$mite_context_3 = $5;
if ($verbose) {
print STDERR "\t5CON: $mite_context_5\n";
print STDERR "\tSTAR: $mite_start\n";
print STDERR "\tMITE: $mite_seq_string\n";
print STDERR "\tEND : $mite_end\n";
print STDERR "\t3CON: $mite_context_3\n";
print STDERR "\n\n";
}
}
#////////////////////////////////
# THE FOLLOWING CODE SHOULD NOT BE THIS REDUNDANT CUT AND COPY
#-----------------------------+
# SET SEQUENCE ID |
#-----------------------------+
if ($fm_seqname) {
$gff_seq_id = $fm_seqname;
}
else {
if ($fm_seq_id =~ m/^>(\S*)\s./) {
$gff_seq_id = $1;
}
elsif ($fm_seq_id =~ m/^>(.*)/) {
$gff_seq_id = $1;
}
else {
$gff_seq_id = $fm_seq_id;
}
}
#-----------------------------+
# SET PROGRAM SOURCE |
#-----------------------------+
$gff_source = $source;
if ($src_suffix) {
$gff_source = $gff_source.":".$src_suffix;
}
# else {
# $gff_source = $gff_source.":".
# $fm_dir_repeats."_".$fm_tir_len;
# }
#-----------------------------+
# SET FEATURE NAME |
#-----------------------------+
if ($src_suffix) {
$gff_name = "findmite_".$src_suffix.
"_".$mite_num;
}
else {
$gff_name = "findmite_".$mite_num;
}
$gff_start = $mite_start;
$gff_end = $mite_end;
my $attribute;
if ($gff_ver =~ "GFF3") {
$attribute = "ID=".$gff_name;
}
else {
$attribute = $gff_name
}
print GFFOUT "$gff_seq_id\t". # Seq name
"$gff_source\t". # Source
"MITE\t". # Feature type
"$gff_start\t". # Start
"$gff_end\t". # End
".\t". # Score
"+\t". # Strand
".\t". # Frame
"$attribute\n"; # Feature name
# print GFFOUT "$gff_seq_id\t". # Seq name
# "$gff_source\t". # Source
# "MITE\t". # Feature type
# "$gff_start\t". # Start
# "$gff_end\t". # End
# ".\t". # Score
# "+\t". # Strand
# ".\t". # Frame
# "$gff_name\n"; # Feature name
#
# # END REDUNDANT CUT AND COPY
# #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
#-----------------------------+
# PRINT MITE TO FASTA FILE |
#-----------------------------+
if ($fasta_out) {
print FASTAOUT ">$gff_name\n";
print FASTAOUT "$mite_seq_string\n";
}
# Print while debu
if ($verbose) {
print STDERR "FILE : $fm_file_an\n";
print STDERR "DIRREP: $fm_dir_repeats\n";
print STDERR "TIRLEN: $fm_tir_len\n";
print STDERR "NUMMIS: $fm_num_mismatch\n";
print STDERR "F_AT : $fm_filter_at\n";
print STDERR "F_CG : $fm_filter_cg\n";
print STDERR "F_ATTA: $fm_filter_atta\n";
print STDERR "F_2BAS: $fm_filter_2_base\n";
print STDERR "MIN : $fm_min_dist\n";
print STDERR "MAX : $fm_max_dist\n";
}
close INFILE;
close GFFOUT;
close FASTAOUT if ($fasta_out);
}
# The original subfunction
sub findmite2gff_old {
#-----------------------------+
# SUBFUNCTION VARS |
#-----------------------------+
my ($findmite_in, $gff_out, $append_gff, $seqname,
$fasta_out, $append_fasta, $fasta_out_path) = @_;
# GFF OUT VARS
my $gff_seq_id; # Seq id for use in gff
my $gff_start; # Start of the feature
my $gff_end; # End of the feature
my $gff_source; # Source ie findmite_at_11
my $gff_name; # Name of the feature
# FINDMITE HEADER VARS
my $fm_dir_repeats; # Direct repeats
my $fm_tir_len; # Lenght of the TIR
my $fm_mismatch_max; # Max number of mistmatches
my $fm_filter_at; # Were A/T strings filtered
my $fm_filter_cg; # Were C/G strings filtered
my $fm_filter_atta; # Were AT/TA strings filtered
my $fm_filter_2_base; # Percent (0 to 100)
my $fm_min_dist; # Minimum distance used
my $fm_max_dist; # Maximum distance used
my $fm_file_an; # Name of the file analyzed
# FINDMATE INDIVIDUAL MITE VARS
my $fm_pattern; # Pattern
my $fm_seq_id; # Id of the query sequence
my $fm_num_mismatch; # Num of mismatches
my $fm_seq = ""; # Sequence string as parsed from findmite
my $mite_seq_string; # Sequence string of the putatitve mite
my $mite_context_5; # 5' Context of the mite (40bp)
my $mite_context_3; # 3' Context of the mite (40bp)
my $mite_start; # Start of the mite as parsed from FM
my $mite_end; # End of the mite as parsed from FM
# Counter
my $mite_num = 0; # Incremented ID number for the mite
# BOOLEANS
my $in_seq = 0; # Boolean, in seq data (past header info)
#-----------------------------+
# OPEN FILES |
#-----------------------------+
open (INFILE, "<$findmite_in") ||
die "Can not open input file:\n$findmite_in\n";
if ($append_gff) {
open (GFFOUT, ">>$gff_out") ||
die "Can not open output file:\n$gff_out\n";
}
else {
open (GFFOUT, ">$gff_out") ||
die "Can not open gff output file:\n$gff_out\n";
}
if ($fasta_out) {
# my $fasta_out_path = $outdir."FINDMITE_".
# $fm_dir_repeats."_".$fm_tir_len.".fasta";
if ($append_fasta) {
open (FASTAOUT, ">>$fasta_out_path") ||
die "Can not FASTA output file:\n$fasta_out_path\n";
}
else {
open (FASTAOUT, ">$fasta_out_path") ||
die "Can not FASTA output file:\n$fasta_out_path\n";
}
} # End of if $fasta_out
#-----------------------------+
# PROCESS FINDMITE FILE |
#-----------------------------+
while (<INFILE>) {
chomp;
#print $_."\n";
if(m/^Pattern : (.*)/) {
# If we have previously loaded seq data then
# futher parse the sequence string and and
# print the results to the gff output
if ($in_seq) {
if ($fm_seq =~ m/(.*)\((.*)\)\-{5}(.*)\-{5}\((.*)\)(.*)/) {
$mite_context_5 = $1;
$mite_start = $2;
$mite_seq_string = $3;
$mite_end = $4;
$mite_context_3 = $5;
if ($verbose) {
print STDERR "\t5CON: $mite_context_5\n";
print STDERR "\tSTAR: $mite_start\n";
print STDERR "\tMITE: $mite_seq_string\n";
print STDERR "\tEND : $mite_end\n";
print STDERR "\t3CON: $mite_context_3\n";
print STDERR "\n\n";
}
#-----------------------------+
# PRINT TO GFF FILE |
#-----------------------------+
# Parse seq id for shorter name
if ($fm_seq_id =~ m/^>(\S*)\s./) {
$gff_seq_id = $1;
}
elsif ($fm_seq_id =~ m/^>(.*)/) {
$gff_seq_id = $1;
}
else {
$gff_seq_id = $fm_seq_id;
}
$gff_source = "findmite:".
$fm_dir_repeats."_".$fm_tir_len;
$gff_name = $gff_seq_id."_".$fm_dir_repeats.
"_".$fm_tir_len."_".$mite_num;
$gff_start = $mite_start;
$gff_end = $mite_end;
print GFFOUT
"$gff_seq_id\t". # Seq name
"$gff_source\t". # Source
"mite\t". # Feature type
"$gff_start\t". # Start
"$gff_end\t". # End
".\t". # Score
".\t". # Strand
".\t". # Frame
"$gff_name\n"; # Feature name
#-----------------------------+
# PRINT MITE TO FASTA FILE |
#-----------------------------+
if ($fasta_out) {
print FASTAOUT ">$gff_name\n";
print FASTAOUT "$mite_seq_string\n";
}
}
# Reset vals to null
$fm_seq = "";
}
$in_seq = 1;
$mite_num++;
$fm_pattern = $1;
print STDERR "$fm_pattern\n" if $verbose;
}
elsif(m/^Sequence : (.*)/) {
$fm_seq_id = $1;
print STDERR "\t$fm_seq_id\n" if $verbose;
}
elsif(m/^Mismatch : (.*)/){
$fm_num_mismatch = $1;
print STDERR "\t$fm_num_mismatch\n" if $verbose;
}
elsif($in_seq) {
$fm_seq = $fm_seq.$_;
}
#-----------------------------+
# HEADER INFORMATION |
#-----------------------------+
elsif(m/Direct repeats.{17}(.*)/) {
$fm_dir_repeats = $1;