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.8';
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 compare cons_splice
131 direction estimated_length
132 evidence label
133 mod_base number
134 rpt_type rpt_unit
135 rpt_unit_range tag_peptide
136 transl_except transl_table
137 usedin
138 LOCATION
139 );
140  
141 2 my %DATA_KEY = (
142 ID => 'ID',
143 AC => 'ACCESSION',
144 DT => 'DATE',
145 DE => 'DESCRIPTION',
146 KW => 'KEYWORDS',
147 OS => 'SOURCE',
148 OC => 'CLASSIFICATION',
149 OG => 'ORGANELLE',
150 RN => 'REFERENCE',
151 RA => 'AUTHORS',
152 RC => 'COMMENT',
153 RG => 'CONSRTM',
154 RP => 'POSITION',
155 RX => 'CROSSREF',
156 RT => 'TITLE',
157 RL => 'LOCATION',
158 XX => 'SPACER',
159 FH => 'FEATHEADER',
160 FT => 'FEATURES',
161 AH => 'TPA_HEADER', # Third party annotation
162 AS => 'TPA_DATA', # Third party annotation
163 DR => 'DBLINK',
164 CC => 'COMMENT',
165 CO => 'CO',
166 CON => 'CON',
167 WGS => 'WGS',
168 ANN => 'ANN',
169 TPA => 'TPA',
170 SQ => 'SEQUENCE',
171 );
172  
173 2 my %SEC = (
174 OC => 'CLASSIFICATION',
175 OH => 'HOST', # not currently handled, bundled with organism data for now
176 OG => 'ORGANELLE',
177 OX => 'CROSSREF',
178 RA => 'AUTHORS',
179 RC => 'COMMENT',
180 RG => 'CONSRTM',
181 RP => 'POSITION',
182 RX => 'CROSSREF',
183 RT => 'TITLE',
184 RL => 'JOURNAL',
185 AS => 'ASSEMBLYINFO', # Third party annotation
186 );
187  
188 2 my %DELIM = (
189 #CC => "\n",
190 #DR => "\n",
191 #DT => "\n",
192 );
193  
194 # signals to process what's in the hash prior to next round
195 # these should be changed to map secondary data
196 2 my %PRIMARY = map {$_ => 1} qw(ID AC DT DE SV KW OS RN AH DR FH CC SQ FT WGS CON ANN TPA //);
197  
198 10 ▶sub _initialize {
Subroutine _initialize: called CC=3 SCAR=11.2
199 10 my($self,@args) = @_;
200  
201 10 $self->SUPER::_initialize(@args);
202 10 my $handler = $self->_rearrange([qw(HANDLER)],@args);
203 # hash for functions for decoding keys.
204 10 ▶ $handler ? $self->seqhandler($handler) :
Branch: 1 branch
BranchTrueFalseTotal
$handler ? : 0 10 10
205 $self->seqhandler(Bio::SeqIO::Handler::GenericRichSeqHandler->new(
206 -format => 'embl',
207 -verbose => $self->verbose,
208 -builder => $self->sequence_builder
209 ));
210 #
211 10 ▶ if( ! defined $self->sequence_factory ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->sequence_factory) 10 0 10
212 10 $self->sequence_factory(Bio::Seq::SeqFactory->new
213 (-verbose => $self->verbose(),
214 -type => 'Bio::Seq::RichSeq'));
215 }
216 }
217  
218 =head2 next_seq
219  
220 Title : next_seq
221 Usage : $seq = $stream->next_seq()
222 Function: returns the next sequence in the stream
223 Returns : Bio::Seq object
224 Args :
225  
226 =cut
227  
228 10 ▶sub next_seq {
Subroutine next_seq: called CC=31 SCAR=34.4
Pod documented
229 10 my $self = shift;
230 10 my $hobj = $self->seqhandler;
231 10 local($/) = "\n";
232 10 my ($featkey, $qual, $annkey, $delim, $seqdata);
233 10 my $lastann = '';
234 10 my $ct = 0;
235 PARSER:
236 10 ▶ while(defined(my $line = $self->_readline)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = $self->_readline)) 2767 1 2768
237 2767 ▶ next PARSER if $line =~ m{^\s*$};
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/ 1 2766 2767
238 2766 chomp $line;
239 2766 my ($ann,$data) = split m{\s{2,3}}, $line , 2;
240 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
241 2602 ▶ if ($ann) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ann) { } 2592 10 2602
242 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
243 2592 ▶ if ($ann eq 'FT') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ann eq 'FT') { } 1752 840 2592
244 # seqfeatures
245 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
246 193 ▶ $hobj->data_handler($seqdata) if $seqdata;
Branch: 1 branch
BranchTrueFalseTotal
if $seqdata 193 0 193
247 193 $seqdata = ();
248 193 ($seqdata->{FEATURE_KEY}, $data) = ($1, $2);
249 193 $seqdata->{NAME} = $ann;
250 193 $qual = 'LOCATION';
251 } elsif ($data =~ m{^\s+/([^=]+)=?(.+)?}) {
252 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
253 $ct = (exists $seqdata->{$qual}) ?
254 935 ▶ ((ref($seqdata->{$qual})) ? scalar(@{ $seqdata->{$qual} }) : 1)
Branch: 2 branches
BranchTrueFalseTotal
exists $seqdata->{$qual} ? : 149 786 935
ref $seqdata->{$qual} ? : 32 117 149
255 : 0 ;
256 }
257 1752 $data =~ s{^\s+}{};
258 1752 $data =~ tr{"}{}d; # we don't care about quotes yet...
259 1752 ▶ my $delim = ($FTQUAL_NO_QUOTE{$qual}) ? '' : ' ';
Branch: 1 branch
BranchTrueFalseTotal
$FTQUAL_NO_QUOTE{$qual} ? : 298 1454 1752
260 1752 ▶ if ($ct == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ct == 0) { } 1601 151 1752
261 1601 ▶ $seqdata->{$qual} .= ($seqdata->{$qual}) ?
Branch: 1 branch
BranchTrueFalseTotal
$seqdata->{$qual} ? : 622 979 1601
262 $delim.$data :
263 $data;
264 } else {
265 151 ▶ if (!ref($seqdata->{$qual})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $seqdata->{$qual}) 117 34 151
266 117 $seqdata->{$qual} = [$seqdata->{$qual}];
267 }
268 (exists $seqdata->{$qual}->[$ct]) ?
269 (($seqdata->{$qual}->[$ct]) .= $delim.$data) :
270 151 ▶ (($seqdata->{$qual}->[$ct]) .= $data);
Branch: 1 branch
BranchTrueFalseTotal
exists $seqdata->{$qual}[$ct] ? : 2 149 151
271 }
272 } else {
273 # simple annotations
274 840 $data =~ s{;$}{};
275 840 ▶ last PARSER if $ann eq '//';
Branch: 1 branch
BranchTrueFalseTotal
if $ann eq "//" 0 840 840
276 840 ▶ if ($ann ne $lastann) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ann ne $lastann) 454 386 840
277 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
278 141 $hobj->data_handler($seqdata);
279 # can't use undef here; it can lead to subtle mem leaks
280 141 $seqdata = ();
281 }
282 $annkey = (!$SEC{$ann}) ? 'DATA' : # primary data
283 454 ▶ $SEC{$ann};
Branch: 1 branch
BranchTrueFalseTotal
!$SEC{$ann} ? : 151 303 454
284 454 ▶ $seqdata->{'NAME'} = $ann if !$SEC{$ann};
Branch: 1 branch
BranchTrueFalseTotal
unless $SEC{$ann} 151 303 454
285 }
286
287 # toss the data for SQ lines; this needs to be done after the
288 # call to the data handler
289
290 840 ▶ next PARSER if $ann eq 'SQ';
Branch: 1 branch
BranchTrueFalseTotal
if $ann eq "SQ" 11 829 840
291 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
292 829 ▶ $seqdata->{$annkey} .= ($seqdata->{$annkey}) ?
Branch: 1 branch
BranchTrueFalseTotal
$seqdata->{$annkey} ? : 386 443 829
293 $delim.$data : $data;
294 829 $lastann = $ann;
295 }
296 } else {
297 # this should only be sequence (fingers crossed!)
298 SEQUENCE:
299 10 ▶ while (defined ($line = $self->_readline)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->_readline)) 2477 1 2478
300 2477 ▶ if (index($line, '//') == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($line, '//') == 0) { } 9 2468 2477
301 9 $data =~ tr{0-9 \n}{}d;
302 9 $seqdata->{DATA} = $data;
303 #$self->debug(Dumper($seqdata));
304 9 $hobj->data_handler($seqdata);
305 9 $seqdata = ();
306 9 last PARSER;
307 } else {
308 2468 $data .= $line;
309 2468 $line = undef;
310 }
311 }
312 }
313 }
314 10 ▶ $hobj->data_handler($seqdata) if $seqdata;
Branch: 1 branch
BranchTrueFalseTotal
if $seqdata 1 9 10
315 10 $seqdata = ();
316 10 return $hobj->build_sequence;
317 }
318  
319 0 ▶sub next_chunk {
Subroutine next_chunk: not called CC=5 SCAR=34.0
Pod undocumented
320 0 my $self = shift;
321 0 my $ct = 0;
322 PARSER:
323 0 ▶ while(defined(my $line = $self->_readline)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = $self->_readline)) 0 0 0
324 0 ▶ next if $line =~ m{^\s*$};
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/ 0 0 0
325 0 chomp $line;
326 0 my ($ann,$data) = split m{\s{2,3}}, $line , 2;
327 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
328 0 $self->debug("Ann: [$ann]\n\tData: [$data]\n");
329 0 ▶ last PARSER if $ann =~ m{//};
Branch: 1 branch
BranchTrueFalseTotal
if $ann =~ m[//] 0 0 0
330 }
331 }
332  
333 =head2 write_seq
334  
335 Title : write_seq
336 Usage : $stream->write_seq($seq)
337 Function: writes the $seq object (must be seq) to the stream
338 Returns : 1 for success and 0 for error
339 Args : array of 1 to n Bio::SeqI objects
340  
341 =cut
342  
343 0 ▶sub write_seq {
Subroutine write_seq: not called CC=1 SCAR=6.9
Pod documented
344 0 shift->throw("Use Bio::SeqIO::embl for output");
345 # maybe make a Writer class as well????
346 }
347  
348 =head2 seqhandler
349  
350 Title : seqhandler
351 Usage : $stream->seqhandler($handler)
352 Function: Get/Set the Bio::Seq::HandlerBaseI object
353 Returns : Bio::Seq::HandlerBaseI
354 Args : Bio::Seq::HandlerBaseI
355  
356 =cut
357  
358 20 ▶sub seqhandler {
Subroutine seqhandler: called CC=4 SCAR=14.5
Pod documented
359 20 my ($self, $handler) = @_;
360 20 ▶ if ($handler) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handler) 10 10 20
361 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
362 ref($handler) && $handler->isa("Bio::HandlerBaseI");
363 10 $self->{'_seqhandler'} = $handler;
364 }
365 20 return $self->{'_seqhandler'};
366 }
367  
368 2 1;
369  
370 __END__
« Bio/SeqIO/qual.pm ↑ Summary Bio/SeqIO/kegg.pm »