Bio/SeqIO/kegg.pm

filter: Statementstmt 90.9% 101 / 111 Branchbran 50.0% 18 / 36 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 90.9% 10 / 11 Podpod 100% 2 / 2 totaltotal 76.5% 134 / 175 CC 24 SCAR 31.1
CC
24
Cov
78%
next_seq
32.5
_initialize
2.0
write_seq
2.0
CRAP 22.4
« Bio/SeqIO/embldriver.pm ↑ Summary Bio/TreeIO/NewickParser.pm »
1 #
2 # BioPerl module for Bio::SeqIO::kegg
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Allen Day <allenday@ucla.edu>
7 #
8 # Copyright Allen Day
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::kegg - KEGG 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 use Bio::SeqIO;
24  
25 $stream = Bio::SeqIO->new(-file => $filename, -format => 'KEGG');
26  
27 while ( my $seq = $stream->next_seq() ) {
28 # do something with $seq
29 }
30  
31 =head1 DESCRIPTION
32  
33 This class transforms KEGG gene records into Bio::Seq objects.
34  
35 =head2 Mapping of record properties to object properties
36  
37 This section is supposed to document which sections and properties of
38 a KEGG databank record end up where in the Bioperl object model. It
39 is far from complete and presently focuses only on those mappings
40 which may be non-obvious. $seq in the text refers to the
41 Bio::Seq::RichSeqI implementing object returned by the parser for each
42 record.
43  
44 =over 4
45  
46 =item 'ENTRY'
47  
48 $seq->primary_id
49  
50 =item 'NAME'
51  
52 $seq->display_id
53  
54 =item 'DEFINITION'
55  
56 $seq->annotation->get_Annotations('description');
57  
58 =item 'ORTHOLOG'
59  
60 grep {$_->database eq 'KO'} $seq->annotation->get_Annotations('dblink')
61  
62 =item 'CLASS'
63  
64 grep {$_->database eq 'PATH'}
65 $seq->annotation->get_Annotations('dblink')
66  
67 =item 'POSITION'
68  
69 FIXME, NOT IMPLEMENTED
70  
71 =item 'PATHWAY'
72  
73 for my $pathway ( $seq->annotation->get_Annotations('pathway') ) {
74 #
75 }
76  
77 =item 'DBLINKS'
78  
79 $seq->annotation->get_Annotations('dblink')
80  
81 =item 'CODON_USAGE'
82  
83 FIXME, NOT IMPLEMENTED
84  
85 =item 'AASEQ'
86  
87 $seq->translate->seq
88  
89 =item 'NTSEQ'
90  
91 $seq-E<gt>seq
92  
93 =back
94  
95 =head1 FEEDBACK
96  
97 =head2 Mailing Lists
98  
99 User feedback is an integral part of the evolution of this and other
100 Bioperl modules. Send your comments and suggestions preferably to one
101 of the Bioperl mailing lists. Your participation is much appreciated.
102  
103 bioperl-l@bioperl.org - General discussion
104 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
105  
106 =head2 Support
107  
108 Please direct usage questions or support issues to the mailing list:
109  
110 I<bioperl-l@bioperl.org>
111  
112 rather than to the module maintainer directly. Many experienced and
113 reponsive experts will be able look at the problem and quickly
114 address it. Please include a thorough description of the problem
115 with code and data examples if at all possible.
116  
117 =head2 Reporting Bugs
118  
119 Report bugs to the Bioperl bug tracking system to help us keep track
120 the bugs and their resolution. Bug reports can be submitted via the web:
121  
122 https://github.com/bioperl/bioperl-live/issues
123  
124 =head1 AUTHOR - Allen Day
125  
126 Email allenday@ucla.edu
127  
128 =head1 APPENDIX
129  
130 The rest of the documentation details each of the object
131 methods. Internal methods are usually preceded with a _
132  
133 =cut
134  
135 # Let the code begin...
136  
137 package Bio::SeqIO::kegg;
138 2 $Bio::SeqIO::kegg::VERSION = '1.7.8';
139 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
140  
141 2 ▶use Bio::SeqFeature::Generic;
Subroutine BEGIN: called CC=1 SCAR=0.0
142 2 ▶use Bio::Species;
Subroutine BEGIN: called CC=1 SCAR=0.0
143 2 ▶use Bio::Seq::SeqFactory;
Subroutine BEGIN: called CC=1 SCAR=0.0
144 2 ▶use Bio::Annotation::Collection;
Subroutine BEGIN: called CC=1 SCAR=0.0
145 2 ▶use Bio::Annotation::Comment;
Subroutine BEGIN: called CC=1 SCAR=0.0
146 2 ▶use Bio::Annotation::DBLink;
Subroutine BEGIN: called CC=1 SCAR=0.0
147  
148 2 ▶use base qw(Bio::SeqIO);
Subroutine BEGIN: called CC=1 SCAR=0.0
149  
150 1 ▶sub _initialize {
Subroutine _initialize: called CC=2 SCAR=7.0
151 1 my($self,@args) = @_;
152  
153 1 $self->SUPER::_initialize(@args);
154 # hash for functions for decoding keys.
155 1 $self->{'_func_ftunit_hash'} = {};
156 1 ▶ if( ! defined $self->sequence_factory ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->sequence_factory) 1 0 1
157 1 $self->sequence_factory(Bio::Seq::SeqFactory->new
158 (-verbose => $self->verbose(),
159 -type => 'Bio::Seq::RichSeq'));
160 }
161 }
162  
163 =head2 next_seq
164  
165 Title : next_seq
166 Usage : $seq = $stream->next_seq()
167 Function: returns the next sequence in the stream
168 Returns : Bio::Seq::RichSeq object
169 Args :
170  
171 =cut
172  
173 1 ▶sub next_seq {
Subroutine next_seq: called CC=23 SCAR=34.8
Pod documented
174 1 my ($self,@args) = @_;
175 1 my $builder = $self->sequence_builder();
176 1 my $seq;
177 my %params;
178  
179 1 my $buffer;
180 1 my (@acc, @features);
181 1 my ($display_id, $annotation);
182 1 my $species;
183  
184 # initialize; we may come here because of starting over
185 1 @features = ();
186 1 $annotation = undef;
187 1 @acc = ();
188 1 $species = undef;
189 1 %params = (-verbose => $self->verbose); # reset hash
190 1 local($/) = "///\n";
191  
192 1 $buffer = $self->_readline();
193  
194 1 ▶ return if( !defined $buffer ); # end of file
Branch: 1 branch
BranchTrueFalseTotal
unless defined $buffer 0 1 1
195 1 ▶ $buffer =~ /^ENTRY/ ||
Branch: 1 branch
BranchTrueFalseTotal
$buffer =~ /^ENTRY/ or $self->throw("KEGG stream with bad ENTRY line. Not KEGG in my book. Got ${buffer}'") 1 0 1
196 $self->throw("KEGG stream with bad ENTRY line. Not KEGG in my book. Got $buffer'");
197  
198 1 my %FIELDS;
199 1 my @chunks = split /\n(?=\S)/, $buffer;
200  
201 1 foreach my $chunk (@chunks){
202 11 my($key) = $chunk =~ /^(\S+)/;
203 11 $FIELDS{$key} = $chunk;
204 }
205  
206 # changing to split method to get entry_ids that include
207 # sequence version like Whatever.1
208 my(undef,$entry_id,$entry_seqtype,$entry_species) =
209 1 split(' ',$FIELDS{ENTRY});
210  
211 1 my($name);
212 1 ▶ if ($FIELDS{NAME}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($FIELDS{"NAME"}) 1 0 1
213 1 ($name) = $FIELDS{NAME} =~ /^NAME\s+(.+)$/;
214 }
215  
216 1 my( $definition, $aa_length, $aa_seq, $nt_length, $nt_seq );
217  
218 1 ▶ if(( exists $FIELDS{DEFINITION} ) and ( $FIELDS{DEFINITION} =~ /^DEFINITION/ )) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $FIELDS{"DEFINITION"} and $FIELDS{"DEFINITION"} =~ /^DEFINITION/) 1 0 1
Condition33%1/3
exists $FIELDS{"DEFINITION"} and $FIELDS{"DEFINITION"} =~ /^DEFINITION/
!ll&&!rl&&r
001
MC/DC0%0/2
exists $FIELDS{"DEFINITION"} and $FIELDS{"DEFINITION"} =~ /^DEFINITION/
exists $FIELDS{"DEFINITION"} $FIELDS{"DEFINITION"} =~ /^DEFINITION/
Truth table33%1/3
A and B
A= exists $FIELDS{"DEFINITION"}B= $FIELDS{"DEFINITION"} =~ /^DEFINITION/
ABresult
0X0
100
111
219 1 ($definition) = $FIELDS{DEFINITION} =~ /^DEFINITION\s+(.+)$/s;
220 1 $definition =~ s/\s+/ /gs;
221 }
222 1 ▶ if(( exists $FIELDS{AASEQ} ) and ( $FIELDS{AASEQ} =~ /^AASEQ/ )) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $FIELDS{"AASEQ"} and $FIELDS{"AASEQ"} =~ /^AASEQ/) 1 0 1
Condition33%1/3
exists $FIELDS{"AASEQ"} and $FIELDS{"AASEQ"} =~ /^AASEQ/
!ll&&!rl&&r
001
MC/DC0%0/2
exists $FIELDS{"AASEQ"} and $FIELDS{"AASEQ"} =~ /^AASEQ/
exists $FIELDS{"AASEQ"} $FIELDS{"AASEQ"} =~ /^AASEQ/
Truth table33%1/3
A and B
A= exists $FIELDS{"AASEQ"}B= $FIELDS{"AASEQ"} =~ /^AASEQ/
ABresult
0X0
100
111
223 1 ($aa_length,$aa_seq) = $FIELDS{AASEQ} =~ /^AASEQ\s+(\d+)\n(.+)$/s;
224 1 $aa_seq =~ s/\s+//g;
225 }
226 1 ▶ if(( exists $FIELDS{NTSEQ} ) and ( $FIELDS{NTSEQ} =~ /^NTSEQ/ )) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $FIELDS{"NTSEQ"} and $FIELDS{"NTSEQ"} =~ /^NTSEQ/) 1 0 1
Condition33%1/3
exists $FIELDS{"NTSEQ"} and $FIELDS{"NTSEQ"} =~ /^NTSEQ/
!ll&&!rl&&r
001
MC/DC0%0/2
exists $FIELDS{"NTSEQ"} and $FIELDS{"NTSEQ"} =~ /^NTSEQ/
exists $FIELDS{"NTSEQ"} $FIELDS{"NTSEQ"} =~ /^NTSEQ/
Truth table33%1/3
A and B
A= exists $FIELDS{"NTSEQ"}B= $FIELDS{"NTSEQ"} =~ /^NTSEQ/
ABresult
0X0
100
111
227 1 ($nt_length,$nt_seq) = $FIELDS{NTSEQ} =~ /^NTSEQ\s+(\d+)\n(.+)$/s;
228 1 $nt_seq =~ s/\s+//g;
229 }
230  
231 1 $annotation = Bio::Annotation::Collection->new();
232  
233 1 $annotation->add_Annotation('description',
234 Bio::Annotation::Comment->new(-text => $definition));
235  
236 1 $annotation->add_Annotation('aa_seq',
237 Bio::Annotation::Comment->new(-text => $aa_seq));
238  
239 1 my($ortholog_db,$ortholog_id,$ortholog_desc);
240 1 ▶ if ($FIELDS{ORTHOLOG}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($FIELDS{"ORTHOLOG"}) 1 0 1
241 ($ortholog_db,$ortholog_id,$ortholog_desc) = $FIELDS{ORTHOLOG}
242 1 =~ /^ORTHOLOG\s+(\S+):\s+(\S+)\s+(.*?)$/;
243  
244 1 $annotation->add_Annotation('dblink',Bio::Annotation::DBLink->new(
245 -database => $ortholog_db,
246 -primary_id => $ortholog_id,
247 -comment => $ortholog_desc) );
248 }
249  
250 1 ▶ if($FIELDS{MOTIF}){
Branch: 1 branch
BranchTrueFalseTotal
if ($FIELDS{"MOTIF"}) 0 1 1
251 0 $FIELDS{MOTIF} =~ s/^MOTIF\s+//;
252 0 ▶ while($FIELDS{MOTIF} =~/\s*?(\S+):\s+(.+?)$/mg){
Branch: 1 branch
BranchTrueFalseTotal
if ($FIELDS{"MOTIF"} =~ /\s*?(\S+):\s+(.+?)$/gm) 0 0 0
253 0 my $db = $1;
254 0 my $ids = $2;
255 0 foreach my $id (split(/\s+/, $ids)){
256  
257 0 $annotation->add_Annotation('dblink',Bio::Annotation::DBLink->new(
258 -database =>$db,
259 -primary_id => $id,
260 -comment => "") );
261 }
262 }
263 }
264  
265 1 ▶ if($FIELDS{PATHWAY}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($FIELDS{"PATHWAY"}) 0 1 1
266 0 $FIELDS{PATHWAY} =~ s/^PATHWAY\s+//;
267 0 ▶ while($FIELDS{PATHWAY} =~ /\s*PATH:\s+(.+)$/mg){
Branch: 1 branch
BranchTrueFalseTotal
if ($FIELDS{"PATHWAY"} =~ /\s*PATH:\s+(.+)$/gm) 0 0 0
268 0 $annotation->add_Annotation('pathway',
269 Bio::Annotation::Comment->new(-text => "$1"));
270 }
271 }
272  
273 1 ▶ if($FIELDS{POSITION}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($FIELDS{"POSITION"}) 1 0 1
274 1 $FIELDS{POSITION} =~ s/^POSITION\s+//;
275 $annotation->add_Annotation('position',
276 1 Bio::Annotation::Comment->new(-text => $FIELDS{POSITION}));
277 }
278
279 1 ▶ if ($FIELDS{CLASS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($FIELDS{"CLASS"}) 1 0 1
280 1 $FIELDS{CLASS} =~ s/^CLASS\s+//;
281 1 $FIELDS{'CLASS'} =~ s/\n//g;
282 1 ▶ while($FIELDS{CLASS} =~ /(.*?)\[(\S+):(\S+)\]/g){
Branch: 1 branch
BranchTrueFalseTotal
if ($FIELDS{"CLASS"} =~ /(.*?)\[(\S+):(\S+)\]/g) 2 1 3
283 2 my ($pathway,$db,$id) = ($1,$2,$3);
284 2 $pathway =~ s/\s+/ /g;
285 2 $pathway =~ s/\s$//g;
286 2 $pathway =~ s/^\s+//;
287 2 $annotation->add_Annotation('pathway',
288 Bio::Annotation::Comment->new(-text => $pathway));
289  
290 2 $annotation->add_Annotation('dblink',Bio::Annotation::DBLink->new(
291 -database => $db, -primary_id => $id));
292 }
293 }
294  
295 1 ▶ if($FIELDS{DBLINKS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($FIELDS{"DBLINKS"}) 1 0 1
296 1 $FIELDS{DBLINKS} =~ s/^DBLINKS/ /;
297 1 ▶ while($FIELDS{DBLINKS} =~ /\s+(\S+):\s+(\S+)\n?/gs){ ### modified
Branch: 1 branch
BranchTrueFalseTotal
if ($FIELDS{"DBLINKS"} =~ /\s+(\S+):\s+(\S+)\n?/gs) 4 1 5
298 4 ▶ $annotation->add_Annotation('dblink',Bio::Annotation::DBLink->new(
Branch: 1 branch
BranchTrueFalseTotal
if $1 4 0 4
299 -database => $1, -primary_id => $2)) if $1;
300 }
301 }
302  
303 1 $params{'-alphabet'} = 'dna';
304 1 $params{'-seq'} = $nt_seq;
305 1 $params{'-display_id'} = $name;
306 1 $params{'-accession_number'} = $entry_id;
307 1 $params{'-species'} = Bio::Species->new(
308 -common_name => $entry_species);
309 1 $params{'-annotation'} = $annotation;
310  
311 1 $builder->add_slot_value(%params);
312 1 $seq = $builder->make_object();
313  
314 1 return $seq;
315 }
316  
317 =head2 write_seq
318  
319 Title : write_seq
320 Note : write_seq() is not implemented for KEGG format output.
321  
322 =cut
323  
324 0 ▶sub write_seq {
Subroutine write_seq: not called CC=1 SCAR=6.9
Pod documented
325 0 shift->throw("write_seq() not implemented for KEGG format output.");
326 }
327  
328 2 1;
« Bio/SeqIO/embldriver.pm ↑ Summary Bio/TreeIO/NewickParser.pm »