Bio/SeqIO/swissdriver.pm

filter: Statementstmt 91.5% 76 / 83 Branchbran 66.6% 36 / 54 Conditioncond 60.0% 6 / 10 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 88.8% 8 / 9 Podpod 100% 3 / 3 totaltotal 80.0% 132 / 165 CC 32 SCAR 31.9
CC
32
Cov
80%
next_seq
34.7
seqhandler
4.2
_initialize
3.1
CRAP 24.2
« Bio/Taxon.pm ↑ Summary Bio/RangeI.pm »
1 #
2 # BioPerl module for Bio::SeqIO::swissdriver
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Bioperl project bioperl-l(at)bioperl.org
7 #
8 # Copyright Chris Fields and contributors see AUTHORS section
9 #
10 # You may distribute this module under the same terms as perl itself
11  
12 # POD documentation - main docs before the code
13  
14 =head1 NAME
15  
16 Bio::SeqIO::swissdriver - SwissProt/UniProt handler-based push parser
17  
18 =head1 SYNOPSIS
19  
20 #It is probably best not to use this object directly, but
21 #rather go through the SeqIO handler:
22  
23 $stream = Bio::SeqIO->new(-file => $filename,
24 -format => 'swissdriver');
25  
26 while ( my $seq = $stream->next_seq() ) {
27 # do something with $seq
28 }
29  
30 =head1 DESCRIPTION
31  
32 This object can transform Bio::Seq objects to and from UniProt flat file
33 databases. The key difference between this parser and the tried-and-true
34 Bio::SeqIO::swiss parser is this version separates the parsing and data
35 manipulation into a 'driver' method (next_seq) and separate object handlers
36 which deal with the data passed to it.
37  
38 =head2 The Driver
39  
40 The main purpose of the driver routine, in this case next_seq(), is to carve out
41 the data into meaningful chunks which are passed along to relevant handlers (see
42 below).
43  
44 Each chunk of data in the has a NAME tag attached to it, similar to that for XML
45 parsing. This designates the type of data passed (annotation type or seqfeature)
46 and the handler to be called for processing the data.
47  
48 =head1 FEEDBACK
49  
50 =head2 Mailing Lists
51  
52 User feedback is an integral part of the evolution of this and other
53 Bioperl modules. Send your comments and suggestions preferably to one
54 of the Bioperl mailing lists. Your participation is much appreciated.
55  
56 bioperl-l@bioperl.org - General discussion
57 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
58  
59 =head2 Support
60  
61 Please direct usage questions or support issues to the mailing list:
62  
63 I<bioperl-l@bioperl.org>
64  
65 rather than to the module maintainer directly. Many experienced and
66 reponsive experts will be able look at the problem and quickly
67 address it. Please include a thorough description of the problem
68 with code and data examples if at all possible.
69  
70 =head2 Reporting Bugs
71  
72 Report bugs to the Bioperl bug tracking system to help us keep track
73 the bugs and their resolution. Bug reports can be submitted via the web:
74  
75 https://github.com/bioperl/bioperl-live/issues
76  
77 =head1 AUTHOR - Bioperl Project
78  
79 bioperl-l at bioperl.org
80  
81 =head1 APPENDIX
82  
83 The rest of the documentation details each of the object
84 methods. Internal methods are usually preceded with a _
85  
86 =cut
87  
88 # POD is at the end of the module
89  
90 # Let the code begin...
91  
92 # Let the code begin...
93  
94 package Bio::SeqIO::swissdriver;
95 2 $Bio::SeqIO::swissdriver::VERSION = '1.7.8';
96 2 ▶use vars qw(%FTQUAL_NO_QUOTE);
Subroutine BEGIN: called CC=1 SCAR=0.0
97 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
98 2 ▶use Bio::SeqIO::Handler::GenericRichSeqHandler;
Subroutine BEGIN: called CC=1 SCAR=0.0
99 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
100  
101 2 ▶use base qw(Bio::SeqIO);
Subroutine BEGIN: called CC=1 SCAR=0.0
102  
103 # signals to process what's in the hash prior to next round, maps ann => names
104 2 my %SEC = (
105 OC => 'CLASSIFICATION',
106 OH => 'HOST', # not currently handled, bundled with organism data for now
107 OG => 'ORGANELLE',
108 OX => 'CROSSREF',
109 RA => 'AUTHORS',
110 RC => 'COMMENT',
111 RG => 'CONSRTM',
112 RP => 'POSITION',
113 RX => 'CROSSREF',
114 RT => 'TITLE',
115 RL => 'JOURNAL',
116 AS => 'ASSEMBLYINFO', # Third party annotation
117 '//' => 'RECORDEND'
118 );
119  
120 # add specialized delimiters here for easier postprocessing
121 2 my %DELIM = (
122 CC => "\n",
123 DR => "\n",
124 DT => "\n",
125 );
126  
127 9 ▶sub _initialize {
Subroutine _initialize: called CC=3 SCAR=11.2
128 9 my($self,@args) = @_;
129  
130 9 $self->SUPER::_initialize(@args);
131 9 my $handler = $self->_rearrange([qw(HANDLER)],@args);
132 # hash for functions for decoding keys.
133 9 ▶ $handler ? $self->seqhandler($handler) :
Branch: 1 branch
BranchTrueFalseTotal
$handler ? : 0 9 9
134 $self->seqhandler(Bio::SeqIO::Handler::GenericRichSeqHandler->new(
135 -format => 'swiss',
136 -verbose => $self->verbose,
137 -builder => $self->sequence_builder
138 ));
139 9 ▶ if( ! defined $self->sequence_factory ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->sequence_factory) 9 0 9
140 9 $self->sequence_factory(Bio::Seq::SeqFactory->new
141 (-verbose => $self->verbose(),
142 -type => 'Bio::Seq::RichSeq'));
143 }
144 }
145  
146 =head2 next_seq
147  
148 Title : next_seq
149 Usage : $seq = $stream->next_seq()
150 Function: returns the next sequence in the stream
151 Returns : Bio::Seq object
152 Args : none
153  
154 =cut
155  
156 19 ▶sub next_seq {
Subroutine next_seq: called CC=27 SCAR=35.5
Pod documented
157 19 my $self = shift;
158 19 my $hobj = $self->seqhandler;
159 19 local($/) = "\n";
160 # these contain values that need to carry over each round
161 19 my ($featkey, $qual, $annkey, $seqdata, $location);
162 19 my $lastann = '';
163 19 my $ct = 0;
164 # main parser
165 PARSER:
166 19 ▶ while(defined(my $line = $self->_readline)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = $self->_readline)) 1866 2 1868
167 1866 chomp $line;
168 1866 my ($ann, $data) = split(m{\s+}, $line, 2);
169 1866 ▶ if ($ann) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ann) { } 1848 18 1866
170 1848 ▶ if ($ann eq 'FT') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ann eq 'FT') { } 114 1734 1848
171 # sequence features
172 114 ▶ if ($data =~ m{^(\w+)\s+([\d\?\<]+)\s+([\d\?\>]+)(?:\s+?(\S.*))?}ox) {
Branch: 2 branches
BranchTrueFalseTotal
if ($data =~ /^(\w+)\s+([\d\?\<]+)\s+([\d\?\>]+)(?:\s+?(\S.*))?/ox) { } 108 6 114
elsif ($data =~ m[^\s+/([^=]+)(?:=(.+))?]ox) { } 0 6 6
173 # has location data and desc
174 108 ▶ if ($seqdata) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seqdata) 108 0 108
175 108 $hobj->data_handler($seqdata);
176 108 $seqdata = ();
177 }
178 108 ($seqdata->{FEATURE_KEY}, my $loc1, my $loc2, $data) = ($1, $2, $3, $4);
179 108 $qual = 'description';
180 108 $seqdata->{$qual} = $data;
181 108 $seqdata->{NAME} = $ann;
182 108 ▶ $seqdata->{LOCATION} = "$loc1..$loc2" if defined $loc1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $loc1 108 0 108
183 108 next PARSER;
184 } elsif ($data =~ m{^\s+/([^=]+)(?:=(.+))?}ox) {
185 # has qualifer
186 0 ▶ ($qual, $data) = ($1, $2 || '');
Condition0%0/2
$2 || ''
l!l
00
MC/DC0%0/1
$2 || ''
$2
Truth table0%0/2
A
A= $2
Aresult
11
00
187 $ct = ($seqdata->{$qual}) ?
188 0 ▶ ((ref($seqdata->{$qual})) ? scalar(@{ $seqdata->{$qual} }) : 1)
Branch: 2 branches
BranchTrueFalseTotal
$seqdata->{$qual} ? : 0 0 0
ref $seqdata->{$qual} ? : 0 0 0
189 : 0 ;
190 }
191 6 $data =~ s{\.$}{};
192 6 ▶ if ($ct == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ct == 0) { } 6 0 6
193 6 ▶ $seqdata->{$qual} .= ($seqdata->{$qual}) ?
Branch: 1 branch
BranchTrueFalseTotal
$seqdata->{$qual} ? : 6 0 6
194 ' '.$data : $data;
195 } else {
196 0 ▶ if (!ref($seqdata->{$qual})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $seqdata->{$qual}) 0 0 0
197 0 $seqdata->{$qual} = [$seqdata->{$qual}];
198 }
199 ($seqdata->{$qual}->[$ct]) ?
200 ($seqdata->{$qual}->[$ct] .= ' '.$data) :
201 0 ▶ ($seqdata->{$qual}->[$ct] .= $data);
Branch: 1 branch
BranchTrueFalseTotal
$seqdata->{$qual}[$ct] ? : 0 0 0
202 }
203 } else {
204 # simple annotations
205 1734 ▶ if ($ann ne $lastann) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ann ne $lastann) 905 829 1734
206 905 ▶ if (!$SEC{$ann} && $seqdata) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $SEC{$ann} and $seqdata) 263 642 905
Condition100%3/3
not $SEC{$ann} and $seqdata
!ll&&!rl&&r
62517263
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
207 263 $hobj->data_handler($seqdata);
208 # can't use undef here; it can lead to subtle mem leaks
209 263 $seqdata = ();
210 }
211 $annkey = (!$SEC{$ann}) ? 'DATA' : # primary data
212 905 ▶ $SEC{$ann};
Branch: 1 branch
BranchTrueFalseTotal
!$SEC{$ann} ? : 280 625 905
213 905 ▶ $seqdata->{'NAME'} = $ann if !$SEC{$ann};
Branch: 1 branch
BranchTrueFalseTotal
unless $SEC{$ann} 280 625 905
214 }
215 1734 ▶ last PARSER if $ann eq '//';
Branch: 1 branch
BranchTrueFalseTotal
if $ann eq "//" 0 1734 1734
216 1734 ▶ next PARSER if $ann eq 'SQ';
Branch: 1 branch
BranchTrueFalseTotal
if $ann eq "SQ" 17 1717 1734
217 1717 ▶ my $delim = $DELIM{$ann} || ' ';
Condition100%2/2
$DELIM{$ann} || ' '
l!l
6561061
MC/DC100%1/1
$DELIM{$ann} || ' '
$DELIM{$ann}
Truth table100%2/2
A
A= $DELIM{$ann}
Aresult
11
00
218 1717 ▶ $seqdata->{$annkey} .= ($seqdata->{$annkey}) ?
Branch: 1 branch
BranchTrueFalseTotal
$seqdata->{$annkey} ? : 829 888 1717
219 $delim.$data : $data;
220 1717 $lastann = $ann;
221 }
222 } else {
223 # this should only be sequence (fingers crossed!)
224 SEQUENCE:
225 18 ▶ while (defined ($line = $self->_readline)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->_readline)) 116 1 117
226 116 ▶ if (index($line, '//') == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($line, '//') == 0) { } 17 99 116
227 17 $data =~ tr{0-9 \n}{}d;
228 17 $seqdata->{DATA} = $data;
229 #$self->debug(Dumper($seqdata));
230 17 $hobj->data_handler($seqdata);
231 17 $seqdata = ();
232 17 last PARSER;
233 } else {
234 99 $data .= $line;
235 99 $line = undef;
236 }
237 }
238 }
239 }
240 # some files have no // for the last file; this catches the last bit o' data
241 19 ▶ $hobj->data_handler($seqdata) if $seqdata;
Branch: 1 branch
BranchTrueFalseTotal
if $seqdata 0 19 19
242 19 return $hobj->build_sequence;
243 }
244  
245 =head2 write_seq
246  
247 Title : write_seq
248 Usage : $stream->write_seq($seq)
249 Function: writes the $seq object (must be seq) to the stream
250 Returns : 1 for success and 0 for error
251 Args : array of 1 to n Bio::SeqI objects
252  
253 =cut
254  
255 0 ▶sub write_seq {
Subroutine write_seq: not called CC=1 SCAR=6.9
Pod documented
256 0 shift->throw("Use Bio::SeqIO::swiss write_seq() for output");
257 # maybe make a Writer class as well????
258 }
259  
260 =head2 seqhandler
261  
262 Title : seqhandler
263 Usage : $stream->seqhandler($handler)
264 Function: Get/Set the Bio::Seq::HandlerBaseI object
265 Returns : Bio::Seq::HandlerBaseI
266 Args : Bio::Seq::HandlerBaseI
267  
268 =cut
269  
270 28 ▶sub seqhandler {
Subroutine seqhandler: called CC=4 SCAR=14.5
Pod documented
271 28 my ($self, $handler) = @_;
272 28 ▶ if ($handler) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handler) 9 19 28
273 9 ▶ $self->throw("Not a Bio::HandlerBaseI") unless
Branch: 1 branch
BranchTrueFalseTotal
unless ref $handler and $handler->isa("Bio::HandlerBaseI") 0 9 9
Condition33%1/3
ref $handler and $handler->isa("Bio::HandlerBaseI")
!ll&&!rl&&r
009
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
274 ref($handler) && $handler->isa("Bio::HandlerBaseI");
275 9 $self->{'_seqhandler'} = $handler;
276 }
277 28 return $self->{'_seqhandler'};
278 }
279  
280 2 1;
281  
282 __END__
« Bio/Taxon.pm ↑ Summary Bio/RangeI.pm »