-
Notifications
You must be signed in to change notification settings - Fork 50
/
ProcessRepeats
executable file
·9414 lines (8492 loc) · 347 KB
/
ProcessRepeats
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
##---------------------------------------------------------------------------##
## File:
## @(#) ProcessRepeats
## Authors:
## Arian Smit <asmit@systemsbiology.org>
## Robert Hubley <rhubley@systemsbiology.org>
## Description:
## Takes RepeatMasker output and produces an annotation table.
##
##
#******************************************************************************
#*
#* Copyright (C) Institute for Systems Biology 2002-2012 Developed by
#* Arian Smit and Robert Hubley.
#*
#* Copyright (C) Arian Smit 2000-2001
#*
#* Copyright (C) University of Washington 1996-1999 Developed by Arian Smit,
#* Philip Green and Colin Wilson of the University of Washington Department of
#* Genomics.
#*
#* This work is licensed under the Open Source License v2.1. To view a copy
#* of this license, visit http://www.opensource.org/licenses/osl-2.1.php or
#* see the license.txt file contained in this distribution.
#*
###############################################################################
# ChangeLog
#
# $Log$
#
###############################################################################
#
#
=head1 NAME
ProcessRepeats - Post process results from RepeatMasker and produce an annotation file.
=head1 SYNOPSIS
ProcessRepeats [-options] <RepeatMasker *.cat file>
=head1 DESCRIPTION
The options are:
=over 4
=item -h(elp)
Detailed help
=item -species <query species>
Post process RepeatMasker results run on sequence from
this species. Default is human.
=item -lib <libfile>
Skips most processing, does not produce a .tbl file unless
the custome library is in the ">name#class" format.
=item -nolow
Does not display simple repeats or low_complexity DNA in the annotation.
=item -noint
Skips steps specific to interspersed repeats, saving lots of time.
=item -lcambig
Outputs ambiguous DNA transposon fragments using a lower case
name. All other repeats are listed in upper case. Ambiguous
fragments match multiple repeat elements and can only be
called based on flanking repeat information.
=item -u
Creates an untouched annotation file besides the manipulated file.
=item -xm
Creates an additional output file in cross_match format (for parsing).
=item -ace
Creates an additional output file in ACeDB format.
=item -gff
Creates an additional Gene Feature Finding format.
=item -poly
Creates an output file listing only potentially polymorphic simple repeats.
=item -no_id
Leaves out final column with unique number for each element (was default).
=item -excln
Calculates repeat densities excluding long stretches of Ns in the query.
=item -orf2
Results in sometimes negative coordinates for L1 elements; all L1 subfamilies
are aligned over the ORF2 region, sometimes improving interpretation of data.
=item -a
Shows the alignments in a .align output file.
=item -maskSource <originalSeqenceFile>
Instructs ProcessRepeats to mask the sequence file using the annotation.
=item -x
Mask repeats with a lower case 'x'.
=item -xsmall
Mask repeats by making the sequence lowercase.
=back
=head1 SEE ALSO
=over 4
RepeatMasker, Crossmatch, Blast
=back
=head1 COPYRIGHT
Copyright 2002-2012 Arian Smit, Robert Hubley, Institute for Systems Biology
=head1 AUTHORS
Arian Smit <asmit@systemsbiology.org>
Robert Hubley <rhubley@systemsbiology.org>
=cut
#
# Module Dependence
#
use strict;
use FindBin;
use lib $FindBin::RealBin;
use SeqDBI;
use FileHandle;
use FastaDB;
use SearchResult;
use SearchEngineI;
use SearchResultCollection;
use ArrayList;
use CrossmatchSearchEngine;
use Getopt::Long;
use Taxonomy;
use Data::Dumper;
use PRSearchResult;
use Matrix;
use RepeatMaskerConfig;
# This is a special database-specific module
my $LIBDIR;
BEGIN {
my $config = $RepeatMaskerConfig::configuration;
$LIBDIR = $config->{'LIBDIR'}->{'value'};
}
use lib $LIBDIR;
use RepeatAnnotationData;
# Global variables
my $DEBUG = 0;
#
# Refinement Hash:
# Contains re-alignments for *.cat alignments which were refined.
# structure is as follows:
# $refinementHash{ "b#s#i#" }->{ ConsensusID } = ( annot1ref, annot2ref, ...)
#
my %refinementHash = (); # Contains refined annotations ordered by catID
my %chainSeq1Length;
# A bug in 5.8 produces way too many warnings
if ( $] && $] >= 5.008003 ) {
use warnings;
}
#
# Option processing
# e.g.
# -t: Single letter binary option
# -t=s: String parameters
# -t=i: Number paramters
#
my @opts =
qw (a ace debug excln gff lib=s noint nolow orf2 orifile=s no_id poly species=s u xm mammal mus rat rod|rodent cow pig artiodactyl cat dog carnivore chicken fugu danio drosophila elegans arabidopsis rice wheat maize primate maskSource=s xsmall x lcambig source html );
#
# Get the supplied command line options, and set flags
#
my %options = ();
unless ( &GetOptions( \%options, @opts ) ) {
exec "pod2text $0";
exit( 0 );
}
## Print the internal POD documentation if something is missing
if ( $#ARGV == -1 && !$options{'help'} ) {
print "No cat file indicated\n\n";
# This is a nifty trick so we don't have to have
# a duplicate "USAGE()" subroutine. Instead we
# just recycle our POD docs. See PERL POD for more
# details.
exec "pod2text $0";
die;
}
##
## option -source is now a deprecated option. We only save
## the source alignments if -a is used
##
if ( $options{'a'} ) {
$options{'source'} = 1;
}
else {
$options{'source'} = 0;
}
##
## Species Options and Taxonomy Processing
##
## NOTE: Tax needs to be global for the moment
my $tax;
if ( $options{'species'} ) {
# Need to set opt_species, opt_mammal, opt_mus
$tax =
Taxonomy->new( famdb_dir => "$LIBDIR/famdb" );
if ( $tax->isA( $options{'species'}, "primates" ) ) {
$options{'primate'} = 1;
}
elsif ( $tax->isA( $options{'species'}, "rodentia" ) ) {
$options{'mus'} = 1;
}
elsif ( $tax->isA( $options{'species'}, "mammalia" ) ) {
$options{'mammal'} = 1;
}
}
else {
if ( ! $options{'lib'} ) {
$options{'species'} = "homo";
$options{'primate'} = 1;
}
}
# warning for debug mode
print "Note that in debug mode the IDs are not adjusted to go up stepwise\n\n"
if $options{'debug'};
#
# Check library type used
#
# TODO: We need different levels of meta data compliance. Ie.
# Pound formatting isn't enough anymore. Also we can glean
# compliance like pound formatting from the cat file. No
# need to open up the lib ( yet ).
my $poundformat = "";
if ( $options{'lib'} ) {
open( IN, $options{'lib'} );
while ( <IN> ) {
if ( /^>\S+\#\S+/ ) {
$poundformat = 1;
# Assuming that this represents my classification formatting; no sure
# thing could make it more restrictive by also requiring a backslash
last;
}
}
}
else {
$poundformat = 1;
}
#
# Loop over input files
#
foreach my $file ( @ARGV ) {
if ( $file =~ /.*\.gz$/ ) {
open( INCAT, "gunzip -c $file |" ) || die "Can\'t open file $file\n";
}
else {
open( INCAT, $file ) || die "Can\'t open file $file\n";
}
# INITIALIZE CAT FILE DATA
# Read the cat file and calculate:
# - The length of the original sequence ( minus 1/2 of the overlap )
# - The number of N bases
# - The number of sequences
# - The length of each sequence
# - The fraction GC the version the masked length and the dbversion.
# Also...grab batch overlap boundaries if information is present.
my %batchOverlapBoundaries = ();
my $numSearchedSeqs = 0;
my $lenSearchedSeqs = 0;
my $lenSearchedSeqsExcludingXNRuns = 0;
my $lenSearchedSeqsExcludingAmbig = 0;
my $versionmode = "";
my $engine = "";
my $dbversion = "";
while ( <INCAT> ) {
if ( /^##\s*(\S+)\s+([\d\s,]+)/ ) {
$batchOverlapBoundaries{$1} = [ sort( split( /,/, $2 ) ) ];
}
elsif ( /^##\s*Total\s+Sequences:\s*(\d+)/i ) {
$numSearchedSeqs = $1;
}
elsif ( /^##\s*Total\s+Length:\s*(\d+)/i ) {
$lenSearchedSeqs = $1;
}
elsif ( /^##\s*Total\s+NonMask.*:\s*(\d+)/i ) {
$lenSearchedSeqsExcludingXNRuns = $1;
}
elsif ( /^##\s*Total\s+NonSub.*:\s*(\d+)/i ) {
$lenSearchedSeqsExcludingAmbig = $1;
}
elsif ( /^RepeatMasker|run|RepBase|RM/ ) {
my @bit = split;
$versionmode = $_ if $bit[ 0 ] eq 'RepeatMasker';
$engine = $1 if /^(run with.*)/;
# Since 4.1.1 we are now using famdb. The version is reported a bit
# differently.
# RM Library: CONS-Dfam_withRBRM_3.3
#
if ( /^(RepBase.*)/ || /^RM Library:\s+(\S.*)/ ) {
$dbversion = $1;
last;
}
}
}
close INCAT;
#
# Parse the cat file into an object
#
my $sortedAnnotationsList = undef;
# Always read in alignment data
$sortedAnnotationsList = &parseCATFile( file => $file );
#
# Separate out refined annotations
#
my $annotIter = $sortedAnnotationsList->getIterator();
while ( $annotIter->hasNext() ) {
my $currentAnnot = $annotIter->next();
if ( $currentAnnot->getClassName() eq "" ) {
$currentAnnot->setClassName( "Unspecified" );
}
if ( $currentAnnot->getLineageId() =~ /\[/ ) {
$annotIter->remove();
$currentAnnot->setOrientation( "+" )
if ( $currentAnnot->getOrientation() ne "C" );
my $catID = $currentAnnot->getLineageId();
die "Missing cat file ID for refined element!"
. Dumper( $currentAnnot ) . "\n"
if ( $catID eq "" );
$catID =~ s/[\[\]]//g;
push @{ $refinementHash{$catID}->{ $currentAnnot->getHitName() } },
( $currentAnnot );
}
}
# Create some filename constants
my $catfile = $file;
$file =~ s/\.(temp)?cat(.gz)?$//;
my $filename = $file;
$filename =~ s/(.*\/)//;
unless ( $sortedAnnotationsList->size() > 0 ) {
my $filenaam = $file;
$filenaam = $options{'orifile'} if $options{'orifile'};
open( OUT, ">$file.out" );
print "\n\n\nNo repetitive sequences were detected in $filenaam\n";
print OUT "There were no repetitive sequences detected in $filenaam\n";
close( OUT );
next;
}
print "processing output: ";
open( OUTRAW, ">$file.ori.out" ) if ( $options{'u'} || !$poundformat );
#
# Initialize data structures and ID each annotation
#
# Makes global %seq1Lengths
# NOTE: Only needed because we are not updating LeftOver
# when we modify Seq1Beg/End
#
$sortedAnnotationsList->sort( \&byNameBeginEndrevSWrev );
my $cycleAnnotIter = $sortedAnnotationsList->getIterator();
my %seq1Lengths = ();
my $i = -1;
while ( $cycleAnnotIter->hasNext() ) {
$i++;
my $currentAnnot = $cycleAnnotIter->next();
$currentAnnot->setPRID( $i );
$currentAnnot->setOrientation( "+" )
if ( $currentAnnot->getOrientation() ne "C" );
# Do this early so we capture all information before it is changed.
# NOTE: I may make derived elements links to the cat file for
# memory brevity.
if ( $options{'source'} ) {
$currentAnnot->addDerivedFromAnnot( $currentAnnot );
$currentAnnot->setAlignData( undef );
}
my $HitName = $currentAnnot->getHitName();
$HitName =~ s/_short_$//;
# RMH 11/21/12: Added for Dfam
$HitName =~ s/_offset$//;
$currentAnnot->setHitName( $HitName );
if ( !defined $seq1Lengths{ $currentAnnot->getQueryName() }
|| $seq1Lengths{ $currentAnnot->getQueryName() } <
( $currentAnnot->getQueryEnd() + $currentAnnot->getQueryRemaining() ) )
{
$seq1Lengths{ $currentAnnot->getQueryName() } =
$currentAnnot->getQueryEnd() + $currentAnnot->getQueryRemaining();
}
}
print "\ncycle 1 ";
#printHitArrayList( $sortedAnnotationsList );
my ( $chainBegRef, $chainEndRef ) = &cycleReJoin( $sortedAnnotationsList );
my %chainBeg = %{$chainBegRef};
my %chainEnd = %{$chainEndRef};
########################## C Y C L E 2 ###############################
# Purpose: Remove Edge Effect Annotations
# Remove Masklevel violations
# Rename Satellite Shifted Copies
# build DNA transposon equivalency datastructure
##########################################################################
print "\ncycle 2 ";
# Sort by name, begin position, and end position descending
$sortedAnnotationsList->sort( \&byNameBeginEndrevSWrev );
# Create an ArrayListIterator for this cycle
$cycleAnnotIter = $sortedAnnotationsList->getIterator();
my %colWidths = &getMaxColWidths( $sortedAnnotationsList );
my $DEBUG = 0;
$i = -1;
CYCLE2:
while ( $cycleAnnotIter->hasNext() ) {
$i++;
print "." if ( $i + 1 ) % 1000 == 0;
# NOTE: An iterator's index is considered
# to be in between elements of a datastructure.
# To obtain the correct index for the
# current element in this pass we should
# get the index *before* we move the iterator.
my $currentIndex = $cycleAnnotIter->getIndex();
my $currentAnnot = $cycleAnnotIter->next();
if ( $DEBUG ) {
print "CYCLE2: Considering\n";
$currentAnnot->print();
}
# TODO: This recursion violation code might not be necessary
# once the cycleReJoin code is changed to use the new *.cat ID field
# or not: What if RM fragmented two overlapping alignments:
# maskelevel 90:
# ------^-------->
# ----------^----->
# You would have
# ++++++++++
# -----/ \--------->
# ++++++++++
# and ----------------/ \----->
#
# HMMM...have to think about this. This is a fine dance with the
# search engine maskelevel parameter.
#
if ( $currentAnnot->getRightLinkedHit() ) {
my $proxIter = $cycleAnnotIter->getIterator();
while ( $proxIter->hasNext() ) {
my $nextAnnot = $proxIter->next();
# Quit once we reach our partner
last if ( $nextAnnot == $currentAnnot->getRightLinkedHit() );
# Break Recursion Violations
if ( $currentAnnot->containsElement( $nextAnnot )
&& $nextAnnot->containsElement( $currentAnnot->getRightLinkedHit() ) )
{
if ( $DEBUG ) {
print "This violates recursion:\nFirst:\n";
$currentAnnot->printLeftRightLinks();
print "Second:\n";
$nextAnnot->printLeftRightLinks();
}
# Break lower scoring link
my $oldRight = $nextAnnot->getRightLinkedHit();
$nextAnnot->setRightLinkedHit( undef );
$oldRight->setLeftLinkedHit( undef );
}
}
}
##
## Edge Effect Removal
##
## The current method of processing overlaps, while better
## than before still produces some edge effects. This
## section attempts to remove these before we start any
## serious analysis.
##
## Overlaps are handled in RepeatMasker thus:
##
## Middle
## <------ |
## ----->
## Batch#1 | ----x---->
## ...-----------------------------|
## |
## |
## |-----------------------------...
## | BATCH#2
## <-x- |
## ---->
## | ---------------->
##
##
## RepeatMasker deletes all annotations which are
## contained in the region left/right ( closest to
## the edge ) of the overlap midpoint. Shown here
## with an "x" in the diagram annotations.
## If an annotation spans the midpoint it is kept
## in the cat file. This leaves several types of
## edge effects in annoation:
##
## Perfect or Near Perfect duplicates. Perfect if
## the same matrix was used and the annotation is
## completely contained in the overlap. Near perfect
## otherwise.
##
## Middle
## |
## ----->
## |
## ----->
##
##
## Cut Level Ambiguities. A full length young repeat
## partially contained in the overlap will be excised
## at a lower cutlevel in one batch and masked at
## a higher cutlevel in the other batch. See below
## for some examples.
##
##
# Remove exact duplicates. Near duplicates get resolved elsewhere
# ( FuseOverlappingSeqs etc ). We do this now especially to handle
# duplicated poly-a tails that we are about to join.
my $prevAnnot = $sortedAnnotationsList->get( $currentIndex - 1 )
if ( $currentIndex > 0 );
if ( $prevAnnot
&& $currentAnnot->getScore() == $prevAnnot->getScore()
&& $currentAnnot->getPctDiverge() == $prevAnnot->getPctDiverge()
&& $currentAnnot->getQueryName() eq $prevAnnot->getQueryName()
&& $currentAnnot->getQueryStart() == $prevAnnot->getQueryStart()
&& $currentAnnot->getQueryEnd() == $prevAnnot->getQueryEnd() )
{
# Lower Scoring Overlap > %90 Covered by Higher Scoring
# Get rid of lower scoring one
# same cutlevel
if ( $DEBUG ) {
print "REMOVING EXACT DUPLICATE:\n";
$currentAnnot->print();
print " because of:\n";
$prevAnnot->print();
}
#$prevAnnot->addDerivedFromAnnot( $currentAnnot )
# if ( $options{'source'} );
# Fix any previous joins to this element
$currentAnnot->removeFromJoins();
$cycleAnnotIter->remove();
next CYCLE2;
}
#
# If a large >1000bp ( 1/2 current overlap distance )
# young repeat starts outside the overlap and spans
# the middle of the overlap you will get edge effect
# duplications. I.e.
#
# Case #1 Middle
# batch1 |
# ---------------------------|
# -----------------> ( excised cutlevels 0-4 )
# ----X----> ( masked cutlevel 5 )
# |------------------------------
# | batch2
# |
# or |
# batch1 ----X--> ( masked cutlevel 5 )
# ----------------------------|
# |------------------------------- batch2
# -----------------> ( excised cutlevel 0-4 )
# |
#
# Because excision is only performed on full length
# elements (lines can be 5' truncated) this can be
# detected by checking for elements which are contained by
# a masked annotation *and* are cut out.
#
# Case #2 Middle
# |
# <---X--- (masked..just outside the other )
# ----------------------------|
# |-------------------------------
# | <---------- (cut)
# |
# |
# Case #3 |
# (masked) --> |
# -------> (cut)
# -----------------------------|
# |----------------------------
# X> |
# -------->
#
# In this case you have a cut out element spaning a middle
# which is one bp longer in one batch. This creates
# a 1bp overlap with a something which has been masked.
#
# So our general rule ends up: Remove all masked elements
# which overlap ( by > 10bp ) or are contained by another
# cut out element.
# These cases should never occur outside the overlap
# region anyway.
#
if ( $currentAnnot->isMasked() ) {
my $proxIter = $cycleAnnotIter->getIterator();
$proxIter->previous();
while ( $proxIter->hasPrevious() ) {
my $prevAnnot = $proxIter->previous();
last
unless ( $currentAnnot->getQueryName eq $prevAnnot->getQueryName()
&& $prevAnnot->getQueryEnd() >= $currentAnnot->getQueryStart() );
if ( $prevAnnot->isCut()
&& $prevAnnot->getQueryEnd() - $currentAnnot->getQueryStart() >= 10 )
{
if ( $DEBUG ) {
print "DELETING MASKED INSIDE CUT:\n";
$currentAnnot->print();
print " because of previous:\n";
$prevAnnot->print();
}
# Fix any previous joins to this element
$currentAnnot->removeFromJoins();
$cycleAnnotIter->remove();
next CYCLE2;
}
}
$proxIter = $cycleAnnotIter->getIterator();
while ( $proxIter->hasNext() ) {
my $nextAnnot = $proxIter->next();
last
unless ( $currentAnnot->getQueryName eq $nextAnnot->getQueryName()
&& $nextAnnot->getQueryStart() <= $currentAnnot->getQueryEnd() );
if ( $nextAnnot->isCut()
&& $currentAnnot->getQueryEnd() - $nextAnnot->getQueryStart() >= 10 )
{
if ( $DEBUG ) {
print "DELETING MASKED INSIDE CUT:\n";
$currentAnnot->print();
print " because of next:\n";
$nextAnnot->print();
}
#$nextAnnot->addDerivedFromAnnot( $currentAnnot )
# if ( $options{'source'} );
# Fix any previous joins to this element
$currentAnnot->removeFromJoins();
$cycleAnnotIter->remove();
next CYCLE2;
}
}
}
#
# Masklevel Violations From Clipping Boundaries
#
# RepeatMasker fragments alignments which span
# cut out elements. This fragmentation process may
# convert a pair of alignments like:
#
# --------------^-------------> SW=1000
# -----------^-----------------> SW=1500
#
# ( where "^" marks the site of a clipped out element )
# into something like:
#
# SW = 1000 SW = 1000
# --------------> ------------->
# -----------> ----------------->
# SW = 1500 SW = 1500
#
# This little block of code resolves this masklevel
# rule-breaker ( lower scoring alignment contained by
# higher scoring one ) by elminating the lower scoring
# subfragments.
#
# i.e Delete element if flanking elements include
# it and has a better or equal score.
#
# SW = 1000
# -------------->
# -----------> ----------------->
# SW = 1500 SW = 1500
#
# This is still a bit artificial.
#
$prevAnnot = $sortedAnnotationsList->get( $currentIndex - 1 )
if ( $currentIndex > 0 );
my $proxIter = $cycleAnnotIter->getIterator();
my ( $prevHitName, $prevClassName ) =
split( /\#/, $prevAnnot->getSubjName() )
if ( $prevAnnot );
#
# Delete iff:
# ----current-----^ SW <= past
# -----past-------^
# -..----past----------^
#
# or
# ^---current----- SW <= past
# ^----past-------
# ^------past----------...--
#
if (
$prevAnnot
&& (
(
$currentAnnot->getQueryEnd() == $prevAnnot->getQueryEnd()
&& $currentAnnot->getScore() <= $prevAnnot->getScore()
&& $currentAnnot->getQueryName() eq $prevAnnot->getQueryName()
&& $currentAnnot->getClassName() eq $prevClassName
)
|| ( $currentAnnot->getQueryStart() == $prevAnnot->getQueryStart()
&& $currentAnnot->getQueryEnd() <= $prevAnnot->getQueryEnd()
&& $currentAnnot->getScore() <= $prevAnnot->getScore()
&& $currentAnnot->getQueryName() eq $prevAnnot->getQueryName()
&& $currentAnnot->getClassName() eq $prevClassName )
)
)
{
if ( $DEBUG ) {
print "Deleting clipping boundary fragment "
. "( masklevel violation ):\n";
$prevAnnot->print();
$currentAnnot->print();
}
#$prevAnnot->addDerivedFromAnnot( $currentAnnot )
# if ( $options{'source'} );
# Fix any previous joins to this element
$currentAnnot->removeFromJoins();
$cycleAnnotIter->remove();
next CYCLE2;
}
my $Seq2BeginPrint = $currentAnnot->getSubjStart();
my $LeftUnalignedPrint = "(" . $currentAnnot->getSubjRemaining() . ")";
my $LeftOverPrint = "(" . $currentAnnot->getQueryRemaining() . ")";
if ( $currentAnnot->getOrientation() eq "C" ) {
$Seq2BeginPrint = "(" . $currentAnnot->getSubjRemaining() . ")";
$LeftUnalignedPrint = $currentAnnot->getSubjStart();
}
#
# Supposedly creates an untouched annotation file.
# What it really does is create an annotation file
# which has been modified to remove exact duplicates
# and batch overlap artifacts only.
#
if ( $options{'u'} || !$poundformat ) {
my $prevAnnot = $sortedAnnotationsList->get( $currentIndex - 1 )
if ( $currentIndex > 0 );
my $nextAnnot = $sortedAnnotationsList->get( $currentIndex + 1 )
if ( $currentIndex < $sortedAnnotationsList->size() - 1 );
my $Overlapped = "";
if ( $prevAnnot
&& $currentAnnot->getQueryStart() <= $prevAnnot->getQueryEnd()
&& $currentAnnot->getScore() < $prevAnnot->getScore()
|| $nextAnnot
&& $currentAnnot->getQueryEnd() >= $nextAnnot->getQueryStart()
&& $currentAnnot->getScore() < $nextAnnot->getScore() )
{
$Overlapped = "*";
}
$currentAnnot->setClassName( "" )
unless ( $currentAnnot->getClassName() );
#
# sequence names get truncated to 20 letters. Too
# cumbersome to change. However, names like
# /mnt/user/users/FlipvanTiel/mystuff/sequence1 better be
# clipped from the end. Thus:
$currentAnnot->setQueryName(
substr( $currentAnnot->getQueryName(), -20 ) )
if ( length $currentAnnot->getQueryName() > 20
&& $currentAnnot->getQueryName() =~ /^\// );
printf OUTRAW "%6d %4s %4s %4s %20s %9s %9s %8s %1s "
. "%20s %15s %7s %7s %7s %3s\n", $currentAnnot->getScore(),
$currentAnnot->getPctDiverge, $currentAnnot->getPctDelete,
$currentAnnot->getPctInsert, $currentAnnot->getQueryName(),
$currentAnnot->getQueryStart(), $currentAnnot->getQueryEnd(),
"(" . $currentAnnot->getQueryRemaining() . ")",
$currentAnnot->getOrientation(), $currentAnnot->getHitName(),
$currentAnnot->getClassName(), $Seq2BeginPrint,
$currentAnnot->getSubjEnd(), $LeftUnalignedPrint;
$Overlapped;
} # if ( $options{'u'} || !$poundformat )
#
# If a user supplied non-classified library was used
#
if ( !$poundformat ) {
if ( $options{'ace'} ) {
if ( $currentAnnot->getOrientation() eq "C" ) {
print OUTACE "Motif_homol \""
. $currentAnnot->getHitName()
. "\" \"RepeatMasker\" "
. $currentAnnot->getPctDiverge() . " "
. $currentAnnot->getQueryStart() . " "
. $currentAnnot->getQueryEnd() . " - "
. $currentAnnot->getSubjEnd() . " "
. $currentAnnot->getSubjStart() . "\n";
}
else {
print OUTACE "Motif_homol \""
. $currentAnnot->getHitName()
. "\" \"RepeatMasker\" "
. $currentAnnot->getPctDiverge() . " "
. $currentAnnot->getQueryStart() . " "
. $currentAnnot->getQueryEnd() . " + "
. $currentAnnot->getSubjStart() . " "
. $currentAnnot->getSubjEnd() . "\n";
}
}
if ( $options{'xm'} ) {
my $tempclassname = "";
$tempclassname = "\#" . $currentAnnot->getClassName()
if ( $currentAnnot->getClassName() );
print OUTXM $currentAnnot->getScore() . " "
. $currentAnnot->getPctDiverge() . " "
. $currentAnnot->getPctDelete() . " "
. $currentAnnot->getPctInsert() . " "
. $currentAnnot->getQueryName() . " "
. $currentAnnot->getQueryStart() . " "
. $currentAnnot->getQueryEnd() . " "
. $LeftOverPrint . " "
. $currentAnnot->getOrientation() . " "
. $currentAnnot->getHitName()
. $tempclassname . " "
. $Seq2BeginPrint . " "
. $currentAnnot->getSubjEnd() . " "
. $LeftUnalignedPrint . "\n";
}
if ( $options{'gff'} ) {
#my $source;
#if ( $currentAnnot->getHitName() =~ /Alu/ ) {
# $source = 'RepeatMasker_SINE';
#}
#else { #
# $source = 'RepeatMasker';
#}
my $source = 'RepeatMasker';
print OUTGFF ""
. $currentAnnot->getQueryName()
. "\t$source\tdispersed_repeat\t"
. $currentAnnot->getQueryStart() . "\t"
. $currentAnnot->getQueryEnd() . "\t"
. $currentAnnot->getPctDiverge() . "\t"
. ( $currentAnnot->getOrientation() eq 'C' ? '-' : '+' ) . "\t.\t"
. "ID=" . $currentAnnot->getPRID()+1 . ";"
. "Target \"Motif:"
. $currentAnnot->getHitName() . "\" "
. $currentAnnot->getSubjStart() . " "
. $currentAnnot->getSubjEnd() . "\n";
}
} # if ( !$poundformat )
else {
#
# Satellite Consensi
# Searching for satellites with consensi is a hack.
# Search engines such as crossmatch will often return
# hits to a single repeating pattern as:
# | | | | |
# abcdefghabcdefghabcdefghabcdefghabcdefgh
# --------->
# -------->
# -------->
# By creating a consensus for the repeat pattern and
# another for the same pattern shifted by 1/2 of the
# cycle. You can nicely overlapping hits.
# These shifted consensi are denoted by the use of a
# trailing "_" in the name.
#
# Here is the regular expression for the syntax:
#
# [A-Z_]+[a-z]?_?#Satellite
#
# So here are some examples:
#
# ALR_#Satellite
# ALRa#Satellite
# ALRa_#Satellite
# CENSAT_MC#Satellite
#
# Since these trailing "_" variants and the "[a-z]"
# variants are equivalent we only need to restore
# the original name by stripping these characters
# HitName.
#
# NOTE: The lowercase varieties are not in repbase.
#
if ( $currentAnnot->getClassName =~ /Satellite/ ) {
my $HitName = $currentAnnot->getHitName();
$HitName =~ s/_(offset)?$//;
# This was truncating newer statellite names which use the
# _??? to indicate species names.
if ( $HitName =~ /ALR|BSR/ && $HitName !~ /_/ ) {
$HitName =~ s/[a-z]$//;
}
$currentAnnot->setHitName( $HitName );
}
if ( $currentAnnot->getClassName =~ /DNA/ ) {
# Find all ambiguous dna transposon fragments and generate
# equivalency lists
&preProcessDNATransp( \%chainBeg, \%chainEnd, $currentAnnot,
\%RepeatAnnotationData::repeatDB );
}
}
} # END CYCLE 2
close( OUTRAW ) if ( $options{'u'} || !$poundformat );
#
# If we do not have a pound formatted database we are done!
#
if ( !$poundformat ) {
&generateOutput(
\%options, \%seq1Lengths,
$file, $filename,
$dbversion, $numSearchedSeqs,
$lenSearchedSeqs, $lenSearchedSeqsExcludingXNRuns,