Bio/SeqIO/genbank.pm

filter: Statementstmt 85.1% 625 / 734 Branchbran 73.9% 352 / 476 Conditioncond 64.8% 72 / 111 MC/DCmcdc 33.8% 22 / 65 Subroutinesub 96.1% 25 / 26 Podpod 100% 2 / 2 totaltotal 77.6% 1098 / 1414 CC 301 SCAR 50.1
CC
301
Cov
79%
next_seq
268.4
write_seq
164.5
_read_GenBank_References
32.8
CRAP 149.6
« Bio/SeqIO/tigr.pm ↑ Summary Bio/DB/WebDBSeqI.pm »
1 #
2 # BioPerl module for Bio::SeqIO::genbank
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Bioperl project bioperl-l(at)bioperl.org
7 #
8 # Copyright Elia Stupka and contributors see AUTHORS section
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::SeqIO::genbank - GenBank sequence input/output stream
17  
18 =head1 SYNOPSIS
19  
20 It is probably best not to use this object directly, but
21 rather go through the SeqIO handler:
22  
23 $stream = Bio::SeqIO->new(-file => $filename,
24 -format => 'GenBank');
25  
26 while ( my $seq = $stream->next_seq ) {
27 # do something with $seq
28 }
29  
30  
31 =head1 DESCRIPTION
32  
33 This object can transform Bio::Seq objects to and from GenBank flat
34 file databases.
35  
36 There is some flexibility here about how to write GenBank output
37 that is not fully documented.
38  
39 =head2 Optional functions
40  
41 =over 3
42  
43 =item _show_dna()
44  
45 (output only) shows the dna or not
46  
47 =item _post_sort()
48  
49 (output only) provides a sorting func which is applied to the FTHelpers
50 before printing
51  
52 =item _id_generation_func()
53  
54 This is function which is called as
55  
56 print "ID ", $func($seq), "\n";
57  
58 To generate the ID line. If it is not there, it generates a sensible ID
59 line using a number of tools.
60  
61 If you want to output annotations in Genbank format they need to be
62 stored in a Bio::Annotation::Collection object which is accessible
63 through the Bio::SeqI interface method L<annotation()|annotation>.
64  
65 The following are the names of the keys which are pulled from a
66 L<Bio::Annotation::Collection> object:
67  
68 reference - Should contain Bio::Annotation::Reference objects
69 comment - Should contain Bio::Annotation::Comment objects
70 dblink - Should contain a Bio::Annotation::DBLink object
71 segment - Should contain a Bio::Annotation::SimpleValue object
72 origin - Should contain a Bio::Annotation::SimpleValue object
73 wgs - Should contain a Bio::Annotation::SimpleValue object
74  
75 =back
76  
77 =head1 Where does the data go?
78  
79 Data parsed in Bio::SeqIO::genbank is stored in a variety of data
80 fields in the sequence object that is returned. Here is a partial list
81 of fields.
82  
83 Items listed as RichSeq or Seq or PrimarySeq and then NAME() tell you
84 the top level object which defines a function called NAME() which
85 stores this information.
86  
87 Items listed as Annotation 'NAME' tell you the data is stored the
88 associated Bio::AnnotationCollectionI object which is associated with
89 Bio::Seq objects. If it is explicitly requested that no annotations
90 should be stored when parsing a record of course they will not be
91 available when you try and get them. If you are having this problem
92 look at the type of SeqBuilder that is being used to construct your
93 sequence object.
94  
95 Comments Annotation 'comment'
96 References Annotation 'reference'
97 Segment Annotation 'segment'
98 Origin Annotation 'origin'
99 Dbsource Annotation 'dblink'
100  
101 Accessions PrimarySeq accession_number()
102 Secondary accessions RichSeq get_secondary_accessions()
103 GI number PrimarySeq primary_id()
104 LOCUS PrimarySeq display_id()
105 Keywords RichSeq get_keywords()
106 Dates RichSeq get_dates()
107 Molecule RichSeq molecule()
108 Seq Version RichSeq seq_version()
109 PID RichSeq pid()
110 Division RichSeq division()
111 Features Seq get_SeqFeatures()
112 Alphabet PrimarySeq alphabet()
113 Definition PrimarySeq description() or desc()
114 Version PrimarySeq version()
115  
116 Sequence PrimarySeq seq()
117  
118 There is more information in the Feature-Annotation HOWTO about each
119 field and how it is mapped to the Sequence object
120 L<http://bioperl.org/howtos/Features_and_Annotations_HOWTO.html>.
121  
122 =head1 FEEDBACK
123  
124 =head2 Mailing Lists
125  
126 User feedback is an integral part of the evolution of this and other
127 Bioperl modules. Send your comments and suggestions preferably to one
128 of the Bioperl mailing lists. Your participation is much appreciated.
129  
130 bioperl-l@bioperl.org - General discussion
131 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
132  
133 =head2 Support
134  
135 Please direct usage questions or support issues to the mailing list:
136  
137 I<bioperl-l@bioperl.org>
138  
139 rather than to the module maintainer directly. Many experienced and
140 reponsive experts will be able look at the problem and quickly
141 address it. Please include a thorough description of the problem
142 with code and data examples if at all possible.
143  
144 =head2 Reporting Bugs
145  
146 Report bugs to the Bioperl bug tracking system to help us keep track
147 the bugs and their resolution. Bug reports can be submitted via the web:
148  
149 https://github.com/bioperl/bioperl-live/issues
150  
151 =head1 AUTHOR - Bioperl Project
152  
153 bioperl-l at bioperl.org
154  
155 Original author Elia Stupka, elia -at- tigem.it
156  
157 =head1 CONTRIBUTORS
158  
159 Ewan Birney birney at ebi.ac.uk
160 Jason Stajich jason at bioperl.org
161 Chris Mungall cjm at fruitfly.bdgp.berkeley.edu
162 Lincoln Stein lstein at cshl.org
163 Heikki Lehvaslaiho, heikki at ebi.ac.uk
164 Hilmar Lapp, hlapp at gmx.net
165 Donald G. Jackson, donald.jackson at bms.com
166 James Wasmuth, james.wasmuth at ed.ac.uk
167 Brian Osborne, bosborne at alum.mit.edu
168 Chris Fields, cjfields at bioperl dot org
169  
170 =head1 APPENDIX
171  
172 The rest of the documentation details each of the object
173 methods. Internal methods are usually preceded with a _
174  
175 =cut
176  
177 # Let the code begin...
178  
179 package Bio::SeqIO::genbank;
180 13 $Bio::SeqIO::genbank::VERSION = '1.7.7';
181 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
182  
183 13 ▶use Bio::SeqIO::FTHelper;
Subroutine BEGIN: called CC=1 SCAR=0.0
184 13 ▶use Bio::SeqFeature::Generic;
Subroutine BEGIN: called CC=1 SCAR=0.0
185 13 ▶use Bio::Species;
Subroutine BEGIN: called CC=1 SCAR=0.0
186 13 ▶use Bio::Seq::SeqFactory;
Subroutine BEGIN: called CC=1 SCAR=0.0
187 13 ▶use Bio::Annotation::Collection;
Subroutine BEGIN: called CC=1 SCAR=0.0
188 13 ▶use Bio::Annotation::Comment;
Subroutine BEGIN: called CC=1 SCAR=0.0
189 13 ▶use Bio::Annotation::Reference;
Subroutine BEGIN: called CC=1 SCAR=0.0
190 13 ▶use Bio::Annotation::DBLink;
Subroutine BEGIN: called CC=1 SCAR=0.0
191  
192 13 ▶use base qw(Bio::SeqIO);
Subroutine BEGIN: called CC=1 SCAR=0.0
193  
194 13 our $FTQUAL_LINE_LENGTH = 60;
195  
196 13 our %FTQUAL_NO_QUOTE = map {$_ => 1} qw(
197 anticodon citation
198 codon codon_start
199 cons_splice direction
200 evidence label
201 mod_base number
202 rpt_type rpt_unit
203 transl_except transl_table
204 usedin
205 );
206  
207 13 our %DBSOURCE = map {$_ => 1} qw(
208 EchoBASE IntAct SWISS-2DPAGE ECO2DBASE ECOGENE TIGRFAMs
209 TIGR GO InterPro Pfam PROSITE SGD GermOnline
210 HSSP PhosSite Ensembl RGD AGD ArrayExpress KEGG
211 H-InvDB HGNC LinkHub PANTHER PRINTS SMART SMR
212 MGI MIM RZPD-ProtExp ProDom MEROPS TRANSFAC Reactome
213 UniGene GlycoSuiteDB PIRSF HSC-2DPAGE PHCI-2DPAGE
214 PMMA-2DPAGE Siena-2DPAGE Rat-heart-2DPAGE Aarhus/Ghent-2DPAGE
215 Biocyc MetaCyc Biocyc:Metacyc GenomeReviews FlyBase
216 TMHOBP COMPLUYEAST-2DPAGE OGP DictyBase HAMAP
217 PhotoList Gramene WormBase WormPep Genew ZFIN
218 PeroxiBase MaizeDB TAIR DrugBank REBASE HPA
219 swissprot GenBank GenPept REFSEQ embl PDB UniProtKB
220 DIP PeptideAtlas PRIDE CYGD HOGENOME Gene3D
221 Project);
222  
223 13 our %VALID_MOLTYPE = map {$_ => 1} qw(NA DNA RNA tRNA rRNA cDNA cRNA ms-DNA
224 mRNA uRNA ss-RNA ss-DNA snRNA snoRNA PRT);
225  
226 13 our %VALID_ALPHABET = (
227 'bp' => 'dna',
228 'aa' => 'protein',
229 'rc' => '' # rc = release candidate; file has no sequences
230 );
231  
232 sub _initialize {
233 110 ▶ my($self, @args) = @_;
Subroutine _initialize: called CC=2 SCAR=7.0
234  
235 110 $self->SUPER::_initialize(@args);
236 # hash for functions for decoding keys.
237 110 $self->{'_func_ftunit_hash'} = {};
238 110 $self->_show_dna(1); # sets this to one by default. People can change it
239 110 ▶ if ( not defined $self->sequence_factory ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->sequence_factory) 110 0 110
240 110 $self->sequence_factory
241 (Bio::Seq::SeqFactory->new(-verbose => $self->verbose,
242 -type => 'Bio::Seq::RichSeq'));
243 }
244 }
245  
246 =head2 next_seq
247  
248 Title : next_seq
249 Usage : $seq = $stream->next_seq()
250 Function: returns the next sequence in the stream
251 Returns : Bio::Seq object
252 Args :
253  
254 =cut
255  
256 sub next_seq {
257 112 ▶ my ($self, @args) = @_;
Subroutine next_seq: called CC=130 SCAR=55.9
Pod documented
258 112 my %args = @args;
259 112 my $builder = $self->sequence_builder;
260 112 my $seq;
261 my %params;
262  
263 RECORDSTART:
264 112 while (1) {
265 114 my $buffer;
266 114 my ( @acc, @features );
267 114 my ( $display_id, $annotation );
268 114 my $species;
269  
270 # initialize; we may come here because of starting over
271 114 @features = ();
272 114 $annotation = undef;
273 114 @acc = ();
274 114 $species = undef;
275 114 %params = ( -verbose => $self->verbose ); # reset hash
276 114 local ($/) = "\n";
277 114 ▶ while ( defined( $buffer = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($buffer = $self->_readline)) 184 6 190
278 184 ▶ last if index( $buffer, 'LOCUS ' ) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($buffer, "LOCUS ") == 0 108 76 184
279 }
280 114 ▶ return unless defined $buffer; # end of file
Branch: 1 branch
BranchTrueFalseTotal
unless defined $buffer 6 108 114
281 108 ▶ $buffer =~ /^LOCUS\s+(\S.*)$/o
Branch: 1 branch
BranchTrueFalseTotal
$buffer =~ /^LOCUS\s+(\S.*)$/o or $self->throw('GenBank stream with bad LOCUS line. ' . "Not GenBank in my book. Got '${buffer}'") 0 108 108
282 or $self->throw( "GenBank stream with bad LOCUS line. "
283 . "Not GenBank in my book. Got '$buffer'");
284 108 my @tokens = split( ' ', $1 );
285  
286 # this is important to have the id for display in e.g. FTHelper,
287 # otherwise you won't know which entry caused an error
288 108 $display_id = shift @tokens;
289 108 $params{'-display_id'} = $display_id;
290  
291 # may still be useful if we don't want the seq
292 108 my $seqlength = shift @tokens;
293 108 ▶ if ( exists $VALID_ALPHABET{$seqlength} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Bio::SeqIO::genbank::VALID_ALPHABET{$seqlength}) { } 0 108 108
294 # moved one token too far. No locus name?
295 0 $self->warn( "Bad LOCUS name? Changing [$params{'-display_id'}] "
296 . "to 'unknown' and length to '$display_id'"
297 );
298 0 $params{'-display_id'} = 'unknown';
299 0 $params{'-length'} = $display_id;
300  
301 # add token back...
302 0 unshift @tokens, $seqlength;
303 }
304 else {
305 108 $params{'-length'} = $seqlength;
306 }
307  
308 # the alphabet of the entry
309 # shouldn't assign alphabet unless one
310 # is specifically designated (such as for rc files)
311 108 my $alphabet = lc( shift @tokens );
312 $params{'-alphabet'} =
313 ( exists $VALID_ALPHABET{$alphabet} )
314 108 ▶ ? $VALID_ALPHABET{$alphabet}
Branch: 1 branch
BranchTrueFalseTotal
exists $Bio::SeqIO::genbank::VALID_ALPHABET{$alphabet} ? : 108 0 108
315 : $self->warn("Unknown alphabet: $alphabet");
316  
317 # for aa there is usually no 'molecule' (mRNA etc)
318 108 ▶ if ( $params{'-alphabet'} eq 'protein' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{'-alphabet'} eq 'protein') { } 10 98 108
319 10 $params{'-molecule'} = 'PRT';
320 }
321 else {
322 98 $params{'-molecule'} = shift(@tokens);
323 }
324  
325 # take care of lower case issues
326 108 ▶ if ( $params{'-molecule'} eq 'dna' or $params{'-molecule'} eq 'rna' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"-molecule"} eq "dna" or $params{"-molecule"} eq "rna") 5 103 108
Condition66%2/3
$params{"-molecule"} eq "dna" or $params{"-molecule"} eq "rna"
l!l&&r!l&&!r
50103
MC/DC50%1/2
$params{"-molecule"} eq "dna" or $params{"-molecule"} eq "rna"
$params{"-molecule"} eq "dna" $params{"-molecule"} eq "rna"
Truth table66%2/3
A or B
A= $params{"-molecule"} eq "dna"B= $params{"-molecule"} eq "rna"
ABresult
1X1
011
000
327 5 $params{'-molecule'} = uc $params{'-molecule'};
328 }
329 $self->debug( "Unrecognized molecule type: " . $params{'-molecule'} )
330 108 ▶ if not exists( $VALID_MOLTYPE{ $params{'-molecule'} } );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Bio::SeqIO::genbank::VALID_MOLTYPE{$params{"-molecule"}} 0 108 108
331  
332 108 my $circ = shift @tokens;
333 108 ▶ if ( $circ eq 'circular' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($circ eq 'circular') { } 7 101 108
334 7 $params{'-is_circular'} = 1;
335 7 $params{'-division'} = shift @tokens;
336 }
337 else {
338 # 'linear' or 'circular' may actually be omitted altogether
339 101 ▶ $params{'-division'} =
Branch: 1 branch
BranchTrueFalseTotal
length $circ == 3 ? : 32 69 101
340 ( CORE::length($circ) == 3 ) ? $circ : shift @tokens;
341 }
342 108 my $date = join( ' ', @tokens ); # we lump together the rest
343  
344 # this is per request bug #1513
345 # we can handle:
346 # 9-10-2003
347 # 9-10-03
348 # 09-10-2003
349 # 09-10-03
350 108 ▶ if ( $date =~ s/\s*((\d{1,2})-(\w{3})-(\d{2,4})).*/$1/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($date =~ s/\s*((\d{1,2})-(\w{3})-(\d{2,4})).*/$1/) 101 7 108
351 101 ▶ if ( length($date) < 11 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $date < 11) { } 0 101 101
352 # improperly formatted date
353 # But we'll be nice and fix it for them
354 0 my ( $d, $m, $y ) = ( $2, $3, $4 );
355 0 ▶ if ( length($d) == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $d == 1) 0 0 0
356 0 $d = "0$d";
357 }
358  
359 # guess the century here
360 0 ▶ if ( length($y) == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $y == 2) 0 0 0
361 0 ▶ if ( $y > 60 ) { # arbitrarily guess that '60' means 1960
Branch: 1 branch
BranchTrueFalseTotal
if ($y > 60) { } 0 0 0
362 0 $y = "19$y";
363 }
364 else {
365 0 $y = "20$y";
366 }
367 0 $self->warn( "Date was malformed, guessing the "
368 . "century for $date to be $y\n"
369 );
370 }
371 0 $params{'-dates'} = [ join( '-', $d, $m, $y ) ];
372 }
373 else {
374 101 $params{'-dates'} = [$date];
375 }
376 }
377  
378 # set them all at once
379 108 $builder->add_slot_value(%params);
380 108 %params = ();
381  
382 # parse the rest if desired, otherwise start over
383 108 ▶ if ( not $builder->want_object ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($builder->want_object) 2 106 108
384 2 $builder->make_object;
385 2 next RECORDSTART;
386 }
387  
388 # set up annotation depending on what the builder wants
389 106 ▶ if ( $builder->want_slot('annotation') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($builder->want_slot("annotation")) 101 5 106
390 101 $annotation = Bio::Annotation::Collection->new;
391 }
392  
393 106 $buffer = $self->_readline;
394 106 ▶ while ( defined( my $line = $buffer ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = $buffer)) 702 0 702
395 # Description line(s)
396 702 ▶ if ($line =~ /^DEFINITION\s+(\S.*\S)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^DEFINITION\s+(\S.*\S)/) 104 598 702
397 104 my @desc = ($1);
398 104 ▶ while ( defined( $line = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->_readline)) 162 0 162
399 162 ▶ if ($line =~ /^\s+(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s+(.*)/) 58 104 162
400 58 push( @desc, $1 );
401 58 next;
402 }
403 104 last;
404 }
405 104 $builder->add_slot_value( -desc => join( ' ', @desc ) );
406  
407 # we'll continue right here because DEFINITION
408 # always comes at the top of the entry
409 104 $buffer = $line;
410 }
411  
412 # accession number (there can be multiple accessions)
413 702 ▶ if ($line =~ /^ACCESSION\s+(\S.*\S)/) {
Branch: 9 branches
BranchTrueFalseTotal
if ($line =~ /^ACCESSION\s+(\S.*\S)/) { } 105 597 702
elsif ($line =~ /^PID\s+(\S+)/) { } 1 596 597
elsif ($line =~ /^VERSION\s+(\S.+)$/) { } 86 510 596
elsif ($line =~ /^KEYWORDS\s+(\S.*)/) { } 101 409 510
elsif ($line =~ /^SOURCE\s+\S/) { } 100 309 409
elsif ($line =~ /^REFERENCE\s+\S/) { } 103 206 309
elsif ($line =~ /^PROJECT\s+(\S.*)/) { } 2 204 206
elsif ($line =~ /^COMMENT\s+(\S.*)/) { } 57 147 204
elsif ($line =~ /^DB(?:SOURCE|LINK)\s+(\S.+)/) { } 20 127 147
414 105 push( @acc, split( /\s+/, $1 ) );
415 105 ▶ while ( defined( $line = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->_readline)) 107 0 107
416 107 ▶ if ($line =~ /^\s+(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s+(.*)/) 2 105 107
417 2 push( @acc, split( /\s+/, $1 ) );
418 2 next;
419 }
420 105 last;
421 }
422 105 $buffer = $line;
423 105 next;
424 }
425  
426 # PID
427 elsif ($line =~ /^PID\s+(\S+)/) {
428 1 $params{'-pid'} = $1;
429 }
430  
431 # Version number
432 elsif ($line =~ /^VERSION\s+(\S.+)$/) {
433 86 my ( $acc, $gi ) = split( ' ', $1 );
434 86 ▶ if ( $acc =~ /^\w+\.(\d+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($acc =~ /^\w+\.(\d+)/) 82 4 86
435 82 $params{'-version'} = $1;
436 82 $params{'-seq_version'} = $1;
437 }
438 86 ▶ if ( $gi && ( index( $gi, "GI:" ) == 0 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gi and index($gi, "GI:") == 0) 85 1 86
Condition66%2/3
$gi and index($gi, "GI:") == 0
!ll&&!rl&&r
1085
MC/DC50%1/2
$gi and index($gi, "GI:") == 0
$gi index($gi, "GI:") == 0
Truth table66%2/3
A and B
A= $giB= index($gi, "GI:") == 0
ABresult
0X0
100
111
439 85 $params{'-primary_id'} = substr( $gi, 3 );
440 }
441 }
442  
443 # Keywords
444 elsif ($line =~ /^KEYWORDS\s+(\S.*)/) {
445 101 my @kw = split( /\s*\;\s*/, $1 );
446 101 ▶ while ( defined( $line = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->_readline)) 132 0 132
447 132 chomp $line;
448 132 ▶ if ($line =~ /^\s+(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s+(.*)/) 31 101 132
449 31 push( @kw, split( /\s*\;\s*/, $1 ) );
450 31 next;
451 }
452 101 last;
453 }
454  
455 101 ▶ @kw && $kw[-1] =~ s/\.$//;
Branch: 1 branch
BranchTrueFalseTotal
@kw and $kw[-1] =~ s/\.$// 101 0 101
456 101 $params{'-keywords'} = \@kw;
457 101 $buffer = $line;
458 101 next;
459 }
460  
461 # Organism name and phylogenetic information
462 elsif ($line =~ /^SOURCE\s+\S/) {
463 100 ▶ if ( $builder->want_slot('species') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($builder->want_slot('species')) { } 95 5 100
464 95 $species = $self->_read_GenBank_Species( \$buffer );
465 95 $builder->add_slot_value( -species => $species );
466 }
467 else {
468 5 ▶ while ( defined( $buffer = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($buffer = $self->_readline)) 18 0 18
469 18 ▶ last if substr( $buffer, 0, 1 ) ne ' ';
Branch: 1 branch
BranchTrueFalseTotal
if substr($buffer, 0, 1) ne " " 5 13 18
470 }
471 }
472 100 next;
473 }
474  
475 # References
476 elsif ($line =~ /^REFERENCE\s+\S/) {
477 103 ▶ if ($annotation) {
Branch: 1 branch
BranchTrueFalseTotal
if ($annotation) { } 94 9 103
478 94 my @refs = $self->_read_GenBank_References( \$buffer );
479 94 foreach my $ref (@refs) {
480 378 $annotation->add_Annotation( 'reference', $ref );
481 }
482 }
483 else {
484 9 ▶ while ( defined( $buffer = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($buffer = $self->_readline)) 47 0 47
485 47 ▶ last if substr( $buffer, 0, 1 ) ne ' ';
Branch: 1 branch
BranchTrueFalseTotal
if substr($buffer, 0, 1) ne " " 9 38 47
486 }
487 }
488 103 next;
489 }
490  
491 # Project
492 elsif ($line =~ /^PROJECT\s+(\S.*)/) {
493 2 ▶ if ($annotation) {
Branch: 1 branch
BranchTrueFalseTotal
if ($annotation) 2 0 2
494 2 my $project =
495 Bio::Annotation::SimpleValue->new( -value => $1 );
496 2 $annotation->add_Annotation( 'project', $project );
497 }
498 }
499  
500 # Comments may be plain text or Structured Comments.
501 # Structured Comments are made up of tag/value pairs and have beginning
502 # and end delimiters like ##*-Data-START## and ##*-Data-END##
503 elsif ($line =~ /^COMMENT\s+(\S.*)/) {
504 57 ▶ if ($annotation) {
Branch: 1 branch
BranchTrueFalseTotal
if ($annotation) { } 55 2 57
505 55 my $comment = $1;
506 55 ▶ while ( defined( $line = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->_readline)) 457 0 457
507 457 ▶ last if ($line =~ /^\S/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\S/ 55 402 457
508 402 $comment .= $line;
509 }
510 55 $comment =~ s/ +/ /g;
511 # Structured Comment, do not remove returns in the tabular section
512 55 ▶ if ( my ( $text, $table )= $comment
Branch: 1 branch
BranchTrueFalseTotal
if (() = $comment =~ /([^#]*)(##\S+Data-START##.+?##\S+Data-END##)/is) { } 2 53 55
513 =~ /([^#]*)(##\S+Data-START##.+?##\S+Data-END##)/is
514 ) {
515 2 ▶ $text =~ s/\n/ /g if $text;
Branch: 1 branch
BranchTrueFalseTotal
if $text 1 1 2
516 2 $table =~ s/START##/START##\n/;
517 2 $table =~ s/^\s+//gm;
518 2 $comment = $text . "\n" . $table;
519 }
520 # Plain text, remove returns
521 else {
522 53 $comment =~ s/\n/ /g;
523 }
524 55 $annotation->add_Annotation(
525 'comment',
526 Bio::Annotation::Comment->new(
527 -text => $comment,
528 -tagname => 'comment'
529 )
530 );
531 55 $buffer = $line;
532 }
533 else {
534 2 ▶ while ( defined( $buffer = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($buffer = $self->_readline)) 7 0 7
535 7 ▶ last if substr( $buffer, 0, 1 ) ne ' ';
Branch: 1 branch
BranchTrueFalseTotal
if substr($buffer, 0, 1) ne " " 2 5 7
536 }
537 }
538 57 next;
539 }
540  
541 # Corresponding Genbank nucleotide id, Genpept only
542 elsif ($line =~ /^DB(?:SOURCE|LINK)\s+(\S.+)/) {
543 20 ▶ if ($annotation) {
Branch: 1 branch
BranchTrueFalseTotal
if ($annotation) { } 20 0 20
544 20 my $dbsource = $1;
545 20 ▶ while ( defined( $line = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->_readline)) 85 0 85
546 85 ▶ last if ($line =~ /^\S/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\S/ 20 65 85
547 65 $dbsource .= $line;
548 }
549  
550 # deal with UniProKB dbsources
551 20 ▶ if ( $dbsource =~
Branch: 1 branch
BranchTrueFalseTotal
if ($dbsource =~ s/(UniProt(?:KB)?|swissprot):\s+locus\s+(\S+)\,.+\n//) { } 5 15 20
552 s/(UniProt(?:KB)?|swissprot):\s+locus\s+(\S+)\,.+\n//
553 ) {
554 5 $annotation->add_Annotation(
555 'dblink',
556 Bio::Annotation::DBLink->new(
557 -primary_id => $2,
558 -database => $1,
559 -tagname => 'dblink'
560 )
561 );
562 5 ▶ if ( $dbsource =~ s/\s+created:\s+([^\.]+)\.\n// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbsource =~ s/\s+created:\s+([^\.]+)\.\n//) 5 0 5
563 5 $annotation->add_Annotation(
564 'swissprot_dates',
565 Bio::Annotation::SimpleValue->new(
566 -tagname => 'date_created',
567 -value => $1
568 )
569 );
570 }
571 5 ▶ while ( $dbsource =~
Branch: 1 branch
BranchTrueFalseTotal
if ($dbsource =~ s/\s+(sequence|annotation)\s+updated:\s+([^\.]+)\.\n//g) 5 5 10
572 s/\s+(sequence|annotation)\s+updated:\s+([^\.]+)\.\n//g
573 ) {
574 5 $annotation->add_Annotation(
575 'swissprot_dates',
576 Bio::Annotation::SimpleValue->new(
577 -tagname => 'date_updated',
578 -value => $2
579 )
580 );
581 }
582 5 $dbsource =~ s/\n/ /g;
583 5 ▶ if ( $dbsource =~
Branch: 2 branches
BranchTrueFalseTotal
if ($dbsource =~ s/\s+xrefs:\s+((?:\S+,\s+)+\S+)\s+xrefs/xrefs/) { } 5 0 5
elsif ($dbsource =~ s/\s+xrefs:\s+(.+)\s+xrefs/xrefs/i) { } 0 0 0
584 s/\s+xrefs:\s+((?:\S+,\s+)+\S+)\s+xrefs/xrefs/
585 ) {
586 # will use $i to determine even or odd
587 # for swissprot the accessions are paired
588 5 my $i = 0;
589 5 for my $dbsrc ( split( /,\s+/, $1 ) ) {
590 49 ▶ if ( $dbsrc =~ /(\S+)\.(\d+)/
Branch: 1 branch
BranchTrueFalseTotal
if ($dbsrc =~ /(\S+)\.(\d+)/ or $dbsrc =~ /(\S+)/) 49 0 49
Condition66%2/3
$dbsrc =~ /(\S+)\.(\d+)/ or $dbsrc =~ /(\S+)/
l!l&&r!l&&!r
38110
MC/DC0%0/2
$dbsrc =~ /(\S+)\.(\d+)/ or $dbsrc =~ /(\S+)/
$dbsrc =~ /(\S+)\.(\d+)/ $dbsrc =~ /(\S+)/
Truth table66%2/3
A or B
A= $dbsrc =~ /(\S+)\.(\d+)/B= $dbsrc =~ /(\S+)/
ABresult
1X1
011
000
591 or $dbsrc =~ /(\S+)/
592 ) {
593 49 my ( $id, $version ) = ( $1, $2 );
594 49 ▶ $version = '' unless defined $version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 11 38 49
595 49 ▶ my $db = ( $id =~ /^\d\S{3}/ ) ? 'PDB'
Branch: 2 branches
BranchTrueFalseTotal
$id =~ /^\d\S{3}/ ? : 6 43 49
$i++ % 2 ? : 20 23 43
596 : ( $i++ % 2 ) ? 'GenPept'
597 : 'GenBank';
598  
599 49 $annotation->add_Annotation(
600 'dblink',
601 Bio::Annotation::DBLink->new(
602 -primary_id => $id,
603 -version => $version,
604 -database => $db,
605 -tagname => 'dblink'
606 )
607 );
608 }
609 }
610 }
611 elsif ( $dbsource =~ s/\s+xrefs:\s+(.+)\s+xrefs/xrefs/i ) {
612 # download screwed up and ncbi didn't put acc in for gi numbers
613 0 my $i = 0;
614 0 for my $id ( split( /\,\s+/, $1 ) ) {
615 0 my ( $acc, $db );
616 0 ▶ if ( $id =~ /gi:\s+(\d+)/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($id =~ /gi:\s+(\d+)/) { } 0 0 0
elsif ($id =~ /pdb\s+accession\s+(\S+)/) { } 0 0 0
617 0 $acc = $1;
618 0 ▶ $db = ( $i++ % 2 ) ? 'GenPept' : 'GenBank';
Branch: 1 branch
BranchTrueFalseTotal
$i++ % 2 ? : 0 0 0
619 }
620 elsif ( $id =~ /pdb\s+accession\s+(\S+)/ ) {
621 0 $acc = $1;
622 0 $db = 'PDB';
623 }
624 else {
625 0 $acc = $id;
626 0 $db = '';
627 }
628 0 $annotation->add_Annotation(
629 'dblink',
630 Bio::Annotation::DBLink->new(
631 -primary_id => $acc,
632 -database => $db,
633 -tagname => 'dblink'
634 )
635 );
636 }
637 }
638 else {
639 0 $self->debug("Cannot match $dbsource\n");
640 }
641 5 ▶ if ( $dbsource =~ s/xrefs\s+
Branch: 1 branch
BranchTrueFalseTotal
if ($dbsource =~ s/xrefs\s+ \(non\-sequence\s+databases\):\s+ ((?:\S+,\s+)+\S+)//x) 5 0 5
642 \(non\-sequence\s+databases\):\s+
643 ((?:\S+,\s+)+\S+)//x
644 ) {
645 5 for my $id ( split( /\,\s+/, $1 ) ) {
646 86 my $db;
647  
648 # this is because GenBank dropped the spaces!!!
649 # I'm sure we're not going to get this right
650 ##if ( $id =~ s/^://i ) {
651 ## $db = $1;
652 ##}
653 86 $db = substr( $id, 0, index( $id, ':' ) );
654 86 ▶ if ( not exists $DBSOURCE{$db} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Bio::SeqIO::genbank::DBSOURCE{$db}) 16 70 86
655 16 $db = ''; # do we want 'GenBank' here?
656 }
657 86 $id = substr( $id, index( $id, ':' ) + 1 );
658 86 $annotation->add_Annotation(
659 'dblink',
660 Bio::Annotation::DBLink->new(
661 -primary_id => $id,
662 -database => $db,
663 -tagname => 'dblink'
664 )
665 );
666 }
667 }
668 }
669 else {
670 15 ▶ if ( $dbsource =~
Branch: 3 branches
BranchTrueFalseTotal
if ($dbsource =~ /^(\S*?):?\s*accession\s+(\S+)\.(\d+)/) { } 4 11 15
elsif ($dbsource =~ /^(\S*?):?\s*accession\s+(\S+)/) { } 1 10 11
elsif ($dbsource =~ /(\S+)([\.:])\s*(\S+)/) { } 10 0 10
671 /^(\S*?):?\s*accession\s+(\S+)\.(\d+)/
672 ) {
673 4 my ( $db, $id, $version ) = ( $1, $2, $3 );
674 4 ▶ $annotation->add_Annotation(
Condition100%2/2
$db || 'GenBank'
l!l
31
MC/DC100%1/1
$db || 'GenBank'
$db
Truth table100%2/2
A
A= $db
Aresult
11
00
675 'dblink',
676 Bio::Annotation::DBLink->new(
677 -primary_id => $id,
678 -version => $version,
679 -database => $db || 'GenBank',
680 -tagname => 'dblink'
681 )
682 );
683 }
684 elsif ( $dbsource =~ /^(\S*?):?\s*accession\s+(\S+)/ ) {
685 1 my ( $db, $id ) = ( $1, $2 );
686 1 ▶ $annotation->add_Annotation(
Condition50%1/2
$db || 'GenBank'
l!l
10
MC/DC0%0/1
$db || 'GenBank'
$db
Truth table50%1/2
A
A= $db
Aresult
11
00
687 'dblink',
688 Bio::Annotation::DBLink->new(
689 -primary_id => $id,
690 -database => $db || 'GenBank',
691 -tagname => 'dblink'
692 )
693 );
694 }
695 elsif ( $dbsource =~ /(\S+)([\.:])\s*(\S+)/ ) {
696 10 my ( $db, $version );
697 10 my @ids = ();
698 10 ▶ if ( $2 eq ':' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 eq ':') { } 9 1 10
699 9 $db = $1;
700  
701 # Genbank 192 release notes say this: "The second
702 # field can consist of multiple comma-separated
703 # identifiers, if a sequence record has multiple
704 # DBLINK cross-references of a given type."
705 # For example: DBLINK Project:100,200,300"
706 9 @ids = split( /,/, $3 );
707 }
708 else {
709 1 ( $db, $version ) = ( 'GenBank', $3 );
710 1 $ids[0] = $1;
711 }
712  
713 10 foreach my $id (@ids) {
714 12 $annotation->add_Annotation(
715 'dblink',
716 Bio::Annotation::DBLink->new(
717 -primary_id => $id,
718 -version => $version,
719 -database => $db,
720 -tagname => 'dblink'
721 )
722 );
723 }
724 }
725 else {
726 0 $self->warn(
727 "Unrecognized DBSOURCE data: $dbsource\n");
728 }
729 }
730 20 $buffer = $line;
731 }
732 else {
733 0 ▶ while ( defined( $buffer = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($buffer = $self->_readline)) 0 0 0
734 0 ▶ last if substr( $buffer, 0, 1 ) ne ' ';
Branch: 1 branch
BranchTrueFalseTotal
if substr($buffer, 0, 1) ne " " 0 0 0
735 }
736 }
737 20 next;
738 }
739  
740 # Exit at start of Feature table, or start of sequence
741 216 ▶ if ($line =~ /^(FEATURES|ORIGIN)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^(FEATURES|ORIGIN)/) 106 110 216
742 106 my $trap;
743 }
744 216 ▶ last if ($line =~ /^(FEATURES|ORIGIN)/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^(FEATURES|ORIGIN)/ 106 110 216
745  
746 # Get next line and loop again
747 110 $buffer = $self->_readline;
748 }
749 106 ▶ return unless defined $buffer;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $buffer 0 106 106
750  
751 # add them all at once for efficiency
752 106 $builder->add_slot_value(
753 -accession_number => shift(@acc),
754 -secondary_accessions => \@acc,
755 %params
756 );
757 106 ▶ $builder->add_slot_value( -annotation => $annotation ) if $annotation;
Branch: 1 branch
BranchTrueFalseTotal
if $annotation 101 5 106
758 106 %params = (); # reset before possible re-use to avoid setting twice
759  
760 # start over if we don't want to continue with this entry
761 106 ▶ if ( not $builder->want_object ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($builder->want_object) 0 106 106
762 0 $builder->make_object;
763 0 next RECORDSTART;
764 }
765  
766 # some "minimal" formats may not necessarily have a feature table
767 106 ▶ if ( $builder->want_slot('features')
Branch: 1 branch
BranchTrueFalseTotal
if ($builder->want_slot("features") and defined $buffer and $buffer =~ /^FEATURES/o) 99 7 106
Condition83%5/6
$builder->want_slot("features") and defined $buffer and $buffer =~ /^FEATURES/o
!ll&&!rl&&r
6199
$builder->want_slot("features") and defined $buffer
!ll&&!rl&&r
60100
MC/DC66%2/3
$builder->want_slot("features") and defined $buffer and $buffer =~ /^FEATURES/o
$builder->want_slot("features") defined $buffer $buffer =~ /^FEATURES/o
Truth table75%3/4
A and B and C
A= $builder->want_slot("features")B= defined $bufferC= $buffer =~ /^FEATURES/o
ABCresult
0XX0
10X0
1100
1111
768 and defined $buffer
769 and $buffer =~ /^FEATURES/o
770 ) {
771 # need to read the first line of the feature table
772 99 $buffer = $self->_readline;
773  
774 # DO NOT read lines in the while condition -- this is done
775 # as a side effect in _read_FTHelper_GenBank!
776  
777 # part of new circular spec:
778 # commented out for now until kinks worked out
779 #my $sourceEnd = 0;
780 #$sourceEnd = $2 if ($buffer =~ /(\d+?)\.\.(\d+?)$/);
781  
782 99 ▶ while ( defined $buffer ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $buffer) 8280 0 8280
783 # check immediately -- not at the end of the loop
784 # note: GenPept entries obviously do not have a BASE line
785 8280 ▶ last if ( $buffer =~ /^BASE|ORIGIN|CONTIG|WGS/o );
Branch: 1 branch
BranchTrueFalseTotal
if $buffer =~ /^BASE|ORIGIN|CONTIG|WGS/o 99 8181 8280
786  
787 # slurp in one feature at a time -- at return, the start of
788 # the next feature will have been read already, so we need
789 # to pass a reference, and the called method must set this
790 # to the last line read before returning
791 8181 my $ftunit = $self->_read_FTHelper_GenBank( \$buffer );
792  
793 # implement new circular spec: features that cross the origin are now
794 # seamless instead of being 2 separate joined features
795 # commented out until kinks get worked out
796 #if ((! $args{'-nojoin'}) && $ftunit->{'loc'} =~ /^join\((\d+?)\.\.(\d+?),(\d+?)..(\d+?)\)$/
797 #&& $sourceEnd == $2 && $3 == 1) {
798 #my $start = $1;
799 #my $end = $2 + $4;
800 #$ftunit->{'loc'} = "$start..$end";
801 #}
802  
803 # fix suggested by James Diggans
804  
805 8181 ▶ if ( not defined $ftunit ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ftunit) 0 8181 8181
806 # GRRRR. We have fallen over. Try to recover
807 $self->warn( "Unexpected error in feature table for "
808 0 . $params{'-display_id'}
809 . " Skipping feature, attempting to recover" );
810  
811 0 ▶ unless ( $buffer =~ /^\s{5,5}\S+/o
Branch: 1 branch
BranchTrueFalseTotal
unless ($buffer =~ /^\s{5,5}\S+/o or $buffer =~ /^\S+/o) 0 0 0
Condition0%0/3
$buffer =~ /^\s{5,5}\S+/o or $buffer =~ /^\S+/o
l!l&&r!l&&!r
000
MC/DC0%0/2
$buffer =~ /^\s{5,5}\S+/o or $buffer =~ /^\S+/o
$buffer =~ /^\s{5,5}\S+/o $buffer =~ /^\S+/o
Truth table0%0/3
A or B
A= $buffer =~ /^\s{5,5}\S+/oB= $buffer =~ /^\S+/o
ABresult
1X1
011
000
812 or $buffer =~ /^\S+/o
813 ) {
814 0 $buffer = $self->_readline;
815 }
816 0 next; # back to reading FTHelpers
817 }
818  
819 # process ftunit
820 8181 my $feat =
821 $ftunit->_generic_seqfeature( $self->location_factory,
822 $display_id );
823  
824 # add taxon_id from source if available
825 8181 ▶ if ( $species
Branch: 1 branch
BranchTrueFalseTotal
if ($species and $feat->primary_tag eq "source" and $feat->has_tag("db_xref") and !$species->ncbi_taxid || $species->ncbi_taxid && $species->ncbi_taxid =~ /^list/) 89 8092 8181
Condition73%11/15
$species and $feat->primary_tag eq "source" and $feat->has_tag("db_xref") and !$species->ncbi_taxid || $species->ncbi_taxid && $species->ncbi_taxid =~ /^list/
!ll&&!rl&&r
8086950
$species and $feat->primary_tag eq "source" and $feat->has_tag("db_xref")
!ll&&!rl&&r
8084295
$species and $feat->primary_tag eq "source"
!ll&&!rl&&r
37804797
not $species->ncbi_taxid or $species->ncbi_taxid and $species->ncbi_taxid =~ /^list/
l!l&&r!l&&!r
8906
$species->ncbi_taxid and $species->ncbi_taxid =~ /^list/
!ll&&!rl&&r
060
MC/DC0%0/6
$species and $feat->primary_tag eq "source" and $feat->has_tag("db_xref") and !$species->ncbi_taxid || $species->ncbi_taxid && $species->ncbi_taxid =~ /^list/
$species $feat->primary_tag eq "source" $feat->has_tag("db_xref") not $species->ncbi_taxid $species->ncbi_taxid $species->ncbi_taxid =~ /^list/
Truth table57%4/7
A and B and C and not(D) or E and F
A= $speciesB= $feat->primary_tag eq "source"C= $feat->has_tag("db_xref")D= not $species->ncbi_taxidE= $species->ncbi_taxidF= $species->ncbi_taxid =~ /^list/
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
11100X0
1110100
1111XX1
1110111
826 and $feat->primary_tag eq 'source'
827 and $feat->has_tag('db_xref')
828 and ( not $species->ncbi_taxid
829 or ( $species->ncbi_taxid
830 and $species->ncbi_taxid =~ /^list/ ) )
831 ) {
832 89 foreach my $tagval ( $feat->get_tag_values('db_xref') ) {
833 90 ▶ if ( index( $tagval, "taxon:" ) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($tagval, "taxon:") == 0) 89 1 90
834 89 $species->ncbi_taxid( substr( $tagval, 6 ) );
835 89 last;
836 }
837 }
838 }
839  
840 # add feature to list of features
841 8181 push( @features, $feat );
842 }
843 99 $builder->add_slot_value( -features => \@features );
844 }
845  
846 106 ▶ if ( defined $buffer ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $buffer) 106 0 106
847 # CONTIG lines: TODO, this needs to be cleaned up
848 106 ▶ if ($buffer =~/^CONTIG\s+(.*)/o) {
Branch: 3 branches
BranchTrueFalseTotal
if ($buffer =~ /^CONTIG\s+(.*)/o) { } 7 99 106
elsif ($buffer =~ /^WGS|WGS_SCAFLD\s+/o) { } 1 98 99
elsif (not $buffer =~ m[^ORIGIN|//]o) { } 48 50 98
849 7 my $ctg = $1;
850 7 ▶ while ( defined( $buffer = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($buffer = $self->_readline)) 29 0 29
851 29 ▶ last if $buffer =~ m{^ORIGIN|//}o;
Branch: 1 branch
BranchTrueFalseTotal
if $buffer =~ m[^ORIGIN|//]o 7 22 29
852 22 $buffer =~ s/\s+(.*)/$1/;
853 22 $ctg .= $buffer;
854 }
855 7 ▶ if ($ctg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctg) 7 0 7
856 7 $annotation->add_Annotation(
857 Bio::Annotation::SimpleValue->new(
858 -tagname => 'contig',
859 -value => $ctg
860 )
861 );
862 }
863 }
864 elsif ($buffer =~ /^WGS|WGS_SCAFLD\s+/o) { # catch WGS/WGS_SCAFLD lines
865 1 ▶ while ( $buffer =~ s/(^WGS|WGS_SCAFLD)\s+// ) { # gulp lines
Branch: 1 branch
BranchTrueFalseTotal
if ($buffer =~ s/(^WGS|WGS_SCAFLD)\s+//) 3 1 4
866 3 chomp $buffer;
867 3 $annotation->add_Annotation(
868 Bio::Annotation::SimpleValue->new(
869 -value => $buffer,
870 -tagname => lc $1
871 )
872 );
873 3 $buffer = $self->_readline;
874 }
875 }
876 elsif ( $buffer !~ m{^ORIGIN|//}o ) { # advance to the sequence, if any
877 48 ▶ while ( defined( $buffer = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($buffer = $self->_readline)) 143 1 144
878 143 ▶ last if $buffer =~ m{^(ORIGIN|//)};
Branch: 1 branch
BranchTrueFalseTotal
if $buffer =~ m[^(ORIGIN|//)] 47 96 143
879 }
880 }
881 }
882 106 ▶ if ( not $builder->want_object ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($builder->want_object) 0 106 106
883 0 $builder->make_object; # implicit end-of-object
884 0 next RECORDSTART;
885 }
886 106 ▶ if ( $builder->want_slot('seq') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($builder->want_slot('seq')) { } 96 10 106
elsif (defined $buffer and substr($buffer, 0, 2) ne '//') { } 10 0 10
887 # the fact that we want a sequence does not necessarily mean that
888 # there also is a sequence ...
889 96 ▶ if ( defined $buffer and $buffer =~ s/^ORIGIN\s+// ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $buffer and $buffer =~ s/^ORIGIN\s+//) 88 8 96
Condition100%3/3
defined $buffer and $buffer =~ s/^ORIGIN\s+//
!ll&&!rl&&r
1788
MC/DC100%2/2
defined $buffer and $buffer =~ s/^ORIGIN\s+//
defined $buffer $buffer =~ s/^ORIGIN\s+//
Truth table100%3/3
A and B
A= defined $bufferB= $buffer =~ s/^ORIGIN\s+//
ABresult
0X0
100
111
890 88 ▶ if ( $annotation and length($buffer) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($annotation and length $buffer > 0) 1 87 88
Condition66%2/3
$annotation and length $buffer > 0
!ll&&!rl&&r
0871
MC/DC50%1/2
$annotation and length $buffer > 0
$annotation length $buffer > 0
Truth table66%2/3
A and B
A= $annotationB= length $buffer > 0
ABresult
0X0
100
111
891 1 $annotation->add_Annotation(
892 'origin',
893 Bio::Annotation::SimpleValue->new(
894 -tagname => 'origin',
895 -value => $buffer
896 )
897 );
898 }
899 88 my $seqc = '';
900 88 ▶ while ( defined( $buffer = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($buffer = $self->_readline)) 48131 1 48132
901 48131 ▶ last if $buffer =~ m{^//};
Branch: 1 branch
BranchTrueFalseTotal
if $buffer =~ m[^//] 87 48044 48131
902 48044 $buffer = uc $buffer;
903 48044 $buffer =~ s/[^A-Za-z]//g;
904 48044 $seqc .= $buffer;
905 }
906  
907 88 $builder->add_slot_value( -seq => $seqc );
908 }
909 }
910 ▶ elsif ( defined($buffer) and ( substr( $buffer, 0, 2 ) ne '//' ) ) {
Condition33%1/3
defined $buffer and substr($buffer, 0, 2) ne "//"
!ll&&!rl&&r
0010
MC/DC0%0/2
defined $buffer and substr($buffer, 0, 2) ne "//"
defined $buffer substr($buffer, 0, 2) ne "//"
Truth table33%1/3
A and B
A= defined $bufferB= substr($buffer, 0, 2) ne "//"
ABresult
0X0
100
111
911 # advance to the end of the record
912 10 ▶ while ( defined( $buffer = $self->_readline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($buffer = $self->_readline)) 172 0 172
913 172 ▶ last if substr( $buffer, 0, 2 ) eq '//';
Branch: 1 branch
BranchTrueFalseTotal
if substr($buffer, 0, 2) eq "//" 10 162 172
914 }
915 }
916  
917 # Unlikely, but maybe the sequence is so weird that we don't want it
918 # anymore. We don't want to return undef if the stream's not exhausted
919 # yet.
920 106 $seq = $builder->make_object;
921 106 ▶ next RECORDSTART unless $seq;
Branch: 1 branch
BranchTrueFalseTotal
unless $seq 0 106 106
922 106 last RECORDSTART;
923 } # end while RECORDSTART
924  
925 106 return $seq;
926 }
927  
928 =head2 write_seq
929  
930 Title : write_seq
931 Usage : $stream->write_seq($seq)
932 Function: writes the $seq object (must be seq) to the stream
933 Returns : 1 for success and 0 for error
934 Args : array of 1 to n Bio::SeqI objects
935  
936 =cut
937  
938 sub write_seq {
939 25 ▶ my ($self,@seqs) = @_;
Subroutine write_seq: called CC=69 SCAR=51.0
Pod documented
940  
941 25 foreach my $seq ( @seqs ) {
942 25 ▶ $self->throw("Attempting to write with no seq!") unless defined $seq;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seq 0 25 25
943  
944 25 ▶ if ( not ref $seq or not $seq->isa('Bio::SeqI') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $seq and $seq->isa("Bio::SeqI")) 0 25 25
Condition33%1/3
ref $seq and $seq->isa("Bio::SeqI")
!ll&&!rl&&r
0025
MC/DC0%0/2
ref $seq and $seq->isa("Bio::SeqI")
ref $seq $seq->isa("Bio::SeqI")
Truth table33%1/3
A and B
A= ref $seqB= $seq->isa("Bio::SeqI")
ABresult
0X0
100
111
945 0 $self->warn(" $seq is not a SeqI compliant module. Attempting to dump, but may fail!");
946 }
947  
948 25 my $str = $seq->seq;
949 25 my $len = $seq->length;
950 25 my $alpha = $seq->alphabet;
951  
952 25 my ($div, $mol);
953 25 ▶ if ( not $seq->can('division')
Branch: 1 branch
BranchTrueFalseTotal
unless ($seq->can("division") and defined($div = $seq->division)) 3 22 25
Condition66%2/3
$seq->can("division") and defined($div = $seq->division)
!ll&&!rl&&r
3022
MC/DC50%1/2
$seq->can("division") and defined($div = $seq->division)
$seq->can("division") defined($div = $seq->division)
Truth table66%2/3
A and B
A= $seq->can("division")B= defined($div = $seq->division)
ABresult
0X0
100
111
954 or not defined($div = $seq->division)
955 ) {
956 3 $div = 'UNK';
957 }
958 25 ▶ if ( not $seq->can('molecule')
Branch: 1 branch
BranchTrueFalseTotal
unless ($seq->can("molecule") and defined($mol = $seq->molecule)) 3 22 25
Condition66%2/3
$seq->can("molecule") and defined($mol = $seq->molecule)
!ll&&!rl&&r
3022
MC/DC50%1/2
$seq->can("molecule") and defined($mol = $seq->molecule)
$seq->can("molecule") defined($mol = $seq->molecule)
Truth table66%2/3
A and B
A= $seq->can("molecule")B= defined($mol = $seq->molecule)
ABresult
0X0
100
111
959 or not defined ($mol = $seq->molecule)
960 ) {
961 3 ▶ $mol = $alpha || 'DNA';
Condition100%2/2
$alpha || 'DNA'
l!l
21
MC/DC100%1/1
$alpha || 'DNA'
$alpha
Truth table100%2/2
A
A= $alpha
Aresult
11
00
962 }
963  
964 25 ▶ my $circular = ($seq->is_circular) ? 'circular' : 'linear ';
Branch: 1 branch
BranchTrueFalseTotal
$seq->is_circular ? : 2 23 25
965  
966 25 local($^W) = 0; # suppressing warnings about uninitialized fields.
967  
968 25 my $temp_line;
969 25 ▶ if ( $self->_id_generation_func ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_id_generation_func) { } 0 25 25
970 0 $temp_line = &{$self->_id_generation_func}($seq);
971 }
972 else {
973 25 my $date = '';
974 25 ▶ if ( $seq->can('get_dates') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq->can("get_dates")) 22 3 25
975 22 ($date) = $seq->get_dates;
976 }
977  
978 25 ▶ $self->warn("No whitespace allowed in GenBank display id [". $seq->display_id. "]")
Branch: 1 branch
BranchTrueFalseTotal
if $seq->display_id =~ /\s/ 0 25 25
979 if $seq->display_id =~ /\s/;
980  
981 25 ▶ my @data = ( lc($alpha) eq 'protein' ) ? ('aa', '', '') : ('bp', '', $mol);
Branch: 1 branch
BranchTrueFalseTotal
lc $alpha eq 'protein' ? : 1 24 25
982 25 $temp_line = sprintf ("%-12s%-15s%13s %s%4s%-8s%-8s %3s %-s\n",
983 'LOCUS', $seq->id, $len,
984 @data, $circular, $div, $date);
985 }
986  
987 25 $self->_print($temp_line);
988 25 $self->_write_line_GenBank_regex("DEFINITION ", " ",
989 $seq->desc, "\\s\+\|\$",80);
990  
991 # if there, write the accession line
992  
993 25 ▶ if ( $self->_ac_generation_func ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_ac_generation_func) { } 0 25 25
994 0 $temp_line = &{$self->_ac_generation_func}($seq);
995 0 $self->_print("ACCESSION $temp_line\n");
996 }
997 else {
998 25 my @acc = ();
999 25 push @acc, $seq->accession_number;
1000 25 ▶ if ( $seq->isa('Bio::Seq::RichSeqI') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq->isa("Bio::Seq::RichSeqI")) 22 3 25
1001 22 push @acc, $seq->get_secondary_accessions;
1002 }
1003 25 $self->_print("ACCESSION ", join(" ", @acc), "\n");
1004 # otherwise - cannot print <sigh>
1005 }
1006  
1007 # if PID defined, print it
1008 25 ▶ if ($seq->isa('Bio::Seq::RichSeqI') and $seq->pid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq->isa("Bio::Seq::RichSeqI") and $seq->pid) 0 25 25
Condition66%2/3
$seq->isa("Bio::Seq::RichSeqI") and $seq->pid
!ll&&!rl&&r
3220
MC/DC0%0/2
$seq->isa("Bio::Seq::RichSeqI") and $seq->pid
$seq->isa("Bio::Seq::RichSeqI") $seq->pid
Truth table66%2/3
A and B
A= $seq->isa("Bio::Seq::RichSeqI")B= $seq->pid
ABresult
0X0
100
111
1009 0 $self->_print("PID ", $seq->pid, "\n");
1010 }
1011  
1012 # if there, write the version line
1013 25 ▶ if ( defined $self->_sv_generation_func ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->_sv_generation_func) { } 0 25 25
elsif ($seq->isa('Bio::Seq::RichSeqI') and defined $seq->seq_version) { } 17 11 28
1014 0 $temp_line = &{$self->_sv_generation_func}($seq);
1015 0 ▶ if ( $temp_line ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($temp_line) 0 0 0
1016 0 $self->_print("VERSION $temp_line\n");
1017 }
1018 }
1019 ▶ elsif ($seq->isa('Bio::Seq::RichSeqI') and defined($seq->seq_version)) {
Condition100%3/3
$seq->isa("Bio::Seq::RichSeqI") and defined $seq->seq_version
!ll&&!rl&&r
3517
MC/DC100%2/2
$seq->isa("Bio::Seq::RichSeqI") and defined $seq->seq_version
$seq->isa("Bio::Seq::RichSeqI") defined $seq->seq_version
Truth table100%3/3
A and B
A= $seq->isa("Bio::Seq::RichSeqI")B= defined $seq->seq_version
ABresult
0X0
100
111
1020 17 my $id = $seq->primary_id; # this may be a GI number
1021 17 ▶ my $data = (defined $id and $id =~ /^\d+$/) ? " GI:$id" : "";
Branch: 1 branch
BranchTrueFalseTotal
defined $id && $id =~ /^\d+$/ ? : 17 0 17
Condition33%1/3
defined $id and $id =~ /^\d+$/
!ll&&!rl&&r
0017
MC/DC0%0/2
defined $id and $id =~ /^\d+$/
defined $id $id =~ /^\d+$/
Truth table33%1/3
A and B
A= defined $idB= $id =~ /^\d+$/
ABresult
0X0
100
111
1022 17 $self->_print("VERSION ",
1023 $seq->accession_number, ".",
1024 $seq->seq_version, $data, "\n");
1025 }
1026  
1027 # if there, write the PROJECT line
1028 25 for my $proj ( $seq->annotation->get_Annotations('project') ) {
1029 2 $self->_print("PROJECT ".$proj->value."\n");
1030 }
1031  
1032 # if there, write the DBSOURCE line
1033 25 foreach my $ref ( $seq->annotation->get_Annotations('dblink') ) {
1034 2 my ($db, $id) = ($ref->database, $ref->primary_id);
1035 2 ▶ my $prefix = $db eq 'Project' ? 'DBLINK' : 'DBSOURCE';
Branch: 1 branch
BranchTrueFalseTotal
$db eq 'Project' ? : 1 1 2
1036 2 ▶ my $text = $db eq 'GenBank' ? ''
Branch: 2 branches
BranchTrueFalseTotal
$db eq 'GenBank' ? : 0 2 2
$db eq 'Project' ? : 1 1 2
1037 : $db eq 'Project' ? "$db:$id"
1038 : "$db accession $id";
1039 2 $self->_print(sprintf ("%-11s %s\n", $prefix, $text));
1040 }
1041  
1042 # if there, write the keywords line
1043 25 ▶ if ( defined $self->_kw_generation_func ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->_kw_generation_func) { } 0 25 25
elsif ($seq->can('keywords')) { } 22 3 25
1044 0 $temp_line = &{$self->_kw_generation_func}($seq);
1045 0 $self->_print("KEYWORDS $temp_line\n");
1046 }
1047 elsif ( $seq->can('keywords') ) {
1048 22 my $kw = $seq->keywords;
1049 22 ▶ $kw .= '.' if ( $kw !~ /\.$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $kw =~ /\.$/ 22 0 22
1050 22 $self->_print("KEYWORDS $kw\n");
1051 }
1052  
1053 # SEGMENT if it exists
1054 25 foreach my $ref ( $seq->annotation->get_Annotations('segment') ) {
1055 0 $self->_print(sprintf ("%-11s %s\n",'SEGMENT',
1056 $ref->value));
1057 }
1058  
1059 # Organism lines
1060 25 ▶ if (my $spec = $seq->species) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $spec = $seq->species) 21 4 25
1061 21 ▶ my ($on, $sn, $cn) = ($spec->can('organelle') ? $spec->organelle : '',
Branch: 1 branch
BranchTrueFalseTotal
$spec->can('organelle') ? : 21 0 21
1062 $spec->scientific_name,
1063 $spec->common_name);
1064 21 my @classification;
1065 21 ▶ if ($spec->isa('Bio::Species')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->isa('Bio::Species')) { } 21 0 21
1066 21 @classification = $spec->classification;
1067 21 shift @classification;
1068 }
1069 else {
1070 # Bio::Taxon should have a DB handle of some type attached, so
1071 # derive the classification from that
1072 0 my $node = $spec;
1073 0 ▶ while ($node) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node) 0 0 0
1074 0 ▶ $node = $node->ancestor || last;
Condition0%0/2
$node->ancestor || (last)
l!l
00
MC/DC0%0/1
$node->ancestor || (last)
$node->ancestor
Truth table0%0/2
A
A= $node->ancestor
Aresult
11
00
1075 0 unshift @classification, $node->node_name;
1076 #$node eq $root && last;
1077 }
1078 0 @classification = reverse @classification;
1079 }
1080 21 ▶ my $abname = $spec->name('abbreviated') ? # from genbank file
Branch: 1 branch
BranchTrueFalseTotal
$spec->name('abbreviated') ? : 21 0 21
1081 $spec->name('abbreviated')->[0] : $sn;
1082 21 ▶ my $sl = $on ? "$on " : '';
Branch: 1 branch
BranchTrueFalseTotal
$on ? : 4 17 21
1083 21 ▶ $sl .= $cn ? "$abname ($cn)" : $abname;
Branch: 1 branch
BranchTrueFalseTotal
$cn ? : 6 15 21
1084  
1085 21 $self->_write_line_GenBank_regex("SOURCE ", ' 'x12, $sl, "\\s\+\|\$", 80);
1086 21 $self->_print(" ORGANISM ", $spec->scientific_name, "\n");
1087 21 my $OC = join('; ', reverse @classification) . '.';
1088 21 $self->_write_line_GenBank_regex(' 'x12,' 'x12, $OC, "\\s\+\|\$", 80);
1089 }
1090  
1091 # Reference lines
1092 25 my $count = 1;
1093 25 foreach my $ref ( $seq->annotation->get_Annotations('reference') ) {
1094 45 $temp_line = "REFERENCE $count";
1095 45 ▶ if ($ref->start) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ref->start) { } 45 0 45
elsif ($ref->gb_reference) { } 0 0 0
1096 45 ▶ $temp_line .= sprintf (" (%s %d to %d)",
Branch: 1 branch
BranchTrueFalseTotal
$seq->alphabet eq 'protein' ? : 3 42 45
1097 ($seq->alphabet() eq "protein" ?
1098 "residues" : "bases"),
1099 $ref->start, $ref->end);
1100 }
1101 elsif ($ref->gb_reference) {
1102 0 $temp_line .= sprintf (" (%s)", $ref->gb_reference);
1103 }
1104 45 $self->_print("$temp_line\n");
1105 45 $self->_write_line_GenBank_regex(" AUTHORS ", ' 'x12,
1106 $ref->authors, "\\s\+\|\$", 80);
1107 45 ▶ $self->_write_line_GenBank_regex(" CONSRTM ", ' 'x12,
Branch: 1 branch
BranchTrueFalseTotal
if $ref->consortium 9 36 45
1108 $ref->consortium, "\\s\+\|\$", 80) if $ref->consortium;
1109 45 $self->_write_line_GenBank_regex(" TITLE ", ' 'x12,
1110 $ref->title, "\\s\+\|\$", 80);
1111 45 $self->_write_line_GenBank_regex(" JOURNAL ", ' 'x12,
1112 $ref->location, "\\s\+\|\$", 80);
1113 45 ▶ if ( $ref->medline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref->medline) 4 41 45
1114 4 $self->_write_line_GenBank_regex(" MEDLINE ", ' 'x12,
1115 $ref->medline, "\\s\+\|\$", 80);
1116 # I am assuming that pubmed entries only exist when there
1117 # are also MEDLINE entries due to the indentation
1118 }
1119 # This could be a wrong assumption
1120 45 ▶ if ( $ref->pubmed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref->pubmed) 12 33 45
1121 12 $self->_write_line_GenBank_regex(" PUBMED ", ' 'x12,
1122 $ref->pubmed, "\\s\+\|\$", 80);
1123 }
1124 # put remark at the end
1125 45 ▶ if ($ref->comment) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref->comment) 0 45 45
1126 0 $self->_write_line_GenBank_regex(" REMARK ", ' 'x12,
1127 $ref->comment, "\\s\+\|\$", 80);
1128 }
1129 45 $count++;
1130 }
1131  
1132 # Comment lines
1133 25 foreach my $comment ( $seq->annotation->get_Annotations('comment') ) {
1134 13 $self->_write_line_GenBank_regex("COMMENT ", ' 'x12,
1135 $comment->text, "\\s\+\|\$", 80);
1136 }
1137  
1138 # FEATURES section
1139 25 $self->_print("FEATURES Location/Qualifiers\n");
1140  
1141 25 ▶ if ( defined $self->_post_sort ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->_post_sort) { } 0 25 25
1142 # we need to read things into an array. Process. Sort them. Print 'em
1143 0 my $post_sort_func = $self->_post_sort;
1144 0 my @fth;
1145  
1146 0 foreach my $sf ( $seq->top_SeqFeatures ) {
1147 0 push @fth, Bio::SeqIO::FTHelper::from_SeqFeature($sf, $seq);
1148 }
1149  
1150 0 @fth = sort { &$post_sort_func($a, $b) } @fth;
1151  
1152 0 foreach my $fth ( @fth ) {
1153 0 $self->_print_GenBank_FTHelper($fth);
1154 }
1155 }
1156 else {
1157 # not post sorted. And so we can print as we get them.
1158 # lower memory load...
1159 25 foreach my $sf ( $seq->top_SeqFeatures ) {
1160 426 my @fth = Bio::SeqIO::FTHelper::from_SeqFeature($sf, $seq);
1161 426 foreach my $fth ( @fth ) {
1162 426 ▶ if ( ! $fth->isa('Bio::SeqIO::FTHelper') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fth->isa("Bio::SeqIO::FTHelper")) 0 426 426
1163 0 $sf->throw("Cannot process FTHelper... $fth");
1164 }
1165 426 $self->_print_GenBank_FTHelper($fth);
1166 }
1167 }
1168 }
1169  
1170 # deal with WGS; WGS_SCAFLD present only if WGS is also present
1171 25 ▶ if ($seq->annotation->get_Annotations('wgs')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq->annotation->get_Annotations("wgs")) 0 25 25
1172 0 foreach my $wgs (map {$seq->annotation->get_Annotations($_)}
1173 qw(wgs wgs_scaffold)
1174 ) {
1175 0 $self->_print(sprintf ("%-11s %s\n",
1176 uc($wgs->tagname),
1177 $wgs->value));
1178 }
1179 0 $self->_show_dna(0);
1180 }
1181 25 ▶ if ($seq->annotation->get_Annotations('contig')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq->annotation->get_Annotations("contig")) 1 24 25
1182 1 my $ct = 0;
1183 1 my $cline;
1184 1 foreach my $contig ($seq->annotation->get_Annotations('contig')) {
1185 1 ▶ unless ($ct) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ct) { } 0 1 1
1186 1 $cline = uc($contig->tagname) . " " . $contig->value . "\n";
1187 }
1188 else {
1189 0 $cline = " " . $contig->value . "\n";
1190 }
1191 1 $self->_print($cline);
1192 1 $ct++;
1193 }
1194 }
1195 25 ▶ if ( $seq->length == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq->length == 0) 1 24 25
1196 1 $self->_show_dna(0);
1197 }
1198  
1199 25 ▶ if ( $self->_show_dna == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_show_dna == 0) 1 24 25
1200 1 $self->_print("\n//\n");
1201 1 return;
1202 }
1203  
1204 # finished printing features.
1205  
1206 24 $str =~ tr/A-Z/a-z/;
1207  
1208 24 my ($o) = $seq->annotation->get_Annotations('origin');
1209 24 ▶ $self->_print(sprintf("%-12s%s\n",
Branch: 1 branch
BranchTrueFalseTotal
$o ? : 0 24 24
1210 'ORIGIN', $o ? $o->value : ''));
1211 # print out the sequence
1212 24 my $nuc = 60; # Number of nucleotides per line
1213 24 my $whole_pat = 'a10' x 6; # Pattern for unpacking a whole line
1214 24 my $out_pat = 'A11' x 6; # Pattern for packing a line
1215 24 my $length = length $str;
1216  
1217 # Calculate the number of nucleotides which fit on whole lines
1218 24 my $whole = int($length / $nuc) * $nuc;
1219  
1220 # Print the whole lines
1221 24 my $i;
1222 24 ▶ for ($i = 0; $i < $whole; $i += $nuc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $whole) 21950 24 21974
1223 21950 my $blocks = pack $out_pat,
1224 unpack $whole_pat,
1225 substr($str, $i, $nuc);
1226 21950 chop $blocks;
1227 21950 $self->_print(sprintf("%9d $blocks\n", $i + $nuc - 59));
1228 }
1229  
1230 # Print the last line
1231 24 ▶ if (my $last = substr($str, $i)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $last = substr($str, $i)) 18 6 24
1232 18 my $last_len = length($last);
1233 18 my $last_pat = 'a10' x int($last_len / 10)
1234 . 'a' . $last_len % 10;
1235 18 my $blocks = pack $out_pat,
1236 unpack($last_pat, $last);
1237 18 $blocks =~ s/ +$//;
1238 18 $self->_print(sprintf("%9d $blocks\n",
1239 $length - $last_len + 1));
1240 }
1241  
1242 24 $self->_print("//\n");
1243  
1244 24 ▶ $self->flush if $self->_flush_on_write && defined $self->_fh;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_flush_on_write and defined $self->_fh 24 0 24
Condition33%1/3
$self->_flush_on_write and defined $self->_fh
!ll&&!rl&&r
0024
MC/DC0%0/2
$self->_flush_on_write and defined $self->_fh
$self->_flush_on_write defined $self->_fh
Truth table33%1/3
A and B
A= $self->_flush_on_writeB= defined $self->_fh
ABresult
0X0
100
111
1245 24 return 1;
1246 }
1247 }
1248  
1249 =head2 _print_GenBank_FTHelper
1250  
1251 Title : _print_GenBank_FTHelper
1252 Usage :
1253 Function:
1254 Example :
1255 Returns :
1256 Args :
1257  
1258 =cut
1259  
1260 sub _print_GenBank_FTHelper {
1261 426 ▶ my ( $self, $fth ) = @_;
Subroutine _print_GenBank_FTHelper: called CC=13 SCAR=29.4
1262  
1263 426 ▶ if ( not ref $fth or not $fth->isa('Bio::SeqIO::FTHelper') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $fth and $fth->isa("Bio::SeqIO::FTHelper")) 0 426 426
Condition33%1/3
ref $fth and $fth->isa("Bio::SeqIO::FTHelper")
!ll&&!rl&&r
00426
MC/DC0%0/2
ref $fth and $fth->isa("Bio::SeqIO::FTHelper")
ref $fth $fth->isa("Bio::SeqIO::FTHelper")
Truth table33%1/3
A and B
A= ref $fthB= $fth->isa("Bio::SeqIO::FTHelper")
ABresult
0X0
100
111
1264 0 $fth->warn(
1265 "$fth is not a FTHelper class. Attempting to print but there could be issues"
1266 );
1267 }
1268  
1269 426 ▶ my $spacer = ( length $fth->key >= 15 ) ? ' ' : '';
Branch: 1 branch
BranchTrueFalseTotal
length $fth->key >= 15 ? : 0 426 426
1270 426 $self->_write_line_GenBank_regex(
1271 sprintf( " %-16s%s", $fth->key, $spacer ),
1272 " " x 21, $fth->loc, "\,\|\$", 80 );
1273  
1274 426 foreach my $tag ( sort keys %{ $fth->field } ) {
1275 # Account for hash structure in Annotation::DBLink, not the expected array
1276 981 ▶ if ( $tag eq 'db_xref' and grep /HASH/, @{ $fth->field->{$tag} }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq 'db_xref' and grep /HASH/, @{$fth->field->{$tag};}) { } 0 981 981
Condition66%2/3
$tag eq "db_xref" and grep /HASH/, @{$fth->field->{$tag};}
!ll&&!rl&&r
8431380
MC/DC0%0/2
$tag eq "db_xref" and grep /HASH/, @{$fth->field->{$tag};}
$tag eq "db_xref" grep /HASH/, @{$fth->field->{$tag};}
Truth table66%2/3
A and B
A= $tag eq "db_xref"B= grep /HASH/, @{$fth->field->{$tag};}
ABresult
0X0
100
111
1277 0 for my $ref ( @{ $fth->field->{$tag} } ) {
1278 0 my $db = $ref->{'database'};
1279 0 my $id = $ref->{'primary_id'};
1280 0 $self->_write_line_GenBank_regex
1281 ( " " x 21, " " x 21,
1282 "/$tag=\"$db:$id\"", "\.\|\$", 80 );
1283 }
1284 }
1285 # The usual case, where all values are found in an array
1286 else {
1287 981 foreach my $value ( @{ $fth->field->{$tag} } ) {
1288 1074 $value =~ s/\"/\"\"/g;
1289 1074 ▶ if ( $value eq "_no_value" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($value eq '_no_value') { } 0 1074 1074
elsif (not $Bio::SeqIO::genbank::FTQUAL_NO_QUOTE{$tag}) { } 966 108 1074
1290 0 $self->_write_line_GenBank_regex
1291 ( " " x 21, " " x 21,
1292 "/$tag", "\.\|\$", 80 );
1293 }
1294  
1295 # There are almost 3x more quoted qualifier values and they
1296 # are more common too so we take quoted ones first.
1297 # Long qualifiers, that will be line wrapped, are always quoted
1298  
1299 # Note (cjf): any tags explicitly *not* quoted must
1300 # remain unquoted in all output for proper round trip
1301 # parsing:
1302 # see https://github.com/bioperl/bioperl-live/issues/321
1303  
1304 # If this breaks *NCBI* examples please file an issue with
1305 # example files
1306 elsif ( not $FTQUAL_NO_QUOTE{$tag} ) {
1307 966 ▶ my ($pat) = ( $value =~ /\s/ ? '\s|$' :
Branch: 1 branch
BranchTrueFalseTotal
$value =~ /\s/ ? : 328 638 966
1308 '.|$' );
1309 966 $self->_write_line_GenBank_regex
1310 ( " " x 21, " " x 21,
1311 "/$tag=\"$value\"", $pat, 80 );
1312 }
1313 else {
1314 108 ▶ my ($pat) = ( $value =~ /[,]/ ? '[,]|$' :
Branch: 1 branch
BranchTrueFalseTotal
$value =~ /[,]/ ? : 1 107 108
1315 '.|$' );
1316 108 $self->_write_line_GenBank_regex
1317 ( " " x 21, " " x 21,
1318 "/$tag=$value", $pat, 80 );
1319 }
1320 }
1321 }
1322 }
1323 }
1324  
1325 =head2 _read_GenBank_References
1326  
1327 Title : _read_GenBank_References
1328 Usage :
1329 Function: Reads references from GenBank format. Internal function really
1330 Returns :
1331 Args :
1332  
1333 =cut
1334  
1335 sub _read_GenBank_References {
1336 94 ▶ my ($self, $buffer) = @_;
Subroutine _read_GenBank_References: called CC=31 SCAR=34.9
1337 94 my (@refs);
1338 my $ref;
1339  
1340 # assume things are starting with RN
1341 94 ▶ if ( $$buffer !~ /^REFERENCE/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$buffer =~ /^REFERENCE/) 0 94 94
1342 0 warn("Not parsing line '$$buffer' which maybe important");
1343 }
1344  
1345 94 my $line = $$buffer;
1346  
1347 94 my (@title,@loc,@authors,@consort,@com,@medline,@pubmed);
1348  
1349 REFLOOP:
1350 94 ▶ while( defined($line) or defined($line = $self->_readline) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line or defined($line = $self->_readline)) 492 0 492
Condition66%2/3
defined $line or defined($line = $self->_readline)
l!l&&r!l&&!r
943980
MC/DC0%0/2
defined $line or defined($line = $self->_readline)
defined $line defined($line = $self->_readline)
Truth table66%2/3
A or B
A= defined $lineB= defined($line = $self->_readline)
ABresult
1X1
011
000
1351 1263 ▶ if ($line =~ /^\s{2}AUTHORS\s+(.*)/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s{2}AUTHORS\s+(.*)/o) 363 900 1263
1352 363 push @authors, $1;
1353 363 ▶ while ( defined($line = $self->_readline) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->_readline)) 933 0 933
1354 933 ▶ if ($line =~ /^\s{9,}(.*)/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s{9,}(.*)/o) 570 363 933
1355 570 push @authors, $1;
1356 570 next;
1357 }
1358 363 last;
1359 }
1360 363 $ref->authors(join(' ', @authors));
1361 }
1362  
1363 1263 ▶ if ($line =~ /^\s{2}CONSRTM\s+(.*)/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s{2}CONSRTM\s+(.*)/o) 33 1230 1263
1364 33 push @consort, $1;
1365 33 ▶ while ( defined($line = $self->_readline) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->_readline)) 34 0 34
1366 34 ▶ if ($line =~ /^\s{9,}(.*)/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s{9,}(.*)/o) 1 33 34
1367 1 push @consort, $1;
1368 1 next;
1369 }
1370 33 last;
1371 }
1372 33 $ref->consortium(join(' ', @consort));
1373 }
1374  
1375 1263 ▶ if ($line =~ /^\s{2}TITLE\s+(.*)/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s{2}TITLE\s+(.*)/o) 369 894 1263
1376 369 push @title, $1;
1377 369 ▶ while ( defined($line = $self->_readline) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->_readline)) 626 0 626
1378 626 ▶ if ($line =~ /^\s{9,}(.*)/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s{9,}(.*)/o) 257 369 626
1379 257 push @title, $1;
1380 257 next;
1381 }
1382 369 last;
1383 }
1384 369 $ref->title(join(' ', @title));
1385 }
1386  
1387 1263 ▶ if ($line =~ /^\s{2}JOURNAL\s+(.*)/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s{2}JOURNAL\s+(.*)/o) 377 886 1263
1388 377 push @loc, $1;
1389 377 ▶ while ( defined($line = $self->_readline) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->_readline)) 519 0 519
1390 # we only match when there are at least 4 spaces
1391 # there is probably a better way to match this
1392 # as it assumes that the describing tag is short enough
1393 519 ▶ if ($line =~ /^\s{9,}(.*)/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s{9,}(.*)/o) 142 377 519
1394 142 push @loc, $1;
1395 142 next;
1396 }
1397 377 last;
1398 }
1399 377 $ref->location(join(' ', @loc));
1400 377 redo REFLOOP;
1401 }
1402  
1403 886 ▶ if ($line =~ /^\s{2}REMARK\s+(.*)/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s{2}REMARK\s+(.*)/o) 59 827 886
1404 59 push @com, $1;
1405 59 ▶ while ( defined($line = $self->_readline) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->_readline)) 83 0 83
1406 83 ▶ if ($line =~ /^\s{9,}(.*)/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s{9,}(.*)/o) 24 59 83
1407 24 push @com, $1;
1408 24 next;
1409 }
1410 59 last;
1411 }
1412 59 $ref->comment(join(' ', @com));
1413 59 redo REFLOOP;
1414 }
1415  
1416 827 ▶ if ( $line =~ /^\s{2}MEDLINE\s+(.*)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s{2}MEDLINE\s+(.*)/) 126 701 827
1417 126 push @medline, $1;
1418 126 ▶ while ( defined($line = $self->_readline) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->_readline)) 126 0 126
1419 126 ▶ if ($line =~ /^\s{9,}(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s{9,}(.*)/) 0 126 126
1420 0 push @medline, $1;
1421 0 next;
1422 }
1423 126 last;
1424 }
1425 126 $ref->medline(join(' ', @medline));
1426 126 redo REFLOOP;
1427 }
1428  
1429 701 ▶ if ( $line =~ /^\s{3}PUBMED\s+(.*)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s{3}PUBMED\s+(.*)/) 209 492 701
1430 209 push @pubmed, $1;
1431 209 ▶ while ( defined($line = $self->_readline) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->_readline)) 209 0 209
1432 209 ▶ if ($line =~ /^\s{9,}(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s{9,}(.*)/) 0 209 209
1433 0 push @pubmed, $1;
1434 0 next;
1435 }
1436 209 last;
1437 }
1438 209 $ref->pubmed(join(' ', @pubmed));
1439 209 redo REFLOOP;
1440 }
1441  
1442 492 ▶ if ( $line =~ /^REFERENCE/o ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^REFERENCE/o) 378 114 492
1443 # store current reference
1444 378 ▶ $self->_add_ref_to_array(\@refs,$ref) if defined $ref;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ref 284 94 378
1445  
1446 # reset
1447 378 @authors = ();
1448 378 @title = ();
1449 378 @loc = ();
1450 378 @com = ();
1451 378 @pubmed = ();
1452 378 @medline = ();
1453  
1454 # create the new reference object
1455 378 $ref = Bio::Annotation::Reference->new(-tagname => 'reference');
1456  
1457 # check whether start and end base is given
1458 378 ▶ if ($line =~ /^REFERENCE\s+\d+\s+\([a-z]+ (\d+) to (\d+)\)/){
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /^REFERENCE\s+\d+\s+\([a-z]+ (\d+) to (\d+)\)/) { } 253 125 378
elsif ($line =~ /^REFERENCE\s+\d+\s+\((.*)\)/) { } 8 117 125
1459 253 $ref->start($1);
1460 253 $ref->end($2);
1461 }
1462 elsif ($line =~ /^REFERENCE\s+\d+\s+\((.*)\)/) {
1463 8 $ref->gb_reference($1);
1464 }
1465 }
1466  
1467 492 ▶ last if ($line =~ /^(FEATURES)|(COMMENT)/o);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^(FEATURES)|(COMMENT)/o 94 398 492
1468  
1469 398 $line = undef; # Empty $line to trigger read of next line
1470 }
1471  
1472 # store last reference
1473 94 ▶ $self->_add_ref_to_array(\@refs, $ref) if defined $ref;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ref 94 0 94
1474  
1475 94 $$buffer = $line;
1476  
1477 #print "\nnumber of references found: ", $#refs+1,"\n";
1478  
1479 94 return @refs;
1480 }
1481  
1482 =head2 _add_ref_to_array
1483  
1484 Title: _add_ref_to_array
1485 Usage:
1486 Function: Adds a Reference object to an array of Reference objects, takes
1487 care of possible cleanups to be done (currently, only author and title
1488 will be chopped of trailing semicolons).
1489 Args: A reference to an array of Reference objects and
1490 the Reference object to be added
1491 Returns: nothing
1492  
1493 =cut
1494  
1495 sub _add_ref_to_array {
1496 378 ▶ my ($self, $refs, $ref) = @_;
Subroutine _add_ref_to_array: called CC=3 SCAR=11.0
1497  
1498 # first, polish author and title by removing possible trailing semicolons
1499 378 my $au = $ref->authors;
1500 378 my $title = $ref->title;
1501 378 ▶ $au =~ s/;\s*$//g if $au;
Branch: 1 branch
BranchTrueFalseTotal
if $au 363 15 378
1502 378 ▶ $title =~ s/;\s*$//g if $title;
Branch: 1 branch
BranchTrueFalseTotal
if $title 369 9 378
1503 378 $ref->authors($au);
1504 378 $ref->title($title);
1505 # the rest should be clean already, so go ahead and add it
1506 378 push @{$refs}, $ref;
1507 }
1508  
1509 =head2 _read_GenBank_Species
1510  
1511 Title : _read_GenBank_Species
1512 Usage :
1513 Function: Reads the GenBank Organism species and classification
1514 lines. Able to deal with unconvential Organism naming
1515 formats, and varietas in plants
1516 Example : ORGANISM unknown marine gamma proteobacterium NOR5
1517 $genus = undef
1518 $species = unknown marine gamma proteobacterium NOR5
1519  
1520 ORGANISM Drosophila sp. 'white tip scutellum'
1521 $genus = Drosophila
1522 $species = sp. 'white tip scutellum'
1523 (yes, this really is a species and that is its name)
1524 $subspecies = undef
1525  
1526 ORGANISM Ajellomyces capsulatus var. farciminosus
1527 $genus = Ajellomyces
1528 $species = capsulatus
1529 $subspecies = var. farciminosus
1530  
1531 ORGANISM Hepatitis delta virus
1532 $genus = undef (though this virus has a genus in its lineage, we
1533 cannot know that without a database lookup)
1534 $species = Hepatitis delta virus
1535  
1536 Returns : A Bio::Species object
1537 Args : A reference to the current line buffer
1538  
1539 =cut
1540  
1541 sub _read_GenBank_Species {
1542 95 ▶ my ($self, $buffer) = @_;
Subroutine _read_GenBank_Species: called CC=25 SCAR=33.2
1543  
1544 95 my @unkn_names = ('other', 'unknown organism', 'not specified', 'not shown',
1545 'Unspecified', 'Unknown', 'None', 'unclassified',
1546 'unidentified organism', 'not supplied');
1547 # dictionary of synonyms for taxid 32644
1548 95 my @unkn_genus = ('unknown', 'unclassified', 'uncultured', 'unidentified');
1549 # all above can be part of valid species name
1550  
1551 95 my $line = $$buffer;
1552  
1553 95 my( $sub_species, $species, $genus, $sci_name, $common,
1554 $class_lines, $source_flag, $abbr_name, $organelle, $sl );
1555 95 my %source = map { $_ => 1 } qw(SOURCE ORGANISM CLASSIFICATION);
1556  
1557 # upon first entering the loop, we must not read a new line -- the SOURCE
1558 # line is already in the buffer (HL 05/10/2000)
1559 95 my ($ann, $tag, $data);
1560 95 ▶ while (defined($line) or defined($line = $self->_readline)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line or defined($line = $self->_readline)) 488 0 488
Condition66%2/3
defined $line or defined($line = $self->_readline)
l!l&&r!l&&!r
953930
MC/DC0%0/2
defined $line or defined($line = $self->_readline)
defined $line defined($line = $self->_readline)
Truth table66%2/3
A or B
A= defined $lineB= defined($line = $self->_readline)
ABresult
1X1
011
000
1561 # de-HTMLify (links that may be encountered here don't contain
1562 # escaped '>', so a simple-minded approach suffices)
1563 488 $line =~ s{<[^>]+>}{}g;
1564 488 ▶ if ($line =~ m{^(?:\s{0,2})(\w+)\s+(.+)?$}ox) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^(?:\s{0,2})(\w+)\s+(.+)?$/ox) { } 285 203 488
1565 285 ▶ ($tag, $data) = ($1, $2 || '');
Condition50%1/2
$2 || ''
l!l
2850
MC/DC0%0/1
$2 || ''
$2
Truth table50%1/2
A
A= $2
Aresult
11
00
1566 285 ▶ last if ($tag and not exists $source{$tag});
Branch: 1 branch
BranchTrueFalseTotal
if $tag and not exists $source{$tag} 95 190 285
Condition66%2/3
$tag and not exists $source{$tag}
!ll&&!rl&&r
019095
MC/DC50%1/2
$tag and not exists $source{$tag}
$tag not exists $source{$tag}
Truth table66%2/3
A and not(B)
A= $tagB= not exists $source{$tag}
ABresult
0X0
100
111
1567 }
1568 else {
1569 203 ▶ return unless $tag;
Branch: 1 branch
BranchTrueFalseTotal
unless $tag 0 203 203
1570 203 ($data = $line) =~ s{^\s+}{};
1571 203 chomp $data;
1572 203 ▶ $tag = 'CLASSIFICATION' if ( $tag ne 'CLASSIFICATION'
Branch: 1 branch
BranchTrueFalseTotal
if $tag ne "CLASSIFICATION" and $tag eq "ORGANISM" and $line =~ /(?<!\bstr|\bvar)[;\.]+(?!\d)/ 95 108 203
Condition100%6/6
$tag ne "CLASSIFICATION" and $tag eq "ORGANISM" and $line =~ /(?<!\bstr|\bvar)[;\.]+(?!\d)/
!ll&&!rl&&r
107195
$tag ne "CLASSIFICATION" and $tag eq "ORGANISM"
!ll&&!rl&&r
101696
MC/DC100%3/3
$tag ne "CLASSIFICATION" and $tag eq "ORGANISM" and $line =~ /(?<!\bstr|\bvar)[;\.]+(?!\d)/
$tag ne "CLASSIFICATION" $tag eq "ORGANISM" $line =~ /(?<!\bstr|\bvar)[;\.]+(?!\d)/
Truth table100%4/4
A and B and C
A= $tag ne "CLASSIFICATION"B= $tag eq "ORGANISM"C= $line =~ /(?<!\bstr|\bvar)[;\.]+(?!\d)/
ABCresult
0XX0
10X0
1100
1111
1573 and $tag eq 'ORGANISM'
1574 # Don't match "str." or "var." (fix NC_021815),
1575 # and don't match ".1" (fix NC_021902)
1576 and $line =~ m{(?<!\bstr|\bvar)[;\.]+(?!\d)});
1577 }
1578 393 ▶ (exists $ann->{$tag}) ? ($ann->{$tag} .= ' '.$data) : ($ann->{$tag} .= $data);
Branch: 1 branch
BranchTrueFalseTotal
exists $ann->{$tag} ? : 108 285 393
1579 393 $line = undef;
1580 }
1581  
1582 95 ($sl, $class_lines, $sci_name) = ($ann->{SOURCE}, $ann->{CLASSIFICATION}, $ann->{ORGANISM});
1583  
1584 95 $$buffer = $line;
1585  
1586 95 ▶ $sci_name or return;
Branch: 1 branch
BranchTrueFalseTotal
$sci_name or return 0 95 95
1587  
1588 # parse out organelle, common name, abbreviated name if present;
1589 # this should catch everything, but falls back to
1590 # entire SOURCE line just in case
1591 95 ▶ if ($sl =~ m{^(mitochondrion|chloroplast|plastid)?
Branch: 1 branch
BranchTrueFalseTotal
if ($sl =~ /^(mitochondrion|chloroplast|plastid)? \s*(.*?) \s*(?: \( (.*?) \) )?\.? $ /msx) { } 95 0 95
1592 \s*(.*?)
1593 \s*(?: \( (.*?) \) )?\.?
1594 $
1595 }xms
1596 ) {
1597 95 ($organelle, $abbr_name, $common) = ($1, $2, $3); # optional
1598 }
1599 else {
1600 0 $abbr_name = $sl; # nothing caught; this is a backup!
1601 }
1602  
1603 # Convert data in classification lines into classification array.
1604 # only split on ';' or '.' so that classification that is 2 or more words will
1605 # still get matched, use map() to remove trailing/leading/intervening spaces
1606 95 my @class = map { $_ =~ s/^\s+//;
1607 906 $_ =~ s/\s+$//;
1608 906 $_ =~ s/\s{2,}/ /g;
1609 906 $_; }
1610 split /(?<!subgen)[;\.]+/, $class_lines;
1611  
1612 # do we have a genus?
1613 95 ▶ my $possible_genus = quotemeta($class[-1])
Branch: 1 branch
BranchTrueFalseTotal
$class[-2] ? : 95 0 95
1614 . ($class[-2] ? "|" . quotemeta($class[-2]) : '');
1615 95 ▶ if ($sci_name =~ /^($possible_genus)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sci_name =~ /^($possible_genus)/) { } 84 11 95
1616 84 $genus = $1;
1617 84 ($species) = $sci_name =~ /^$genus\s+(.+)/;
1618 }
1619 else {
1620 11 $species = $sci_name;
1621 }
1622  
1623 # is this organism of rank species or is it lower?
1624 # (we don't catch everything lower than species, but it doesn't matter -
1625 # this is just so we abide by previous behaviour whilst not calling a
1626 # species a subspecies)
1627 95 ▶ if ($species and $species =~ /(.+)\s+((?:subsp\.|var\.).+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($species and $species =~ /(.+)\s+((?:subsp\.|var\.).+)/) 5 90 95
Condition66%2/3
$species and $species =~ /(.+)\s+((?:subsp\.|var\.).+)/
!ll&&!rl&&r
0905
MC/DC50%1/2
$species and $species =~ /(.+)\s+((?:subsp\.|var\.).+)/
$species $species =~ /(.+)\s+((?:subsp\.|var\.).+)/
Truth table66%2/3
A and B
A= $speciesB= $species =~ /(.+)\s+((?:subsp\.|var\.).+)/
ABresult
0X0
100
111
1628 5 ($species, $sub_species) = ($1, $2);
1629 }
1630  
1631 # Don't make a species object if it's empty or "Unknown" or "None"
1632 # return unless $genus and $genus !~ /^(Unknown|None)$/oi;
1633 # Don't make a species object if it belongs to taxid 32644
1634 # my $unkn = grep { $_ =~ /^\Q$sl\E$/; } @unkn_names;
1635 95 my $unkn = grep { $_ eq $sl } @unkn_names;
1636 95 ▶ return unless (defined $species or defined $genus) and $unkn == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $species || defined $genus and $unkn == 0 0 95 95
Condition33%2/6
defined $species || defined $genus and $unkn == 0
!ll&&!rl&&r
0095
defined $species or defined $genus
l!l&&r!l&&!r
9500
MC/DC0%0/3
defined $species || defined $genus and $unkn == 0
defined $species defined $genus $unkn == 0
Truth table20%1/5
A or B and C
A= defined $speciesB= defined $genusC= $unkn == 0
ABCresult
00X0
1X00
0100
1X11
0111
1637  
1638 # Bio::Species array needs array in Species -> Kingdom direction
1639 95 push @class, $sci_name;
1640 95 @class = reverse @class;
1641  
1642 95 my $make = Bio::Species->new;
1643 95 $make->scientific_name($sci_name);
1644 95 ▶ $make->classification(@class) if @class > 0;
Branch: 1 branch
BranchTrueFalseTotal
if @class > 0 95 0 95
1645 95 ▶ $make->common_name( $common ) if $common;
Branch: 1 branch
BranchTrueFalseTotal
if $common 29 66 95
1646 95 ▶ $make->name('abbreviated', $abbr_name) if $abbr_name;
Branch: 1 branch
BranchTrueFalseTotal
if $abbr_name 95 0 95
1647 95 ▶ $make->organelle($organelle) if $organelle;
Branch: 1 branch
BranchTrueFalseTotal
if $organelle 9 86 95
1648 #$make->sub_species( $sub_species ) if $sub_species;
1649 95 return $make;
1650 }
1651  
1652 =head2 _read_FTHelper_GenBank
1653  
1654 Title : _read_FTHelper_GenBank
1655 Usage : _read_FTHelper_GenBank($buffer)
1656 Function: reads the next FT key line
1657 Example :
1658 Returns : Bio::SeqIO::FTHelper object
1659 Args : filehandle and reference to a scalar
1660  
1661 =cut
1662  
1663 sub _read_FTHelper_GenBank {
1664 8181 ▶ my ($self, $buffer) = @_;
Subroutine _read_FTHelper_GenBank: called CC=20 SCAR=30.6
1665  
1666 8181 my ($key, # The key of the feature
1667 $loc # The location line from the feature
1668 );
1669 8181 my @qual = (); # An array of lines making up the qualifiers
1670  
1671 8181 ▶ if ($$buffer =~ /^\s{5}(\S+)\s+(.+?)\s*$/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$buffer =~ /^\s{5}(\S+)\s+(.+?)\s*$/o) { } 8181 0 8181
1672 8181 $key = $1;
1673 8181 $loc = $2;
1674 # Read all the lines up to the next feature
1675 8181 ▶ while ( defined(my $line = $self->_readline) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = $self->_readline)) 87901 0 87901
1676 87901 ▶ if ($line =~ /^(\s+)(.+?)\s*$/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^(\s+)(.+?)\s*$/o) { } 87803 98 87901
1677 # Lines inside features are preceded by 21 spaces
1678 # A new feature is preceded by 5 spaces
1679 87803 ▶ if (length($1) > 6) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $1 > 6) { } 79720 8083 87803
1680 # Add to qualifiers if we're in the qualifiers, or if it's
1681 # the first qualifier
1682 79720 ▶ if (@qual or (index($2,'/') == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@qual or index($2, '/') == 0) { } 67554 12166 79720
Condition100%3/3
@qual or index($2, "/") == 0
l!l&&r!l&&!r
59384817012166
MC/DC100%2/2
@qual or index($2, "/") == 0
@qual index($2, "/") == 0
Truth table100%3/3
A or B
A= @qualB= index($2, "/") == 0
ABresult
1X1
011
000
1683 67554 push @qual, $2;
1684 }
1685 # We're still in the location line, so append to location
1686 else {
1687 12166 $loc .= $2;
1688 }
1689 }
1690 else {
1691 # We've reached the start of the next feature
1692 # Put the first line of the next feature into the buffer
1693 8083 $$buffer = $line;
1694 8083 last;
1695 }
1696 }
1697 else {
1698 # We're at the end of the feature table
1699 # Put the first line of the next feature into the buffer
1700 98 $$buffer = $line;
1701 98 last;
1702 }
1703 }
1704 }
1705 else {
1706 # No feature key
1707 0 $self->debug("no feature key!\n");
1708 # change suggested by JDiggans to avoid infinite loop-
1709 # see bugreport 1062.
1710 # reset buffer to prevent infinite loop
1711 0 $$buffer = $self->_readline;
1712 0 return;
1713 }
1714  
1715 # Make the new FTHelper object
1716 8181 my $out = Bio::SeqIO::FTHelper->new;
1717 8181 $out->verbose($self->verbose);
1718 8181 $out->key($key);
1719 8181 $out->loc($loc);
1720  
1721 # Now parse and add any qualifiers. (@qual is kept
1722 # intact to provide informative error messages.)
1723 QUAL:
1724 8181 ▶ for (my $i = 0; $i < @qual; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @qual) 55395 8181 63576
1725 55395 my $data = $qual[$i];
1726 55395 ▶ my ( $qualifier, $value ) = ($data =~ m{^/([^=]+)(?:=\s*(.+))?})
Branch: 1 branch
BranchTrueFalseTotal
() = $data =~ m[^/([^=]+)(?:=\s*(.+))?] or $self->warn("cannot see new qualifier in feature ${key}: " . $data) 0 55395 55395
1727 or $self->warn( "cannot see new qualifier in feature $key: "
1728 . $data);
1729 55395 ▶ $qualifier = '' if not defined $qualifier;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $qualifier 0 55395 55395
1730  
1731 55395 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 54491 904 55395
1732 # Do we have a quoted value?
1733 54491 ▶ if (substr($value, 0, 1) eq '"') {
Branch: 2 branches
BranchTrueFalseTotal
if (substr($value, 0, 1) eq '"') { } 51711 2780 54491
elsif ($value =~ /^\(/) { } 28 2752 2780
1734 # Keep adding to value until we find the trailing quote
1735 # and the quotes are balanced
1736 51711 ▶ while ($value !~ /\"$/ or $value =~ tr/"/"/ % 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $value =~ /\"$/ or $value =~ tr/"// % 2) 12156 51711 63867
Condition66%2/3
not $value =~ /\"$/ or $value =~ tr/"// % 2
l!l&&r!l&&!r
12156051711
MC/DC50%1/2
not $value =~ /\"$/ or $value =~ tr/"// % 2
not $value =~ /\"$/ $value =~ tr/"// % 2
Truth table66%2/3
not(A) or B
A= not $value =~ /\"$/B= $value =~ tr/"// % 2
ABresult
1X1
011
000
1737 12156 ▶ if ($i >= $#qual) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= $#qual) 0 12156 12156
1738 0 $self->warn( "Unbalanced quote in:\n"
1739 . join("\n", @qual)
1740 . "No further qualifiers will "
1741 . "be added for this feature");
1742 0 last QUAL;
1743 }
1744 # modifying a for-loop variable inside of the loop
1745 # is not the best programming style ...
1746 12156 $i++;
1747 12156 my $next = $qual[$i];
1748  
1749 # add to value with a space unless the value appears
1750 # to be a sequence (translation for example)
1751 # if (($value.$next) =~ /[^A-Za-z\"\-]/o) {
1752 # changed to explicitly look for translation tag - cjf 06/8/29
1753 12156 ▶ if ($qualifier !~ /^translation$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($qualifier =~ /^translation$/i) 9867 2289 12156
1754 9867 $value .= " ";
1755 }
1756 12156 $value .= $next;
1757 }
1758 # Trim leading and trailing quotes
1759 51711 $value =~ s/^"|"$//g;
1760 # Undouble internal quotes
1761 51711 $value =~ s/""/\"/g;
1762 }
1763 elsif ( $value =~ /^\(/ ) { # values quoted by ()s
1764 # Keep adding to value until we find the trailing bracket
1765 # and the ()s are balanced
1766 28 my $left = ($value =~ tr/\(/\(/); # count left parens
1767 28 my $right = ($value =~ tr/\)/\)/); # count right parens
1768  
1769 28 ▶ while( $left != $right ) { # was "$value !~ /\)$/ or $left != $right"
Branch: 1 branch
BranchTrueFalseTotal
if ($left != $right) 3 28 31
1770 3 ▶ if ( $i >= $#qual) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= $#qual) 0 3 3
1771 0 $self->warn( "Unbalanced parens in:\n"
1772 . join("\n", @qual)
1773 . "\nNo further qualifiers will "
1774 . "be added for this feature");
1775 0 last QUAL;
1776 }
1777 3 $i++;
1778 3 my $next = $qual[$i];
1779 3 $value .= $next;
1780 3 $left += ($next =~ tr/\(/\(/);
1781 3 $right += ($next =~ tr/\)/\)/);
1782 }
1783 }
1784 }
1785 else {
1786 904 $value = '_no_value';
1787 }
1788 # Store the qualifier
1789 55395 ▶ $out->field->{$qualifier} ||= [];
Condition100%2/2
$out->field->{$qualifier} ||= []
l!l
1630039095
MC/DC100%1/1
$out->field->{$qualifier} ||= []
$out->field->{$qualifier}
Truth table100%2/2
A
A= $out->field->{$qualifier}
Aresult
11
00
1790 55395 push @{$out->field->{$qualifier}}, $value;
1791 }
1792 8181 return $out;
1793 }
1794  
1795 =head2 _write_line_GenBank
1796  
1797 Title : _write_line_GenBank
1798 Usage :
1799 Function: internal function
1800 Example :
1801 Returns :
1802 Args :
1803  
1804 =cut
1805  
1806 sub _write_line_GenBank {
1807 0 ▶ my ($self, $pre1, $pre2, $line, $length) = @_;
Subroutine _write_line_GenBank: not called CC=3 SCAR=24.8
1808  
1809 0 ▶ $length or $self->throw("Miscalled write_line_GenBank without length. Programming error!");
Branch: 1 branch
BranchTrueFalseTotal
$length or $self->throw("Miscalled write_line_GenBank without length. Programming error!") 0 0 0
1810 0 my $subl = $length - length $pre2;
1811 0 my $linel = length $line;
1812 0 my $i;
1813  
1814 0 my $subr = substr($line,0,$length - length $pre1);
1815  
1816 0 $self->_print("$pre1$subr\n");
1817 0 ▶ for($i = ($length - length $pre1); $i < $linel; $i += $subl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $linel) 0 0 0
1818 0 $subr = substr($line, $i, $subl);
1819 0 $self->_print("$pre2$subr\n");
1820 }
1821 }
1822  
1823 =head2 _write_line_GenBank_regex
1824  
1825 Title : _write_line_GenBank_regex
1826 Usage :
1827 Function: internal function for writing lines of specified
1828 length, with different first and the next line
1829 left hand headers and split at specific points in the
1830 text
1831 Example :
1832 Returns : nothing
1833 Args : file handle,
1834 first header,
1835 second header,
1836 text-line,
1837 regex for line breaks,
1838 total line length
1839  
1840 =cut
1841  
1842 sub _write_line_GenBank_regex {
1843 1740 ▶ my ($self, $pre1, $pre2, $line, $regex, $length) = @_;
Subroutine _write_line_GenBank_regex: called CC=8 SCAR=21.2
1844  
1845 # print STDOUT "Going to print with $line!\n";
1846  
1847 1740 ▶ $length or $self->throw("Miscalled write_line_GenBank without length. Programming error!");
Branch: 1 branch
BranchTrueFalseTotal
$length or $self->throw("Miscalled write_line_GenBank without length. Programming error!") 0 1740 1740
1848  
1849 1740 my $subl = $length - (length $pre1) - 2;
1850 1740 my @lines = ();
1851  
1852 CHUNK:
1853 1740 ▶ while ($line) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line) 2087 1740 3827
1854 2087 foreach my $pat ($regex, '[,;\.\/-]\s|'.$regex, '[,;\.\/-]|'.$regex) {
1855 2087 ▶ if ($line =~ m/^(.{0,$subl})($pat)(.*)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^(.{0,$subl})($pat)(.*)/) 2087 0 2087
1856 2087 my $l = $1 . $2;
1857 2087 $line = substr($line, length $l);
1858 # be strict about not padding spaces according to
1859 # genbank format
1860 2087 $l =~ s/\s+$//;
1861 2087 ▶ next CHUNK if ($l eq '');
Branch: 1 branch
BranchTrueFalseTotal
if $l eq "" 0 2087 2087
1862 2087 push @lines, $l;
1863 2087 next CHUNK;
1864 }
1865 }
1866 # if we get here none of the patterns matched $subl or less chars
1867 0 $self->warn( "trouble dissecting \"$line\"\n into chunks "
1868 . "of $subl chars or less - this tag won't print right");
1869 # insert a space char to prevent infinite loops
1870 0 $line = substr($line, 0, $subl) . " " . substr($line, $subl);
1871 }
1872 1740 my $s = shift @lines;
1873 1740 ▶ $self->_print("$pre1$s\n") if $s;
Branch: 1 branch
BranchTrueFalseTotal
if $s 1734 6 1740
1874 1740 foreach my $s ( @lines ) {
1875 353 $self->_print("$pre2$s\n");
1876 }
1877 }
1878  
1879 =head2 _post_sort
1880  
1881 Title : _post_sort
1882 Usage : $obj->_post_sort($newval)
1883 Function:
1884 Returns : value of _post_sort
1885 Args : newvalue (optional)
1886  
1887 =cut
1888  
1889 sub _post_sort {
1890 25 ▶ my ($obj,$value) = @_;
Subroutine _post_sort: called CC=2 SCAR=7.6
1891 25 ▶ if ( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 25 25
1892 0 $obj->{'_post_sort'} = $value;
1893 }
1894 25 return $obj->{'_post_sort'};
1895 }
1896  
1897 =head2 _show_dna
1898  
1899 Title : _show_dna
1900 Usage : $obj->_show_dna($newval)
1901 Function:
1902 Returns : value of _show_dna
1903 Args : newvalue (optional)
1904  
1905 =cut
1906  
1907 sub _show_dna {
1908 136 ▶ my ($obj,$value) = @_;
Subroutine _show_dna: called CC=2 SCAR=6.9
1909 136 ▶ if ( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 111 25 136
1910 111 $obj->{'_show_dna'} = $value;
1911 }
1912 136 return $obj->{'_show_dna'};
1913 }
1914  
1915 =head2 _id_generation_func
1916  
1917 Title : _id_generation_func
1918 Usage : $obj->_id_generation_func($newval)
1919 Function:
1920 Returns : value of _id_generation_func
1921 Args : newvalue (optional)
1922  
1923 =cut
1924  
1925 sub _id_generation_func {
1926 25 ▶ my ($obj,$value) = @_;
Subroutine _id_generation_func: called CC=2 SCAR=7.6
1927 25 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 25 25
1928 0 $obj->{'_id_generation_func'} = $value;
1929 }
1930 25 return $obj->{'_id_generation_func'};
1931 }
1932  
1933 =head2 _ac_generation_func
1934  
1935 Title : _ac_generation_func
1936 Usage : $obj->_ac_generation_func($newval)
1937 Function:
1938 Returns : value of _ac_generation_func
1939 Args : newvalue (optional)
1940  
1941 =cut
1942  
1943 sub _ac_generation_func {
1944 25 ▶ my ($obj,$value) = @_;
Subroutine _ac_generation_func: called CC=2 SCAR=7.6
1945 25 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 25 25
1946 0 $obj->{'_ac_generation_func'} = $value;
1947 }
1948 25 return $obj->{'_ac_generation_func'};
1949 }
1950  
1951 =head2 _sv_generation_func
1952  
1953 Title : _sv_generation_func
1954 Usage : $obj->_sv_generation_func($newval)
1955 Function:
1956 Returns : value of _sv_generation_func
1957 Args : newvalue (optional)
1958  
1959 =cut
1960  
1961 sub _sv_generation_func {
1962 25 ▶ my ($obj,$value) = @_;
Subroutine _sv_generation_func: called CC=2 SCAR=7.6
1963 25 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 25 25
1964 0 $obj->{'_sv_generation_func'} = $value;
1965 }
1966 25 return $obj->{'_sv_generation_func'};
1967 }
1968  
1969 =head2 _kw_generation_func
1970  
1971 Title : _kw_generation_func
1972 Usage : $obj->_kw_generation_func($newval)
1973 Function:
1974 Returns : value of _kw_generation_func
1975 Args : newvalue (optional)
1976  
1977 =cut
1978  
1979 sub _kw_generation_func {
1980 25 ▶ my ($obj,$value) = @_;
Subroutine _kw_generation_func: called CC=2 SCAR=7.6
1981 25 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 25 25
1982 0 $obj->{'_kw_generation_func'} = $value;
1983 }
1984 25 return $obj->{'_kw_generation_func'};
1985 }
1986  
1987 13 1;
« Bio/SeqIO/tigr.pm ↑ Summary Bio/DB/WebDBSeqI.pm »