Bio/SeqIO/genbank.pm

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