Bio/SeqIO/swiss.pm

filter: Statementstmt 78.8% 477 / 605 Branchbran 65.6% 243 / 370 Conditioncond 61.1% 63 / 103 MC/DCmcdc 42.4% 28 / 66 Subroutinesub 87.5% 28 / 32 Podpod 100% 2 / 2 totaltotal 71.3% 841 / 1178 CC 247 SCAR 47.9
CC
247
Cov
73%
write_seq
309.3
_read_swissprot_Species
97.0
next_seq
49.7
CRAP 119.8
« Bio/Tools/ESTScan.pm ↑ Summary Bio/Tools/GFF.pm »
1 #
2 # BioPerl module for Bio::SeqIO::swiss
3 #
4 # Copyright Elia Stupka
5 #
6 # You may distribute this module under the same terms as perl itself
7  
8 # POD documentation - main docs before the code
9  
10 =head1 NAME
11  
12 Bio::SeqIO::swiss - Swissprot sequence input/output stream
13  
14 =head1 SYNOPSIS
15  
16 It is probably best not to use this object directly, but
17 rather go through the SeqIO handler system:
18  
19 use Bio::SeqIO;
20  
21 $stream = Bio::SeqIO->new(-file => $filename,
22 -format => 'swiss');
23  
24 while ( my $seq = $stream->next_seq() ) {
25 # do something with $seq
26 }
27  
28 =head1 DESCRIPTION
29  
30 This object can transform Bio::Seq objects to and from Swiss-Pprot flat
31 file databases.
32  
33 There is a lot of flexibility here about how to dump things which needs
34 to be documented.
35  
36 =head2 GN (Gene name) line management details
37  
38 A Uniprot/Swiss-Prot entry holds information on one protein
39 sequence. If that sequence is identical across genes and species, they
40 are all merged into one entry. This creates complex needs for several
41 annotation fields in swiss-prot format.
42  
43 The latest syntax for GN line is described in the user manual:
44  
45 http://www.expasy.ch/sprot/userman.html#GN_line
46  
47 Each of the possibly multiple genes in an entry can have Name,
48 Synonyms (only if there is a name), OrderedLocusNames (names from
49 genomic sequences) and ORFNames (temporary or cosmid names). "Name"
50 here really means "symbol". This complexity is now dealt with the
51 following way:
52  
53 A new Bio::AnnotationI class was created in order to store the
54 data in tag-value pairs. This class (Bio::Annotation::TagTree)
55 is stored in the Bio::Annotation::Collection object and is
56 accessed like all other annotations. The tag name is 'gene_name'.
57  
58 There is a single Bio::Annotation::TagTree per sequence record, which
59 corresponds to the original class that stored this data
60 (Bio::Annotation::StructuredValue). Depending on how we progress
61 this may change to represent each group of gene names.
62  
63 For now, to access the gene name tree annotation, one uses the below method:
64  
65 my ($gene) = $seq->annotation->get_Annotations('gene_name');
66  
67 If you are only interested in displaying the values, value() returns a
68 string with similar formatting.
69  
70 There are several ways to get directly at the information you want if you
71 know the element (tag) for the data. For gene names all data is stored with
72 the element-tag pairs:
73  
74 "element1=tag1, tag2, tag3; element2=tag4, tag5;"
75  
76 This normally means the element will be 'Name', 'Synonyms', etc. and the
77 gene names the values. Using findval(), you can do the following:
78  
79 # grab a flattened list of all gene names
80 my @names = $ann->findval('Name');
81  
82 # or iterated through the nodes and grab the name for each group
83 for my $node ($ann->findnode('gene_name')) {
84 my @names = $node->findval('Name');
85 }
86  
87 The current method for parsing gene name data (and reconstructing gene name
88 output) is very generic. This is somewhat preemptive if, for instance, UniProt
89 decides to update and add another element name to the current ones using the
90 same formatting layout. Under those circumstances, one can iterate through the
91 tag tree in a safe way and retrieve all node data like so.
92  
93 # retrieve the gene name nodes (groups like names, synonyms, etc).
94 for my $ann ($seq->annotation->get_Annotations('gene_name')) {
95  
96 # each gene name group
97 for my $node ($ann->findnode('gene_name')) {
98 print "Gene name:\n";
99  
100 # each gene name node (tag => value pair)
101 for my $n ($node->children) {
102 print "\t".$n->element.": ".$n->children."\n";
103 }
104 }
105 }
106  
107 For more uses see Bio::Annotation::TagTree.
108  
109 Since Uniprot/Swiss-Prot format have been around for quite some time, the
110 parser is also able to read in the older GN line syntax where genes
111 are separated by AND and various symbols by OR. The first symbol is
112 taken to be the 'Name' and the remaining ones are stored as 'Synonyms'.
113  
114 Also, for UniProt output we support using other Bio::AnnotationI, but in this
115 case we only use the stringified version of the annotation. This is to allow for
116 backwards compatibility with code that previously used
117 Bio::Annotation::SimpleValue or other Bio::AnnotationI classes.
118  
119 =head2 Optional functions
120  
121 =over 3
122  
123 =item _show_dna()
124  
125 (output only) shows the dna or not
126  
127 =item _post_sort()
128  
129 (output only) provides a sorting func which is applied to the FTHelpers
130 before printing
131  
132 =item _id_generation_func()
133  
134 This is function which is called as
135  
136 print "ID ", $func($seq), "\n";
137  
138 To generate the ID line. If it is not there, it generates a sensible ID
139 line using a number of tools.
140  
141 If you want to output annotations in Swissprot format they need to be
142 stored in a Bio::Annotation::Collection object which is accessible
143 through the Bio::SeqI interface method L<annotation()|annotation>.
144  
145 The following are the names of the keys which are polled from a
146 L<Bio::Annotation::Collection> object.
147  
148 reference - Should contain Bio::Annotation::Reference objects
149 comment - Should contain Bio::Annotation::Comment objects
150 dblink - Should contain Bio::Annotation::DBLink objects
151 gene_name - Should contain Bio::Annotation::SimpleValue object
152  
153 =back
154  
155 =head1 FEEDBACK
156  
157 =head2 Mailing Lists
158  
159 User feedback is an integral part of the evolution of this
160 and other Bioperl modules. Send your comments and suggestions,
161 preferably to one of the Bioperl mailing lists.
162 Your participation is much appreciated.
163  
164 bioperl-l@bioperl.org - General discussion
165 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
166  
167 =head2 Support
168  
169 Please direct usage questions or support issues to the mailing list:
170  
171 I<bioperl-l@bioperl.org>
172  
173 rather than to the module maintainer directly. Many experienced and
174 reponsive experts will be able look at the problem and quickly
175 address it. Please include a thorough description of the problem
176 with code and data examples if at all possible.
177  
178 =head2 Reporting Bugs
179  
180 Report bugs to the Bioperl bug tracking system to help us keep track
181 the bugs and their resolution.
182 Bug reports can be submitted via the web:
183  
184 https://github.com/bioperl/bioperl-live/issues
185  
186 =head1 AUTHOR - Elia Stupka
187  
188 Email elia@tll.org.sg
189  
190 =head1 APPENDIX
191  
192 The rest of the documentation details each of the object methods.
193 Internal methods are usually preceded with a _
194  
195 =cut
196  
197 # Let the code begin...
198  
199 package Bio::SeqIO::swiss;
200 3 $Bio::SeqIO::swiss::VERSION = '1.7.8';
201 3 ▶use vars qw(@Unknown_names @Unknown_genus);
Subroutine BEGIN: called CC=1 SCAR=0.0
202 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
203 3 ▶use Bio::SeqIO::FTHelper;
Subroutine BEGIN: called CC=1 SCAR=0.0
204 3 ▶use Bio::SeqFeature::Generic;
Subroutine BEGIN: called CC=1 SCAR=0.0
205 3 ▶use Bio::Species;
Subroutine BEGIN: called CC=1 SCAR=0.0
206 3 ▶use Bio::Tools::SeqStats;
Subroutine BEGIN: called CC=1 SCAR=0.0
207 3 ▶use Bio::Seq::SeqFactory;
Subroutine BEGIN: called CC=1 SCAR=0.0
208 3 ▶use Bio::Annotation::Collection;
Subroutine BEGIN: called CC=1 SCAR=0.0
209 3 ▶use Bio::Annotation::Comment;
Subroutine BEGIN: called CC=1 SCAR=0.0
210 3 ▶use Bio::Annotation::Reference;
Subroutine BEGIN: called CC=1 SCAR=0.0
211 3 ▶use Bio::Annotation::DBLink;
Subroutine BEGIN: called CC=1 SCAR=0.0
212 3 ▶use Bio::Annotation::SimpleValue;
Subroutine BEGIN: called CC=1 SCAR=0.0
213 3 ▶use Bio::Annotation::TagTree;
Subroutine BEGIN: called CC=1 SCAR=0.0
214  
215 3 ▶use base qw(Bio::SeqIO);
Subroutine BEGIN: called CC=1 SCAR=0.0
216  
217 3 our $LINE_LENGTH = 76;
218  
219 # this is for doing species name parsing
220 3 @Unknown_names=('other', 'unidentified',
221 'unknown organism', 'not specified',
222 'not shown', 'Unspecified', 'Unknown',
223 'None', 'unclassified', 'unidentified organism',
224 'not supplied'
225 );
226 # dictionary of synonyms for taxid 32644
227 # all above can be part of valid species name
228 3 @Unknown_genus = qw(unknown unclassified uncultured unidentified);
229  
230 # if there are any other gene name tags, they are added to the end
231 3 our @GENE_NAME_ORDER = qw(Name Synonyms OrderedLocusNames ORFNames);
232  
233 18 ▶sub _initialize {
Subroutine _initialize: called CC=2 SCAR=7.0
234 18 my($self,@args) = @_;
235 18 $self->SUPER::_initialize(@args);
236 # hash for functions for decoding keys.
237 18 $self->{'_func_ftunit_hash'} = {};
238 # sets this to one by default. People can change it
239 18 $self->_show_dna(1);
240 18 ▶ if ( ! defined $self->sequence_factory ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->sequence_factory) 18 0 18
241 18 $self->sequence_factory(Bio::Seq::SeqFactory->new
242 (-verbose => $self->verbose(),
243 -type => 'Bio::Seq::RichSeq'));
244 }
245 }
246  
247 =head2 next_seq
248  
249 Title : next_seq
250 Usage : $seq = $stream->next_seq()
251 Function: returns the next sequence in the stream
252 Returns : Bio::Seq object
253 Args :
254  
255 =cut
256  
257 26 ▶sub next_seq {
Subroutine next_seq: called CC=47 SCAR=39.1
Pod documented
258 26 my ($self,@args) = @_;
259 26 my ($pseq,$c,$line,$name,$desc,$acc,$seqc,$mol,$div, $sptr,$seq_div,
260 $date,$comment,@date_arr);
261 26 my $genename = "";
262 26 my ($annotation, %params, @features) = ( Bio::Annotation::Collection->new());
263  
264 26 local $_;
265  
266 26 ▶ 1 while defined($_ = $self->_readline) && /^\s+$/;
Branch: 1 branch
BranchTrueFalseTotal
defined($_ = $self->_readline) and /^\s+$/ and do { '???' } 1 26 27
Condition100%3/3
defined($_ = $self->_readline) and /^\s+$/
!ll&&!rl&&r
4221
MC/DC100%2/2
defined($_ = $self->_readline) and /^\s+$/
defined($_ = $self->_readline) /^\s+$/
Truth table100%3/3
A and B
A= defined($_ = $self->_readline)B= /^\s+$/
ABresult
0X0
100
111
267 26 ▶ return unless defined $_ && /^ID\s/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ and /^ID\s/ 4 22 26
Condition66%2/3
defined $_ and /^ID\s/
!ll&&!rl&&r
4022
MC/DC50%1/2
defined $_ and /^ID\s/
defined $_ /^ID\s/
Truth table66%2/3
A and B
A= defined $_B= /^ID\s/
ABresult
0X0
100
111
268  
269 # fixed to allow _DIVISION to be optional for bug #946
270 # see bug report for more information
271 #
272 # 9/6/06 Note: Swiss/TrEMBL sequences have no division acc. to UniProt
273 # release notes; this is fixed to simplify the regex parsing
274 # STANDARD (SwissProt) and PRELIMINARY (TrEMBL) added to namespace()
275 22 ▶ unless( m{^
Branch: 1 branch
BranchTrueFalseTotal
unless (/^ ID \s+ # (\S+) \s+ # $1 entryname ([^\s;]+); \s+ # $2 DataClass (?:PRT;)? \s+ # Molecule Type (optional) [0-9]+[ ]AA \. # Sequencelength (capture?) $ /ox) 0 22 22
276 ID \s+ #
277 (\S+) \s+ # $1 entryname
278 ([^\s;]+); \s+ # $2 DataClass
279 (?:PRT;)? \s+ # Molecule Type (optional)
280 [0-9]+[ ]AA \. # Sequencelength (capture?)
281 $
282 }ox ) {
283 # I couldn't find any new current UniProt sequences
284 # that matched this format:
285 # || m/^ID\s+(\S+)\s+(_([^\s_]+))? /ox ) {
286 0 $self->throw("swissprot stream with no ID. Not swissprot in my book");
287 }
288 22 ($name, $seq_div) = ($1, $2);
289 22 ▶ $params{'-namespace'} =
Branch: 2 branches
BranchTrueFalseTotal
$seq_div eq 'Reviewed' || $seq_div eq 'STANDARD' ? : 18 4 22
$seq_div eq 'Unreviewed' || $seq_div eq 'PRELIMINARY' ? : 4 0 4
Condition83%5/6
$seq_div eq "Reviewed" or $seq_div eq "STANDARD"
l!l&&r!l&&!r
5134
$seq_div eq "Unreviewed" or $seq_div eq "PRELIMINARY"
l!l&&r!l&&!r
220
MC/DC100%2/2
$seq_div eq "Reviewed" or $seq_div eq "STANDARD"
$seq_div eq "Reviewed" $seq_div eq "STANDARD"
MC/DC0%0/2
$seq_div eq "Unreviewed" or $seq_div eq "PRELIMINARY"
$seq_div eq "Unreviewed" $seq_div eq "PRELIMINARY"
Truth table100%3/3
A or B
A= $seq_div eq "Reviewed"B= $seq_div eq "STANDARD"
ABresult
1X1
011
000
Truth table66%2/3
A or B
A= $seq_div eq "Unreviewed"B= $seq_div eq "PRELIMINARY"
ABresult
1X1
011
000
290 ($seq_div eq 'Reviewed' || $seq_div eq 'STANDARD') ? 'Swiss-Prot' :
291 ($seq_div eq 'Unreviewed' || $seq_div eq 'PRELIMINARY') ? 'TrEMBL' :
292 $seq_div;
293 # we shouldn't be setting the division, but for now...
294 22 my ($junk, $division) = split q(_), $name;
295 22 $params{'-division'} = $division;
296 22 $params{'-alphabet'} = 'protein';
297 # this is important to have the id for display in e.g. FTHelper, otherwise
298 # you won't know which entry caused an error
299 22 $params{'-display_id'} = $name;
300  
301 BEFORE_FEATURE_TABLE :
302 22 ▶ while ( defined($_ = $self->_readline) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 710 0 710
303 # Exit at start of Feature table and at the sequence at the
304 # latest HL 05/11/2000
305 710 ▶ last if( /^(FT|SQ)/ );
Branch: 1 branch
BranchTrueFalseTotal
if /^(FT|SQ)/ 22 688 710
306  
307 # Description line(s)
308 688 ▶ if (/^DE\s+(\S.*\S)/) {
Branch: 10 branches
BranchTrueFalseTotal
if (/^DE\s+(\S.*\S)/) { } 35 653 688
elsif (/^GN\s+(.*)/) { } 27 626 653
elsif (/^AC\s+(.+)/) { } 22 604 626
elsif (/^DT\s+(.*)/) { } 66 538 604
elsif (/^PE\s+(.*)/) { } 1 537 538
elsif (/^O[SCG]/) { } 22 515 537
elsif (/^R/) { } 22 493 515
elsif (/^CC\s{3}(.*)/) { } 22 471 493
elsif (/^DR\s+(\S+)\;\s+(\S+)\;\s+([^;]+)[\;\.](.*)$/) { } 435 36 471
elsif (/^KW\s+(.*)$/) { } 36 0 36
309 35 ▶ $desc .= $desc ? " $1" : $1;
Branch: 1 branch
BranchTrueFalseTotal
$desc ? : 13 22 35
310 }
311 #Gene name
312 elsif (/^GN\s+(.*)/) {
313 27 ▶ $genename .= " " if $genename;
Branch: 1 branch
BranchTrueFalseTotal
if $genename 5 22 27
314 27 $genename .= $1;
315 }
316 #accession number(s)
317 elsif ( /^AC\s+(.+)/) {
318 22 my @accs = split(/[; ]+/, $1); # allow space in addition
319 $params{'-accession_number'} = shift @accs
320 22 ▶ unless defined $params{'-accession_number'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params{"-accession_number"} 22 0 22
321 22 push @{$params{'-secondary_accessions'}}, @accs;
322 }
323 #date and sequence version
324 elsif ( /^DT\s+(.*)/ ) {
325 66 my $line = $1;
326 66 my ($date, $version) = split(' ', $line, 2);
327 66 $date =~ tr/,//d; # remove comma if new version
328 66 ▶ if ($version =~ /\(Rel\. (\d+), Last sequence update\)/ || # old
Branch: 2 branches
BranchTrueFalseTotal
if ($version =~ /\(Rel\. (\d+), Last sequence update\)/ or /sequence version (\d+)/) { } 22 44 66
elsif ($version =~ /\(Rel\. (\d+), Last annotation update\)/ or /entry version (\d+)/) { } 22 22 44
Condition100%3/3
$version =~ /\(Rel\. (\d+), Last sequence update\)/ or /sequence version (\d+)/
l!l&&r!l&&!r
111144
MC/DC100%2/2
$version =~ /\(Rel\. (\d+), Last sequence update\)/ or /sequence version (\d+)/
$version =~ /\(Rel\. (\d+), Last sequence update\)/ /sequence version (\d+)/
Truth table100%3/3
A or B
A= $version =~ /\(Rel\. (\d+), Last sequence update\)/B= /sequence version (\d+)/
ABresult
1X1
011
000
329 /sequence version (\d+)/) { #new
330 22 my $update = Bio::Annotation::SimpleValue->new
331 (-tagname => 'seq_update',
332 -value => $1
333 );
334 22 $annotation->add_Annotation($update);
335 ▶ } elsif ($version =~ /\(Rel\. (\d+), Last annotation update\)/ || #old
Condition100%3/3
$version =~ /\(Rel\. (\d+), Last annotation update\)/ or /entry version (\d+)/
l!l&&r!l&&!r
111122
MC/DC100%2/2
$version =~ /\(Rel\. (\d+), Last annotation update\)/ or /entry version (\d+)/
$version =~ /\(Rel\. (\d+), Last annotation update\)/ /entry version (\d+)/
Truth table100%3/3
A or B
A= $version =~ /\(Rel\. (\d+), Last annotation update\)/B= /entry version (\d+)/
ABresult
1X1
011
000
336 /entry version (\d+)/) { #new
337 22 $params{'-version'} = $1;
338 }
339 66 push @{$params{'-dates'}}, $date;
340 }
341 # Evidence level
342 elsif ( /^PE\s+(.*)/ ) {
343 1 my $line = $1;
344 1 $line =~ s/;\s*//; # trim trailing semicolon and any spaces at the end of the line
345 1 my $evidence = Bio::Annotation::SimpleValue->new
346 (-tagname => 'evidence',
347 -value => $line
348 );
349 1 $annotation->add_Annotation($evidence);
350 }
351 # Organism name and phylogenetic information
352 elsif (/^O[SCG]/) {
353 22 my $species = $self->_read_swissprot_Species($_);
354 22 $params{'-species'}= $species;
355 # now we are one line ahead -- so continue without reading the next
356 # line HL 05/11/2000
357 }
358 # References
359 elsif (/^R/) {
360 22 my $refs = $self->_read_swissprot_References($_);
361 22 foreach my $r (@$refs) {
362 158 $annotation->add_Annotation('reference',$r);
363 }
364 }
365 # Comments
366 elsif (/^CC\s{3}(.*)/) {
367 22 $comment .= $1;
368 22 $comment .= "\n";
369 22 ▶ while (defined ($_ = $self->_readline) && /^CC\s{3}(.*)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline) and /^CC\s{3}(.*)/) 337 22 359
Condition66%2/3
defined($_ = $self->_readline) and /^CC\s{3}(.*)/
!ll&&!rl&&r
022337
MC/DC50%1/2
defined($_ = $self->_readline) and /^CC\s{3}(.*)/
defined($_ = $self->_readline) /^CC\s{3}(.*)/
Truth table66%2/3
A and B
A= defined($_ = $self->_readline)B= /^CC\s{3}(.*)/
ABresult
0X0
100
111
370 337 $comment .= $1 . "\n";
371 }
372  
373 # note: don't try to process comments here -- they may contain
374 # structure. LP 07/30/2000
375  
376 22 my $commobj = Bio::Annotation::Comment->new(-tagname => 'comment',
377 -text => $comment);
378 22 $annotation->add_Annotation('comment',$commobj);
379 22 $comment = "";
380 22 $self->_pushback($_);
381 }
382 #DBLinks
383 # old regexp
384 # /^DR\s+(\S+)\;\s+(\S+)\;\s+(\S+)[\;\.](.*)$/) {
385 # new regexp from Andreas Kahari bug #1584
386 elsif (/^DR\s+(\S+)\;\s+(\S+)\;\s+([^;]+)[\;\.](.*)$/) {
387 435 my ($database,$primaryid,$optional,$comment) = ($1,$2,$3,$4);
388  
389 # drop leading and training spaces and trailing .
390 435 $comment =~ s/\.\s*$//;
391 435 $comment =~ s/^\s+//;
392  
393 435 my $dblinkobj = Bio::Annotation::DBLink->new
394 (-database => $database,
395 -primary_id => $primaryid,
396 -optional_id => $optional,
397 -comment => $comment,
398 -tagname => 'dblink',
399 );
400  
401 435 $annotation->add_Annotation('dblink',$dblinkobj);
402 }
403 #keywords
404 elsif ( /^KW\s+(.*)$/ ) {
405 36 my @kw = split(/\s*\;\s*/,$1);
406 36 ▶ defined $kw[-1] && $kw[-1] =~ s/\.$//;
Branch: 1 branch
BranchTrueFalseTotal
defined $kw[-1] and $kw[-1] =~ s/\.$// 36 0 36
407 36 push @{$params{'-keywords'}}, @kw;
408 }
409 }
410 # process and parse the gene name line if there was one (note: we
411 # can't do this above b/c GN may be multi-line and we can't
412 # unequivocally determine whether we've seen the last GN line in
413 # the new format)
414 22 ▶ if ($genename) {
Branch: 1 branch
BranchTrueFalseTotal
if ($genename) 22 0 22
415 22 my @stags;
416 22 ▶ if ($genename =~ /\w=\w/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($genename =~ /\w=\w/) { } 12 10 22
417 # new format (e.g., Name=RCHY1; Synonyms=ZNF363, CHIMP)
418 12 for my $n (split(m{\s+and\s+},$genename)) {
419 14 my @genenames;
420 14 for my $section (split(m{\s*;\s*},$n)) {
421 19 my ($tag, $rest) = split("=",$section);
422 19 ▶ $rest ||= '';
Condition50%1/2
$rest ||= ""
l!l
190
MC/DC0%0/1
$rest ||= ""
$rest
Truth table50%1/2
A
A= $rest
Aresult
11
00
423 19 for my $val (split(m{\s*,\s*},$rest)) {
424 23 push @genenames, [$tag => $val];
425 }
426 }
427 14 push @stags, ['gene_name' => \@genenames];
428 }
429 } else {
430 # old format
431 10 for my $section (split(/ AND /, $genename)) {
432 12 my @genenames;
433 12 $section =~ s/[\(\)\.]//g;
434 12 my @names = split(m{\s+OR\s+}, $section);
435 12 push @genenames, ['Name' => shift @names];
436 12 push @genenames, map {['Synonyms' => $_]} @names;
437 12 push @stags, ['gene_name' => \@genenames]
438 }
439 } #use Data::Dumper; print Dumper $gn, $genename;# exit;
440 22 my $gn = Bio::Annotation::TagTree->new(-tagname => 'gene_name',
441 -value => ['gene_names' => \@stags]);
442 22 $annotation->add_Annotation('gene_name', $gn);
443 }
444  
445 FEATURE_TABLE :
446 # if there is no feature table, or if we've got beyond, exit loop or don't
447 # even enter HL 05/11/2000
448 22 ▶ while (defined $_ && /^FT/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_ and /^FT/) 391 22 413
Condition66%2/3
defined $_ and /^FT/
!ll&&!rl&&r
022391
MC/DC50%1/2
defined $_ and /^FT/
defined $_ /^FT/
Truth table66%2/3
A and B
A= defined $_B= /^FT/
ABresult
0X0
100
111
449 391 my $ftunit = $self->_read_FTHelper_swissprot($_);
450  
451 # process ftunit
452 # when parsing of the line fails we get undef returned
453 391 ▶ if ($ftunit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ftunit) { } 391 0 391
454 push(@features,
455 $ftunit->_generic_seqfeature($self->location_factory(),
456 391 $params{'-seqid'}, "SwissProt"));
457 } else {
458 $self->warn("failed to parse feature table line for seq " .
459 0 $params{'-display_id'}. "\n$_");
460 }
461 391 $_ = $self->_readline;
462 }
463 22 ▶ while ( defined($_) && ! /^SQ/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_ and not /^SQ/) 0 22 22
Condition33%1/3
defined $_ and not /^SQ/
!ll&&!rl&&r
0220
MC/DC0%0/2
defined $_ and not /^SQ/
defined $_ not /^SQ/
Truth table33%1/3
A and not(B)
A= defined $_B= not /^SQ/
ABresult
0X0
100
111
464 0 $_ = $self->_readline;
465 }
466 22 $seqc = "";
467 22 ▶ while ( defined ($_ = $self->_readline) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline)) 175 0 175
468 175 ▶ last if m{^//};
Branch: 1 branch
BranchTrueFalseTotal
if m[^//] 22 153 175
469 153 s/[^A-Za-z]//g;
470 153 $seqc .= uc($_);
471 }
472  
473 22 my $seq= $self->sequence_factory->create
474 (-verbose => $self->verbose,
475 %params,
476 -seq => $seqc,
477 -desc => $desc,
478 -features => \@features,
479 -annotation => $annotation,
480 );
481  
482 # The annotation doesn't get added by the constructor
483 22 $seq->annotation($annotation);
484  
485 22 return $seq;
486 }
487  
488 =head2 write_seq
489  
490 Title : write_seq
491 Usage : $stream->write_seq($seq)
492 Function: writes the $seq object (must be seq) to the stream
493 Returns : 1 for success and 0 for error
494 Args : array of 1 to n Bio::SeqI objects
495  
496  
497 =cut
498  
499 3 ▶sub write_seq {
Subroutine write_seq: called CC=82 SCAR=57.3
Pod documented
500 3 my ($self,@seqs) = @_;
501 3 foreach my $seq ( @seqs ) {
502 3 ▶ $self->throw("Attempting to write with no seq!") unless defined $seq;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seq 0 3 3
503  
504 3 ▶ if ( ! ref $seq || ! $seq->isa('Bio::SeqI') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $seq and $seq->isa("Bio::SeqI")) 0 3 3
Condition33%1/3
ref $seq and $seq->isa("Bio::SeqI")
!ll&&!rl&&r
003
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
505 0 $self->warn(" $seq is not a SeqI compliant module. Attempting to dump, but may fail!");
506 }
507  
508 3 my $i;
509 3 my $str = $seq->seq;
510  
511 3 my $div;
512 3 ▶ my $ns = ($seq->can('namespace')) && $seq->namespace();
Condition66%2/3
$seq->can('namespace') && $seq->namespace
!ll&&!rl&&r
012
MC/DC50%1/2
$seq->can('namespace') && $seq->namespace
$seq->can('namespace') $seq->namespace
Truth table66%2/3
A && B
A= $seq->can('namespace')B= $seq->namespace
ABresult
0X0
100
111
513 3 my $len = $seq->length();
514  
515 3 ▶ if ( !$seq->can('division') || ! defined ($div = $seq->division()) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($seq->can("division") and defined($div = $seq->division)) 1 2 3
Condition66%2/3
$seq->can("division") and defined($div = $seq->division)
!ll&&!rl&&r
102
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
516 1 $div = 'UNK';
517 }
518  
519 # namespace dictates database, takes precedent over division. Sorry!
520 3 ▶ if (defined($ns) && $ns ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ns and $ns ne '') { } 2 1 3
Condition66%2/3
defined $ns and $ns ne ""
!ll&&!rl&&r
012
MC/DC50%1/2
defined $ns and $ns ne ""
defined $ns $ns ne ""
Truth table66%2/3
A and B
A= defined $nsB= $ns ne ""
ABresult
0X0
100
111
521 2 ▶ $div = ($ns eq 'Swiss-Prot') ? 'Reviewed' :
Branch: 2 branches
BranchTrueFalseTotal
$ns eq 'Swiss-Prot' ? : 2 0 2
$ns eq 'TrEMBL' ? : 0 0 0
522 ($ns eq 'TrEMBL') ? 'Unreviewed' :
523 $ns;
524 } else {
525 1 $ns = 'Swiss-Prot';
526 # division not reset; acts as fallback
527 }
528  
529 3 ▶ $self->warn("No whitespace allowed in SWISS-PROT display id [". $seq->display_id. "]")
Branch: 1 branch
BranchTrueFalseTotal
if $seq->display_id =~ /\s/ 0 3 3
530 if $seq->display_id =~ /\s/;
531  
532 3 my $temp_line;
533 3 ▶ if ( $self->_id_generation_func ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_id_generation_func) { } 0 3 3
534 0 $temp_line = &{$self->_id_generation_func}($seq);
535 } else {
536 #$temp_line = sprintf ("%10s STANDARD; %3s; %d AA.",
537 # $seq->primary_id()."_".$div,$mol,$len);
538 # Reconstructing the ID relies heavily upon the input source having
539 # been in a format that is parsed as this routine expects it -- that is,
540 # by this module itself. This is bad, I think, and immediately breaks
541 # if e.g. the Bio::DB::GenPept module is used as input.
542 # Hence, switch to display_id(); _every_ sequence is supposed to have
543 # this. HL 2000/09/03
544 # Changed to reflect ID line changes in UniProt
545 # Oct 2006 - removal of molecule type - see bug 2134
546 3 $temp_line = sprintf ("%-24s%-12s%9d AA.",
547 $seq->display_id(), $div.';', $len);
548 }
549  
550 3 $self->_print( "ID $temp_line\n");
551  
552 # if there, write the accession line
553 3 local($^W) = 0; # suppressing warnings about uninitialized fields
554  
555 3 ▶ if ( $self->_ac_generation_func ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_ac_generation_func) { } 0 3 3
elsif ($seq->can('accession_number')) { } 3 0 3
556 0 $temp_line = &{$self->_ac_generation_func}($seq);
557 0 $self->_print( "AC $temp_line\n");
558 }
559 elsif ($seq->can('accession_number') ) {
560 3 my $ac_line = $seq->accession_number;
561 3 ▶ if ($seq->can('get_secondary_accessions') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq->can("get_secondary_accessions")) 2 1 3
562 2 foreach my $sacc ($seq->get_secondary_accessions) {
563 0 $ac_line .= "; ". $sacc;;
564 }
565 2 $ac_line .= ";";
566 }
567  
568 3 $self->_write_line_swissprot_regex("AC ","AC ",$ac_line,
569 "\\s\+\|\$",$LINE_LENGTH);
570 }
571 # otherwise - cannot print <sigh>
572  
573  
574 # Date lines and sequence versions (changed 6/15/2006)
575 # This is rebuilt from scratch using the current SwissProt/UniProt format
576 3 ▶ if ( $seq->can('get_dates') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq->can("get_dates")) 2 1 3
577 2 my @dates = $seq->get_dates();
578 2 my $ct = 1;
579 2 my $seq_version = $seq->version;
580 2 my ($update_version) = $seq->annotation->get_Annotations("seq_update");
581 2 foreach my $dt (@dates) {
582 6 ▶ $self->_write_line_swissprot_regex("DT ","DT ",
Branch: 1 branch
BranchTrueFalseTotal
if $ct == 1 2 4 6
583 $dt.', integrated into UniProtKB/'.$ns.'.',
584 "\\s\+\|\$",$LINE_LENGTH) if $ct == 1;
585 6 ▶ $self->_write_line_swissprot_regex("DT ","DT ",
Branch: 1 branch
BranchTrueFalseTotal
if $ct == 2 2 4 6
586 $dt.", sequence version ".$update_version->display_text.'.',
587 "\\s\+\|\$",$LINE_LENGTH) if $ct == 2;
588 6 ▶ $self->_write_line_swissprot_regex("DT ","DT ",
Branch: 1 branch
BranchTrueFalseTotal
if $ct == 3 2 4 6
589 $dt.", entry version $seq_version.",
590 "\\s\+\|\$",$LINE_LENGTH) if $ct == 3;
591 6 $ct++;
592 }
593 }
594  
595 #Definition lines
596 3 $self->_write_line_swissprot_regex("DE ","DE ",$seq->desc(),"\\s\+\|\$",$LINE_LENGTH);
597  
598 #Gene name; print out new format
599 3 foreach my $gene ( my @genes = $seq->annotation->get_Annotations('gene_name') ) {
600 # gene is a Bio::Annotation::TagTree;
601 2 ▶ if ($gene->isa('Bio::Annotation::TagTree')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gene->isa('Bio::Annotation::TagTree')) { } 2 0 2
602 2 my @genelines;
603 2 for my $node ($gene->findnode('gene_name')) {
604 # check for Name and Synonym first, then the rest get tagged on
605 2 my $geneline = "GN ";
606 2 my %genedata = $node->hash;
607 2 for my $tag (@GENE_NAME_ORDER) {
608 8 ▶ if (exists $genedata{$tag}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $genedata{$tag}) 2 6 8
609 $geneline .= (ref $genedata{$tag} eq 'ARRAY') ?
610 0 ▶ "$tag=".join(', ',@{$genedata{$tag}})."; " :
Branch: 1 branch
BranchTrueFalseTotal
ref $genedata{$tag} eq 'ARRAY' ? : 0 2 2
611 "$tag=$genedata{$tag}; ";
612 2 delete $genedata{$tag};
613 }
614 }
615 # add rest
616 2 for my $tag (sort keys %genedata) {
617 $geneline .= (ref $genedata{$tag} eq 'ARRAY') ?
618 0 ▶ "$tag=".join(', ',@{$genedata{$tag}})."; " :
Branch: 1 branch
BranchTrueFalseTotal
ref $genedata{$tag} eq 'ARRAY' ? : 0 0 0
619 "$tag=$genedata{$tag}; ";
620 0 delete $genedata{$tag};
621 }
622 2 push @genelines, "$geneline\n";
623 }
624 2 $self->_print(join("GN and\n",@genelines));
625 } else { # fall back to getting stringified output
626 0 $self->_write_line_swissprot_regex("GN ","GN ",
627 $gene->display_text,
628 "\\s\+\|\$",
629 $LINE_LENGTH);
630 }
631 }
632  
633 # Organism lines
634 3 ▶ if ($seq->can('species') && (my $spec = $seq->species)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seq->can("species") and my $spec = $seq->species) 2 1 3
Condition66%2/3
$seq->can("species") and my $spec = $seq->species
!ll&&!rl&&r
012
MC/DC50%1/2
$seq->can("species") and my $spec = $seq->species
$seq->can("species") my $spec = $seq->species
Truth table66%2/3
A and B
A= $seq->can("species")B= my $spec = $seq->species
ABresult
0X0
100
111
635 2 my @class = $spec->classification();
636 2 shift(@class);
637 2 my $species = $spec->species;
638 2 my $genus = $spec->genus;
639 2 my $OS = $spec->scientific_name;
640 2 ▶ if ($class[-1] =~ /viruses/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class[-1] =~ /viruses/i) 0 2 2
641 0 $OS = $species;
642 0 ▶ $OS .= " ". $spec->sub_species if $spec->sub_species;
Branch: 1 branch
BranchTrueFalseTotal
if $spec->sub_species 0 0 0
643 }
644 2 foreach (($spec->variant, $spec->common_name)) {
645 2 ▶ $OS .= " ($_)" if $_;
Branch: 1 branch
BranchTrueFalseTotal
if $_ 0 2 2
646 }
647 2 $self->_print( "OS $OS.\n");
648 2 my $OC = join('; ', reverse(@class)) .'.';
649 2 $self->_write_line_swissprot_regex("OC ","OC ",$OC,"\; \|\$",$LINE_LENGTH);
650 2 ▶ if ($spec->organelle) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->organelle) 0 2 2
651 0 $self->_write_line_swissprot_regex("OG ","OG ",$spec->organelle,"\; \|\$",$LINE_LENGTH);
652 }
653 2 ▶ if ($spec->ncbi_taxid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->ncbi_taxid) 2 0 2
654 2 $self->_print("OX NCBI_TaxID=".$spec->ncbi_taxid.";\n");
655 }
656 }
657  
658 # Reference lines
659 3 my $t = 1;
660 3 foreach my $ref ( $seq->annotation->get_Annotations('reference') ) {
661 2 $self->_print( "RN [$t]\n");
662 # changed by lorenz 08/03/00
663 # j.gilbert and h.lapp agreed that the rp line in swissprot seems
664 # more like a comment than a parseable value, so print it as is
665 2 ▶ if ($ref->rp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref->rp) 2 0 2
666 2 $self->_write_line_swissprot_regex("RP ","RP ",$ref->rp,
667 "\\s\+\|\$",$LINE_LENGTH);
668 }
669 2 ▶ if ($ref->comment) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref->comment) 1 1 2
670 1 $self->_write_line_swissprot_regex("RC ","RC ",$ref->comment,
671 "\\s\+\|\$",$LINE_LENGTH);
672 }
673 2 ▶ if ($ref->medline or $ref->pubmed or $ref->doi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref->medline or $ref->pubmed or $ref->doi) 0 2 2
Condition33%2/6
$ref->medline or $ref->pubmed or $ref->doi
l!l&&r!l&&!r
002
$ref->medline or $ref->pubmed
l!l&&r!l&&!r
002
MC/DC0%0/3
$ref->medline or $ref->pubmed or $ref->doi
$ref->medline $ref->pubmed $ref->doi
Truth table25%1/4
A or B or C
A= $ref->medlineB= $ref->pubmedC= $ref->doi
ABCresult
1XX1
01X1
0011
0000
674 # new RX format in swissprot LP 09/17/00
675 # RX line can now have a DOI, Heikki 13 Feb 2008
676  
677 0 my $line;
678 0 ▶ $line .= "MEDLINE=". $ref->medline. '; ' if $ref->medline;
Branch: 1 branch
BranchTrueFalseTotal
if $ref->medline 0 0 0
679 0 ▶ $line .= "PubMed=". $ref->pubmed. '; ' if $ref->pubmed;
Branch: 1 branch
BranchTrueFalseTotal
if $ref->pubmed 0 0 0
680 0 ▶ $line .= "DOI=". $ref->doi. '; ' if $ref->doi;
Branch: 1 branch
BranchTrueFalseTotal
if $ref->doi 0 0 0
681 0 chop $line;
682  
683 0 $self->_write_line_swissprot_regex("RX ","RX ",
684 $line,
685 "\\s\+\|\$",$LINE_LENGTH);
686  
687 }
688 2 ▶ my $author = $ref->authors .';' if($ref->authors);
Branch: 1 branch
BranchTrueFalseTotal
if $ref->authors 2 0 2
689 2 ▶ my $title = $ref->title .';' if( $ref->title);
Branch: 1 branch
BranchTrueFalseTotal
if $ref->title 0 2 2
690 2 ▶ my $rg = $ref->rg . ';' if $ref->rg;
Branch: 1 branch
BranchTrueFalseTotal
if $ref->rg 0 2 2
691 2 $author =~ s/([\w\.]) (\w)/$1#$2/g; # add word wrap protection char '#'
692  
693 2 ▶ $self->_write_line_swissprot_regex("RG ","RG ",$rg,"\\s\+\|\$",$LINE_LENGTH) if $rg;
Branch: 1 branch
BranchTrueFalseTotal
if $rg 0 2 2
694 2 ▶ $self->_write_line_swissprot_regex("RA ","RA ",$author,"\\s\+\|\$",$LINE_LENGTH) if $author;
Branch: 1 branch
BranchTrueFalseTotal
if $author 2 0 2
695 2 ▶ $self->_write_line_swissprot_regex("RT ","RT ",$title,'[\s\-]+|$',$LINE_LENGTH) if $title;
Branch: 1 branch
BranchTrueFalseTotal
if $title 0 2 2
696 2 $self->_write_line_swissprot_regex("RL ","RL ",$ref->location,"\\s\+\|\$",$LINE_LENGTH);
697 2 $t++;
698 }
699  
700 # Comment lines
701  
702 3 foreach my $comment ( $seq->annotation->get_Annotations('comment') ) {
703 2 foreach my $cline (split ("\n", $comment->text)) {
704 32 ▶ while (length $cline > 74) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $cline > 74) 0 32 32
705 0 $self->_print("CC ",(substr $cline,0,74),"\n");
706 0 $cline = substr $cline,74;
707 }
708 32 $self->_print("CC ",$cline,"\n");
709 }
710 }
711  
712 # Database xref lines
713  
714 3 foreach my $dblink ( $seq->annotation->get_Annotations('dblink') ) {
715 18 my ($primary_id) = $dblink->primary_id;
716
717 18 ▶ if (defined($dblink->comment) && ($dblink->comment) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $dblink->comment and $dblink->comment) { } 6 12 18
elsif ($dblink->optional_id) { } 12 0 12
Condition66%2/3
defined $dblink->comment and $dblink->comment
!ll&&!rl&&r
1206
MC/DC50%1/2
defined $dblink->comment and $dblink->comment
defined $dblink->comment $dblink->comment
Truth table66%2/3
A and B
A= defined $dblink->commentB= $dblink->comment
ABresult
0X0
100
111
718 6 $self->_print("DR ",$dblink->database,"; ",$primary_id,"; ",
719 $dblink->optional_id,"; ",$dblink->comment,".\n");
720 } elsif ($dblink->optional_id) {
721 12 $self->_print("DR ",$dblink->database,"; ",
722 $primary_id,"; ",
723 $dblink->optional_id,".\n");
724 } else {
725 0 $self->_print("DR ",$dblink->database,
726 "; ",$primary_id,"; ","-.\n");
727 }
728 }
729  
730 # Evidence lines
731  
732 3 foreach my $evidence ( $seq->annotation->get_Annotations('evidence') ) {
733 0 $self->_print("PE ",$evidence->value,";\n");
734 }
735  
736 # if there, write the kw line
737 {
738 3 my $kw;
739 3 ▶ if ( my $func = $self->_kw_generation_func ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $func = $self->_kw_generation_func) { } 0 3 3
elsif ($seq->can('keywords')) { } 2 1 3
740 0 $kw = &{$func}($seq);
741 } elsif ( $seq->can('keywords') ) {
742 2 $kw = $seq->keywords;
743 2 ▶ if ( ref($kw) =~ /ARRAY/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($kw) =~ /ARRAY/i) 0 2 2
744 0 $kw = join("; ", @$kw);
745 }
746 2 ▶ $kw .= '.' if $kw and $kw !~ /\.$/ ;
Branch: 1 branch
BranchTrueFalseTotal
if $kw and not $kw =~ /\.$/ 2 0 2
Condition33%1/3
$kw and not $kw =~ /\.$/
!ll&&!rl&&r
002
MC/DC0%0/2
$kw and not $kw =~ /\.$/
$kw not $kw =~ /\.$/
Truth table33%1/3
A and not(B)
A= $kwB= not $kw =~ /\.$/
ABresult
0X0
100
111
747 }
748 3 $kw =~ s/([\w\.]) (\w)/$1#$2/g; # add word wrap protection char '#'
749 3 ▶ $self->_write_line_swissprot_regex("KW ","KW ",
Branch: 1 branch
BranchTrueFalseTotal
if $kw 2 1 3
750 $kw, "\\s\+\|\$",$LINE_LENGTH)
751 if $kw;
752 }
753  
754 #Check if there is seqfeatures before printing the FT line
755 3 ▶ my @feats = $seq->can('top_SeqFeatures') ? $seq->top_SeqFeatures : ();
Branch: 1 branch
BranchTrueFalseTotal
$seq->can('top_SeqFeatures') ? : 3 0 3
756 3 ▶ if ($feats[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($feats[0]) 2 1 3
757 2 ▶ if ( defined $self->_post_sort ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->_post_sort) { } 0 2 2
758  
759 # we need to read things into an array. Process. Sort them. Print 'em
760  
761 0 my $post_sort_func = $self->_post_sort();
762 0 my @fth;
763  
764 0 foreach my $sf ( @feats ) {
765 0 push(@fth,Bio::SeqIO::FTHelper::from_SeqFeature($sf,$seq));
766 }
767 0 @fth = sort { &$post_sort_func($a,$b) } @fth;
768  
769 0 foreach my $fth ( @fth ) {
770 0 $self->_print_swissprot_FTHelper($fth);
771 }
772 } else {
773 # not post sorted. And so we can print as we get them.
774 # lower memory load...
775  
776 2 foreach my $sf ( @feats ) {
777 6 my @fth = Bio::SeqIO::FTHelper::from_SeqFeature($sf,$seq);
778 6 foreach my $fth ( @fth ) {
779 6 ▶ if ( ! $fth->isa('Bio::SeqIO::FTHelper') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fth->isa("Bio::SeqIO::FTHelper")) 0 6 6
780 0 $sf->throw("Cannot process FTHelper... $fth");
781 }
782 6 $self->_print_swissprot_FTHelper($fth);
783 }
784 }
785 }
786  
787 2 ▶ if ( $self->_show_dna() == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_show_dna == 0) 0 2 2
788 0 return;
789 }
790 }
791 # finished printing features.
792  
793 # molecular weight
794 3 my $mw = ${Bio::Tools::SeqStats->get_mol_wt($seq->primary_seq)}[0];
795 # checksum
796 # was crc32 checksum, changed it to crc64
797 3 my $crc64 = $self->_crc64(\$str);
798 3 $self->_print( sprintf("SQ SEQUENCE %4d AA; %d MW; %16s CRC64;\n",
799 $len,$mw,$crc64));
800 3 $self->_print( " ");
801 3 my $linepos;
802 3 ▶ for ($i = 0; $i < length($str); $i += 10) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $str) 123 3 126
803 123 $self->_print( " ", substr($str,$i,10));
804 123 $linepos += 11;
805 123 ▶ if ( ($i+10)%60 == 0 && (($i+10) < length($str))) {
Branch: 1 branch
BranchTrueFalseTotal
if (($i + 10) % 60 == 0 and $i + 10 < length $str) 18 105 123
Condition66%2/3
($i + 10) % 60 == 0 and $i + 10 < length $str
!ll&&!rl&&r
105018
MC/DC50%1/2
($i + 10) % 60 == 0 and $i + 10 < length $str
($i + 10) % 60 == 0 $i + 10 < length $str
Truth table66%2/3
A and B
A= ($i + 10) % 60 == 0B= $i + 10 < length $str
ABresult
0X0
100
111
806 18 $self->_print( "\n ");
807 }
808 }
809 3 $self->_print( "\n//\n");
810  
811 3 ▶ $self->flush if $self->_flush_on_write && defined $self->_fh;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_flush_on_write and defined $self->_fh 3 0 3
Condition33%1/3
$self->_flush_on_write and defined $self->_fh
!ll&&!rl&&r
003
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
812 3 return 1;
813 }
814 }
815  
816 # Thanks to James Gilbert for the following two. LP 08/01/2000
817  
818 =head2 _generateCRCTable
819  
820 Title : _generateCRCTable
821 Usage :
822 Function:
823 Example :
824 Returns :
825 Args :
826  
827  
828 =cut
829  
830 0 ▶sub _generateCRCTable {
Subroutine _generateCRCTable: not called CC=4 SCAR=30.0
831 # 10001000001010010010001110000100
832 # 32
833 0 my $poly = 0xEDB88320;
834 0 my ($self) = shift;
835  
836 0 $self->{'_crcTable'} = [];
837 0 foreach my $i (0..255) {
838 0 my $crc = $i;
839 0 ▶ for (my $j=8; $j > 0; $j--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j > 0) 0 0 0
840 0 ▶ if ($crc & 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($crc & 1) { } 0 0 0
841 0 $crc = ($crc >> 1) ^ $poly;
842 } else {
843 0 $crc >>= 1;
844 }
845 }
846 0 ${$self->{'_crcTable'}}[$i] = $crc;
847 }
848 }
849  
850  
851 =head2 _crc32
852  
853 Title : _crc32
854 Usage :
855 Function:
856 Example :
857 Returns :
858 Args :
859  
860  
861 =cut
862  
863 0 ▶sub _crc32 {
Subroutine _crc32: not called CC=4 SCAR=30.0
864 0 my( $self, $str ) = @_;
865  
866 0 ▶ $self->throw("Argument to crc32() must be ref to scalar")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $str eq "SCALAR" 0 0 0
867 unless ref($str) eq 'SCALAR';
868  
869 0 ▶ $self->_generateCRCTable() unless exists $self->{'_crcTable'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_crcTable"} 0 0 0
870  
871 0 my $len = length($$str);
872  
873 0 my $crc = 0xFFFFFFFF;
874 0 ▶ for (my $i = 0; $i < $len; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $len) 0 0 0
875 # Get upper case value of each letter
876 0 my $int = ord uc substr $$str, $i, 1;
877 $crc = (($crc >> 8) & 0x00FFFFFF) ^
878 0 ${$self->{'_crcTable'}}[ ($crc ^ $int) & 0xFF ];
879 }
880 0 return $crc;
881 }
882  
883 =head2 _crc64
884  
885 Title : _crc64
886 Usage :
887 Function:
888 Example :
889 Returns :
890 Args :
891  
892  
893 =cut
894  
895 3 ▶sub _crc64{
Subroutine _crc64: called CC=7 SCAR=19.5
896 3 my ($self, $sequence) = @_;
897 3 my $POLY64REVh = 0xd8000000;
898 3 my @CRCTableh = 256;
899 3 my @CRCTablel = 256;
900 3 my $initialized;
901  
902 3 my $seq = $$sequence;
903  
904 3 my $crcl = 0;
905 3 my $crch = 0;
906 3 ▶ if (!$initialized) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($initialized) 3 0 3
907 3 $initialized = 1;
908 3 ▶ for (my $i=0; $i<256; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 256) 768 3 771
909 768 my $partl = $i;
910 768 my $parth = 0;
911 768 ▶ for (my $j=0; $j<8; $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < 8) 6144 768 6912
912 6144 my $rflag = $partl & 1;
913 6144 $partl >>= 1;
914 6144 ▶ $partl |= (1 << 31) if $parth & 1;
Branch: 1 branch
BranchTrueFalseTotal
if $parth & 1 0 6144 6144
915 6144 $parth >>= 1;
916 6144 ▶ $parth ^= $POLY64REVh if $rflag;
Branch: 1 branch
BranchTrueFalseTotal
if $rflag 3072 3072 6144
917 }
918 768 $CRCTableh[$i] = $parth;
919 768 $CRCTablel[$i] = $partl;
920 }
921 }
922  
923 3 foreach (split '', $seq) {
924 1227 my $shr = ($crch & 0xFF) << 24;
925 1227 my $temp1h = $crch >> 8;
926 1227 my $temp1l = ($crcl >> 8) | $shr;
927 1227 my $tableindex = ($crcl ^ (unpack "C", $_)) & 0xFF;
928 1227 $crch = $temp1h ^ $CRCTableh[$tableindex];
929 1227 $crcl = $temp1l ^ $CRCTablel[$tableindex];
930 }
931 3 my $crc64 = sprintf("%08X%08X", $crch, $crcl);
932 3 return $crc64;
933 }
934  
935 =head2 _print_swissprot_FTHelper
936  
937 Title : _print_swissprot_FTHelper
938 Usage :
939 Function:
940 Example :
941 Returns :
942 Args :
943  
944  
945 =cut
946  
947 6 ▶sub _print_swissprot_FTHelper {
Subroutine _print_swissprot_FTHelper: called CC=15 SCAR=34.7
948 6 my ($self,$fth,$always_quote) = @_;
949 6 ▶ $always_quote ||= 0;
Condition50%1/2
$always_quote ||= 0
l!l
06
MC/DC0%0/1
$always_quote ||= 0
$always_quote
Truth table50%1/2
A
A= $always_quote
Aresult
11
00
950 6 my ($start,$end) = ('?', '?');
951  
952 6 ▶ if ( ! ref $fth || ! $fth->isa('Bio::SeqIO::FTHelper') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $fth and $fth->isa("Bio::SeqIO::FTHelper")) 0 6 6
Condition33%1/3
ref $fth and $fth->isa("Bio::SeqIO::FTHelper")
!ll&&!rl&&r
006
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
953 0 $fth->warn("$fth is not a FTHelper class. ".
954 "Attempting to print, but there could be tears!");
955 }
956 6 my $desc = "";
957  
958 6 for my $tag ( qw(description gene note product) ) {
959 6 ▶ if ( exists $fth->field->{$tag} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $fth->field->{$tag}) 6 0 6
960 6 $desc = @{$fth->field->{$tag}}[0].".";
961 6 last;
962 }
963 }
964 6 $desc =~ s/\.$//;
965  
966 6 my $ftid = "";
967 6 ▶ if ( exists $fth->field->{'FTId'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $fth->field->{"FTId"}) 0 6 6
968 0 $ftid = @{$fth->field->{'FTId'}}[0]. '.';
969 }
970  
971 6 my $key =substr($fth->key,0,8);
972 6 my $loc = $fth->loc;
973 6 ▶ if ( $loc =~ /(\?|\d+|\>\d+|<\d+)?\.\.(\?|\d+|<\d+|>\d+)?/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($loc =~ /(\?|\d+|\>\d+|<\d+)?\.\.(\?|\d+|<\d+|>\d+)?/) { } 4 2 6
elsif ($loc =~ /join\((\d+)((?:,\d+)+)?\)/) { } 0 2 2
974 4 ▶ $start = $1 if defined $1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $1 4 0 4
975 4 ▶ $end = $2 if defined $2;
Branch: 1 branch
BranchTrueFalseTotal
if defined $2 4 0 4
976  
977 # to_FTString only returns one value when start == end, #JB955
978 # so if no match is found, assume it is both start and end #JB955
979 } elsif ( $loc =~ /join\((\d+)((?:,\d+)+)?\)/) {
980 0 my @y = ($1);
981 0 ▶ if ( defined( my $m = $2) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $m = $2)) 0 0 0
982 0 $m =~ s/^\,//;
983 0 push @y, split(/,/,$m);
984 }
985 0 for my $x ( @y ) {
986 0 $self->_write_line_swissprot_regex(
987 sprintf("FT %-8s %6s %6s ",
988 $key,
989 $x ,$x),
990 "FT ",
991 $desc.'.','\s+|$',$LINE_LENGTH);
992 }
993 0 return;
994 } else {
995 2 $start = $end = $fth->loc;
996 }
997 6 ▶ if ($desc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc) { } 6 0 6
998 6 $self->_write_line_swissprot_regex(sprintf("FT %-8s %6s %6s ",
999 $key,
1000 $start ,$end),
1001 "FT ",
1002 $desc. '.', '\s+|$', $LINE_LENGTH);
1003 } else { #HELIX and STRAND do not have descriptions
1004 0 $self->_write_line_swissprot_regex(sprintf("FT %-8s %6s %6s",
1005 $key,
1006 $start ,$end),
1007 "FT ",
1008 ' ', '\s+|$', $LINE_LENGTH);
1009 }
1010  
1011  
1012 6 ▶ if ($ftid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ftid) 0 6 6
1013 0 $self->_write_line_swissprot_regex("FT ",
1014 "FT ",
1015 "/FTId=$ftid",'.|$',$LINE_LENGTH);
1016  
1017 }
1018  
1019 }
1020 #'
1021  
1022 =head2 _read_swissprot_References
1023  
1024 Title : _read_swissprot_References
1025 Usage :
1026 Function: Reads references from swissprot format. Internal function really
1027 Example :
1028 Returns :
1029 Args :
1030  
1031  
1032 =cut
1033  
1034 22 ▶sub _read_swissprot_References{
Subroutine _read_swissprot_References: called CC=27 SCAR=33.0
1035 22 my ($self,$line) = @_;
1036 22 my ($b1, $b2, $rp, $rg, $title, $loc, $au, $med, $com, $pubmed, $doi);
1037 22 my @refs;
1038 22 local $_ = $line;
1039 22 ▶ while ( defined $_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_) 1273 0 1273
1040 1273 ▶ if ( /^[^R]/ || /^RN/ ) {
Branch: 9 branches
BranchTrueFalseTotal
if (/^[^R]/ or /^RN/) { } 180 1093 1273
elsif (/^RP\s{3}(.+? OF (\d+)-(\d+).*)/) { } 23 1070 1093
elsif (/^RP\s{3}(.*)/) { } 141 929 1070
elsif (/^RX\s{3}(.*)/) { } 124 805 929
elsif (/^RA\s{3}(.*)/) { } 282 523 805
elsif (/^RG\s{3}(.*)/) { } 16 507 523
elsif (/^RT\s{3}(.*)/) { } 266 241 507
elsif (/^RL\s{3}(.*)/) { } 158 83 241
elsif (/^RC\s{3}(.*)/) { } 83 0 83
Condition100%3/3
/^[^R]/ or /^RN/
l!l&&r!l&&!r
221581093
MC/DC100%2/2
/^[^R]/ or /^RN/
/^[^R]/ /^RN/
Truth table100%3/3
A or B
A= /^[^R]/B= /^RN/
ABresult
1X1
011
000
1041 180 ▶ if ( $rp ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rp) 158 22 180
1042 158 ▶ $rg =~ s/;\s*$//g if defined($rg);
Branch: 1 branch
BranchTrueFalseTotal
if defined $rg 16 142 158
1043 158 ▶ if (defined($au)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $au) { } 154 4 158
1044 154 $au =~ s/;\s*$//;
1045 } else {
1046 4 $au = $rg;
1047 }
1048 158 ▶ $title =~ s/;\s*$//g if defined($title);
Branch: 1 branch
BranchTrueFalseTotal
if defined $title 142 16 158
1049 158 push @refs, Bio::Annotation::Reference->new
1050 (-title => $title,
1051 -start => $b1,
1052 -end => $b2,
1053 -authors => $au,
1054 -location=> $loc,
1055 -medline => $med,
1056 -pubmed => $pubmed,
1057 -doi => $doi,
1058 -comment => $com,
1059 -rp => $rp,
1060 -rg => $rg,
1061 -tagname => 'reference',
1062 );
1063 # reset state for the next reference
1064 158 $rp = '';
1065 }
1066 180 ▶ if (index($_,'R') != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($_, "R") != 0) 22 158 180
1067 22 $self->_pushback($_); # want this line to go back on the list
1068 22 last; # may be the safest exit point HL 05/11/2000
1069 }
1070 # don't forget to reset the state for the next reference
1071 158 $b1 = $b2 = $rg = $med = $com = $pubmed = $doi = undef;
1072 158 $title = $loc = $au = undef;
1073 } elsif ( /^RP\s{3}(.+? OF (\d+)-(\d+).*)/) {
1074 23 $rp .= $1;
1075 23 $b1 = $2;
1076 23 $b2 = $3;
1077 } elsif ( /^RP\s{3}(.*)/) {
1078 141 ▶ if ($rp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rp) { } 6 135 141
1079 6 $rp .= " ".$1;
1080 } else {
1081 135 $rp = $1;
1082 }
1083 } elsif (/^RX\s{3}(.*)/) { # each reference can have only one RX line
1084 124 my $line = $1;
1085 124 ▶ $med = $1 if $line =~ /MEDLINE=(\d+);/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /MEDLINE=(\d+);/ 104 20 124
1086 124 ▶ $pubmed = $1 if $line =~ /PubMed=(\d+);/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /PubMed=(\d+);/ 114 10 124
1087 124 ▶ $doi = $1 if $line =~ /DOI=(.+);/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /DOI=(.+);/ 13 111 124
1088 } elsif ( /^RA\s{3}(.*)/ ) {
1089 282 ▶ $au .= $au ? " $1" : $1;
Branch: 1 branch
BranchTrueFalseTotal
$au ? : 128 154 282
1090 } elsif ( /^RG\s{3}(.*)/ ) {
1091 16 ▶ $rg .= $rg ? " $1" : $1;
Branch: 1 branch
BranchTrueFalseTotal
$rg ? : 0 16 16
1092 } elsif ( /^RT\s{3}(.*)/ ) {
1093 266 ▶ if ($title) {
Branch: 1 branch
BranchTrueFalseTotal
if ($title) { } 124 142 266
1094 124 my $tline = $1;
1095 124 ▶ $title .= ($title =~ /[\w;,:\?!]$/) ? " $tline" : $tline;
Branch: 1 branch
BranchTrueFalseTotal
$title =~ /[\w;,:\?!]$/ ? : 114 10 124
1096 } else {
1097 142 $title = $1;
1098 }
1099 } elsif (/^RL\s{3}(.*)/ ) {
1100 158 ▶ $loc .= $loc ? " $1" : $1;
Branch: 1 branch
BranchTrueFalseTotal
$loc ? : 0 158 158
1101 } elsif ( /^RC\s{3}(.*)/ ) {
1102 83 ▶ $com .= $com ? " $1" : $1;
Branch: 1 branch
BranchTrueFalseTotal
$com ? : 0 83 83
1103 }
1104 1251 $_ = $self->_readline;
1105 }
1106 22 return \@refs;
1107 }
1108  
1109  
1110 =head2 _read_swissprot_Species
1111  
1112 Title : _read_swissprot_Species
1113 Usage :
1114 Function: Reads the swissprot Organism species and classification
1115 lines.
1116 Able to deal with unconventional species names.
1117 Example : OS Unknown prokaryotic organism
1118 $genus = undef ; $species = Unknown prokaryotic organism
1119 Returns : A Bio::Species object
1120 Args :
1121  
1122 =cut
1123  
1124 22 ▶sub _read_swissprot_Species {
Subroutine _read_swissprot_Species: called CC=38 SCAR=45.7
1125 22 my( $self,$line ) = @_;
1126 22 my $org;
1127 22 local $_ = $line;
1128  
1129 22 my( $sub_species, $species, $genus, $common, $variant, $ncbi_taxid, $sci_name, $class_lines, $descr );
1130 22 my $osline = "";
1131 22 my $do_genus_check = 1;
1132 22 ▶ while ( defined $_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_) 126 0 126
1133 126 ▶ last unless /^O[SCGX]/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^O[SCGX]/ 22 104 126
1134 # believe it or not, but OS may come multiple times -- at this time
1135 # we can't capture multiple species
1136 104 ▶ if (/^OS\s+(\S.+)/ && (! defined($sci_name))) {
Branch: 4 branches
BranchTrueFalseTotal
if (/^OS\s+(\S.+)/ and not defined $sci_name) { } 22 82 104
elsif (s/^OC\s+(\S.+)$//) { } 45 37 82
elsif (/^OG\s+(.*)/) { } 0 37 37
elsif (/^OX\s+(.*)/ and not defined $ncbi_taxid) { } 21 31 52
Condition100%3/3
/^OS\s+(\S.+)/ and not defined $sci_name
!ll&&!rl&&r
671522
MC/DC100%2/2
/^OS\s+(\S.+)/ and not defined $sci_name
/^OS\s+(\S.+)/ not defined $sci_name
Truth table100%3/3
A and not(B)
A= /^OS\s+(\S.+)/B= not defined $sci_name
ABresult
0X0
100
111
1137 22 ▶ $osline .= " " if $osline;
Branch: 1 branch
BranchTrueFalseTotal
if $osline 0 22 22
1138 22 $osline .= $1;
1139 22 ▶ if ($osline =~ s/(,|, and|\.)$//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($osline =~ s/(,|, and|\.)$//) 22 0 22
1140 # OS lines are usually like:
1141 # Homo sapiens (human)
1142 # where we have $sci_name followed by $descr (common name) in
1143 # brackets, but we can also have:
1144 # Venerupis (Ruditapes) philippinarum
1145 # where we have brackets but they don't indicate a $descr
1146 22 ▶ if ($osline =~ /[^\(\)]+\(.+\)[^\(\)]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($osline =~ /[^\(\)]+\(.+\)[^\(\)]+$/) { } 0 22 22
1147 #*** Danger! no idea if this will pick up some syntaxes for
1148 # common names as well)
1149 0 $sci_name = $osline;
1150 0 $sci_name =~ s/\.$//;
1151 0 $descr = '';
1152 0 $do_genus_check = 0;
1153 } else {
1154 22 ($sci_name, $descr) = $osline =~ /(\S[^\(]+)(.*)/;
1155 }
1156 22 $sci_name =~ s/\s+$//;
1157  
1158 22 ▶ while ($descr =~ /\(([^\)]+)\)/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($descr =~ /\(([^\)]+)\)/g) 8 22 30
1159 8 my $item = $1;
1160 # strain etc may not necessarily come first (yes, swissprot
1161 # is messy)
1162 8 ▶ if ((! defined($variant)) &&
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $variant and $item =~ /(^|[^\(\w])([Ss]train|isolate|serogroup|serotype|subtype|clone)\b/ || $item =~ /^(biovar|pv\.|type\s+)/) { } 0 8 8
elsif ($item =~ s/^subsp\.\s+//) { } 0 8 8
elsif (not defined $common) { } 8 0 8
Condition33%2/6
not defined $variant and $item =~ /(^|[^\(\w])([Ss]train|isolate|serogroup|serotype|subtype|clone)\b/ || $item =~ /^(biovar|pv\.|type\s+)/
!ll&&!rl&&r
080
$item =~ /(^|[^\(\w])([Ss]train|isolate|serogroup|serotype|subtype|clone)\b/ or $item =~ /^(biovar|pv\.|type\s+)/
l!l&&r!l&&!r
008
MC/DC0%0/3
not defined $variant and $item =~ /(^|[^\(\w])([Ss]train|isolate|serogroup|serotype|subtype|clone)\b/ || $item =~ /^(biovar|pv\.|type\s+)/
not defined $variant $item =~ /(^|[^\(\w])([Ss]train|isolate|serogroup|serotype|subtype|clone)\b/ $item =~ /^(biovar|pv\.|type\s+)/
Truth table25%1/4
not(A) and B or C
A= not defined $variantB= $item =~ /(^|[^\(\w])([Ss]train|isolate|serogroup|serotype|subtype|clone)\b/C= $item =~ /^(biovar|pv\.|type\s+)/
ABCresult
0XX0
1000
11X1
1011
1163 (($item =~ /(^|[^\(\w])([Ss]train|isolate|serogroup|serotype|subtype|clone)\b/) ||
1164 ($item =~ /^(biovar|pv\.|type\s+)/))) {
1165 0 $variant = $item;
1166 } elsif ($item =~ s/^subsp\.\s+//) {
1167 0 ▶ if (! $sub_species) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $sub_species) { } 0 0 0
elsif (not $variant) { } 0 0 0
1168 0 $sub_species = $item;
1169 } elsif (! $variant) {
1170 0 $variant = $item;
1171 }
1172 } elsif (! defined($common)) {
1173 # we're only interested in the first common name
1174 8 $common = $item;
1175 8 ▶ if ((index($common, '(') >= 0) &&
Branch: 1 branch
BranchTrueFalseTotal
if ((index($common, "(") != -1) and (index($common, ")") == -1)) 0 8 8
Condition33%1/3
(index($common, "(") != -1) and (index($common, ")") == -1)
!ll&&!rl&&r
800
MC/DC0%0/2
(index($common, "(") != -1) and (index($common, ")") == -1)
(index($common, "(") != -1) (index($common, ")") == -1)
Truth table33%1/3
A and B
A= (index($common, "(") != -1)B= (index($common, ")") == -1)
ABresult
0X0
100
111
1176 (index($common, ')') < 0)) {
1177 0 $common .= ')';
1178 }
1179 }
1180 }
1181 }
1182 } elsif (s/^OC\s+(\S.+)$//) {
1183 45 $class_lines .= $1;
1184 } elsif (/^OG\s+(.*)/) {
1185 0 $org = $1;
1186 ▶ } elsif (/^OX\s+(.*)/ && (! defined($ncbi_taxid))) {
Condition100%3/3
/^OX\s+(.*)/ and not defined $ncbi_taxid
!ll&&!rl&&r
15121
MC/DC100%2/2
/^OX\s+(.*)/ and not defined $ncbi_taxid
/^OX\s+(.*)/ not defined $ncbi_taxid
Truth table100%3/3
A and not(B)
A= /^OX\s+(.*)/B= not defined $ncbi_taxid
ABresult
0X0
100
111
1187 21 my $taxstring = $1;
1188 # we only keep the first one and ignore all others
1189 21 ▶ if ($taxstring =~ /NCBI_TaxID=([\w\d]+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($taxstring =~ /NCBI_TaxID=([\w\d]+)/) { } 21 0 21
1190 21 $ncbi_taxid = $1;
1191 } else {
1192 0 $self->throw("$taxstring doesn't look like NCBI_TaxID");
1193 }
1194 }
1195 104 $_ = $self->_readline;
1196 }
1197 22 $self->_pushback($_); # pushback the last line because we need it
1198  
1199 22 ▶ $sci_name || return;
Branch: 1 branch
BranchTrueFalseTotal
$sci_name or return 22 0 22
1200  
1201 # if the organism belongs to taxid 32644 then no Bio::Species object.
1202 22 ▶ return if grep { $_ eq $sci_name } @Unknown_names;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $sci_name;} @Bio::SeqIO::swiss::Unknown_names 0 22 22
1203  
1204 # Convert data in classification lines into classification array.
1205 # Remove trailing . then split on ';' or '.;' so that classification that is 2
1206 # or more words will still get matched, use map() to remove trailing/leading/intervening
1207 # spaces
1208 22 $class_lines=~s/\.\s*$//;
1209 22 my @class = map { s/^\s+//; s/\s+$//; s/\s{2,}/ /g; $_; } split /[;\.]*;/, $class_lines;
1210  
1211 22 ▶ if ($class[0] =~ /viruses/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($class[0] =~ /viruses/i) { } 0 22 22
elsif ($do_genus_check) { } 22 0 22
1212 # viruses have different OS/OC syntax
1213 0 my @virusnames = split(/\s+/, $sci_name);
1214 0 ▶ $species = (@virusnames > 1) ? pop(@virusnames) : '';
Branch: 1 branch
BranchTrueFalseTotal
@virusnames > 1 ? : 0 0 0
1215 0 $genus = join(" ", @virusnames);
1216 0 $sub_species = $descr;
1217 } elsif ($do_genus_check) {
1218 # do we have a genus?
1219 22 my $possible_genus = $class[-1];
1220 22 ▶ $possible_genus .= "|$class[-2]" if $class[-2];
Branch: 1 branch
BranchTrueFalseTotal
if $class[-2] 22 0 22
1221 22 ▶ if ($sci_name =~ /^($possible_genus)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sci_name =~ /^($possible_genus)/) { } 22 0 22
1222 22 $genus = $1;
1223 22 ($species) = $sci_name =~ /^$genus\s+(.+)/;
1224 } else {
1225 0 $species = $sci_name;
1226 }
1227 # is this organism of rank species or is it lower?
1228 # (doesn't catch everything, but at least the guess isn't dangerous)
1229 22 ▶ if ($species && $species =~ /subsp\.|var\./) {
Branch: 1 branch
BranchTrueFalseTotal
if ($species and $species =~ /subsp\.|var\./) 0 22 22
Condition33%1/3
$species and $species =~ /subsp\.|var\./
!ll&&!rl&&r
0220
MC/DC0%0/2
$species and $species =~ /subsp\.|var\./
$species $species =~ /subsp\.|var\./
Truth table33%1/3
A and B
A= $speciesB= $species =~ /subsp\.|var\./
ABresult
0X0
100
111
1230 0 ($species, $sub_species) = $species =~ /(.+)\s+((?:subsp\.|var\.).+)/;
1231 }
1232 }
1233  
1234 # Bio::Species array needs array in Species -> Kingdom direction
1235 22 ▶ unless ($class[-1] eq $sci_name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class[-1] eq $sci_name) 22 0 22
1236 22 push(@class, $sci_name);
1237 }
1238 22 @class = reverse @class;
1239  
1240 22 my $taxon = Bio::Species->new();
1241 22 $taxon->scientific_name($sci_name);
1242 22 $taxon->classification(@class);
1243 22 ▶ $taxon->common_name($common) if $common;
Branch: 1 branch
BranchTrueFalseTotal
if $common 8 14 22
1244 22 ▶ $taxon->sub_species($sub_species) if $sub_species;
Branch: 1 branch
BranchTrueFalseTotal
if $sub_species 0 22 22
1245 22 ▶ $taxon->organelle($org) if $org;
Branch: 1 branch
BranchTrueFalseTotal
if $org 0 22 22
1246 22 ▶ $taxon->ncbi_taxid($ncbi_taxid) if $ncbi_taxid;
Branch: 1 branch
BranchTrueFalseTotal
if $ncbi_taxid 21 1 22
1247 22 ▶ $taxon->variant($variant) if $variant;
Branch: 1 branch
BranchTrueFalseTotal
if $variant 0 22 22
1248  
1249 # done
1250 22 return $taxon;
1251 }
1252  
1253 =head2 _filehandle
1254  
1255 Title : _filehandle
1256 Usage : $obj->_filehandle($newval)
1257 Function:
1258 Example :
1259 Returns : value of _filehandle
1260 Args : newvalue (optional)
1261  
1262  
1263 =cut
1264  
1265 # inherited from SeqIO.pm ! HL 05/11/2000
1266  
1267 =head2 _read_FTHelper_swissprot
1268  
1269 Title : _read_FTHelper_swissprot
1270 Usage : _read_FTHelper_swissprot(\$buffer)
1271 Function: reads the next FT key line
1272 Example :
1273 Returns : Bio::SeqIO::FTHelper object
1274 Args :
1275  
1276  
1277 =cut
1278  
1279 391 ▶sub _read_FTHelper_swissprot {
Subroutine _read_FTHelper_swissprot: called CC=15 SCAR=31.2
1280 391 my ($self,$line ) = @_;
1281 # initial version implemented by HL 05/10/2000
1282 # FIXME this may not be perfect, so please review
1283 # lots of cleaning up by JES 2004/07/01, still may not be perfect =)
1284 # FTId now sepated from description as a qualifier
1285  
1286 391 local $_ = $line;
1287 391 my ($key, # The key of the feature
1288 $loc, # The location line from the feature
1289 $desc, # The descriptive text
1290 $ftid, # feature Id is like a qualifier but there can be only one of them
1291 );
1292 391 ▶ if ( m/^FT\s{3}(\w+)\s+([\d\?\<]+)[\s.]+([\d\?\>]+)\s*(.*)$/ox) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^FT\s{3}(\w+)\s+([\d\?\<]+)[\s.]+([\d\?\>]+)\s*(.*)$/ox) { } 391 0 391
elsif (/^FT\s{3}(\w+)\s+([\d\?\<]+)\s+(.*)$/ox) { } 0 0 0
1293 391 $key = $1;
1294 391 my $loc1 = $2;
1295 391 my $loc2 = $3;
1296 391 $loc = "$loc1..$loc2";
1297 391 ▶ if ($4 && (length($4) > 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($4 and length $4 > 0) { } 350 41 391
Condition66%2/3
$4 and length $4 > 0
!ll&&!rl&&r
410350
MC/DC50%1/2
$4 and length $4 > 0
$4 length $4 > 0
Truth table66%2/3
A and B
A= $4B= length $4 > 0
ABresult
0X0
100
111
1298 350 $desc = $4;
1299 350 chomp($desc);
1300 } else {
1301 41 $desc = "";
1302 }
1303 } elsif ( m/^FT\s{3}(\w+)\s+([\d\?\<]+)\s+(.*)$/ox) {
1304 0 $key = $1;
1305 0 my $loc1 = $2;
1306 0 my $loc2 = $2;
1307 0 $loc = "$loc1";
1308 0 ▶ if ($3 && (length($3) > 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($3 and length $3 > 0) { } 0 0 0
Condition0%0/3
$3 and length $3 > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$3 and length $3 > 0
$3 length $3 > 0
Truth table0%0/3
A and B
A= $3B= length $3 > 0
ABresult
0X0
100
111
1309 0 $desc = $3;
1310 0 chomp($desc);
1311 } else {
1312 0 $desc = "";
1313 }
1314 }
1315  
1316 391 ▶ while ( defined($_ = $self->_readline) && /^FT\s{4,}(\S.*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = $self->_readline) and /^FT\s{4,}(\S.*)$/) 310 391 701
Condition66%2/3
defined($_ = $self->_readline) and /^FT\s{4,}(\S.*)$/
!ll&&!rl&&r
0391310
MC/DC50%1/2
defined($_ = $self->_readline) and /^FT\s{4,}(\S.*)$/
defined($_ = $self->_readline) /^FT\s{4,}(\S.*)$/
Truth table66%2/3
A and B
A= defined($_ = $self->_readline)B= /^FT\s{4,}(\S.*)$/
ABresult
0X0
100
111
1317 310 my $continuation_line = $1;
1318 310 ▶ if ( $continuation_line =~ /.FTId=(.*)\./ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($continuation_line =~ /.FTId=(.*)\./) { } 272 38 310
elsif ($desc) { } 38 0 38
1319 272 $ftid=$1;
1320 }
1321 elsif ( $desc) {
1322 38 $desc .= " $continuation_line";
1323 } else {
1324 0 $desc = $continuation_line;
1325 }
1326 310 chomp $desc;
1327 }
1328 391 $self->_pushback($_);
1329 391 ▶ unless( $key ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($key) 0 391 391
1330 # No feature key. What's this?
1331 0 $self->warn("No feature key in putative feature table line: $line");
1332 0 return;
1333 }
1334  
1335 # Make the new FTHelper object
1336 391 my $out = Bio::SeqIO::FTHelper->new(-verbose => $self->verbose());
1337 391 $out->key($key);
1338 391 $out->loc($loc);
1339  
1340 # store the description if there is one
1341 391 ▶ if ( $desc && length($desc) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc and length $desc) 350 41 391
Condition66%2/3
$desc and length $desc
!ll&&!rl&&r
410350
MC/DC50%1/2
$desc and length $desc
$desc length $desc
Truth table66%2/3
A and B
A= $descB= length $desc
ABresult
0X0
100
111
1342 350 $desc =~ s/\.$//;
1343 350 push(@{$out->field->{"description"}}, $desc);
1344 }
1345 # Store the qualifier i.e. FTId
1346 391 ▶ if ( $ftid ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ftid) 272 119 391
1347 272 push(@{$out->field->{"FTId"}}, $ftid);
1348 }
1349 391 return $out;
1350 }
1351  
1352  
1353 =head2 _write_line_swissprot
1354  
1355 Title : _write_line_swissprot
1356 Usage :
1357 Function: internal function
1358 Example :
1359 Returns :
1360 Args :
1361  
1362  
1363 =cut
1364  
1365 0 ▶sub _write_line_swissprot{
Subroutine _write_line_swissprot: not called CC=3 SCAR=24.8
1366 0 my ($self,$pre1,$pre2,$line,$length) = @_;
1367  
1368 0 ▶ $length || $self->throw( "Miscalled write_line_swissprot without length. Programming error!");
Branch: 1 branch
BranchTrueFalseTotal
$length or $self->throw("Miscalled write_line_swissprot without length. Programming error!") 0 0 0
1369 0 my $subl = $length - length $pre2;
1370 0 my $linel = length $line;
1371 0 my $i;
1372  
1373 0 my $sub = substr($line,0,$length - length $pre1);
1374  
1375 0 $self->_print( "$pre1$sub\n");
1376  
1377 0 ▶ for ($i= ($length - length $pre1);$i < $linel;) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $linel) 0 0 0
1378 0 $sub = substr($line,$i,($subl));
1379 0 $self->_print( "$pre2$sub\n");
1380 0 $i += $subl;
1381 }
1382  
1383 }
1384  
1385 =head2 _write_line_swissprot_regex
1386  
1387 Title : _write_line_swissprot_regex
1388 Usage :
1389 Function: internal function for writing lines of specified
1390 length, with different first and the next line
1391 left hand headers and split at specific points in the
1392 text
1393 Example :
1394 Returns : nothing
1395 Args : file handle, first header, second header, text-line, regex for line breaks, total line length
1396  
1397  
1398 =cut
1399  
1400 29 ▶sub _write_line_swissprot_regex {
Subroutine _write_line_swissprot_regex: called CC=8 SCAR=21.0
1401 29 my ($self,$pre1,$pre2,$line,$regex,$length) = @_;
1402  
1403 #print STDOUT "Going to print with $line!\n";
1404  
1405 29 ▶ $length || $self->throw( "Miscalled write_line_swissprot without length. Programming error!");
Branch: 1 branch
BranchTrueFalseTotal
$length or $self->throw("Miscalled write_line_swissprot without length. Programming error!") 29 0 29
1406  
1407 29 ▶ if ( length $pre1 != length $pre2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $pre1 != length $pre2) 0 29 29
1408 0 $self->warn( "len 1 is ". length ($pre1) . " len 2 is ". length ($pre2) . "\n");
1409 0 $self->throw( "Programming error - cannot called write_line_swissprot_regex with different length \npre1 ($pre1) and \npre2 ($pre2) tags!");
1410 }
1411  
1412 29 my $subl = $length - (length $pre1) -1 ;
1413  
1414 29 my $first_line = 1;
1415 29 ▶ while ($line =~ m/(.{1,$subl})($regex)/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /(.{1,$subl})($regex)/g) 36 29 65
1416 36 my $s = $1.$2;
1417 36 ▶ $s =~ s/([\w\.])#(\w)/$1 $2/g # remove word wrap protection char '#'
Branch: 1 branch
BranchTrueFalseTotal
if $pre1 eq "RA " or $pre1 eq "KW " 6 30 36
Condition100%3/3
$pre1 eq "RA " or $pre1 eq "KW "
l!l&&r!l&&!r
2430
MC/DC100%2/2
$pre1 eq "RA " or $pre1 eq "KW "
$pre1 eq "RA " $pre1 eq "KW "
Truth table100%3/3
A or B
A= $pre1 eq "RA "B= $pre1 eq "KW "
ABresult
1X1
011
000
1418 if $pre1 eq "RA " or $pre1 eq "KW ";
1419 # remove annoying extra spaces at the end of the wrapped lines
1420 36 ▶ substr($s, -1, 1, '') if substr($s, -1, 1) eq ' ';
Branch: 1 branch
BranchTrueFalseTotal
if substr($s, -1, 1) eq " " 7 29 36
1421 36 ▶ if ($first_line) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first_line) { } 29 7 36
1422 29 $self->_print( "$pre1$s\n");
1423 29 $first_line = 0;
1424 } else {
1425 7 $self->_print( "$pre2$s\n");
1426 }
1427  
1428 }
1429 }
1430  
1431 =head2 _post_sort
1432  
1433 Title : _post_sort
1434 Usage : $obj->_post_sort($newval)
1435 Function:
1436 Returns : value of _post_sort
1437 Args : newvalue (optional)
1438  
1439  
1440 =cut
1441  
1442 2 ▶sub _post_sort{
Subroutine _post_sort: called CC=2 SCAR=8.4
1443 2 my $obj = shift;
1444 2 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
1445 0 my $value = shift;
1446 0 $obj->{'_post_sort'} = $value;
1447 }
1448 2 return $obj->{'_post_sort'};
1449  
1450 }
1451  
1452 =head2 _show_dna
1453  
1454 Title : _show_dna
1455 Usage : $obj->_show_dna($newval)
1456 Function:
1457 Returns : value of _show_dna
1458 Args : newvalue (optional)
1459  
1460  
1461 =cut
1462  
1463 20 ▶sub _show_dna{
Subroutine _show_dna: called CC=2 SCAR=6.9
1464 20 my $obj = shift;
1465 20 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 18 2 20
1466 18 my $value = shift;
1467 18 $obj->{'_show_dna'} = $value;
1468 }
1469 20 return $obj->{'_show_dna'};
1470  
1471 }
1472  
1473 =head2 _id_generation_func
1474  
1475 Title : _id_generation_func
1476 Usage : $obj->_id_generation_func($newval)
1477 Function:
1478 Returns : value of _id_generation_func
1479 Args : newvalue (optional)
1480  
1481  
1482 =cut
1483  
1484 3 ▶sub _id_generation_func{
Subroutine _id_generation_func: called CC=2 SCAR=8.4
1485 3 my $obj = shift;
1486 3 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 3 3
1487 0 my $value = shift;
1488 0 $obj->{'_id_generation_func'} = $value;
1489 }
1490 3 return $obj->{'_id_generation_func'};
1491  
1492 }
1493  
1494 =head2 _ac_generation_func
1495  
1496 Title : _ac_generation_func
1497 Usage : $obj->_ac_generation_func($newval)
1498 Function:
1499 Returns : value of _ac_generation_func
1500 Args : newvalue (optional)
1501  
1502  
1503 =cut
1504  
1505 3 ▶sub _ac_generation_func{
Subroutine _ac_generation_func: called CC=2 SCAR=8.4
1506 3 my $obj = shift;
1507 3 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 3 3
1508 0 my $value = shift;
1509 0 $obj->{'_ac_generation_func'} = $value;
1510 }
1511 3 return $obj->{'_ac_generation_func'};
1512  
1513 }
1514  
1515 =head2 _sv_generation_func
1516  
1517 Title : _sv_generation_func
1518 Usage : $obj->_sv_generation_func($newval)
1519 Function:
1520 Returns : value of _sv_generation_func
1521 Args : newvalue (optional)
1522  
1523  
1524 =cut
1525  
1526 0 ▶sub _sv_generation_func{
Subroutine _sv_generation_func: not called CC=2 SCAR=17.9
1527 0 my $obj = shift;
1528 0 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1529 0 my $value = shift;
1530 0 $obj->{'_sv_generation_func'} = $value;
1531 }
1532 0 return $obj->{'_sv_generation_func'};
1533  
1534 }
1535  
1536 =head2 _kw_generation_func
1537  
1538 Title : _kw_generation_func
1539 Usage : $obj->_kw_generation_func($newval)
1540 Function:
1541 Returns : value of _kw_generation_func
1542 Args : newvalue (optional)
1543  
1544  
1545 =cut
1546  
1547 3 ▶sub _kw_generation_func{
Subroutine _kw_generation_func: called CC=2 SCAR=8.4
1548 3 my $obj = shift;
1549 3 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 3 3
1550 0 my $value = shift;
1551 0 $obj->{'_kw_generation_func'} = $value;
1552 }
1553 3 return $obj->{'_kw_generation_func'};
1554  
1555 }
1556  
1557 3 1;
« Bio/Tools/ESTScan.pm ↑ Summary Bio/Tools/GFF.pm »