Bio::Tools::CodonTable and Bio::Tools::IUPAC: use our and drop BEGIN blocks.
[bioperl-live.git] / lib / Bio / Tools / Eponine.pm
blobef59b3bf24ade31e7aa654d5058acaf9ad09be7a
2 # BioPerl module for Bio::Tools::Eponine
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Tania Oh <gisoht@nus.edu.sg>
8 # Copyright Tania Oh
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::Eponine - Results of one Eponine run
18 =head1 SYNOPSIS
20 use Bio::Tools::Eponine;
21 use strict;
22 my $seq = "/data/seq.fa";
23 my $threshold = "0.999";
24 my @params = ( -seq => $seq,
25 -threshold => $threshold);
27 my $factory = Bio::Tools::Run::Eponine->new(@params);
28 # run eponine against fasta
29 my $r = $factory->run_eponine($seq);
30 my $parser = Bio::Tools::Eponine->new($r);
32 while (my $feat = $parser->next_prediction){
33 #$feat contains array of SeqFeature
34 foreach my $orf($feat) {
35 print $orf->seq_id. "\n";
39 =head1 DESCRIPTION
41 Parser for Eponine, a probabilistic transcription start site detector
42 optimized for mammalian genomic sequence. This module inherits off
43 Bio::Tools::AnalysisResult and therefore implements
44 Bio::SeqAnalysisParserI (see L<Bio::Tools::AnalysisResult> and
45 L<Bio::SeqAnalysisParserI>).
47 =head1 FEEDBACK
49 =head2 Mailing Lists
51 User feedback is an integral part of the evolution of this and other
52 Bioperl modules. Send your comments and suggestions preferably to one
53 of the Bioperl mailing lists. Your participation is much appreciated.
55 bioperl-l@bioperl.org - General discussion
56 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
58 =head2 Support
60 Please direct usage questions or support issues to the mailing list:
62 I<bioperl-l@bioperl.org>
64 rather than to the module maintainer directly. Many experienced and
65 reponsive experts will be able look at the problem and quickly
66 address it. Please include a thorough description of the problem
67 with code and data examples if at all possible.
69 =head2 Reporting Bugs
71 Report bugs to the Bioperl bug tracking system to help us keep track
72 the bugs and their resolution. Bug reports can be submitted via the
73 web:
75 https://github.com/bioperl/bioperl-live/issues
77 =head1 AUTHOR - Tania Oh
79 E<lt>gisoht-at-nus.edu.sgE<gt>
81 =head1 APPENDIX
83 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
85 =cut
88 # Let the code begin...
91 package Bio::Tools::Eponine;
93 use strict;
95 use Bio::Tools::Prediction::Gene;
96 use Bio::Tools::Prediction::Exon;
98 use base qw(Bio::Tools::AnalysisResult);
100 sub _initialize_state {
101 my($self,@args) = @_;
103 # first call the inherited method!
104 my $make = $self->SUPER::_initialize_state(@args);
106 # handle our own parameters
108 # our private state variables
109 $self->{'_preds_parsed'} = 0;
110 #array of Bio::SeqFeatures
111 $self->{'_flist'} =[];
114 =head2 analysis_method
116 Usage : $mzef->analysis_method();
117 Purpose : Inherited method. Overridden to ensure that the name matches
118 /mzef/i.
119 Returns : String
120 Argument : n/a
122 =cut
124 #-------------
125 sub analysis_method {
126 #-------------
127 my ($self, $method) = @_;
128 if($method && ($method !~ /epo/i)) {
129 $self->throw("method $method not supported in " . ref($self));
131 return $self->SUPER::analysis_method($method);
134 =head2 next_feature
136 Title : next_feature
137 Usage : while($gene = $mzef->next_feature()) {
138 # do something
140 Function: Returns the next gene structure prediction of the MZEF result
141 file. Call this method repeatedly until FALSE is returned.
143 The returned object is actually a SeqFeatureI implementing object.
144 This method is required for classes implementing the
145 SeqAnalysisParserI interface, and is merely an alias for
146 next_prediction() at present.
148 Note that with the present version of MZEF there will only be one
149 object returned, because MZEF does not predict individual genes
150 but just potential internal exons.
151 Example :
152 Returns : A Bio::Tools::Prediction::Gene object.
153 Args :
155 =cut
157 sub next_feature {
158 my ($self,@args) = @_;
159 # even though next_prediction doesn't expect any args (and this method
160 # does neither), we pass on args in order to be prepared if this changes
161 # ever
162 return $self->next_prediction(@args);
165 =head2 next_prediction
167 Title : next_prediction
168 Usage : while($gene = $mzef->next_prediction()) {
169 # do something
171 Function: Returns the next gene structure prediction of the MZEF result
172 file. Call this method repeatedly until FALSE is returned.
174 Note that with the present version of MZEF there will only be one
175 object returned, because MZEF does not predict individual genes
176 but just potential internal exons.
177 Example :
178 Returns : A Bio::Tools::Prediction::Gene object.
179 Args :
181 =cut
183 sub next_prediction {
184 my ($self) = @_;
185 my $gene;
187 # if the prediction section hasn't been parsed yet, we do this now
188 $self->_parse_predictions() unless $self->_predictions_parsed();
190 # return the next gene structure (transcript)
191 return $self->_prediction();
194 =head2 _parse_predictions
196 Title : _parse_predictions()
197 Usage : $obj->_parse_predictions()
198 Function: Parses the prediction section. Automatically called by
199 next_prediction() if not yet done.
200 Example :
201 Returns :
203 =cut
205 sub _parse_predictions {
206 my ($self) = @_;
208 while(defined($_ = $self->_readline())) {
209 if (! /^\#/){ #ignore introductory lines
211 my @element = split;
212 my (%feature);
213 $feature {name} = $element[0];
214 $feature {score} = $element[5];
215 $feature {start} = $element[3];
216 $feature {end} = $element[4];
217 $feature {strand} = $element[6];
218 $feature {source}= 'Eponine';
219 $feature {primary}= 'TSS';
220 $feature {program} = 'eponine-scan';
221 $feature {program_version} = '2';
223 $self->create_feature(\%feature);
224 next;
228 $self->_predictions_parsed(1);
231 =head2 create_feature
233 Title : create_feature
234 Usage : obj->create_feature($feature)
235 Function: Returns an array of features
236 Returns : Returns an array of features
237 Args : none
239 =cut
241 sub create_feature {
242 my ($self, $feat) = @_;
243 #create and fill Bio::EnsEMBL::Seqfeature object
245 my $tss = Bio::SeqFeature::Generic->new
246 ( -seq_id => $feat->{'name'},
247 -start => $feat->{'start'},
248 -end => $feat->{'end'},
249 -strand => $feat->{'strand'},
250 -score => $feat->{'score'},
251 -source_tag => $feat->{'source'},
252 -primary_tag => $feat->{'primary'});
256 if ($tss) {
257 # add to _flist
258 push(@{$self->{'_flist'}}, $tss);
261 #print $tss->gff_string;
269 =head2 _prediction
271 Title : _prediction()
272 Usage : $gene = $obj->_prediction()
273 Function: internal
274 Example :
275 Returns :
277 =cut
279 sub _prediction {
280 my ($self) = @_;
282 return unless(exists($self->{'_flist'}) && @{$self->{'_flist'}});
283 return shift(@{$self->{'_flist'}});
286 =head2 _predictions_parsed
288 Title : _predictions_parsed
289 Usage : $obj->_predictions_parsed
290 Function: internal
291 Example :
292 Returns : TRUE or FALSE
294 =cut
296 sub _predictions_parsed {
297 my ($self, $val) = @_;
299 $self->{'_preds_parsed'} = $val if $val;
300 # array of pre-parsed predictions
301 if(! exists($self->{'_preds_parsed'})) {
302 $self->{'_preds_parsed'} = 0;
304 return $self->{'_preds_parsed'};