tag fourth (and hopefully last) alpha
[bioperl-live.git] / branch-1-6 / Bio / Tools / RepeatMasker.pm
blob49abd033ce7e91b0ff7ed060dc84a906a2726de5
1 # $Id$
3 # BioPerl module for Bio::Tools::RepeatMasker
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by Shawn Hoon <shawnh@fugu-sg.org>
9 # Copyright Shawn Hoon
11 # You may distribute this module under the same terms as perl itself
13 # POD documentation - main docs before the code
15 =head1 NAME
17 Bio::Tools::RepeatMasker - a parser for RepeatMasker output
19 =head1 SYNOPSIS
21 use Bio::Tools::RepeatMasker;
22 my $parser = Bio::Tools::RepeatMasker->new(-file => 'seq.fa.out');
23 while( my $result = $parser->next_result ) {
24 # get some value
27 =head1 DESCRIPTION
29 A parser for RepeatMasker output
31 =head1 FEEDBACK
33 =head2 Mailing Lists
35 User feedback is an integral part of the evolution of this and other
36 Bioperl modules. Send your comments and suggestions preferably to
37 the Bioperl mailing list. Your participation is much appreciated.
39 bioperl-l@bioperl.org - General discussion
40 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
42 =head2 Support
44 Please direct usage questions or support issues to the mailing list:
46 I<bioperl-l@bioperl.org>
48 rather than to the module maintainer directly. Many experienced and
49 reponsive experts will be able look at the problem and quickly
50 address it. Please include a thorough description of the problem
51 with code and data examples if at all possible.
53 =head2 Reporting Bugs
55 Report bugs to the Bioperl bug tracking system to help us keep track
56 of the bugs and their resolution. Bug reports can be submitted via
57 the web:
59 http://bugzilla.open-bio.org/
61 =head1 AUTHOR - Shawn Hoon
63 Email shawnh@fugu-sg.org
65 =head1 APPENDIX
67 The rest of the documentation details each of the object methods.
68 Internal methods are usually preceded with a _
70 =cut
73 # Let the code begin...
76 package Bio::Tools::RepeatMasker;
77 use strict;
79 use Bio::SeqFeature::FeaturePair;
81 use base qw(Bio::Root::Root Bio::Root::IO);
83 =head2 new
85 Title : new
86 Usage : my $obj = Bio::Tools::RepeatMasker->new();
87 Function: Builds a new Bio::Tools::RepeatMasker object
88 Returns : Bio::Tools::RepeatMasker
89 Args : -fh/-file => $val, for initing input, see Bio::Root::IO
91 =cut
93 sub new {
94 my($class,@args) = @_;
96 my $self = $class->SUPER::new(@args);
97 $self->_initialize_io(@args);
99 return $self;
102 =head2 next_result
104 Title : next_result
105 Usage : my $r = $rpt_masker->next_result
106 Function: Get the next result set from parser data
107 Returns : Bio::SeqFeature::FeaturePair
108 Feature1 is the Query coordinates and Feature2 is the Hit
109 Args : none
111 =cut
113 sub next_result {
114 my ($self) = @_;
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_start, $hit_end) = @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;