Bio/SeqIO/embldriver.pm

filter: Statementstmt 90.0% 90 / 100 Branchbran 82.8% 53 / 64 Conditioncond 64.7% 11 / 17 MC/DCmcdc 50.0% 5 / 10 Subroutinesub 80.0% 8 / 10 Podpod 75.0% 3 / 4 totaltotal 82.9% 170 / 205 CC 40 SCAR 31.5
CC
40
Cov
85%
next_seq
31.0
next_chunk
30.0
seqhandler
4.2
CRAP 23.4
« Bio/SeqIO/qual.pm ↑ Summary Bio/SeqIO/kegg.pm »
1 #
2 # BioPerl module for Bio::SeqIO::embldriver
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Ewan Birney <birney@ebi.ac.uk>
7 #
8 # Copyright Ewan Birney
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::embldriver - EMBL 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 system. Go:
22  
23 $stream = Bio::SeqIO->new(-file => $filename, -format => 'embldriver');
24  
25 while ( (my $seq = $stream->next_seq()) ) {
26 # do something with $seq
27 }
28  
29 =head1 DESCRIPTION
30  
31 This object can transform Bio::Seq objects to and from EMBL flat
32 file databases.
33  
34 There is a lot of flexibility here about how to dump things which
35 should be documented more fully.
36  
37 There should be a common object that this and Genbank share (probably
38 with Swissprot). Too much of the magic is identical.
39  
40 =head2 Optional functions
41  
42 =over 3
43  
44 =item _show_dna()
45  
46 (output only) shows the dna or not
47  
48 =item _post_sort()
49  
50 (output only) provides a sorting func which is applied to the FTHelpers
51 before printing
52  
53 =item _id_generation_func()
54  
55 This is function which is called as
56  
57 print "ID ", $func($annseq), "\n";
58  
59 To generate the ID line. If it is not there, it generates a sensible ID
60 line using a number of tools.
61  
62 If you want to output annotations in EMBL format they need to be
63 stored in a Bio::Annotation::Collection object which is accessible
64 through the Bio::SeqI interface method L<annotation()|annotation>.
65  
66 The following are the names of the keys which are polled from a
67 L<Bio::Annotation::Collection> object.
68  
69 reference - Should contain Bio::Annotation::Reference objects
70 comment - Should contain Bio::Annotation::Comment objects
71 dblink - Should contain Bio::Annotation::DBLink objects
72  
73 =back
74  
75 =head1 FEEDBACK
76  
77 =head2 Mailing Lists
78  
79 User feedback is an integral part of the evolution of this and other
80 Bioperl modules. Send your comments and suggestions preferably to one
81 of the Bioperl mailing lists. Your participation is much appreciated.
82  
83 bioperl-l@bioperl.org - General discussion
84 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
85  
86 =head2 Support
87  
88 Please direct usage questions or support issues to the mailing list:
89  
90 I<bioperl-l@bioperl.org>
91  
92 rather than to the module maintainer directly. Many experienced and
93 reponsive experts will be able look at the problem and quickly
94 address it. Please include a thorough description of the problem
95 with code and data examples if at all possible.
96  
97 =head2 Reporting Bugs
98  
99 Report bugs to the Bioperl bug tracking system to help us keep track
100 the bugs and their resolution. Bug reports can be submitted via
101 the web:
102  
103 https://github.com/bioperl/bioperl-live/issues
104  
105 =head1 AUTHOR - Ewan Birney
106  
107 Email birney@ebi.ac.uk
108  
109 =head1 APPENDIX
110  
111 The rest of the documentation details each of the object
112 methods. Internal methods are usually preceded with a _
113  
114 =cut
115  
116 # Let the code begin...
117  
118 package Bio::SeqIO::embldriver;
119 2 $Bio::SeqIO::embldriver::VERSION = '1.7.7';
120 2 ▶use vars qw(%FTQUAL_NO_QUOTE);
Subroutine BEGIN: called CC=1 SCAR=0.0
121 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
122 2 ▶use Bio::SeqIO::Handler::GenericRichSeqHandler;
Subroutine BEGIN: called CC=1 SCAR=0.0
123 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
124  
125 2 ▶use base qw(Bio::SeqIO);
Subroutine BEGIN: called CC=1 SCAR=0.0
126  
127 2 my %FTQUAL_NO_QUOTE = map {$_ => 1} qw(
128 anticodon citation
129 codon codon_start
130 cons_splice direction
131 evidence label
132 mod_base number
133 rpt_type rpt_unit
134 transl_except transl_table
135 usedin
136 LOCATION
137 );
138  
139 2 my %DATA_KEY = (
140 ID => 'ID',
141 AC => 'ACCESSION',
142 DT => 'DATE',
143 DE => 'DESCRIPTION',
144 KW => 'KEYWORDS',
145 OS => 'SOURCE',
146 OC => 'CLASSIFICATION',
147 OG => 'ORGANELLE',
148 RN => 'REFERENCE',
149 RA => 'AUTHORS',
150 RC => 'COMMENT',
151 RG => 'CONSRTM',
152 RP => 'POSITION',
153 RX => 'CROSSREF',
154 RT => 'TITLE',
155 RL => 'LOCATION',
156 XX => 'SPACER',
157 FH => 'FEATHEADER',
158 FT => 'FEATURES',
159 AH => 'TPA_HEADER', # Third party annotation
160 AS => 'TPA_DATA', # Third party annotation
161 DR => 'DBLINK',
162 CC => 'COMMENT',
163 CO => 'CO',
164 CON => 'CON',
165 WGS => 'WGS',
166 ANN => 'ANN',
167 TPA => 'TPA',
168 SQ => 'SEQUENCE',
169 );
170  
171 2 my %SEC = (
172 OC => 'CLASSIFICATION',
173 OH => 'HOST', # not currently handled, bundled with organism data for now
174 OG => 'ORGANELLE',
175 OX => 'CROSSREF',
176 RA => 'AUTHORS',
177 RC => 'COMMENT',
178 RG => 'CONSRTM',
179 RP => 'POSITION',
180 RX => 'CROSSREF',
181 RT => 'TITLE',
182 RL => 'JOURNAL',
183 AS => 'ASSEMBLYINFO', # Third party annotation
184 );
185  
186 2 my %DELIM = (
187 #CC => "\n",
188 #DR => "\n",
189 #DT => "\n",
190 );
191  
192 # signals to process what's in the hash prior to next round
193 # these should be changed to map secondary data
194 2 my %PRIMARY = map {$_ => 1} qw(ID AC DT DE SV KW OS RN AH DR FH CC SQ FT WGS CON ANN TPA //);
195  
196 sub _initialize {
197 10 ▶ my($self,@args) = @_;
Subroutine _initialize: called CC=3 SCAR=11.2
198  
199 10 $self->SUPER::_initialize(@args);
200 10 my $handler = $self->_rearrange([qw(HANDLER)],@args);
201 # hash for functions for decoding keys.
202 10 ▶ $handler ? $self->seqhandler($handler) :
Branch: 1 branch
BranchTrueFalseTotal
$handler ? : 0 10 10
203 $self->seqhandler(Bio::SeqIO::Handler::GenericRichSeqHandler->new(
204 -format => 'embl',
205 -verbose => $self->verbose,
206 -builder => $self->sequence_builder
207 ));
208 #
209 10 ▶ if( ! defined $self->sequence_factory ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->sequence_factory) 10 0 10
210 10 $self->sequence_factory(Bio::Seq::SeqFactory->new
211 (-verbose => $self->verbose(),
212 -type => 'Bio::Seq::RichSeq'));
213 }
214 }
215  
216 =head2 next_seq
217  
218 Title : next_seq
219 Usage : $seq = $stream->next_seq()
220 Function: returns the next sequence in the stream
221 Returns : Bio::Seq object
222 Args :
223  
224 =cut
225  
226 sub next_seq {
227 10 ▶ my $self = shift;
Subroutine next_seq: called CC=31 SCAR=34.4
Pod documented
228 10 my $hobj = $self->seqhandler;
229 10 local($/) = "\n";
230 10 my ($featkey, $qual, $annkey, $delim, $seqdata);
231 10 my $lastann = '';
232 10 my $ct = 0;
233 PARSER:
234 10 ▶ while(defined(my $line = $self->_readline)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = $self->_readline)) 2767 1 2768
235 2767 ▶ next PARSER if $line =~ m{^\s*$};
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/ 1 2766 2767
236 2766 chomp $line;
237 2766 my ($ann,$data) = split m{\s{2,3}}, $line , 2;
238 2766 ▶ next PARSER if ($ann eq 'XX' || $ann eq 'FH');
Branch: 1 branch
BranchTrueFalseTotal
if $ann eq "XX" or $ann eq "FH" 164 2602 2766
Condition100%3/3
$ann eq "XX" or $ann eq "FH"
l!l&&r!l&&!r
148162602
MC/DC100%2/2
$ann eq "XX" or $ann eq "FH"
$ann eq "XX" $ann eq "FH"
Truth table100%3/3
A or B
A= $ann eq "XX"B= $ann eq "FH"
ABresult
1X1
011
000
239 2602 ▶ if ($ann) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ann) { } 2592 10 2602
240 2592 ▶ $data ||='';
Condition100%2/2
$data ||= ""
l!l
256032
MC/DC100%1/1
$data ||= ""
$data
Truth table100%2/2
A
A= $data
Aresult
11
00
241 2592 ▶ if ($ann eq 'FT') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ann eq 'FT') { } 1752 840 2592
242 # seqfeatures
243 1752 ▶ if ($data =~ m{^(\S+)\s+([^\n]+)}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($data =~ /^(\S+)\s+([^\n]+)/) { } 193 1559 1752
elsif ($data =~ m[^\s+/([^=]+)=?(.+)?]) { } 935 624 1559
244 193 ▶ $hobj->data_handler($seqdata) if $seqdata;
Branch: 1 branch
BranchTrueFalseTotal
if $seqdata 193 0 193
245 193 $seqdata = ();
246 193 ($seqdata->{FEATURE_KEY}, $data) = ($1, $2);
247 193 $seqdata->{NAME} = $ann;
248 193 $qual = 'LOCATION';
249 } elsif ($data =~ m{^\s+/([^=]+)=?(.+)?}) {
250 935 ▶ ($qual, $data) = ($1, $2 ||'');
Condition50%1/2
$2 || ''
l!l
9350
MC/DC0%0/1
$2 || ''
$2
Truth table50%1/2
A
A= $2
Aresult
11
00
251 $ct = (exists $seqdata->{$qual}) ?
252 935 ▶ ((ref($seqdata->{$qual})) ? scalar(@{ $seqdata->{$qual} }) : 1)
Branch: 2 branches
BranchTrueFalseTotal
exists $seqdata->{$qual} ? : 149 786 935
ref $seqdata->{$qual} ? : 32 117 149
253 : 0 ;
254 }
255 1752 $data =~ s{^\s+}{};
256 1752 $data =~ tr{"}{}d; # we don't care about quotes yet...
257 1752 ▶ my $delim = ($FTQUAL_NO_QUOTE{$qual}) ? '' : ' ';
Branch: 1 branch
BranchTrueFalseTotal
$FTQUAL_NO_QUOTE{$qual} ? : 298 1454 1752
258 1752 ▶ if ($ct == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ct == 0) { } 1601 151 1752
259 1601 ▶ $seqdata->{$qual} .= ($seqdata->{$qual}) ?
Branch: 1 branch
BranchTrueFalseTotal
$seqdata->{$qual} ? : 622 979 1601
260 $delim.$data :
261 $data;
262 } else {
263 151 ▶ if (!ref($seqdata->{$qual})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $seqdata->{$qual}) 117 34 151
264 117 $seqdata->{$qual} = [$seqdata->{$qual}];
265 }
266 (exists $seqdata->{$qual}->[$ct]) ?
267 (($seqdata->{$qual}->[$ct]) .= $delim.$data) :
268 151 ▶ (($seqdata->{$qual}->[$ct]) .= $data);
Branch: 1 branch
BranchTrueFalseTotal
exists $seqdata->{$qual}[$ct] ? : 2 149 151
269 }
270 } else {
271 # simple annotations
272 840 $data =~ s{;$}{};
273 840 ▶ last PARSER if $ann eq '//';
Branch: 1 branch
BranchTrueFalseTotal
if $ann eq "//" 0 840 840
274 840 ▶ if ($ann ne $lastann) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ann ne $lastann) 454 386 840
275 454 ▶ if (!$SEC{$ann} && $seqdata) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $SEC{$ann} and $seqdata) 141 313 454
Condition100%3/3
not $SEC{$ann} and $seqdata
!ll&&!rl&&r
30310141
MC/DC100%2/2
not $SEC{$ann} and $seqdata
not $SEC{$ann} $seqdata
Truth table100%3/3
not(A) and B
A= not $SEC{$ann}B= $seqdata
ABresult
0X0
100
111
276 141 $hobj->data_handler($seqdata);
277 # can't use undef here; it can lead to subtle mem leaks
278 141 $seqdata = ();
279 }
280 $annkey = (!$SEC{$ann}) ? 'DATA' : # primary data
281 454 ▶ $SEC{$ann};
Branch: 1 branch
BranchTrueFalseTotal
!$SEC{$ann} ? : 151 303 454
282 454 ▶ $seqdata->{'NAME'} = $ann if !$SEC{$ann};
Branch: 1 branch
BranchTrueFalseTotal
unless $SEC{$ann} 151 303 454
283 }
284
285 # toss the data for SQ lines; this needs to be done after the
286 # call to the data handler
287
288 840 ▶ next PARSER if $ann eq 'SQ';
Branch: 1 branch
BranchTrueFalseTotal
if $ann eq "SQ" 11 829 840
289 829 ▶ my $delim = $DELIM{$ann} || ' ';
Condition50%1/2
$DELIM{$ann} || ' '
l!l
0829
MC/DC0%0/1
$DELIM{$ann} || ' '
$DELIM{$ann}
Truth table50%1/2
A
A= $DELIM{$ann}
Aresult
11
00
290 829 ▶ $seqdata->{$annkey} .= ($seqdata->{$annkey}) ?
Branch: 1 branch
BranchTrueFalseTotal
$seqdata->{$annkey} ? : 386 443 829
291 $delim.$data : $data;
292 829 $lastann = $ann;
293 }
294 } else {
295 # this should only be sequence (fingers crossed!)
296 SEQUENCE:
297 10 ▶ while (defined ($line = $self->_readline)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->_readline)) 2477 1 2478
298 2477 ▶ if (index($line, '//') == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($line, '//') == 0) { } 9 2468 2477
299 9 $data =~ tr{0-9 \n}{}d;
300 9 $seqdata->{DATA} = $data;
301 #$self->debug(Dumper($seqdata));
302 9 $hobj->data_handler($seqdata);
303 9 $seqdata = ();
304 9 last PARSER;
305 } else {
306 2468 $data .= $line;
307 2468 $line = undef;
308 }
309 }
310 }
311 }
312 10 ▶ $hobj->data_handler($seqdata) if $seqdata;
Branch: 1 branch
BranchTrueFalseTotal
if $seqdata 1 9 10
313 10 $seqdata = ();
314 10 return $hobj->build_sequence;
315 }
316  
317 sub next_chunk {
318 0 ▶ my $self = shift;
Subroutine next_chunk: not called CC=5 SCAR=34.0
Pod undocumented
319 0 my $ct = 0;
320 PARSER:
321 0 ▶ while(defined(my $line = $self->_readline)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = $self->_readline)) 0 0 0
322 0 ▶ next if $line =~ m{^\s*$};
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/ 0 0 0
323 0 chomp $line;
324 0 my ($ann,$data) = split m{\s{2,3}}, $line , 2;
325 0 ▶ $data ||= '';
Condition0%0/2
$data ||= ""
l!l
00
MC/DC0%0/1
$data ||= ""
$data
Truth table0%0/2
A
A= $data
Aresult
11
00
326 0 $self->debug("Ann: [$ann]\n\tData: [$data]\n");
327 0 ▶ last PARSER if $ann =~ m{//};
Branch: 1 branch
BranchTrueFalseTotal
if $ann =~ m[//] 0 0 0
328 }
329 }
330  
331 =head2 write_seq
332  
333 Title : write_seq
334 Usage : $stream->write_seq($seq)
335 Function: writes the $seq object (must be seq) to the stream
336 Returns : 1 for success and 0 for error
337 Args : array of 1 to n Bio::SeqI objects
338  
339 =cut
340  
341 sub write_seq {
342 0 ▶ shift->throw("Use Bio::SeqIO::embl for output");
Subroutine write_seq: not called CC=1 SCAR=6.9
Pod documented
343 # maybe make a Writer class as well????
344 }
345  
346 =head2 seqhandler
347  
348 Title : seqhandler
349 Usage : $stream->seqhandler($handler)
350 Function: Get/Set the Bio::Seq::HandlerBaseI object
351 Returns : Bio::Seq::HandlerBaseI
352 Args : Bio::Seq::HandlerBaseI
353  
354 =cut
355  
356 sub seqhandler {
357 20 ▶ my ($self, $handler) = @_;
Subroutine seqhandler: called CC=4 SCAR=14.5
Pod documented
358 20 ▶ if ($handler) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handler) 10 10 20
359 10 ▶ $self->throw("Not a Bio::HandlerBaseI") unless
Branch: 1 branch
BranchTrueFalseTotal
unless ref $handler and $handler->isa("Bio::HandlerBaseI") 0 10 10
Condition33%1/3
ref $handler and $handler->isa("Bio::HandlerBaseI")
!ll&&!rl&&r
0010
MC/DC0%0/2
ref $handler and $handler->isa("Bio::HandlerBaseI")
ref $handler $handler->isa("Bio::HandlerBaseI")
Truth table33%1/3
A and B
A= ref $handlerB= $handler->isa("Bio::HandlerBaseI")
ABresult
0X0
100
111
360 ref($handler) && $handler->isa("Bio::HandlerBaseI");
361 10 $self->{'_seqhandler'} = $handler;
362 }
363 20 return $self->{'_seqhandler'};
364 }
365  
366 2 1;
367  
368 __END__
« Bio/SeqIO/qual.pm ↑ Summary Bio/SeqIO/kegg.pm »