Bio/SeqIO/genbank.pm

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