Bio/Tools/ESTScan.pm

filter: Statementstmt 15.1% 17 / 112 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 45.4% 5 / 11 Podpod 100% 4 / 4 totaltotal 15.0% 26 / 173 CC 21 SCAR 47.9
CC
21
Cov
11%
next_prediction
240.0
_fasta_stream
20.0
analysis_method
12.0
CRAP 120.5
« Bio/Root/RootI.pm ↑ Summary Bio/SeqIO/swiss.pm »
1 #
2 # BioPerl module for Bio::Tools::ESTScan
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Hilmar Lapp <hlapp@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::ESTScan - Results of one ESTScan run
17  
18 =head1 SYNOPSIS
19  
20 $estscan = Bio::Tools::ESTScan->new(-file => 'result.estscan');
21 # filehandle:
22 $estscan = Bio::Tools::ESTScan->new( -fh => \*INPUT );
23  
24 # parse the results
25 # note: this class is-a Bio::Tools::AnalysisResult which implements
26 # Bio::SeqAnalysisParserI, i.e., $genscan->next_feature() is the same
27 while($gene = $estscan->next_prediction()) {
28 # $gene is an instance of Bio::Tools::Prediction::Gene
29 foreach my $orf ($gene->exons()) {
30 # $orf is an instance of Bio::Tools::Prediction::Exon
31 $cds_str = $orf->predicted_cds();
32 }
33 }
34  
35 # essential if you gave a filename at initialization (otherwise the file
36 # will stay open)
37 $estscan->close();
38  
39 =head1 DESCRIPTION
40  
41 The ESTScan module provides a parser for ESTScan coding region prediction
42 output.
43  
44 This module inherits off L<Bio::Tools::AnalysisResult> and therefore
45 implements the L<Bio::SeqAnalysisParserI> interface.
46 See L<Bio::SeqAnalysisParserI>.
47  
48 =head1 FEEDBACK
49  
50 =head2 Mailing Lists
51  
52 User feedback is an integral part of the evolution of this and other
53 Bioperl modules. Send your comments and suggestions preferably to one
54 of the Bioperl mailing lists. Your participation is much appreciated.
55  
56 bioperl-l@bioperl.org - General discussion
57 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
58  
59 =head2 Support
60  
61 Please direct usage questions or support issues to the mailing list:
62  
63 I<bioperl-l@bioperl.org>
64  
65 rather than to the module maintainer directly. Many experienced and
66 reponsive experts will be able look at the problem and quickly
67 address it. Please include a thorough description of the problem
68 with code and data examples if at all possible.
69  
70 =head2 Reporting Bugs
71  
72 Report bugs to the Bioperl bug tracking system to help us keep track
73 the bugs and their resolution. Bug reports can be submitted via the
74 web:
75  
76 https://github.com/bioperl/bioperl-live/issues
77  
78 =head1 AUTHOR - Hilmar Lapp
79  
80 Email hlapp@gmx.net (or hilmar.lapp@pharma.novartis.com)
81  
82 =head1 APPENDIX
83  
84 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
85  
86 =cut
87  
88 # Let the code begin...
89  
90 package Bio::Tools::ESTScan;
91 1 $Bio::Tools::ESTScan::VERSION = '1.7.8';
92 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
93 1 ▶use Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
94  
95 1 ▶use Bio::Root::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
96 1 ▶use Bio::Tools::Prediction::Exon;
Subroutine BEGIN: called CC=1 SCAR=0.0
97  
98 1 ▶use base qw(Bio::Tools::AnalysisResult);
Subroutine BEGIN: called CC=1 SCAR=0.0
99  
100 0 ▶sub _initialize_state {
Subroutine _initialize_state: not called CC=2 SCAR=17.9
101 0 my ($self,@args) = @_;
102  
103 # first call the inherited method!
104 0 my $make = $self->SUPER::_initialize_state(@args);
105  
106 0 ▶ if(! $self->analysis_method()) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->analysis_method) 0 0 0
107 0 $self->analysis_method('ESTScan');
108 }
109 }
110  
111 =head2 analysis_method
112  
113 Usage : $estscan->analysis_method();
114 Purpose : Inherited method. Overridden to ensure that the name matches
115 /estscan/i.
116 Returns : String
117 Argument : n/a
118  
119 =cut
120  
121 #-------------
122 0 ▶sub analysis_method {
Subroutine analysis_method: not called CC=3 SCAR=24.8
Pod documented
123 #-------------
124 0 my ($self, $method) = @_;
125 0 ▶ if($method && ($method !~ /estscan/i)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method and not $method =~ /estscan/i) 0 0 0
Condition0%0/3
$method and not $method =~ /estscan/i
!ll&&!rl&&r
000
MC/DC0%0/2
$method and not $method =~ /estscan/i
$method not $method =~ /estscan/i
Truth table0%0/3
A and not(B)
A= $methodB= not $method =~ /estscan/i
ABresult
0X0
100
111
126 0 $self->throw("method $method not supported in " . ref($self));
127 }
128 0 return $self->SUPER::analysis_method($method);
129 }
130  
131 =head2 next_feature
132  
133 Title : next_feature
134 Usage : while($orf = $estscan->next_feature()) {
135 # do something
136 }
137 Function: Returns the next gene structure prediction of the ESTScan result
138 file. Call this method repeatedly until FALSE is returned.
139  
140 The returned object is actually a SeqFeatureI implementing object.
141 This method is required for classes implementing the
142 SeqAnalysisParserI interface, and is merely an alias for
143 next_prediction() at present.
144  
145 Example :
146 Returns : A Bio::Tools::Prediction::Gene object.
147 Args :
148  
149 =cut
150  
151 0 ▶sub next_feature {
Subroutine next_feature: not called CC=1 SCAR=6.9
Pod documented
152 0 my ($self,@args) = @_;
153 # even though next_prediction doesn't expect any args (and this method
154 # does neither), we pass on args in order to be prepared if this changes
155 # ever
156 0 return $self->next_prediction(@args);
157 }
158  
159 =head2 next_prediction
160  
161 Title : next_prediction
162 Usage : while($gene = $estscan->next_prediction()) {
163 # do something
164 }
165 Function: Returns the next gene structure prediction of the ESTScan result
166 file. Call this method repeatedly until FALSE is returned.
167  
168 So far, this method DOES NOT work for reverse strand predictions,
169 even though the code looks like.
170 Example :
171 Returns : A Bio::Tools::Prediction::Gene object.
172 Args :
173  
174 =cut
175  
176 0 ▶sub next_prediction {
Subroutine next_prediction: not called CC=15 SCAR=54.8
Pod documented
177 0 my ($self) = @_;
178 0 my ($gene, $seq, $cds, $predobj);
179 0 my $numins = 0;
180  
181 # predictions are in the format of FASTA sequences and can be parsed one
182 # at a time
183 0 $seq = $self->_fasta_stream()->next_seq();
184 0 ▶ return unless $seq;
Branch: 1 branch
BranchTrueFalseTotal
unless $seq 0 0 0
185 # there is a new prediction
186 0 $gene = Bio::Tools::Prediction::Gene->new('-primary' => "ORFprediction",
187 '-source' => "ESTScan");
188 # score starts the description
189 0 ▶ $seq->desc() =~ /^([\d.]+)\s*(.*)/ or
Branch: 1 branch
BranchTrueFalseTotal
$seq->desc =~ /^([\d.]+)\s*(.*)/ or $self->throw('unexpected format of description: no score in ' . $seq->desc) 0 0 0
190 $self->throw("unexpected format of description: no score in " .
191 $seq->desc());
192 0 $gene->score($1);
193 0 $seq->desc($2);
194 # strand may end the description
195 0 ▶ if($seq->desc() =~ /(.*)minus strand$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq->desc =~ /(.*)minus strand$/) { } 0 0 0
196 0 my $desc = $1;
197 0 $desc =~ s/;\s+$//;
198 0 $seq->desc($desc);
199 0 $gene->strand(-1);
200 } else {
201 0 $gene->strand(1);
202 }
203 # check for the format: default or 'all-in-one' (option -a)
204 0 ▶ if($seq->desc() =~ /^(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s*(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq->desc =~ /^(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s*(.*)/) { } 0 0 0
205 # default format
206 0 $seq->desc($5);
207 0 $predobj = Bio::Tools::Prediction::Exon->new('-source' => "ESTScan",
208 '-start' => $3,
209 '-end' => $4);
210 0 $predobj->strand($gene->strand());
211 0 $predobj->score($gene->score()); # FIXME or $1, or $2 ?
212 0 $predobj->primary_tag("InternalExon");
213 0 $predobj->seq_id($seq->display_id());
214 # add to gene structure object
215 0 $gene->add_exon($predobj);
216 # add predicted CDS
217 0 $cds = $seq->seq();
218 0 $cds =~ s/[a-z]//g; # remove the deletions, but keep the insertions
219 0 $cds = Bio::PrimarySeq->new('-seq' => $cds,
220 '-display_id' => $seq->display_id(),
221 '-desc' => $seq->desc(),
222 '-alphabet' => "dna");
223 0 $gene->predicted_cds($cds);
224 0 $predobj->predicted_cds($cds);
225 0 ▶ if($gene->strand() == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gene->strand == -1) 0 0 0
226 0 $self->warn("reverse strand ORF, but unable to reverse coordinates!");
227 }
228 } else {
229 #
230 # All-in-one format (hopefully). This encodes the following information
231 # into the sequence:
232 # 1) untranslated regions: stretches of lower-case letters
233 # 2) translated regions: stretches of upper-case letters
234 # 3) insertions in the translated regions: capital X
235 # 4) deletions in the translated regions: a single lower-case letter
236 #
237 # if reverse strand ORF, save a lot of hassle by reversing the sequence
238 0 ▶ if($gene->strand() == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gene->strand == -1) 0 0 0
239 0 $seq = $seq->revcom();
240 }
241 0 my $seqstr = $seq->seq();
242 0 ▶ while($seqstr =~ /^([a-z]*)([A-Z].*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seqstr =~ /^([a-z]*)([A-Z].*)$/) 0 0 0
243 # leading 5'UTR
244 0 my $utr5 = $1;
245 # exon + 3'UTR
246 0 my $exonseq = $2;
247 # strip 3'UTR and following exons
248 0 ▶ if($exonseq =~ s/([a-z]{2,}.*)$//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exonseq =~ s/([a-z]{2,}.*)$//) { } 0 0 0
249 0 $seqstr = $1;
250 } else {
251 0 $seqstr = "";
252 }
253 # start: take care of yielding the absolute coordinate
254 0 my $start = CORE::length($utr5) + 1;
255 0 ▶ if($predobj) {
Branch: 1 branch
BranchTrueFalseTotal
if ($predobj) 0 0 0
256 0 $start += $predobj->end() + $numins;
257 }
258 # for the end coordinate, we need to subtract the insertions
259 0 $cds = $exonseq;
260 0 $cds =~ s/[X]//g;
261 0 my $end = $start + CORE::length($cds) - 1;
262 # construct next exon object
263 0 $predobj = Bio::Tools::Prediction::Exon->new('-start' => $start,
264 '-end' => $end);
265 0 $predobj->source_tag("ESTScan");
266 0 $predobj->primary_tag("InternalExon");
267 0 $predobj->seq_id($seq->display_id());
268 0 $predobj->strand($gene->strand());
269 0 $predobj->score($gene->score());
270 # add the exon to the gene structure object
271 0 $gene->add_exon($predobj);
272 # add the predicted CDS
273 0 $cds = $exonseq;
274 0 $cds =~ s/[a-z]//g; # remove the deletions, but keep the insertions
275 0 $cds = Bio::PrimarySeq->new('-seq' => $cds,
276 '-display_id' => $seq->display_id(),
277 '-desc' => $seq->desc(),
278 '-alphabet' => "dna");
279 # only store the first one in the overall prediction
280 0 ▶ $gene->predicted_cds($cds) unless $gene->predicted_cds();
Branch: 1 branch
BranchTrueFalseTotal
unless $gene->predicted_cds 0 0 0
281 0 $predobj->predicted_cds($cds);
282 # add the predicted insertions and deletions as subfeatures
283 # of the exon
284 0 my $fea = undef;
285 0 ▶ while($exonseq =~ /([a-zX])/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exonseq =~ /([a-zX])/g) 0 0 0
286 0 my $indel = $1;
287 # start and end: start looking at the position after the
288 # previous feature
289 0 ▶ if($fea) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fea) { } 0 0 0
290 0 $start = $fea->start()+$numins;
291 0 ▶ $start -= 1 if($fea->primary_tag() eq 'insertion');
Branch: 1 branch
BranchTrueFalseTotal
if $fea->primary_tag eq "insertion" 0 0 0
292 } else {
293 0 $start = $predobj->start()+$numins-1;
294 }
295 #print "# numins = $numins, indel = $indel, start = $start\n";
296 0 $start = index($seq->seq(), $indel, $start) + 1 - $numins;
297 0 $fea = Bio::SeqFeature::Generic->new('-start' => $start,
298 '-end' => $start);
299 0 $fea->source_tag("ESTScan");
300 0 $fea->seq_id($seq->display_id());
301 0 $fea->strand($predobj->strand());
302 0 ▶ if($indel eq 'X') {
Branch: 1 branch
BranchTrueFalseTotal
if ($indel eq 'X') { } 0 0 0
303 # an insertion (depends on viewpoint: to get the 'real'
304 # CDS, a base has to be inserted, i.e., the HMMER model
305 # inserted a base; however, the sequencing process deleted
306 # a base that was there).
307 0 $fea->primary_tag("insertion");
308 # we need to count insertions because these are left out
309 # of any coordinates saved in the objects (which is correct
310 # because insertions change the original sequence, so
311 # coordinates wouldn't match)
312 0 $numins++;
313 } else {
314 # a deletion (depends on viewpoint: to get the 'real'
315 # CDS, a base has to be deleted, i.e., the HMMER model
316 # deleted a base; however, the sequencing process inserted
317 # a base that wasn't there).
318 0 $fea->primary_tag("deletion");
319 0 $fea->add_tag_value('base', $indel);
320 }
321 0 $predobj->add_sub_SeqFeature($fea);
322 }
323 }
324 }
325
326 0 return $gene;
327 }
328  
329 =head2 close
330  
331 Title : close
332 Usage : $result->close()
333 Function: Closes the file handle associated with this result file.
334 Inherited method, overridden.
335 Example :
336 Returns :
337 Args :
338  
339 =cut
340  
341 0 ▶sub close {
Subroutine close: not called CC=1 SCAR=6.9
Pod documented
342 0 my ($self, @args) = @_;
343  
344 0 delete($self->{'_fastastream'});
345 0 $self->SUPER::close(@args);
346 }
347  
348 =head2 _fasta_stream
349  
350 Title : _fasta_stream
351 Usage : $result->_fasta_stream()
352 Function: Gets/Sets the FASTA sequence IO stream for reading the contents of
353 the file associated with this MZEF result object.
354  
355 If called for the first time, creates the stream from the filehandle
356 if necessary.
357 Example :
358 Returns :
359 Args :
360  
361 =cut
362  
363 0 ▶sub _fasta_stream {
Subroutine _fasta_stream: not called CC=4 SCAR=30.0
364 0 my ($self, $stream) = @_;
365
366 0 ▶ if($stream || (! exists($self->{'_fastastream'}))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stream or not exists $self->{"_fastastream"}) 0 0 0
Condition0%0/3
$stream or not exists $self->{"_fastastream"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$stream or not exists $self->{"_fastastream"}
$stream not exists $self->{"_fastastream"}
Truth table0%0/3
A or not(B)
A= $streamB= not exists $self->{"_fastastream"}
ABresult
1X1
011
000
367 0 ▶ if(! $stream) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stream) 0 0 0
368 0 $stream = Bio::SeqIO->new('-fh' => $self->_fh(),
369 '-format' => "fasta");
370 }
371 0 $self->{'_fastastream'} = $stream;
372 }
373 0 return $self->{'_fastastream'};
374 }
375  
376 1 1;
377  
« Bio/Root/RootI.pm ↑ Summary Bio/SeqIO/swiss.pm »