Pull out the 'recommends' table and refactor to make a bit more
[bioperl-live.git] / Bio / Seq / RichSeq.pm
blob9bfff6d7b3fa6980ff09d249f75fbdc327ae56c7
2 # BioPerl module for Bio::Seq::RichSeq
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Ewan Birney <birney@ebi.ac.uk>
8 # Copyright Ewan Birney
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
14 =head1 NAME
16 Bio::Seq::RichSeq - Module implementing a sequence created from a rich
17 sequence database entry
19 =head1 SYNOPSIS
21 See L<Bio::Seq::RichSeqI> and documentation of methods.
23 =head1 DESCRIPTION
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.
31 For more information, please see the relevant
33 =head1 Implemented Interfaces
35 This class implementes the following interfaces.
37 =over 4
39 =item L<Bio::Seq::RichSeqI>
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.
46 =item L<Bio::IdentifiableI>
48 =item L<Bio::DescribableI>
50 =item L<Bio::AnnotatableI>
52 =back
54 =head1 FEEDBACK
56 =head2 Mailing Lists
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.
63 bioperl-l@bioperl.org - General discussion
64 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
66 =head2 Support
68 Please direct usage questions or support issues to the mailing list:
70 I<bioperl-l@bioperl.org>
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.
77 =head2 Reporting Bugs
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:
83 https://redmine.open-bio.org/projects/bioperl/
85 =head1 AUTHOR - Ewan Birney
87 Email birney@ebi.ac.uk
89 =head1 APPENDIX
91 The rest of the documentation details each of the object
92 methods. Internal methods are usually preceded with a _
94 =cut
97 # Let the code begin...
100 package Bio::Seq::RichSeq;
101 use vars qw($AUTOLOAD);
102 use strict;
106 use base qw(Bio::Seq Bio::Seq::RichSeqI);
109 =head2 new
111 Title : new
112 Usage : $seq = Bio::Seq::RichSeq->new( -seq => 'ATGGGGGTGGTGGTACCCT',
113 -id => 'human_id',
114 -accession_number => 'AL000012',
117 Function: Returns a new seq object from
118 basic constructors, being a string for the sequence
119 and strings for id and accession_number
120 Returns : a new Bio::Seq::RichSeq object
122 =cut
124 sub new {
125 # standard new call..
126 my($caller,@args) = @_;
127 my $self = $caller->SUPER::new(@args);
129 $self->{'_dates'} = [];
130 $self->{'_secondary_accession'} = [];
132 my ($dates, $xtra, $sv,
133 $keywords, $pid, $mol,
134 $division ) = $self->_rearrange([qw(DATES
135 SECONDARY_ACCESSIONS
136 SEQ_VERSION
137 KEYWORDS
139 MOLECULE
140 DIVISION
142 @args);
143 defined $division && $self->division($division);
144 defined $mol && $self->molecule($mol);
145 if(defined($keywords)) {
146 if(ref($keywords) && (ref($keywords) eq "ARRAY")) {
147 $self->add_keyword(@$keywords);
148 } else {
149 # got a string - use the old API
150 $self->keywords($keywords);
153 defined $sv && $self->seq_version($sv);
154 defined $pid && $self->pid($pid);
156 if( defined $dates ) {
157 if( ref($dates) eq "ARRAY" ) {
158 foreach ( @$dates) {
159 $self->add_date($_);
161 } else {
162 $self->add_date($dates);
166 if( defined $xtra ) {
167 if( ref($xtra) eq "ARRAY" ) {
168 foreach ( @$xtra) {
169 $self->add_secondary_accession($_);
171 } else {
172 $self->add_secondary_accession($xtra);
176 return $self;
180 =head2 division
182 Title : division
183 Usage : $obj->division($newval)
184 Function:
185 Returns : value of division
186 Args : newvalue (optional)
189 =cut
191 sub division {
192 my $obj = shift;
193 if( @_ ) {
194 my $value = shift;
195 $obj->{'_division'} = $value;
197 return $obj->{'_division'};
201 =head2 molecule
203 Title : molecule
204 Usage : $obj->molecule($newval)
205 Function:
206 Returns : type of molecule (DNA, mRNA)
207 Args : newvalue (optional)
210 =cut
212 sub molecule {
213 my $obj = shift;
214 if( @_ ) {
215 my $value = shift;
216 $obj->{'_molecule'} = $value;
218 return $obj->{'_molecule'};
222 =head2 add_date
224 Title : add_date
225 Usage : $self->add_date($datestr)
226 Function: adds one or more dates
228 This implementation stores dates as keyed annotation, the
229 key being 'date_changed'. You can take advantage of this
230 fact when accessing the annotation collection directly.
232 Example :
233 Returns :
234 Args : a date string or an array of such strings
237 =cut
239 sub add_date {
240 return shift->_add_annotation_value('date_changed',@_);
243 =head2 get_dates
245 Title : get_dates
246 Usage : my @dates = $seq->get_dates;
247 Function: Get the dates of the sequence (usually, when it was created and
248 changed.
249 Returns : an array of date strings
250 Args :
253 =cut
255 sub get_dates{
256 return shift->_get_annotation_values('date_changed');
260 =head2 pid
262 Title : pid
263 Usage : my $pid = $seq->pid();
264 Function: Get (and set, depending on the implementation) the PID property
265 for the sequence.
266 Returns : a string
267 Args :
270 =cut
272 sub pid{
273 my $self = shift;
275 return $self->{'_pid'} = shift if @_;
276 return $self->{'_pid'};
280 =head2 accession
282 Title : accession
283 Usage : $obj->accession($newval)
284 Function: Whilst the underlying sequence object does not
285 have an accession, so we need one here.
287 In this implementation this is merely a synonym for
288 accession_number().
289 Example :
290 Returns : value of accession
291 Args : newvalue (optional)
294 =cut
296 sub accession {
297 my ($obj,@args) = @_;
298 return $obj->accession_number(@args);
301 =head2 add_secondary_accession
303 Title : add_secondary_accession
304 Usage : $self->add_domment($ref)
305 Function: adds a secondary_accession
307 This implementation stores secondary accession numbers as
308 keyed annotation, the key being 'secondary_accession'. You
309 can take advantage of this fact when accessing the
310 annotation collection directly.
312 Example :
313 Returns :
314 Args : a string or an array of strings
317 =cut
319 sub add_secondary_accession {
320 return shift->_add_annotation_value('secondary_accession',@_);
323 =head2 get_secondary_accessions
325 Title : get_secondary_accessions
326 Usage : my @acc = $seq->get_secondary_accessions();
327 Function: Get the secondary accession numbers as strings.
328 Returns : An array of strings
329 Args : none
332 =cut
334 sub get_secondary_accessions{
335 return shift->_get_annotation_values('secondary_accession');
338 =head2 seq_version
340 Title : seq_version
341 Usage : $obj->seq_version($newval)
342 Function: Get/set the sequence version
343 Returns : value of seq_version (a scalar)
344 Args : on set, new value (a scalar or undef, optional)
345 Note : this differs from Bio::PrimarySeq version() in that this explicitly
346 refers to the sequence record version one would find in a typical
347 sequence file.
349 =cut
351 sub seq_version{
352 my $self = shift;
354 return $self->{'_seq_version'} = shift if @_;
355 return $self->{'_seq_version'};
359 =head2 add_keyword
361 Title : add_keyword
362 Usage : $obj->add_keyword($newval)
363 Function: Add a new keyword to the annotation of the sequence.
365 This implementation stores keywords as keyed annotation,
366 the key being 'keyword'. You can take advantage of this
367 fact when accessing the annotation collection directly.
369 Returns :
370 Args : value to be added (optional) (a string)
373 =cut
375 sub add_keyword {
376 return shift->_add_annotation_value('keyword',@_);
379 =head2 get_keywords
381 Title : get_keywords
382 Usage : $obj->get_keywords($newval)
383 Function: Get the keywords for this sequence as an array of strings.
384 Returns : an array of strings
385 Args :
388 =cut
390 sub get_keywords {
391 return shift->_get_annotation_values('keyword');
394 =head1 Private methods and synonyms for backward compatibility
396 =cut
398 =head2 _add_annotation_value
400 Title : _add_annotation_value
401 Usage :
402 Function: Adds a value to the annotation collection under the specified
403 key. Note that this is not a public method.
404 Returns :
405 Args : key (a string), value(s) (one or more scalars)
408 =cut
410 sub _add_annotation_value{
411 my $self = shift;
412 my $key = shift;
414 foreach my $val (@_) {
415 $self->annotation->add_Annotation(
416 Bio::Annotation::SimpleValue->new(-tagname => $key,
417 -value => $val)
422 =head2 _get_annotation_values
424 Title : _get_annotation_values
425 Usage :
426 Function: Gets the values of a specific annotation as identified by the
427 key from the annotation collection. Note that this is not a
428 public method.
429 Example :
430 Returns : an array of strings
431 Args : the key (a string)
434 =cut
436 sub _get_annotation_values{
437 my $self = shift;
439 return map { $_->value(); } $self->annotation->get_Annotations(shift);
444 ### Deprecated methods kept for ease of transition
448 sub keywords {
449 my $self = shift;
451 # have we been called in set mode?
452 if(@_) {
453 # yes; translate to the new API
454 foreach my $kwd (@_) {
455 $self->add_keyword(split(/\s*;\s*/,$kwd));
457 } else {
458 # no; translate read-only to the new API
459 return join("; ",$self->get_keywords());
463 sub each_date {
464 my ($self) = @_;
465 $self->warn("Deprecated method... please use get_dates");
466 return $self->get_dates;
470 sub each_secondary_accession {
471 my ($self) = @_;
472 $self->warn("each_secondary_accession - deprecated method. use get_secondary_accessions");
473 return $self->get_secondary_accessions;
477 sub sv {
478 my ($obj,$value) = @_;
479 $obj->warn("sv - deprecated method. use seq_version");
480 $obj->seq_version($value);