* sync with trunk
[bioperl-live.git] / Bio / Tools / Eponine.pm
blobfd416b2ef5637d2b677ebe64a8b67ec3d02394d5
1 # $Id$
3 # BioPerl module for Bio::Tools::Eponine
5 # Cared for by Tania Oh <gisoht@nus.edu.sg>
7 # Copyright Tania Oh
9 # You may distribute this module under the same terms as perl itself
11 # POD documentation - main docs before the code
13 =head1 NAME
15 Bio::Tools::Eponine - Results of one Eponine run
17 =head1 SYNOPSIS
19 use Bio::Tools::Eponine;
20 use strict;
21 my $seq = "/data/seq.fa";
22 my $threshold = "0.999";
23 my @params = ( -seq => $seq,
24 -threshold => $threshold);
26 my $factory = Bio::Tools::Run::Eponine->new(@params);
27 # run eponine against fasta
28 my $r = $factory->run_eponine($seq);
29 my $parser = Bio::Tools::Eponine->new($r);
31 while (my $feat = $parser->next_prediction){
32 #$feat contains array of SeqFeature
33 foreach my $orf($feat) {
34 print $orf->seq_id. "\n";
38 =head1 DESCRIPTION
40 Parser for Eponine, a probabilistic transcription start site detector
41 optimized for mammalian genomic sequence. This module inherits off
42 Bio::Tools::AnalysisResult and therefore implements
43 Bio::SeqAnalysisParserI (see L<Bio::Tools::AnalysisResult> and
44 L<Bio::SeqAnalysisParserI>).
46 =head1 FEEDBACK
48 =head2 Mailing Lists
50 User feedback is an integral part of the evolution of this and other
51 Bioperl modules. Send your comments and suggestions preferably to one
52 of the Bioperl mailing lists. Your participation is much appreciated.
54 bioperl-l@bioperl.org - General discussion
55 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
57 =head2 Reporting Bugs
59 Report bugs to the Bioperl bug tracking system to help us keep track
60 the bugs and their resolution. Bug reports can be submitted via the
61 web:
63 http://bugzilla.open-bio.org/
65 =head1 AUTHOR - Tania Oh
67 E<lt>gisoht-at-nus.edu.sgE<gt>
69 =head1 APPENDIX
71 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
73 =cut
76 # Let the code begin...
79 package Bio::Tools::Eponine;
80 use strict;
82 use Bio::Tools::Prediction::Gene;
83 use Bio::Tools::Prediction::Exon;
85 use base qw(Bio::Tools::AnalysisResult);
87 sub _initialize_state {
88 my($self,@args) = @_;
90 # first call the inherited method!
91 my $make = $self->SUPER::_initialize_state(@args);
93 # handle our own parameters
95 # our private state variables
96 $self->{'_preds_parsed'} = 0;
97 #array of Bio::SeqFeatures
98 $self->{'_flist'} =[];
101 =head2 analysis_method
103 Usage : $mzef->analysis_method();
104 Purpose : Inherited method. Overridden to ensure that the name matches
105 /mzef/i.
106 Returns : String
107 Argument : n/a
109 =cut
111 #-------------
112 sub analysis_method {
113 #-------------
114 my ($self, $method) = @_;
115 if($method && ($method !~ /epo/i)) {
116 $self->throw("method $method not supported in " . ref($self));
118 return $self->SUPER::analysis_method($method);
121 =head2 next_feature
123 Title : next_feature
124 Usage : while($gene = $mzef->next_feature()) {
125 # do something
127 Function: Returns the next gene structure prediction of the MZEF result
128 file. Call this method repeatedly until FALSE is returned.
130 The returned object is actually a SeqFeatureI implementing object.
131 This method is required for classes implementing the
132 SeqAnalysisParserI interface, and is merely an alias for
133 next_prediction() at present.
135 Note that with the present version of MZEF there will only be one
136 object returned, because MZEF does not predict individual genes
137 but just potential internal exons.
138 Example :
139 Returns : A Bio::Tools::Prediction::Gene object.
140 Args :
142 =cut
144 sub next_feature {
145 my ($self,@args) = @_;
146 # even though next_prediction doesn't expect any args (and this method
147 # does neither), we pass on args in order to be prepared if this changes
148 # ever
149 return $self->next_prediction(@args);
152 =head2 next_prediction
154 Title : next_prediction
155 Usage : while($gene = $mzef->next_prediction()) {
156 # do something
158 Function: Returns the next gene structure prediction of the MZEF result
159 file. Call this method repeatedly until FALSE is returned.
161 Note that with the present version of MZEF there will only be one
162 object returned, because MZEF does not predict individual genes
163 but just potential internal exons.
164 Example :
165 Returns : A Bio::Tools::Prediction::Gene object.
166 Args :
168 =cut
170 sub next_prediction {
171 my ($self) = @_;
172 my $gene;
174 # if the prediction section hasn't been parsed yet, we do this now
175 $self->_parse_predictions() unless $self->_predictions_parsed();
177 # return the next gene structure (transcript)
178 return $self->_prediction();
181 =head2 _parse_predictions
183 Title : _parse_predictions()
184 Usage : $obj->_parse_predictions()
185 Function: Parses the prediction section. Automatically called by
186 next_prediction() if not yet done.
187 Example :
188 Returns :
190 =cut
192 sub _parse_predictions {
193 my ($self) = @_;
195 while(defined($_ = $self->_readline())) {
196 if (! /^\#/){ #ignore introductory lines
198 my @element = split;
199 my (%feature);
200 $feature {name} = $element[0];
201 $feature {score} = $element[5];
202 $feature {start} = $element[3];
203 $feature {end} = $element[4];
204 $feature {strand} = $element[6];
205 $feature {source}= 'Eponine';
206 $feature {primary}= 'TSS';
207 $feature {program} = 'eponine-scan';
208 $feature {program_version} = '2';
210 $self->create_feature(\%feature);
211 next;
215 $self->_predictions_parsed(1);
218 =head2 create_feature
220 Title : create_feature
221 Usage : obj->create_feature($feature)
222 Function: Returns an array of features
223 Returns : Returns an array of features
224 Args : none
226 =cut
228 sub create_feature {
229 my ($self, $feat) = @_;
230 #create and fill Bio::EnsEMBL::Seqfeature object
232 my $tss = Bio::SeqFeature::Generic->new
233 ( -seq_id => $feat->{'name'},
234 -start => $feat->{'start'},
235 -end => $feat->{'end'},
236 -strand => $feat->{'strand'},
237 -score => $feat->{'score'},
238 -source_tag => $feat->{'source'},
239 -primary_tag => $feat->{'primary'});
243 if ($tss) {
244 # add to _flist
245 push(@{$self->{'_flist'}}, $tss);
248 #print $tss->gff_string;
256 =head2 _prediction
258 Title : _prediction()
259 Usage : $gene = $obj->_prediction()
260 Function: internal
261 Example :
262 Returns :
264 =cut
266 sub _prediction {
267 my ($self) = @_;
269 return unless(exists($self->{'_flist'}) && @{$self->{'_flist'}});
270 return shift(@{$self->{'_flist'}});
273 =head2 _predictions_parsed
275 Title : _predictions_parsed
276 Usage : $obj->_predictions_parsed
277 Function: internal
278 Example :
279 Returns : TRUE or FALSE
281 =cut
283 sub _predictions_parsed {
284 my ($self, $val) = @_;
286 $self->{'_preds_parsed'} = $val if $val;
287 # array of pre-parsed predictions
288 if(! exists($self->{'_preds_parsed'})) {
289 $self->{'_preds_parsed'} = 0;
291 return $self->{'_preds_parsed'};