Bio/Tools/MZEF.pm

filter: Statementstmt 94.2% 82 / 87 Branchbran 76.6% 23 / 30 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 12 / 12 Podpod 100% 3 / 3 totaltotal 87.3% 124 / 142 CC 18 SCAR 14.9
CC
18
Cov
88%
_parse_predictions
9.1
analysis_method
3.8
_predictions_parsed
3.1
CRAP 4.4
« Bio/Ontology/Path.pm ↑ Summary Bio/Seq/TraceI.pm »
1 #
2 # BioPerl module for Bio::Tools::MZEF
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Hilmar Lapp <hlapp-at-gmx.net>
7 #
8 # Copyright Hilmar Lapp
9 #
10 # You may distribute this module under the same terms as perl itself
11  
12 # POD documentation - main docs before the code
13  
14 =head1 NAME
15  
16 Bio::Tools::MZEF - Results of one MZEF run
17  
18 =head1 SYNOPSIS
19  
20 $mzef = Bio::Tools::MZEF->new(-file => 'result.mzef');
21 # filehandle:
22 $mzef = Bio::Tools::MZEF->new( -fh => \*INPUT );
23 # to indicate that the sequence was reversed prior to feeding it to MZEF
24 # and that you want to have this reflected in the strand() attribute of
25 # the exons, as well have the coordinates translated to the non-reversed
26 # sequence
27 $mzef = Bio::Tools::MZEF->new( -file => 'result.mzef',
28 -strand => -1 );
29  
30 # parse the results
31 # note: this class is-a Bio::Tools::AnalysisResult which implements
32 # Bio::SeqAnalysisParserI, i.e., $genscan->next_feature() is the same
33 while($gene = $mzef->next_prediction()) {
34 # $gene is an instance of Bio::Tools::Prediction::Gene
35  
36 # $gene->exons() returns an array of
37 # Bio::Tools::Prediction::Exon objects
38 # all exons:
39 @exon_arr = $gene->exons();
40  
41 # internal exons only
42 @intrl_exons = $gene->exons('Internal');
43 # note that presently MZEF predicts only internal exons!
44 }
45  
46 # essential if you gave a filename at initialization (otherwise the file
47 # will stay open)
48 $mzef->close();
49  
50 =head1 DESCRIPTION
51  
52 The MZEF module provides a parser for MZEF gene structure prediction
53 output.
54  
55 This module inherits off L<Bio::Tools::AnalysisResult> and therefore
56 implements L<Bio::SeqAnalysisParserI>.
57  
58 =head1 FEEDBACK
59  
60 =head2 Mailing Lists
61  
62 User feedback is an integral part of the evolution of this and other
63 Bioperl modules. Send your comments and suggestions preferably to one
64 of the Bioperl mailing lists. Your participation is much appreciated.
65  
66 bioperl-l@bioperl.org - General discussion
67 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
68  
69 =head2 Support
70  
71 Please direct usage questions or support issues to the mailing list:
72  
73 I<bioperl-l@bioperl.org>
74  
75 rather than to the module maintainer directly. Many experienced and
76 reponsive experts will be able look at the problem and quickly
77 address it. Please include a thorough description of the problem
78 with code and data examples if at all possible.
79  
80 =head2 Reporting Bugs
81  
82 Report bugs to the Bioperl bug tracking system to help us keep track
83 the bugs and their resolution. Bug reports can be submitted via the
84 web:
85  
86 https://github.com/bioperl/bioperl-live/issues
87  
88 =head1 AUTHOR - Hilmar Lapp
89  
90 Email hlapp-at-gmx.net (or hilmar.lapp-at-pharma.novartis.com)
91  
92 =head1 APPENDIX
93  
94 The rest of the documentation details each of the object
95 methods. Internal methods are usually preceded with a _
96  
97 =cut
98  
99  
100 # Let the code begin...
101  
102  
103 package Bio::Tools::MZEF;
104 3 $Bio::Tools::MZEF::VERSION = '1.7.8';
105 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
106  
107 3 ▶use Bio::Tools::Prediction::Gene;
Subroutine BEGIN: called CC=1 SCAR=0.0
108 3 ▶use Bio::Tools::Prediction::Exon;
Subroutine BEGIN: called CC=1 SCAR=0.0
109  
110 3 ▶use base qw(Bio::Tools::AnalysisResult);
Subroutine BEGIN: called CC=1 SCAR=0.0
111  
112 2 ▶sub _initialize_state {
Subroutine _initialize_state: called CC=2 SCAR=7.0
113 2 my($self,@args) = @_;
114  
115 # first call the inherited method!
116 2 my $make = $self->SUPER::_initialize_state(@args);
117  
118 # handle our own parameters
119 2 my ($strand, $params) =
120 $self->_rearrange([qw(STRAND
121 )],
122 @args);
123  
124 # our private state variables
125 2 ▶ $strand = 1 unless defined($strand);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $strand 2 0 2
126 2 $self->{'_strand'} = $strand;
127 2 $self->{'_preds_parsed'} = 0;
128 2 $self->{'_has_cds'} = 0;
129 # array of pre-parsed predictions
130 2 $self->{'_preds'} = [];
131 }
132  
133 =head2 analysis_method
134  
135 Usage : $mzef->analysis_method();
136 Purpose : Inherited method. Overridden to ensure that the name matches
137 /mzef/i.
138 Returns : String
139 Argument : n/a
140  
141 =cut
142  
143 #-------------
144 2 ▶sub analysis_method {
Subroutine analysis_method: called CC=3 SCAR=13.3
Pod documented
145 #-------------
146 2 my ($self, $method) = @_;
147 2 ▶ if($method && ($method !~ /mzef/i)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method and not $method =~ /mzef/i) 0 2 2
Condition33%1/3
$method and not $method =~ /mzef/i
!ll&&!rl&&r
020
MC/DC0%0/2
$method and not $method =~ /mzef/i
$method not $method =~ /mzef/i
Truth table33%1/3
A and not(B)
A= $methodB= not $method =~ /mzef/i
ABresult
0X0
100
111
148 0 $self->throw("method $method not supported in " . ref($self));
149 }
150 2 return $self->SUPER::analysis_method($method);
151 }
152  
153 =head2 next_feature
154  
155 Title : next_feature
156 Usage : while($gene = $mzef->next_feature()) {
157 # do something
158 }
159 Function: Returns the next gene structure prediction of the MZEF result
160 file. Call this method repeatedly until FALSE is returned.
161  
162 The returned object is actually a SeqFeatureI implementing object.
163 This method is required for classes implementing the
164 SeqAnalysisParserI interface, and is merely an alias for
165 next_prediction() at present.
166  
167 Note that with the present version of MZEF there will only be one
168 object returned, because MZEF does not predict individual genes
169 but just potential internal exons.
170 Example :
171 Returns : A Bio::Tools::Prediction::Gene object.
172 Args :
173  
174 =cut
175  
176 2 ▶sub next_feature {
Subroutine next_feature: called CC=1 SCAR=0.0
Pod documented
177 2 my ($self,@args) = @_;
178 # even though next_prediction doesn't expect any args (and this method
179 # does neither), we pass on args in order to be prepared if this changes
180 # ever
181 2 return $self->next_prediction(@args);
182 }
183  
184 =head2 next_prediction
185  
186 Title : next_prediction
187 Usage : while($gene = $mzef->next_prediction()) {
188 # do something
189 }
190 Function: Returns the next gene structure prediction of the MZEF result
191 file. Call this method repeatedly until FALSE is returned.
192  
193 Note that with the present version of MZEF there will only be one
194 object returned, because MZEF does not predict individual genes
195 but just potential internal exons.
196 Example :
197 Returns : A Bio::Tools::Prediction::Gene object.
198 Args :
199  
200 =cut
201  
202 3 ▶sub next_prediction {
Subroutine next_prediction: called CC=2 SCAR=6.9
Pod documented
203 3 my ($self) = @_;
204 3 my $gene;
205  
206 # if the prediction section hasn't been parsed yet, we do this now
207 3 ▶ $self->_parse_predictions() unless $self->_predictions_parsed();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_predictions_parsed 2 1 3
208  
209 # return the next gene structure (transcript)
210 3 return $self->_prediction();
211 }
212  
213 =head2 _parse_predictions
214  
215 Title : _parse_predictions()
216 Usage : $obj->_parse_predictions()
217 Function: Parses the prediction section. Automatically called by
218 next_prediction() if not yet done.
219 Example :
220 Returns :
221  
222 =cut
223  
224 2 ▶sub _parse_predictions {
Subroutine _parse_predictions: called CC=9 SCAR=22.0
225 2 my ($self) = @_;
226 2 my ($method); # set but not used presently
227 2 my $exon_tag = "InternalExon";
228 2 my $gene;
229 # my $seqname; # name given in output is poorly formatted
230 my $seqlen;
231 2 my $prednr = 1;
232  
233 2 ▶ while(defined($_ = $self->_readline())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 68 2 70
234 68 ▶ if(/^\s*(\d+)\s*-\s*(\d+)\s+/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*(\d+)\s*-\s*(\d+)\s+/) 46 22 68
235 # exon or signal
236 46 ▶ if(! defined($gene)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $gene) 2 44 46
237 2 $gene = Bio::Tools::Prediction::Gene->new(
238 '-primary' => "GenePrediction$prednr",
239 '-source' => 'MZEF');
240 }
241 # we handle start-end first because may not be space delimited
242 # for large numbers
243 46 my ($start,$end) = ($1,$2);
244 46 s/^\s*(\d+)\s*-\s*(\d+)\s+//;
245 # split the rest into fields
246 46 chomp();
247 # format: Coordinates P Fr1 Fr2 Fr3 Orf 3ss Cds 5ss
248 # index: 0 1 2 3 4 5 6 7
249 46 my @flds = split(' ', $_);
250 # create the feature object depending on the type of signal --
251 # which is always an (internal) exon for MZEF
252 46 my $predobj = Bio::Tools::Prediction::Exon->new();
253 # set common fields
254 46 $predobj->source_tag('MZEF');
255 46 $predobj->significance($flds[0]);
256 46 $predobj->score($flds[0]); # what shall we set as overall score?
257 46 $predobj->strand($self->{'_strand'}); # MZEF searches only one
258 46 ▶ if($predobj->strand() == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($predobj->strand == 1) { } 46 0 46
259 46 $predobj->start($start);
260 46 $predobj->end($end);
261 } else {
262 0 $predobj->start($seqlen-$end+1);
263 0 $predobj->end($seqlen-$start+1);
264 }
265 # set scores
266 46 $predobj->start_signal_score($flds[5]);
267 46 $predobj->end_signal_score($flds[7]);
268 46 $predobj->coding_signal_score($flds[6]);
269 # frame -- we simply extract the one with highest score from the
270 # orf field, and store the individual scores for now
271 46 my $frm = index($flds[4], "1");
272 46 ▶ $predobj->frame(($frm < 0) ? undef : $frm);
Branch: 1 branch
BranchTrueFalseTotal
$frm < 0 ? : 0 46 46
273 46 $predobj->primary_tag($exon_tag);
274 46 $predobj->is_coding(1);
275 # add to gene structure (should be done only when start and end
276 # are set, in order to allow for proper expansion of the range)
277 46 $gene->add_exon($predobj);
278 46 next;
279 }
280 22 ▶ if(/^\s*Internal .*(MZEF)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*Internal .*(MZEF)/) 2 20 22
281 2 $self->analysis_method($1);
282 2 next;
283 }
284 20 ▶ if(/^\s*File_Name:\s+(\S+)\s+Sequence_length:\s+(\d+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*File_Name:\s+(\S+)\s+Sequence_length:\s+(\d+)/) 2 18 20
285 # $seqname = $1; # this is too poor currently (file name truncated
286 # to 10 chars) in order to be sensible enough
287 2 $seqlen = $2;
288 2 next;
289 }
290 }
291 # $gene->seq_id($seqname);
292 2 ▶ $self->_add_prediction($gene) if defined($gene);
Branch: 1 branch
BranchTrueFalseTotal
if defined $gene 2 0 2
293 2 $self->_predictions_parsed(1);
294 }
295  
296 =head2 _prediction
297  
298 Title : _prediction()
299 Usage : $gene = $obj->_prediction()
300 Function: internal
301 Example :
302 Returns :
303  
304 =cut
305  
306 3 ▶sub _prediction {
Subroutine _prediction: called CC=3 SCAR=11.0
307 3 my ($self) = @_;
308  
309 3 ▶ return unless(exists($self->{'_preds'}) && @{$self->{'_preds'}});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_preds"} and @{$self->{"_preds"};} 1 2 3
Condition66%2/3
exists $self->{"_preds"} and @{$self->{"_preds"};}
!ll&&!rl&&r
012
MC/DC50%1/2
exists $self->{"_preds"} and @{$self->{"_preds"};}
exists $self->{"_preds"} @{$self->{"_preds"};}
Truth table66%2/3
A and B
A= exists $self->{"_preds"}B= @{$self->{"_preds"};}
ABresult
0X0
100
111
310 2 return shift(@{$self->{'_preds'}});
311 }
312  
313 =head2 _add_prediction
314  
315 Title : _add_prediction()
316 Usage : $obj->_add_prediction($gene)
317 Function: internal
318 Example :
319 Returns :
320  
321 =cut
322  
323 2 ▶sub _add_prediction {
Subroutine _add_prediction: called CC=2 SCAR=7.4
324 2 my ($self, $gene) = @_;
325  
326 2 ▶ if(! exists($self->{'_preds'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_preds"}) 0 2 2
327 0 $self->{'_preds'} = [];
328 }
329 2 push(@{$self->{'_preds'}}, $gene);
330 }
331  
332 =head2 _predictions_parsed
333  
334 Title : _predictions_parsed
335 Usage : $obj->_predictions_parsed
336 Function: internal
337 Example :
338 Returns : TRUE or FALSE
339  
340 =cut
341  
342 5 ▶sub _predictions_parsed {
Subroutine _predictions_parsed: called CC=3 SCAR=11.3
343 5 my ($self, $val) = @_;
344  
345 5 ▶ $self->{'_preds_parsed'} = $val if $val;
Branch: 1 branch
BranchTrueFalseTotal
if $val 2 3 5
346 5 ▶ if(! exists($self->{'_preds_parsed'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_preds_parsed"}) 0 5 5
347 0 $self->{'_preds_parsed'} = 0;
348 }
349 5 return $self->{'_preds_parsed'};
350 }
351  
352  
353 3 1;
« Bio/Ontology/Path.pm ↑ Summary Bio/Seq/TraceI.pm »