Bio/Tools/Glimmer.pm

filter: Statementstmt 91.4% 160 / 175 Branchbran 87.2% 96 / 110 Conditioncond 58.5% 24 / 41 MC/DCmcdc 43.4% 10 / 23 Subroutinesub 90.0% 18 / 20 Podpod 100% 4 / 4 totaltotal 83.6% 312 / 373 CC 71 SCAR 27.7
CC
71
Cov
86%
_parse_prokaryotic
31.9
_parse_eukaryotic
14.0
analysis_method
12.0
CRAP 15.9
« Bio/SeqIO/metafasta.pm ↑ Summary Bio/Tools/Analysis/SimpleAnalysisBase.pm »
1 #
2 # BioPerl module for Bio::Tools::Glimmer
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Jason Stajich <jason-at-bioperl-dot-org>
7 #
8 # Copyright Jason Stajich
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::Glimmer - parser for Glimmer 2.X/3.X prokaryotic and
17 GlimmerM/GlimmerHMM eukaryotic gene predictions
18  
19 =head1 SYNOPSIS
20  
21 use Bio::Tools::Glimmer;
22  
23 # file
24 my $parser = Bio::Tools::Glimmer->new(-file => $file);
25 # filehandle:
26 $parser = Bio::Tools::Glimmer->new( -fh => \*INPUT );
27 # provide a sequence identifier (Glimmer 2.X)
28 my $parser = Bio::Tools::Glimmer->new(-file => $file, -seqname => seqname);
29 # force format (override automatic detection)
30 my $parser = Bio::Tools::Glimmer->new(-file => $file, -format => 'GlimmerM');
31  
32 # parse the results
33 # note: this class is-a Bio::Tools::AnalysisResult which implements
34 # Bio::SeqAnalysisParserI, i.e., $glimmer->next_feature() is the same
35  
36 while(my $gene = $parser->next_prediction()) {
37 # For eukaryotic input (GlimmerM/GlimmerHMM), $gene will be an instance
38 # of Bio::Tools::Prediction::Gene, which inherits off
39 # Bio::SeqFeature::Gene::Transcript, and $gene->exons() will return an
40 # array of Bio::Tools::Prediction::Exon objects.
41 # For prokaryotic input (Glimmer2.X/Glimmer3.X), $gene will be an
42 # instance of Bio::SeqFeature::Generic
43  
44 # all exons (eukaryotic only):
45 @exon_arr = $gene->exons();
46 # initial exons only
47 @init_exons = $gene->exons('Initial');
48 # internal exons only
49 @intrl_exons = $gene->exons('Internal');
50 # terminal exons only
51 @term_exons = $gene->exons('Terminal');
52 }
53  
54 =head1 DESCRIPTION
55  
56 This is a module for parsing Glimmer, GlimmerM and GlimmerHMM predictions.
57 It will create gene objects from the prediction report which can
58 be attached to a sequence using Bioperl objects, or output as GFF
59 suitable for loading into Bio::DB::GFF for use with Gbrowse.
60  
61 Glimmer is open source and available at
62 L<http://www.cbcb.umd.edu/software/glimmer/>.
63  
64 GlimmerM is open source and available at
65 L<http://www.tigr.org/software/glimmerm/>.
66  
67 GlimmerHMM is open source and available at
68 L<http://www.cbcb.umd.edu/software/GlimmerHMM/>.
69  
70 Note that Glimmer 2.X will only process the first
71 sequence in a fasta file, and the prediction report does not contain any
72 sort of sequence identifier
73  
74 Note that Glimmer 3.X produces two output files. This module only parses
75 the .predict file.
76  
77  
78 =head1 FEEDBACK
79  
80 =head2 Mailing Lists
81  
82 User feedback is an integral part of the evolution of this and other
83 Bioperl modules. Send your comments and suggestions preferably to
84 the Bioperl mailing list. Your participation is much appreciated.
85  
86 bioperl-l@bioperl.org - General discussion
87 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
88  
89 =head2 Support
90  
91 Please direct usage questions or support issues to the mailing list:
92  
93 I<bioperl-l@bioperl.org>
94  
95 rather than to the module maintainer directly. Many experienced and
96 reponsive experts will be able look at the problem and quickly
97 address it. Please include a thorough description of the problem
98 with code and data examples if at all possible.
99  
100 =head2 Reporting Bugs
101  
102 Report bugs to the Bioperl bug tracking system to help us keep track
103 of the bugs and their resolution. Bug reports can be submitted via
104 email or the web:
105  
106 https://github.com/bioperl/bioperl-live/issues
107  
108 =head1 AUTHOR - Jason Stajich
109  
110 Email jason-at-bioperl-dot-org
111  
112 =head1 CONTRIBUTORS
113  
114 Torsten Seemann
115  
116 Mark Johnson
117  
118 =head1 APPENDIX
119  
120 The rest of the documentation details each of the object methods.
121 Internal methods are usually preceded with a _
122  
123 =cut
124  
125  
126 # Let the code begin...
127  
128  
129 package Bio::Tools::Glimmer;
130 2 $Bio::Tools::Glimmer::VERSION = '1.7.8';
131 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
132  
133 2 ▶use Bio::Factory::FTLocationFactory;
Subroutine BEGIN: called CC=1 SCAR=0.0
134 2 ▶use Bio::Tools::Prediction::Gene;
Subroutine BEGIN: called CC=1 SCAR=0.0
135 2 ▶use Bio::Tools::Prediction::Exon;
Subroutine BEGIN: called CC=1 SCAR=0.0
136  
137 2 ▶use base qw(Bio::Tools::AnalysisResult);
Subroutine BEGIN: called CC=1 SCAR=0.0
138  
139 5 ▶sub _initialize_state {
Subroutine _initialize_state: called CC=1 SCAR=0.0
140 5 my($self,@args) = @_;
141  
142 # first call the inherited method!
143 5 my $make = $self->SUPER::_initialize_state(@args);
144  
145 5 $self->{'_preds_parsed'} = 0;
146 # array of pre-parsed predictions
147 5 $self->{'_preds'} = [];
148 }
149  
150 =head2 new
151  
152 Title : new
153 Usage : my $obj = Bio::Tools::Glimmer->new();
154 Function: Builds a new Bio::Tools::Glimmer object
155 Returns : an instance of Bio::Tools::Glimmer
156 Args : format ('Glimmer', 'GlimmerM', 'GlimmerHMM'), seqname
157  
158  
159 =cut
160  
161 5 ▶sub new {
Subroutine new: called CC=8 SCAR=23.9
Pod documented
162 5 my($class,@args) = @_;
163  
164 5 my $self = $class->SUPER::new(@args);
165  
166 5 my ($format, $seqname, $seqlength, $detail) =
167 $self->_rearrange([qw(FORMAT SEQNAME SEQLENGTH DETAIL)], @args);
168  
169 # override automagic format detection
170 5 ▶ if (defined($format) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $format and $format eq "Glimmer" || $format eq "GlimmerM" || $format eq "GlimmerHMM") 0 5 5
Condition11%1/9
defined $format and $format eq "Glimmer" || $format eq "GlimmerM" || $format eq "GlimmerHMM"
!ll&&!rl&&r
500
$format eq "Glimmer" or $format eq "GlimmerM" or $format eq "GlimmerHMM"
l!l&&r!l&&!r
000
$format eq "Glimmer" or $format eq "GlimmerM"
l!l&&r!l&&!r
000
MC/DC0%0/4
defined $format and $format eq "Glimmer" || $format eq "GlimmerM" || $format eq "GlimmerHMM"
defined $format $format eq "Glimmer" $format eq "GlimmerM" $format eq "GlimmerHMM"
Truth table20%1/5
A and B or C or D
A= defined $formatB= $format eq "Glimmer"C= $format eq "GlimmerM"D= $format eq "GlimmerHMM"
ABCDresult
0XXX0
10000
11XX1
101X1
10011
171 (($format eq 'Glimmer') ||
172 ($format eq 'GlimmerM') ||
173 ($format eq 'GlimmerHMM'))
174 ) {
175 0 $self->_format($format);
176 }
177
178 5 ▶ if (defined($detail)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $detail) 2 3 5
179 2 $self->_format('Glimmer');
180 2 $self->_detail_file($detail);
181 }
182
183 # hardwire seq_id when creating gene and exon objects (Glimmer 2.X)
184 5 ▶ $self->_seqname($seqname) if defined($seqname);
Branch: 1 branch
BranchTrueFalseTotal
if defined $seqname 1 4 5
185
186 # store the length of the input sequence (Glimmer 2.X)
187 5 ▶ $self->_seqlength($seqlength) if defined($seqlength);
Branch: 1 branch
BranchTrueFalseTotal
if defined $seqlength 1 4 5
188
189 5 return $self;
190 }
191  
192 =head2 analysis_method
193  
194 Usage : $glimmer->analysis_method();
195 Purpose : Inherited method. Overridden to ensure that the name matches
196 /glimmer/i.
197 Returns : String
198 Argument : n/a
199  
200 =cut
201  
202 #-------------
203 0 ▶sub analysis_method {
Subroutine analysis_method: not called CC=3 SCAR=24.8
Pod documented
204 #-------------
205 0 my ($self, $method) = @_;
206 0 ▶ if($method && ($method !~ /glimmer/i)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method and not $method =~ /glimmer/i) 0 0 0
Condition0%0/3
$method and not $method =~ /glimmer/i
!ll&&!rl&&r
000
MC/DC0%0/2
$method and not $method =~ /glimmer/i
$method not $method =~ /glimmer/i
Truth table0%0/3
A and not(B)
A= $methodB= not $method =~ /glimmer/i
ABresult
0X0
100
111
207 0 $self->throw("method $method not supported in " . ref($self));
208 }
209 0 return $self->SUPER::analysis_method($method);
210 }
211  
212 =head2 next_feature
213  
214 Title : next_feature
215 Usage : while($gene = $glimmer->next_feature()) {
216 # do something
217 }
218 Function: Returns the next gene structure prediction of the Glimmer result
219 file. Call this method repeatedly until FALSE is returned.
220  
221 The returned object is actually a SeqFeatureI implementing object.
222 This method is required for classes implementing the
223 SeqAnalysisParserI interface, and is merely an alias for
224 next_prediction() at present.
225  
226 Example :
227 Returns : A Bio::Tools::Prediction::Gene object.
228 Args :
229  
230 =cut
231  
232 0 ▶sub next_feature {
Subroutine next_feature: not called CC=1 SCAR=6.9
Pod documented
233 0 my ($self,@args) = @_;
234 # even though next_prediction doesn't expect any args (and this method
235 # does neither), we pass on args in order to be prepared if this changes
236 # ever
237 0 return $self->next_prediction(@args);
238 }
239  
240 =head2 next_prediction
241  
242 Title : next_prediction
243 Usage : while($gene = $glimmer->next_prediction()) {
244 # do something
245 }
246 Function: Returns the next gene structure prediction of the Glimmer result
247 file. Call this method repeatedly until FALSE is returned.
248  
249 Example :
250 Returns : A Bio::Tools::Prediction::Gene object.
251 Args :
252  
253 =cut
254  
255 114 ▶sub next_prediction {
Subroutine next_prediction: called CC=2 SCAR=6.9
Pod documented
256 114 my ($self) = @_;
257 114 my $gene;
258  
259 # if the prediction section hasn't been parsed yet, we do this now
260 114 ▶ $self->_parse_predictions() unless $self->_predictions_parsed();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_predictions_parsed 5 109 114
261
262 # get next gene structure
263 114 $gene = $self->_prediction();
264 114 return $gene;
265 }
266  
267 =head2 _parse_predictions
268  
269 Title : _parse_predictions()
270 Usage : $obj->_parse_predictions()
271 Function: Parses the prediction section. Automatically called by
272 next_prediction() if not yet done.
273 Example :
274 Returns :
275  
276 =cut
277  
278 5 ▶sub _parse_predictions {
Subroutine _parse_predictions: called CC=8 SCAR=21.2
279  
280 5 my ($self) = @_;
281  
282
283 5 my %method = (
284 'Glimmer' => '_parse_prokaryotic',
285 'GlimmerM' => '_parse_eukaryotic',
286 'GlimmerHMM' => '_parse_eukaryotic',
287 '_DEFAULT_' => '_parse_eukaryotic',
288 );
289
290 5 my $format = $self->_format();
291
292 5 ▶ if (!$format) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($format) 3 2 5
293
294 3 ▶ while (my $line = $self->_readline()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = $self->_readline) 233 0 233
295  
296 233 ▶ if ( $line =~ /^Glimmer\S*\s+\(Version\s*\S+\)/ ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($line =~ /^Glimmer\S*\s+\(Version\s*\S+\)/) { } 1 232 233
elsif ($line =~ /^Glimmer\S*$/) { } 1 231 232
elsif ($line =~ /^Putative Genes:$/) { } 1 230 231
elsif ($line =~ /^>(\S+)/) { } 0 230 230
297 1 $format = 'GlimmerM';
298 1 $self->_pushback($line);
299 1 last;
300 }
301 elsif ( $line =~ /^Glimmer\S*$/ ) {
302 1 $format = 'GlimmerHMM';
303 1 $self->_pushback($line);
304 1 last;
305 }
306 elsif ($line =~ /^Putative Genes:$/) {
307 1 $format = 'Glimmer';
308 1 $self->_pushback($line);
309 1 last;
310 }
311 elsif ($line =~ /^>(\S+)/) {
312 0 $format = 'Glimmer';
313 0 $self->_pushback($line);
314 0 last;
315 }
316
317 }
318
319 }
320  
321 my $method =
322 5 ▶ (exists($method{$format})) ? $method{$format} : $method{'_DEFAULT_'};
Branch: 1 branch
BranchTrueFalseTotal
exists $method{$format} ? : 5 0 5
323  
324 5 return $self->$method();
325
326 }
327  
328  
329 =head2 _parse_eukaryotic
330  
331 Title : _parse_eukaryotic()
332 Usage : $obj->_parse_eukaryotic()
333 Function: Parses the prediction section. Automatically called by
334 next_prediction() if not yet done.
335 Example :
336 Returns :
337  
338 =cut
339  
340 2 ▶sub _parse_eukaryotic {
Subroutine _parse_eukaryotic: called CC=14 SCAR=26.4
341 2 my ($self) = @_;
342  
343 2 my ($gene,$seqname,$seqlen,$source,$lastgenenum);
344
345 2 ▶ while(defined($_ = $self->_readline())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 310 2 312
346 310 ▶ if( /^(Glimmer\S*)\s+\(Version\s*(\S+)\)/ ) {
Branch: 6 branches
BranchTrueFalseTotal
if (/^(Glimmer\S*)\s+\(Version\s*(\S+)\)/) { } 1 309 310
elsif (/^(GlimmerHMM\S*)$/) { } 1 308 309
elsif (/^Sequence name:\s+(.+)$/) { } 2 306 308
elsif (/^Sequence length:\s+(\S+)/) { } 2 304 306
elsif (/^(Predicted genes)|(Gene)|\s+\#/ or /^\s+$/) { } 66 238 304
elsif (/^\s+(\d+)\s+ # gene num (\d+)\s+ # exon num ([\+\-])\s+ # strand (\S+)\s+ # exon type (\d+)\s+(\d+) # exon start, end \s+(\d+) # exon length /ox) { } 238 0 238
347 1 $source = "$1_$2";
348 1 next;
349 } elsif( /^(GlimmerHMM\S*)$/ ) { # GlimmerHMM has no version
350 1 $source = $1;
351 1 next;
352 } elsif(/^Sequence name:\s+(.+)$/ ) {
353 2 $seqname = $1;
354 2 next;
355 } elsif( /^Sequence length:\s+(\S+)/ ) {
356 2 $seqlen = $1;
357 2 next;
358 ▶ } elsif( m/^(Predicted genes)|(Gene)|\s+\#/ || /^\s+$/ ) {
Condition100%3/3
/^(Predicted genes)|(Gene)|\s+\#/ or /^\s+$/
l!l&&r!l&&!r
660238
MC/DC100%2/2
/^(Predicted genes)|(Gene)|\s+\#/ or /^\s+$/
/^(Predicted genes)|(Gene)|\s+\#/ /^\s+$/
Truth table100%3/3
A or B
A= /^(Predicted genes)|(Gene)|\s+\#/B= /^\s+$/
ABresult
1X1
011
000
359 66 next;
360
361 } elsif( # GlimmerM/HMM gene-exon prediction line
362 /^\s+(\d+)\s+ # gene num
363 (\d+)\s+ # exon num
364 ([\+\-])\s+ # strand
365 (\S+)\s+ # exon type
366 (\d+)\s+(\d+) # exon start, end
367 \s+(\d+) # exon length
368 /ox ) {
369 238 my ($genenum,$exonnum,$strand,$type,$start,$end,$len) =
370 ( $1,$2,$3,$4,$5,$6,$7);
371 238 ▶ if( ! $lastgenenum || $lastgenenum != $genenum) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $lastgenenum or $lastgenenum != $genenum) 54 184 238
Condition100%3/3
not $lastgenenum or $lastgenenum != $genenum
l!l&&r!l&&!r
252184
MC/DC100%2/2
not $lastgenenum or $lastgenenum != $genenum
not $lastgenenum $lastgenenum != $genenum
Truth table100%3/3
not(A) or B
A= not $lastgenenumB= $lastgenenum != $genenum
ABresult
1X1
011
000
372 54 ▶ $self->_add_prediction($gene) if ( $gene );
Branch: 1 branch
BranchTrueFalseTotal
if $gene 52 2 54
373 54 $gene = Bio::Tools::Prediction::Gene->new
374 (
375 '-seq_id' => $seqname,
376 '-primary_tag' => "gene",
377 '-source_tag' => $source,
378 '-tag' => { 'Group' => "GenePrediction$genenum"},
379 );
380 }
381 238 ▶ my $exon = Bio::Tools::Prediction::Exon->new
Branch: 1 branch
BranchTrueFalseTotal
$strand eq '-' ? : 39 199 238
382 ('-seq_id' => $seqname,
383 '-start' => $start,
384 '-end' => $end,
385 '-strand' => $strand eq '-' ? '-1' : '1',
386 '-source_tag' => $source,
387 '-primary_tag'=> 'exon',
388 '-tag' => { 'Group' => "GenePrediction$genenum"},
389 );
390 238 $gene->add_exon($exon,lc($type));
391 238 $lastgenenum = $genenum;
392 }
393 }
394 2 ▶ $self->_add_prediction($gene) if( $gene );
Branch: 1 branch
BranchTrueFalseTotal
if $gene 2 0 2
395 2 $self->_predictions_parsed(1);
396 }
397  
398 =head2 _parse_prokaryotic
399  
400 Title : _parse_prokaryotic()
401 Usage : $obj->_parse_prokaryotic()
402 Function: Parses the prediction section. Automatically called by
403 next_prediction() if not yet done.
404 Example :
405 Returns :
406  
407 =cut
408  
409 3 ▶sub _parse_prokaryotic {
Subroutine _parse_prokaryotic: called CC=31 SCAR=34.6
410 3 my ($self) = @_;
411  
412 # default value, possibly overriden later
413 3 my $source = 'Glimmer';
414  
415 # Store the sequence length(s) here, either from the
416 # seqlength arg to the constructor, or from the
417 # Glimmer 3.X detail file
418 3 my %seqlength = ( );
419
420 # Glimmer 2.X does not provide a sequence identifer
421 # in the prediction report (will default to unknown
422 # if not specified in the seqname arg to the
423 # constructor
424 #
425 # Glimmer 2.X does not report the length of the
426 # input sequence, either (will default to undef
427 # if not specified in the seqlength arg to the
428 # constructor
429 3 my $seqname = $self->_seqname();
430 3 my $seqlength = $self->_seqlength();
431  
432 3 ▶ if (defined($seqlength)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $seqlength) 1 2 3
433 1 $seqlength{$seqname} = $seqlength
434 }
435  
436 # Parse the detail file, if we have one (Glimmer 3.X)
437 3 my $detail_file = $self->_detail_file();
438
439 3 ▶ if (defined($detail_file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $detail_file) 2 1 3
440  
441 2 my $io = Bio::Root::IO->new(-file => $detail_file);
442 2 my $seqname;
443
444 2 ▶ while (defined($_ = $io->_readline())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $io->_readline)) 222 2 224
445 222 ▶ if ($_ =~ /^>(\S+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^>(\S+)/) 2 220 222
446 2 $seqname = $1;
447 2 next;
448 }
449  
450 220 ▶ if (defined($seqname) && ($_ =~ /^Sequence length = (\d+)$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $seqname and $_ =~ /^Sequence length = (\d+)$/) 2 218 220
Condition100%3/3
defined $seqname and $_ =~ /^Sequence length = (\d+)$/
!ll&&!rl&&r
401782
MC/DC100%2/2
defined $seqname and $_ =~ /^Sequence length = (\d+)$/
defined $seqname $_ =~ /^Sequence length = (\d+)$/
Truth table100%3/3
A and B
A= defined $seqnameB= $_ =~ /^Sequence length = (\d+)$/
ABresult
0X0
100
111
451 2 $seqlength{$seqname} = $1;
452 2 next;
453 }
454 }
455 }
456
457 3 my $location_factory = Bio::Factory::FTLocationFactory->new();
458
459 3 ▶ while(defined($_ = $self->_readline())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 59 3 62
460 # Glimmer 3.X does provide a sequence identifier -
461 # beware whitespace at the end (comes through from
462 # the fasta file)
463 59 ▶ if ($_ =~ /^Putative Genes:$/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($_ =~ /^Putative Genes:$/) { } 1 58 59
elsif ($_ =~ /^>(\S+)/) { } 2 56 58
elsif (/^\s+(\d+)\s+ # gene num (\d+)\s+(\d+)\s+ # start, end \[([\+\-])(\d{1})\s+ # strand, frame /ox or /^[^\d]+(\d+)\s+ # orf (numeric portion) (\d+)\s+(\d+)\s+ # start, end ([\+\-])(\d{1})\s+ # strand, frame ([\d\.]+) # score /ox) { } 56 0 56
464 1 $source = 'Glimmer_2.X';
465 1 next;
466 }
467 # Glimmer 3.X sequence identifier
468 elsif ($_ =~ /^>(\S+)/) {
469 2 $seqname = $1;
470 2 $seqlength = $seqlength{$seqname};
471 2 $source = 'Glimmer_3.X';
472 2 next;
473 }
474 ▶ elsif (
Condition66%2/3
/^\s+(\d+)\s+ # gene num (\d+)\s+(\d+)\s+ # start, end \[([\+\-])(\d{1})\s+ # strand, frame /ox or /^[^\d]+(\d+)\s+ # orf (numeric portion) (\d+)\s+(\d+)\s+ # start, end ([\+\-])(\d{1})\s+ # strand, frame ([\d\.]+) # score /ox
l!l&&r!l&&!r
25310
MC/DC0%0/2
/^\s+(\d+)\s+ # gene num (\d+)\s+(\d+)\s+ # start, end \[([\+\-])(\d{1})\s+ # strand, frame /ox or /^[^\d]+(\d+)\s+ # orf (numeric portion) (\d+)\s+(\d+)\s+ # start, end ([\+\-])(\d{1})\s+ # strand, frame ([\d\.]+) # score /ox
/^\s+(\d+)\s+ # gene num (\d+)\s+(\d+)\s+ # start, end \[([\+\-])(\d{1})\s+ # strand, frame /ox /^[^\d]+(\d+)\s+ # orf (numeric portion) (\d+)\s+(\d+)\s+ # start, end ([\+\-])(\d{1})\s+ # strand, frame ([\d\.]+) # score /ox
Truth table66%2/3
A or B
A= /^\s+(\d+)\s+ # gene num (\d+)\s+(\d+)\s+ # start, end \[([\+\-])(\d{1})\s+ # strand, frame /oxB= /^[^\d]+(\d+)\s+ # orf (numeric portion) (\d+)\s+(\d+)\s+ # start, end ([\+\-])(\d{1})\s+ # strand, frame ([\d\.]+) # score /ox
ABresult
1X1
011
000
475 # Glimmer 2.X prediction
476 (/^\s+(\d+)\s+ # gene num
477 (\d+)\s+(\d+)\s+ # start, end
478 \[([\+\-])(\d{1})\s+ # strand, frame
479 /ox ) ||
480 # Glimmer 3.X prediction
481 (/^[^\d]+(\d+)\s+ # orf (numeric portion)
482 (\d+)\s+(\d+)\s+ # start, end
483 ([\+\-])(\d{1})\s+ # strand, frame
484 ([\d\.]+) # score
485 /ox)) {
486 56 my ($genenum,$start,$end,$strand,$frame,$score) =
487 ( $1,$2,$3,$4,$5,$6 );
488  
489 56 my $circular_prediction = 0;
490  
491 # Check for a circular prediction before we
492 # start fiddling with the coordinates
493 56 ▶ if ($strand eq '+') {
Branch: 1 branch
BranchTrueFalseTotal
if ($strand eq '+') { } 43 13 56
494 43 ▶ if ($start > $end) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start > $end) 2 41 43
495 2 $circular_prediction = 1;
496 }
497 }
498 else {
499 13 ▶ if ($start < $end) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start < $end) 0 13 13
500 0 $circular_prediction = 1;
501 }
502 }
503  
504 56 ▶ if ($circular_prediction) {
Branch: 1 branch
BranchTrueFalseTotal
if ($circular_prediction) 2 54 56
505 2 ▶ unless (defined($seqlength)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $seqlength) 0 2 2
506 0 $self->throw("need to know the sequence length to handle wraparound genes");
507 }
508 }
509
510 # Glimmer 2.X predictions do not include
511 # the stop codon - this might extend the
512 # prediction off either end of the sequence.
513 # This works fine even on circular/wraparound
514 # predictions.
515 56 ▶ if ($source eq 'Glimmer_2.X') {
Branch: 1 branch
BranchTrueFalseTotal
if ($source eq "Glimmer_2.X") 25 31 56
516 25 ▶ if ($strand eq '+') {
Branch: 1 branch
BranchTrueFalseTotal
if ($strand eq '+') { } 19 6 25
517 19 $end += 3;
518 }
519 else {
520 6 $end -= 3;
521 }
522 }
523  
524 # We might have extended a Glimmer 2.X prediction
525 # beyond the boundaries of the input sequence.
526 # Also, Glimmer 3.X (with -X) will output predictions
527 # with coordinates less than 1 or greater than the
528 # length of the sequence.
529 56 my ($fst, $fend);
530 56 foreach my $coord ($start, $end) {
531 112 ▶ if ($coord < 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($coord < 1) { } 1 111 112
elsif (defined $seqlength and $coord > $seqlength) { } 1 110 111
532 1 $coord = '<1';
533 1 $fst++;
534 ▶ } elsif (defined($seqlength) && ($coord > $seqlength)) {
Condition66%2/3
defined $seqlength and $coord > $seqlength
!ll&&!rl&&r
01101
MC/DC50%1/2
defined $seqlength and $coord > $seqlength
defined $seqlength $coord > $seqlength
Truth table66%2/3
A and B
A= defined $seqlengthB= $coord > $seqlength
ABresult
0X0
100
111
535 1 $coord = ">$seqlength";
536 1 $fend++;
537 }
538 }
539
540 56 my $location_string;
541  
542 56 ▶ if ($circular_prediction) {
Branch: 1 branch
BranchTrueFalseTotal
if ($circular_prediction) { } 2 54 56
543 2 ▶ if ($strand eq '+') {
Branch: 1 branch
BranchTrueFalseTotal
if ($strand eq '+') { } 2 0 2
544 2 $location_string = "join($start..$seqlength,1..$end)";
545 }
546 else {
547 0 $location_string = "join($start..1,$seqlength..$end)";
548 }
549 }
550 else {
551 # start must always be less than end for gene locations
552 54 ▶ if ($strand eq '-' && !$fst && !$fend && $start > $end) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strand eq "-" and not $fst and not $fend and $start > $end) 13 41 54
Condition66%6/9
$strand eq "-" and not $fst and not $fend and $start > $end
!ll&&!rl&&r
41013
$strand eq "-" and not $fst and not $fend
!ll&&!rl&&r
41013
$strand eq "-" and not $fst
!ll&&!rl&&r
41013
MC/DC25%1/4
$strand eq "-" and not $fst and not $fend and $start > $end
$strand eq "-" not $fst not $fend $start > $end
Truth table40%2/5
A and not(B) and not(C) and D
A= $strand eq "-"B= not $fstC= not $fendD= $start > $end
ABCDresult
0XXX0
10XX0
110X0
11100
11111
553 13 ($start, $end) = ($end, $start);
554 }
555 54 $location_string = "$start..$end";
556 }
557
558 56 my $location_object =
559 $location_factory->from_string($location_string);
560
561 # convert glimmer's frame range from 1-3 to SeqFeature's 0-2.
562 56 $frame--;
563
564 56 ▶ my $gene = Bio::SeqFeature::Generic->new
Branch: 1 branch
BranchTrueFalseTotal
$strand eq '-' ? : 13 43 56
Condition100%2/2
$score || undef
l!l
3125
MC/DC100%1/1
$score || undef
$score
Truth table100%2/2
A
A= $score
Aresult
11
00
565 (
566 '-seq_id' => $seqname,
567 '-location' => $location_object,
568 '-strand' => $strand eq '-' ? '-1' : '1',
569 '-frame' => $frame,
570 '-source_tag' => $source,
571 '-display_name' => "orf$genenum",
572 '-primary_tag'=> 'gene',
573 '-tag' => { 'Group' => "GenePrediction_$genenum"},
574 '-score' => $score || undef
575 );
576
577 56 $self->_add_prediction($gene)
578 }
579 }
580
581 3 $self->_predictions_parsed(1);
582 }
583  
584 =head2 _prediction
585  
586 Title : _prediction()
587 Usage : $gene = $obj->_prediction()
588 Function: internal
589 Example :
590 Returns :
591  
592 =cut
593  
594 114 ▶sub _prediction {
Subroutine _prediction: called CC=3 SCAR=11.0
595 114 my ($self) = @_;
596  
597 114 ▶ return unless(exists($self->{'_preds'}) && @{$self->{'_preds'}});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_preds"} and @{$self->{"_preds"};} 4 110 114
Condition66%2/3
exists $self->{"_preds"} and @{$self->{"_preds"};}
!ll&&!rl&&r
04110
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
598 110 return shift(@{$self->{'_preds'}});
599 }
600  
601 =head2 _add_prediction
602  
603 Title : _add_prediction()
604 Usage : $obj->_add_prediction($gene)
605 Function: internal
606 Example :
607 Returns :
608  
609 =cut
610  
611 110 ▶sub _add_prediction {
Subroutine _add_prediction: called CC=2 SCAR=7.4
612 110 my ($self, $gene) = @_;
613  
614 110 ▶ if(! exists($self->{'_preds'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_preds"}) 0 110 110
615 0 $self->{'_preds'} = [];
616 }
617 110 push(@{$self->{'_preds'}}, $gene);
618 }
619  
620 =head2 _predictions_parsed
621  
622 Title : _predictions_parsed
623 Usage : $obj->_predictions_parsed
624 Function: internal
625 Example :
626 Returns : TRUE or FALSE
627  
628 =cut
629  
630 119 ▶sub _predictions_parsed {
Subroutine _predictions_parsed: called CC=3 SCAR=11.3
631 119 my ($self, $val) = @_;
632  
633 119 ▶ $self->{'_preds_parsed'} = $val if $val;
Branch: 1 branch
BranchTrueFalseTotal
if $val 5 114 119
634 119 ▶ if(! exists($self->{'_preds_parsed'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_preds_parsed"}) 0 119 119
635 0 $self->{'_preds_parsed'} = 0;
636 }
637 119 return $self->{'_preds_parsed'};
638 }
639  
640 =head2 _seqname
641  
642 Title : _seqname
643 Usage : $obj->_seqname($seqname)
644 Function: internal (for Glimmer 2.X)
645 Example :
646 Returns : String
647  
648 =cut
649  
650 4 ▶sub _seqname {
Subroutine _seqname: called CC=3 SCAR=11.0
651 4 my ($self, $val) = @_;
652  
653 4 ▶ $self->{'_seqname'} = $val if $val;
Branch: 1 branch
BranchTrueFalseTotal
if $val 1 3 4
654 4 ▶ if(! exists($self->{'_seqname'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_seqname"}) 2 2 4
655 2 $self->{'_seqname'} = 'unknown';
656 }
657 4 return $self->{'_seqname'};
658 }
659  
660 =head2 _seqlength
661  
662 Title : _seqlength
663 Usage : $obj->_seqlength($seqlength)
664 Function: internal (for Glimmer 2.X)
665 Example :
666 Returns : String
667  
668 =cut
669  
670 4 ▶sub _seqlength {
Subroutine _seqlength: called CC=2 SCAR=6.9
671 4 my ($self, $val) = @_;
672  
673 4 ▶ $self->{'_seqlength'} = $val if $val;
Branch: 1 branch
BranchTrueFalseTotal
if $val 1 3 4
674 4 return $self->{'_seqlength'};
675 }
676  
677 =head2 _format
678  
679 Title : _format
680 Usage : $obj->_format($format)
681 Function: internal
682 Example :
683 Returns : String
684  
685 =cut
686  
687 7 ▶sub _format {
Subroutine _format: called CC=2 SCAR=6.9
688 7 my ($self, $val) = @_;
689  
690 7 ▶ $self->{'_format'} = $val if $val;
Branch: 1 branch
BranchTrueFalseTotal
if $val 2 5 7
691  
692 7 return $self->{'_format'};
693 }
694  
695 =head2 _detail_file
696  
697 Title : _detail_file
698 Usage : $obj->_detail_file($filename)
699 Function: internal (for Glimmer 3.X)
700 Example :
701 Returns : String
702  
703 =cut
704  
705 5 ▶sub _detail_file {
Subroutine _detail_file: called CC=2 SCAR=6.9
706 5 my ($self, $val) = @_;
707  
708 5 ▶ $self->{'_detail_file'} = $val if $val;
Branch: 1 branch
BranchTrueFalseTotal
if $val 2 3 5
709 5 return $self->{'_detail_file'};
710 }
711  
712 2 1;
« Bio/SeqIO/metafasta.pm ↑ Summary Bio/Tools/Analysis/SimpleAnalysisBase.pm »