Bio/Seq/RichSeq.pm

filter: Statementstmt 87.5% 70 / 80 Branchbran 96.6% 29 / 30 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 85.7% 18 / 21 Podpod 75.0% 12 / 16 totaltotal 86.8% 132 / 152 CC 21 SCAR 17.8
CC
21
Cov
89%
new
14.1
keywords
3.0
division
2.0
CRAP 5.9
« Bio/DB/IndexedBase.pm ↑ Summary Bio/Seq.pm »
1 #
2 # BioPerl module for Bio::Seq::RichSeq
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::Seq::RichSeq - Module implementing a sequence created from a rich
17 sequence database entry
18  
19 =head1 SYNOPSIS
20  
21 See L<Bio::Seq::RichSeqI> and documentation of methods.
22  
23 =head1 DESCRIPTION
24  
25 This module implements Bio::Seq::RichSeqI, an interface for sequences
26 created from or created for entries from/of rich sequence databanks,
27 like EMBL, GenBank, and SwissProt. Methods added to the Bio::SeqI
28 interface therefore focus on databank-specific information. Note that
29 not every rich databank format may use all of the properties provided.
30  
31 For more information, please see the relevant
32  
33 =head1 Implemented Interfaces
34  
35 This class implementes the following interfaces.
36  
37 =over 4
38  
39 =item L<Bio::Seq::RichSeqI>
40  
41 Note that this includes implementing L<Bio::PrimarySeqI> and L<Bio::SeqI>,
42 specifically via L<Bio::Seq> and L<Bio::PrimarySeq>. Please review the
43 documentation for those modules on implementation details relevant to those
44 interfaces, as well as the ones below.
45  
46 =item L<Bio::IdentifiableI>
47  
48 =item L<Bio::DescribableI>
49  
50 =item L<Bio::AnnotatableI>
51  
52 =back
53  
54 =head1 FEEDBACK
55  
56 =head2 Mailing Lists
57  
58 User feedback is an integral part of the evolution of this
59 and other Bioperl modules. Send your comments and suggestions preferably
60 to one of the Bioperl mailing lists.
61 Your participation is much appreciated.
62  
63 bioperl-l@bioperl.org - General discussion
64 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
65  
66 =head2 Support
67  
68 Please direct usage questions or support issues to the mailing list:
69  
70 I<bioperl-l@bioperl.org>
71  
72 rather than to the module maintainer directly. Many experienced and
73 reponsive experts will be able look at the problem and quickly
74 address it. Please include a thorough description of the problem
75 with code and data examples if at all possible.
76  
77 =head2 Reporting Bugs
78  
79 Report bugs to the Bioperl bug tracking system to help us keep track
80 the bugs and their resolution. Bug reports can be submitted via the
81 web:
82  
83 https://github.com/bioperl/bioperl-live/issues
84  
85 =head1 AUTHOR - Ewan Birney
86  
87 Email birney@ebi.ac.uk
88  
89 =head1 APPENDIX
90  
91 The rest of the documentation details each of the object
92 methods. Internal methods are usually preceded with a _
93  
94 =cut
95  
96  
97 # Let the code begin...
98  
99  
100 package Bio::Seq::RichSeq;
101 26 $Bio::Seq::RichSeq::VERSION = '1.7.8';
102 26 ▶use vars qw($AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
103 26 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
104  
105  
106  
107 26 ▶use base qw(Bio::Seq Bio::Seq::RichSeqI);
Subroutine BEGIN: called CC=1 SCAR=0.0
108  
109  
110 =head2 new
111  
112 Title : new
113 Usage : $seq = Bio::Seq::RichSeq->new( -seq => 'ATGGGGGTGGTGGTACCCT',
114 -id => 'human_id',
115 -accession_number => 'AL000012',
116 );
117  
118 Function: Returns a new seq object from
119 basic constructors, being a string for the sequence
120 and strings for id and accession_number
121 Returns : a new Bio::Seq::RichSeq object
122  
123 =cut
124  
125 334 ▶sub new {
Subroutine new: called CC=14 SCAR=26.4
Pod documented
126 # standard new call..
127 334 my($caller,@args) = @_;
128 334 my $self = $caller->SUPER::new(@args);
129
130 334 $self->{'_dates'} = [];
131 334 $self->{'_secondary_accession'} = [];
132  
133 334 my ($dates, $xtra, $sv,
134 $keywords, $pid, $mol,
135 $division ) = $self->_rearrange([qw(DATES
136 SECONDARY_ACCESSIONS
137 SEQ_VERSION
138 KEYWORDS
139 PID
140 MOLECULE
141 DIVISION
142 )],
143 @args);
144 334 ▶ defined $division && $self->division($division);
Branch: 1 branch
BranchTrueFalseTotal
defined $division and $self->division($division) 201 133 334
145 334 ▶ defined $mol && $self->molecule($mol);
Branch: 1 branch
BranchTrueFalseTotal
defined $mol and $self->molecule($mol) 163 171 334
146 334 ▶ if(defined($keywords)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $keywords) 193 141 334
147 193 ▶ if(ref($keywords) && (ref($keywords) eq "ARRAY")) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $keywords and ref $keywords eq 'ARRAY') { } 192 1 193
Condition66%2/3
ref $keywords and ref $keywords eq "ARRAY"
!ll&&!rl&&r
10192
MC/DC50%1/2
ref $keywords and ref $keywords eq "ARRAY"
ref $keywords ref $keywords eq "ARRAY"
Truth table66%2/3
A and B
A= ref $keywordsB= ref $keywords eq "ARRAY"
ABresult
0X0
100
111
148 192 $self->add_keyword(@$keywords);
149 } else {
150 # got a string - use the old API
151 1 $self->keywords($keywords);
152 }
153 }
154 334 ▶ defined $sv && $self->seq_version($sv);
Branch: 1 branch
BranchTrueFalseTotal
defined $sv and $self->seq_version($sv) 137 197 334
155 334 ▶ defined $pid && $self->pid($pid);
Branch: 1 branch
BranchTrueFalseTotal
defined $pid and $self->pid($pid) 2 332 334
156  
157 334 ▶ if( defined $dates ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dates) 190 144 334
158 190 ▶ if( ref($dates) eq "ARRAY" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $dates eq 'ARRAY') { } 190 0 190
159 190 foreach ( @$dates) {
160 282 $self->add_date($_);
161 }
162 } else {
163 0 $self->add_date($dates);
164 }
165 }
166  
167 334 ▶ if( defined $xtra ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $xtra) 157 177 334
168 157 ▶ if( ref($xtra) eq "ARRAY" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $xtra eq 'ARRAY') { } 156 1 157
169 156 foreach ( @$xtra) {
170 117 $self->add_secondary_accession($_);
171 }
172 } else {
173 1 $self->add_secondary_accession($xtra);
174 }
175 }
176
177 334 return $self;
178 }
179  
180  
181 =head2 division
182  
183 Title : division
184 Usage : $obj->division($newval)
185 Function:
186 Returns : value of division
187 Args : newvalue (optional)
188  
189  
190 =cut
191  
192 252 ▶sub division {
Subroutine division: called CC=2 SCAR=6.9
Pod documented
193 252 my $obj = shift;
194 252 ▶ if( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 202 50 252
195 202 my $value = shift;
196 202 $obj->{'_division'} = $value;
197 }
198 252 return $obj->{'_division'};
199  
200 }
201  
202 =head2 molecule
203  
204 Title : molecule
205 Usage : $obj->molecule($newval)
206 Function:
207 Returns : type of molecule (DNA, mRNA)
208 Args : newvalue (optional)
209  
210  
211 =cut
212  
213 209 ▶sub molecule {
Subroutine molecule: called CC=2 SCAR=6.9
Pod documented
214 209 my $obj = shift;
215 209 ▶ if( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 164 45 209
216 164 my $value = shift;
217 164 $obj->{'_molecule'} = $value;
218 }
219 209 return $obj->{'_molecule'};
220  
221 }
222  
223 =head2 add_date
224  
225 Title : add_date
226 Usage : $self->add_date($datestr)
227 Function: adds one or more dates
228  
229 This implementation stores dates as keyed annotation, the
230 key being 'date_changed'. You can take advantage of this
231 fact when accessing the annotation collection directly.
232  
233 Example :
234 Returns :
235 Args : a date string or an array of such strings
236  
237  
238 =cut
239  
240 286 ▶sub add_date {
Subroutine add_date: called CC=1 SCAR=0.0
Pod documented
241 286 return shift->_add_annotation_value('date_changed',@_);
242 }
243  
244 =head2 get_dates
245  
246 Title : get_dates
247 Usage : my @dates = $seq->get_dates;
248 Function: Get the dates of the sequence (usually, when it was created and
249 changed.
250 Returns : an array of date strings
251 Args :
252  
253  
254 =cut
255  
256 63 ▶sub get_dates{
Subroutine get_dates: called CC=1 SCAR=0.0
Pod documented
257 63 return shift->_get_annotation_values('date_changed');
258 }
259  
260  
261 =head2 pid
262  
263 Title : pid
264 Usage : my $pid = $seq->pid();
265 Function: Get (and set, depending on the implementation) the PID property
266 for the sequence.
267 Returns : a string
268 Args :
269  
270  
271 =cut
272  
273 25 ▶sub pid{
Subroutine pid: called CC=2 SCAR=6.9
Pod documented
274 25 my $self = shift;
275  
276 25 ▶ return $self->{'_pid'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 2 23 25
277 23 return $self->{'_pid'};
278 }
279  
280  
281 =head2 accession
282  
283 Title : accession
284 Usage : $obj->accession($newval)
285 Function: Whilst the underlying sequence object does not
286 have an accession, so we need one here.
287  
288 In this implementation this is merely a synonym for
289 accession_number().
290 Example :
291 Returns : value of accession
292 Args : newvalue (optional)
293  
294  
295 =cut
296  
297 4 ▶sub accession {
Subroutine accession: called CC=1 SCAR=0.0
Pod documented
298 4 my ($obj,@args) = @_;
299 4 return $obj->accession_number(@args);
300 }
301  
302 =head2 add_secondary_accession
303  
304 Title : add_secondary_accession
305 Usage : $self->add_domment($ref)
306 Function: adds a secondary_accession
307  
308 This implementation stores secondary accession numbers as
309 keyed annotation, the key being 'secondary_accession'. You
310 can take advantage of this fact when accessing the
311 annotation collection directly.
312  
313 Example :
314 Returns :
315 Args : a string or an array of strings
316  
317  
318 =cut
319  
320 118 ▶sub add_secondary_accession {
Subroutine add_secondary_accession: called CC=1 SCAR=0.0
Pod documented
321 118 return shift->_add_annotation_value('secondary_accession',@_);
322 }
323  
324 =head2 get_secondary_accessions
325  
326 Title : get_secondary_accessions
327 Usage : my @acc = $seq->get_secondary_accessions();
328 Function: Get the secondary accession numbers as strings.
329 Returns : An array of strings
330 Args : none
331  
332  
333 =cut
334  
335 35 ▶sub get_secondary_accessions{
Subroutine get_secondary_accessions: called CC=1 SCAR=0.0
Pod documented
336 35 return shift->_get_annotation_values('secondary_accession');
337 }
338  
339 =head2 seq_version
340  
341 Title : seq_version
342 Usage : $obj->seq_version($newval)
343 Function: Get/set the sequence version
344 Returns : value of seq_version (a scalar)
345 Args : on set, new value (a scalar or undef, optional)
346 Note : this differs from Bio::PrimarySeq version() in that this explicitly
347 refers to the sequence record version one would find in a typical
348 sequence file.
349  
350 =cut
351  
352 196 ▶sub seq_version{
Subroutine seq_version: called CC=2 SCAR=6.9
Pod documented
353 196 my $self = shift;
354  
355 196 ▶ return $self->{'_seq_version'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 140 56 196
356 56 return $self->{'_seq_version'};
357 }
358  
359  
360 =head2 add_keyword
361  
362 Title : add_keyword
363 Usage : $obj->add_keyword($newval)
364 Function: Add a new keyword to the annotation of the sequence.
365  
366 This implementation stores keywords as keyed annotation,
367 the key being 'keyword'. You can take advantage of this
368 fact when accessing the annotation collection directly.
369  
370 Returns :
371 Args : value to be added (optional) (a string)
372  
373  
374 =cut
375  
376 193 ▶sub add_keyword {
Subroutine add_keyword: called CC=1 SCAR=0.0
Pod documented
377 193 return shift->_add_annotation_value('keyword',@_);
378 }
379  
380 =head2 get_keywords
381  
382 Title : get_keywords
383 Usage : $obj->get_keywords($newval)
384 Function: Get the keywords for this sequence as an array of strings.
385 Returns : an array of strings
386 Args :
387  
388  
389 =cut
390  
391 39 ▶sub get_keywords {
Subroutine get_keywords: called CC=1 SCAR=0.0
Pod documented
392 39 return shift->_get_annotation_values('keyword');
393 }
394  
395 =head1 Private methods and synonyms for backward compatibility
396  
397 =cut
398  
399 =head2 _add_annotation_value
400  
401 Title : _add_annotation_value
402 Usage :
403 Function: Adds a value to the annotation collection under the specified
404 key. Note that this is not a public method.
405 Returns :
406 Args : key (a string), value(s) (one or more scalars)
407  
408  
409 =cut
410  
411 597 ▶sub _add_annotation_value{
Subroutine _add_annotation_value: called CC=2 SCAR=6.9
412 597 my $self = shift;
413 597 my $key = shift;
414  
415 597 foreach my $val (@_) {
416 1365 $self->annotation->add_Annotation(
417 Bio::Annotation::SimpleValue->new(-tagname => $key,
418 -value => $val)
419 );
420 }
421 }
422  
423 =head2 _get_annotation_values
424  
425 Title : _get_annotation_values
426 Usage :
427 Function: Gets the values of a specific annotation as identified by the
428 key from the annotation collection. Note that this is not a
429 public method.
430 Example :
431 Returns : an array of strings
432 Args : the key (a string)
433  
434  
435 =cut
436  
437 137 ▶sub _get_annotation_values{
Subroutine _get_annotation_values: called CC=1 SCAR=0.0
438 137 my $self = shift;
439  
440 137 return map { $_->value(); } $self->annotation->get_Annotations(shift);
441 }
442  
443 #
444 ##
445 ### Deprecated methods kept for ease of transition
446 ##
447 #
448  
449 36 ▶sub keywords {
Subroutine keywords: called CC=3 SCAR=11.0
Pod undocumented
450 36 my $self = shift;
451  
452 # have we been called in set mode?
453 36 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 1 35 36
454 # yes; translate to the new API
455 1 foreach my $kwd (@_) {
456 1 $self->add_keyword(split(/\s*;\s*/,$kwd));
457 }
458 } else {
459 # no; translate read-only to the new API
460 35 return join("; ",$self->get_keywords());
461 }
462 }
463  
464 0 ▶sub each_date {
Subroutine each_date: not called CC=1 SCAR=6.9
Pod undocumented
465 0 my ($self) = @_;
466 0 $self->warn("Deprecated method... please use get_dates");
467 0 return $self->get_dates;
468 }
469  
470  
471 0 ▶sub each_secondary_accession {
Subroutine each_secondary_accession: not called CC=1 SCAR=6.9
Pod undocumented
472 0 my ($self) = @_;
473 0 $self->warn("each_secondary_accession - deprecated method. use get_secondary_accessions");
474 0 return $self->get_secondary_accessions;
475  
476 }
477  
478 0 ▶sub sv {
Subroutine sv: not called CC=1 SCAR=6.9
Pod undocumented
479 0 my ($obj,$value) = @_;
480 0 $obj->warn("sv - deprecated method. use seq_version");
481 0 $obj->seq_version($value);
482 }
483  
484  
485 26 1;
« Bio/DB/IndexedBase.pm ↑ Summary Bio/Seq.pm »