maint: restructure to use Dist::Zilla
[bioperl-live.git] / lib / Bio / Tools / RepeatMasker.pm
blobcfdec98dc5997929d82bd93c792757f1932bd96a
2 # BioPerl module for Bio::Tools::RepeatMasker
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Shawn Hoon <shawnh@fugu-sg.org>
8 # Copyright Shawn Hoon
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
14 =head1 NAME
16 Bio::Tools::RepeatMasker - a parser for RepeatMasker output
18 =head1 SYNOPSIS
20 use Bio::Tools::RepeatMasker;
21 my $parser = Bio::Tools::RepeatMasker->new(-file => 'seq.fa.out');
22 while( my $result = $parser->next_result ) {
23 # get some value
26 =head1 DESCRIPTION
28 A parser for RepeatMasker output
30 =head1 FEEDBACK
32 =head2 Mailing Lists
34 User feedback is an integral part of the evolution of this and other
35 Bioperl modules. Send your comments and suggestions preferably to
36 the Bioperl mailing list. Your participation is much appreciated.
38 bioperl-l@bioperl.org - General discussion
39 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
41 =head2 Support
43 Please direct usage questions or support issues to the mailing list:
45 I<bioperl-l@bioperl.org>
47 rather than to the module maintainer directly. Many experienced and
48 reponsive experts will be able look at the problem and quickly
49 address it. Please include a thorough description of the problem
50 with code and data examples if at all possible.
52 =head2 Reporting Bugs
54 Report bugs to the Bioperl bug tracking system to help us keep track
55 of the bugs and their resolution. Bug reports can be submitted via
56 the web:
58 https://github.com/bioperl/bioperl-live/issues
60 =head1 AUTHOR - Shawn Hoon
62 Email shawnh@fugu-sg.org
64 =head1 APPENDIX
66 The rest of the documentation details each of the object methods.
67 Internal methods are usually preceded with a _
69 =cut
72 # Let the code begin...
75 package Bio::Tools::RepeatMasker;
76 use strict;
78 use Bio::SeqFeature::FeaturePair;
80 use base qw(Bio::Root::Root Bio::Root::IO);
82 =head2 new
84 Title : new
85 Usage : my $obj = Bio::Tools::RepeatMasker->new();
86 Function: Builds a new Bio::Tools::RepeatMasker object
87 Returns : Bio::Tools::RepeatMasker
88 Args : -fh/-file => $val, for initing input, see Bio::Root::IO
90 =cut
92 sub new {
93 my($class,@args) = @_;
95 my $self = $class->SUPER::new(@args);
96 $self->_initialize_io(@args);
98 return $self;
101 =head2 next_result
103 Title : next_result
104 Usage : my $r = $rpt_masker->next_result
105 Function: Get the next result set from parser data
106 Returns : Bio::SeqFeature::FeaturePair
107 Feature1 is the Query coordinates and Feature2 is the Hit
108 Args : none
110 =cut
112 sub next_result {
113 my ($self) = @_;
114 local $_;
115 while (defined($_=$self->_readline()) ) {
116 if (/no repetitive sequences detected/) {
117 $self->warn( "RepeatMasker didn't find any repetitive sequences\n");
118 return ;
120 #ignore introductory lines
121 if (/\d+/) {
122 my @element = split;
123 # ignore features with negatives
124 next if ($element[11-13] =~ /-/);
125 my (%feat1, %feat2);
126 my @line = split;
127 my ($score, $query_name, $query_start, $query_end, $strand,
128 $repeat_name, $repeat_class ) = @line[0, 4, 5, 6, 8, 9, 10];
130 my ($hit_start,$hit_end);
132 if ($strand eq '+') {
133 ($hit_start, $hit_end) = @line[11, 12];
134 $strand = 1;
135 } elsif ($strand eq 'C') {
136 ($hit_end, $hit_start) = @line[12, 13];
137 $strand = -1;
139 my $rf = Bio::SeqFeature::Generic->new
140 (-seq_id => $query_name,
141 -score => $score,
142 -start => $query_start,
143 -end => $query_end,
144 -strand => $strand,
145 -source_tag => 'RepeatMasker',
146 -primary_tag => $repeat_class,
147 -tag => { 'Target'=> [$repeat_name, $hit_start, $hit_end]},
150 my $rf2 = Bio::SeqFeature::Generic->new
151 (-seq_id => $repeat_name,
152 -score => $score,
153 -start => $hit_start,
154 -end => $hit_end,
155 -strand => $strand,
156 -source_tag => "RepeatMasker",
157 -primary_tag => $repeat_class,
158 -tag => { 'Target'=> [$query_name,$query_start,$query_end] },
161 my $fp = Bio::SeqFeature::FeaturePair->new(-feature1 => $rf,
162 -feature2 => $rf2);
163 return $fp;