sync w/ main trunk
[bioperl-live.git] / Bio / Annotation / Reference.pm
blobcb5ab348a3423fdbb7471e1f53b8a15b4d2714c8
1 # $Id$
3 # BioPerl module for Bio::Annotation::Reference
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by Ewan Birney <birney@ebi.ac.uk>
9 # Copyright Ewan Birney
11 # You may distribute this module under the same terms as perl itself
13 # POD documentation - main docs before the code
15 =head1 NAME
17 Bio::Annotation::Reference - Specialised DBLink object for Literature References
19 =head1 SYNOPSIS
21 $reg = Bio::Annotation::Reference->new( -title => 'title line',
22 -location => 'location line',
23 -authors => 'author line',
24 -medline => 998122 );
26 =head1 DESCRIPTION
28 Object which presents a literature reference. This is considered to be
29 a specialised form of database link. The additional methods provided
30 are all set/get methods to store strings commonly associated with
31 references, in particular title, location (ie, journal page) and
32 authors line.
34 There is no attempt to do anything more than store these things as
35 strings for processing elsewhere. This is mainly because parsing these
36 things suck and generally are specific to the specific format one is
37 using. To provide an easy route to go format --E<gt> object --E<gt> format
38 without losing data, we keep them as strings. Feel free to post the
39 list for a better solution, but in general this gets very messy very
40 fast...
42 =head1 AUTHOR - Ewan Birney
44 Email birney@ebi.ac.uk
46 =head1 APPENDIX
48 The rest of the documentation details each of the object
49 methods. Internal methods are usually preceded with a _
51 =cut
54 # Let the code begin...
56 package Bio::Annotation::Reference;
57 use strict;
59 use base qw(Bio::Annotation::DBLink);
61 =head2 new
63 Title : new
64 Usage : $ref = Bio::Annotation::Reference->new( -title => 'title line',
65 -authors => 'author line',
66 -location => 'location line',
67 -medline => 9988812);
68 Function:
69 Example :
70 Returns : a new Bio::Annotation::Reference object
71 Args : a hash with optional title, authors, location, medline, pubmed,
72 start, end, consortium, rp and rg attributes
75 =cut
77 sub new{
78 my ($class,@args) = @_;
80 my $self = $class->SUPER::new(@args);
82 my ($start,$end,$authors,$consortium,$location,$title,$medline,
83 $pubmed,$rp,$rg,$doi) =
84 $self->_rearrange([qw(START
85 END
86 AUTHORS
87 CONSORTIUM
88 LOCATION
89 TITLE
90 MEDLINE
91 PUBMED
94 DOI
95 )],@args);
97 defined $start && $self->start($start);
98 defined $end && $self->end($end);
99 defined $authors && $self->authors($authors);
100 defined $consortium && $self->consortium($consortium);
101 defined $location && $self->location($location);
102 defined $title && $self->title($title);
103 defined $medline && $self->medline($medline);
104 defined $pubmed && $self->pubmed($pubmed);
105 defined $rp && $self->rp($rp);
106 defined $rg && $self->rg($rg);
107 defined $doi && $self->doi($doi);
108 return $self;
112 =head1 AnnotationI implementing functions
114 =cut
116 =head2 as_text
118 Title : as_text
119 Usage :
120 Function:
121 Example :
122 Returns :
123 Args :
126 =cut
128 sub as_text{
129 my ($self) = @_;
131 # this could get out of hand!
132 return "Reference: ".$self->title;
135 =head2 display_text
137 Title : display_text
138 Usage : my $str = $ann->display_text();
139 Function: returns a string. Unlike as_text(), this method returns a string
140 formatted as would be expected for te specific implementation.
142 One can pass a callback as an argument which allows custom text
143 generation; the callback is passed the current instance and any text
144 returned
145 Example :
146 Returns : a string
147 Args : [optional] callback
149 =cut
152 my $DEFAULT_CB = sub { $_[0]->title || ''};
154 sub display_text {
155 my ($self, $cb) = @_;
156 $cb ||= $DEFAULT_CB;
157 $self->throw("Callback must be a code reference") if ref $cb ne 'CODE';
158 return $cb->($self);
163 =head2 hash_tree
165 Title : hash_tree
166 Usage :
167 Function:
168 Example :
169 Returns :
170 Args :
173 =cut
175 sub hash_tree{
176 my ($self) = @_;
178 my $h = {};
179 $h->{'title'} = $self->title;
180 $h->{'authors'} = $self->authors;
181 $h->{'location'} = $self->location;
182 if (defined $self->start) {
183 $h->{'start'} = $self->start;
185 if (defined $self->end) {
186 $h->{'end'} = $self->end;
188 $h->{'medline'} = $self->medline;
189 if (defined $self->pubmed) {
190 $h->{'pubmed'} = $self->pubmed;
193 return $h;
196 =head2 tagname
198 Title : tagname
199 Usage : $obj->tagname($newval)
200 Function: Get/set the tagname for this annotation value.
202 Setting this is optional. If set, it obviates the need to provide
203 a tag to Bio::AnnotationCollectionI when adding this object. When
204 obtaining an AnnotationI object from the collection, the collection
205 will set the value to the tag under which it was stored unless the
206 object has a tag stored already.
207 Example :
208 Returns : value of tagname (a scalar)
209 Args : new value (a scalar, optional)
212 =cut
215 =head1 Specific accessors for References
217 =cut
220 =head2 start
222 Title : start
223 Usage : $self->start($newval)
224 Function: Gives the reference start base
225 Example :
226 Returns : value of start
227 Args : newvalue (optional)
230 =cut
232 sub start {
233 my ($self,$value) = @_;
234 if( defined $value) {
235 $self->{'start'} = $value;
237 return $self->{'start'};
241 =head2 end
243 Title : end
244 Usage : $self->end($newval)
245 Function: Gives the reference end base
246 Example :
247 Returns : value of end
248 Args : newvalue (optional)
251 =cut
253 sub end {
254 my ($self,$value) = @_;
255 if( defined $value) {
256 $self->{'end'} = $value;
258 return $self->{'end'};
261 =head2 rp
263 Title : rp
264 Usage : $self->rp($newval)
265 Function: Gives the RP line. No attempt is made to parse this line.
266 Example :
267 Returns : value of rp
268 Args : newvalue (optional)
271 =cut
273 sub rp{
274 my ($self,$value) = @_;
275 if( defined $value) {
276 $self->{'rp'} = $value;
278 return $self->{'rp'};
281 =head2 rg
283 Title : rg
284 Usage : $obj->rg($newval)
285 Function: Gives the RG line. This is Swissprot/Uniprot specific, and
286 if set will usually be identical to the authors attribute,
287 but the swissprot manual does allow both RG and RA (author)
288 to be present for the same reference.
290 Example :
291 Returns : value of rg (a scalar)
292 Args : on set, new value (a scalar or undef, optional)
295 =cut
297 sub rg{
298 my $self = shift;
300 return $self->{'rg'} = shift if @_;
301 return $self->{'rg'};
304 =head2 authors
306 Title : authors
307 Usage : $self->authors($newval)
308 Function: Gives the author line. No attempt is made to parse the author line
309 Example :
310 Returns : value of authors
311 Args : newvalue (optional)
314 =cut
316 sub authors{
317 my ($self,$value) = @_;
318 if( defined $value) {
319 $self->{'authors'} = $value;
321 return $self->{'authors'};
325 =head2 location
327 Title : location
328 Usage : $self->location($newval)
329 Function: Gives the location line. No attempt is made to parse the location line
330 Example :
331 Returns : value of location
332 Args : newvalue (optional)
335 =cut
337 sub location{
338 my ($self,$value) = @_;
339 if( defined $value) {
340 $self->{'location'} = $value;
342 return $self->{'location'};
346 =head2 title
348 Title : title
349 Usage : $self->title($newval)
350 Function: Gives the title line (if exists)
351 Example :
352 Returns : value of title
353 Args : newvalue (optional)
356 =cut
358 sub title{
359 my ($self,$value) = @_;
360 if( defined $value) {
361 $self->{'title'} = $value;
363 return $self->{'title'};
367 =head2 medline
369 Title : medline
370 Usage : $self->medline($newval)
371 Function: Gives the medline number
372 Example :
373 Returns : value of medline
374 Args : newvalue (optional)
377 =cut
379 sub medline{
380 my ($self,$value) = @_;
381 if( defined $value) {
382 $self->{'medline'} = $value;
384 return $self->{'medline'};
387 =head2 pubmed
389 Title : pubmed
390 Usage : $refobj->pubmed($newval)
391 Function: Get/Set the PubMed number, if it is different from the MedLine
392 number.
393 Example :
394 Returns : value of medline
395 Args : newvalue (optional)
398 =cut
400 sub pubmed {
401 my ($self,$value) = @_;
402 if( defined $value) {
403 $self->{'pubmed'} = $value;
405 return $self->{'pubmed'};
408 =head2 database
410 Title : database
411 Usage :
412 Function: Overrides DBLink database to be hard coded to 'MEDLINE' (or 'PUBMED'
413 if only pubmed id has been supplied), unless the database has been
414 set explicitely before.
415 Example :
416 Returns :
417 Args :
420 =cut
422 sub database{
423 my ($self, @args) = @_;
424 my $default = 'MEDLINE';
425 if (! defined $self->medline && defined $self->pubmed) {
426 $default = 'PUBMED';
428 return $self->SUPER::database(@args) || $default;
431 =head2 primary_id
433 Title : primary_id
434 Usage :
435 Function: Overrides DBLink primary_id to provide medline number, or pubmed
436 number if only that has been defined
437 Example :
438 Returns :
439 Args :
442 =cut
444 sub primary_id{
445 my ($self, @args) = @_;
446 if (@args) {
447 $self->medline(@args);
449 if (! defined $self->medline && defined $self->pubmed) {
450 return $self->pubmed;
452 return $self->medline;
455 =head2 optional_id
457 Title : optional_id
458 Usage :
459 Function: Overrides DBLink optional_id to provide the PubMed number.
460 Example :
461 Returns :
462 Args :
465 =cut
467 sub optional_id{
468 my ($self, @args) = @_;
470 return $self->pubmed(@args);
473 =head2 publisher
475 Title : publisher
476 Usage : $self->publisher($newval)
477 Function: Gives the publisher line. No attempt is made to parse the publisher line
478 Example :
479 Returns : value of publisher
480 Args : newvalue (optional)
483 =cut
485 sub publisher {
486 my ($self,$value) = @_;
487 if( defined $value) {
488 $self->{'publisher'} = $value;
490 return $self->{'publisher'};
494 =head2 editors
496 Title : editors
497 Usage : $self->editors($newval)
498 Function: Gives the editors line. No attempt is made to parse the editors line
499 Example :
500 Returns : value of editors
501 Args : newvalue (optional)
504 =cut
506 sub editors {
507 my ($self,$value) = @_;
508 if( defined $value) {
509 $self->{'editors'} = $value;
511 return $self->{'editors'};
515 =head2 encoded_ref
517 Title : encoded_ref
518 Usage : $self->encoded_ref($newval)
519 Function: Gives the encoded_ref line. No attempt is made to parse the encoded_ref line
520 (this is added for reading PDB records (REFN record), where this contains
521 ISBN/ISSN/ASTM code)
522 Example :
523 Returns : value of encoded_ref
524 Args : newvalue (optional)
527 =cut
529 sub encoded_ref {
530 my ($self,$value) = @_;
531 if( defined $value) {
532 $self->{'encoded_ref'} = $value;
534 return $self->{'encoded_ref'};
537 =head2 doi
539 Title : doi
540 Usage : $self->doi($newval)
541 Function: Gives the DOI (Digital Object Identifier) from the International
542 DOI Foundation (http://www.doi.org/), which can be used to resolve
543 URL links for the full-text documents using:
545 http://dx.doi.org/<doi>
547 Example :
548 Returns : value of doi
549 Args : newvalue (optional)
551 =cut
553 sub doi {
554 my ($self,$value) = @_;
555 if( defined $value) {
556 $self->{'doi'} = $value;
558 return $self->{'doi'};
561 =head2 consortium
563 Title : consortium
564 Usage : $self->consortium($newval)
565 Function: Gives the consortium line. No attempt is made to parse the consortium line
566 Example :
567 Returns : value of consortium
568 Args : newvalue (optional)
571 =cut
573 sub consortium{
574 my ($self,$value) = @_;
575 if( defined $value) {
576 $self->{'consortium'} = $value;
578 return $self->{'consortium'};
581 =head2 gb_reference
583 Title : gb_reference
584 Usage : $obj->gb_reference($newval)
585 Function: Gives the generic GenBank REFERENCE line. This is GenBank-specific.
586 If set, this includes everything on the reference line except
587 the REFERENCE tag and the reference count. This is mainly a
588 fallback for the few instances when REFERENCE lines have unusual
589 additional information such as split sequence locations, feature
590 references, etc. See Bug 2020 in Bugzilla for more information.
591 Example :
592 Returns : value of gb_reference (a scalar)
593 Args : on set, new value (a scalar or undef, optional)
596 =cut
598 sub gb_reference{
599 my ($self,$value) = @_;
600 if( defined $value) {
601 $self->{'gb_reference'} = $value;
603 return $self->{'gb_reference'};