Bio::DB::Universal: move into its own distribution
[bioperl-live.git] / Bio / Annotation / Reference.pm
blobbb458fc229bd665c23197c3a81f91ec1e9049d18
2 # BioPerl module for Bio::Annotation::Reference
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::Annotation::Reference - Specialised DBLink object for Literature References
18 =head1 SYNOPSIS
20 $reg = Bio::Annotation::Reference->new( -title => 'title line',
21 -location => 'location line',
22 -authors => 'author line',
23 -medline => 998122 );
25 =head1 DESCRIPTION
27 Object which presents a literature reference. This is considered to be
28 a specialised form of database link. The additional methods provided
29 are all set/get methods to store strings commonly associated with
30 references, in particular title, location (ie, journal page) and
31 authors line.
33 There is no attempt to do anything more than store these things as
34 strings for processing elsewhere. This is mainly because parsing these
35 things suck and generally are specific to the specific format one is
36 using. To provide an easy route to go format --E<gt> object --E<gt> format
37 without losing data, we keep them as strings. Feel free to post the
38 list for a better solution, but in general this gets very messy very
39 fast...
41 =head1 AUTHOR - Ewan Birney
43 Email birney@ebi.ac.uk
45 =head1 APPENDIX
47 The rest of the documentation details each of the object
48 methods. Internal methods are usually preceded with a _
50 =cut
53 # Let the code begin...
55 package Bio::Annotation::Reference;
56 use strict;
58 use base qw(Bio::Annotation::DBLink);
60 =head2 new
62 Title : new
63 Usage : $ref = Bio::Annotation::Reference->new( -title => 'title line',
64 -authors => 'author line',
65 -location => 'location line',
66 -medline => 9988812);
67 Function:
68 Example :
69 Returns : a new Bio::Annotation::Reference object
70 Args : a hash with optional title, authors, location, medline, pubmed,
71 start, end, consortium, rp and rg attributes
74 =cut
76 sub new{
77 my ($class,@args) = @_;
79 my $self = $class->SUPER::new(@args);
81 my ($start,$end,$authors,$consortium,$location,$title,$medline,
82 $pubmed,$rp,$rg,$doi) =
83 $self->_rearrange([qw(START
84 END
85 AUTHORS
86 CONSORTIUM
87 LOCATION
88 TITLE
89 MEDLINE
90 PUBMED
93 DOI
94 )],@args);
96 defined $start && $self->start($start);
97 defined $end && $self->end($end);
98 defined $authors && $self->authors($authors);
99 defined $consortium && $self->consortium($consortium);
100 defined $location && $self->location($location);
101 defined $title && $self->title($title);
102 defined $medline && $self->medline($medline);
103 defined $pubmed && $self->pubmed($pubmed);
104 defined $rp && $self->rp($rp);
105 defined $rg && $self->rg($rg);
106 defined $doi && $self->doi($doi);
107 return $self;
111 =head1 AnnotationI implementing functions
113 =cut
115 =head2 as_text
117 Title : as_text
118 Usage :
119 Function:
120 Example :
121 Returns :
122 Args :
125 =cut
127 sub as_text{
128 my ($self) = @_;
130 # this could get out of hand!
131 return "Reference: ".$self->title;
134 =head2 display_text
136 Title : display_text
137 Usage : my $str = $ann->display_text();
138 Function: returns a string. Unlike as_text(), this method returns a string
139 formatted as would be expected for te specific implementation.
141 One can pass a callback as an argument which allows custom text
142 generation; the callback is passed the current instance and any text
143 returned
144 Example :
145 Returns : a string
146 Args : [optional] callback
148 =cut
151 my $DEFAULT_CB = sub { $_[0]->title || ''};
153 sub display_text {
154 my ($self, $cb) = @_;
155 $cb ||= $DEFAULT_CB;
156 $self->throw("Callback must be a code reference") if ref $cb ne 'CODE';
157 return $cb->($self);
162 =head2 hash_tree
164 Title : hash_tree
165 Usage :
166 Function:
167 Example :
168 Returns :
169 Args :
172 =cut
174 sub hash_tree{
175 my ($self) = @_;
177 my $h = {};
178 $h->{'title'} = $self->title;
179 $h->{'authors'} = $self->authors;
180 $h->{'location'} = $self->location;
181 if (defined $self->start) {
182 $h->{'start'} = $self->start;
184 if (defined $self->end) {
185 $h->{'end'} = $self->end;
187 $h->{'medline'} = $self->medline;
188 if (defined $self->pubmed) {
189 $h->{'pubmed'} = $self->pubmed;
192 return $h;
195 =head2 tagname
197 Title : tagname
198 Usage : $obj->tagname($newval)
199 Function: Get/set the tagname for this annotation value.
201 Setting this is optional. If set, it obviates the need to provide
202 a tag to Bio::AnnotationCollectionI when adding this object. When
203 obtaining an AnnotationI object from the collection, the collection
204 will set the value to the tag under which it was stored unless the
205 object has a tag stored already.
206 Example :
207 Returns : value of tagname (a scalar)
208 Args : new value (a scalar, optional)
211 =cut
214 =head1 Specific accessors for References
216 =cut
219 =head2 start
221 Title : start
222 Usage : $self->start($newval)
223 Function: Gives the reference start base
224 Example :
225 Returns : value of start
226 Args : newvalue (optional)
229 =cut
231 sub start {
232 my ($self,$value) = @_;
233 if( defined $value) {
234 $self->{'start'} = $value;
236 return $self->{'start'};
240 =head2 end
242 Title : end
243 Usage : $self->end($newval)
244 Function: Gives the reference end base
245 Example :
246 Returns : value of end
247 Args : newvalue (optional)
250 =cut
252 sub end {
253 my ($self,$value) = @_;
254 if( defined $value) {
255 $self->{'end'} = $value;
257 return $self->{'end'};
260 =head2 rp
262 Title : rp
263 Usage : $self->rp($newval)
264 Function: Gives the RP line. No attempt is made to parse this line.
265 Example :
266 Returns : value of rp
267 Args : newvalue (optional)
270 =cut
272 sub rp{
273 my ($self,$value) = @_;
274 if( defined $value) {
275 $self->{'rp'} = $value;
277 return $self->{'rp'};
280 =head2 rg
282 Title : rg
283 Usage : $obj->rg($newval)
284 Function: Gives the RG line. This is Swissprot/Uniprot specific, and
285 if set will usually be identical to the authors attribute,
286 but the swissprot manual does allow both RG and RA (author)
287 to be present for the same reference.
289 Example :
290 Returns : value of rg (a scalar)
291 Args : on set, new value (a scalar or undef, optional)
294 =cut
296 sub rg{
297 my $self = shift;
299 return $self->{'rg'} = shift if @_;
300 return $self->{'rg'};
303 =head2 authors
305 Title : authors
306 Usage : $self->authors($newval)
307 Function: Gives the author line. No attempt is made to parse the author line
308 Example :
309 Returns : value of authors
310 Args : newvalue (optional)
313 =cut
315 sub authors{
316 my ($self,$value) = @_;
317 if( defined $value) {
318 $self->{'authors'} = $value;
320 return $self->{'authors'};
324 =head2 location
326 Title : location
327 Usage : $self->location($newval)
328 Function: Gives the location line. No attempt is made to parse the location line
329 Example :
330 Returns : value of location
331 Args : newvalue (optional)
334 =cut
336 sub location{
337 my ($self,$value) = @_;
338 if( defined $value) {
339 $self->{'location'} = $value;
341 return $self->{'location'};
345 =head2 title
347 Title : title
348 Usage : $self->title($newval)
349 Function: Gives the title line (if exists)
350 Example :
351 Returns : value of title
352 Args : newvalue (optional)
355 =cut
357 sub title{
358 my ($self,$value) = @_;
359 if( defined $value) {
360 $self->{'title'} = $value;
362 return $self->{'title'};
366 =head2 medline
368 Title : medline
369 Usage : $self->medline($newval)
370 Function: Gives the medline number
371 Example :
372 Returns : value of medline
373 Args : newvalue (optional)
376 =cut
378 sub medline{
379 my ($self,$value) = @_;
380 if( defined $value) {
381 $self->{'medline'} = $value;
383 return $self->{'medline'};
386 =head2 pubmed
388 Title : pubmed
389 Usage : $refobj->pubmed($newval)
390 Function: Get/Set the PubMed number, if it is different from the MedLine
391 number.
392 Example :
393 Returns : value of medline
394 Args : newvalue (optional)
397 =cut
399 sub pubmed {
400 my ($self,$value) = @_;
401 if( defined $value) {
402 $self->{'pubmed'} = $value;
404 return $self->{'pubmed'};
407 =head2 database
409 Title : database
410 Usage :
411 Function: Overrides DBLink database to be hard coded to 'MEDLINE' (or 'PUBMED'
412 if only pubmed id has been supplied), unless the database has been
413 set explicitly before.
414 Example :
415 Returns :
416 Args :
419 =cut
421 sub database{
422 my ($self, @args) = @_;
423 my $default = 'MEDLINE';
424 if (! defined $self->medline && defined $self->pubmed) {
425 $default = 'PUBMED';
427 return $self->SUPER::database(@args) || $default;
430 =head2 primary_id
432 Title : primary_id
433 Usage :
434 Function: Overrides DBLink primary_id to provide medline number, or pubmed
435 number if only that has been defined
436 Example :
437 Returns :
438 Args :
441 =cut
443 sub primary_id{
444 my ($self, @args) = @_;
445 if (@args) {
446 $self->medline(@args);
448 if (! defined $self->medline && defined $self->pubmed) {
449 return $self->pubmed;
451 return $self->medline;
454 =head2 optional_id
456 Title : optional_id
457 Usage :
458 Function: Overrides DBLink optional_id to provide the PubMed number.
459 Example :
460 Returns :
461 Args :
464 =cut
466 sub optional_id{
467 my ($self, @args) = @_;
469 return $self->pubmed(@args);
472 =head2 publisher
474 Title : publisher
475 Usage : $self->publisher($newval)
476 Function: Gives the publisher line. No attempt is made to parse the publisher line
477 Example :
478 Returns : value of publisher
479 Args : newvalue (optional)
482 =cut
484 sub publisher {
485 my ($self,$value) = @_;
486 if( defined $value) {
487 $self->{'publisher'} = $value;
489 return $self->{'publisher'};
493 =head2 editors
495 Title : editors
496 Usage : $self->editors($newval)
497 Function: Gives the editors line. No attempt is made to parse the editors line
498 Example :
499 Returns : value of editors
500 Args : newvalue (optional)
503 =cut
505 sub editors {
506 my ($self,$value) = @_;
507 if( defined $value) {
508 $self->{'editors'} = $value;
510 return $self->{'editors'};
514 =head2 encoded_ref
516 Title : encoded_ref
517 Usage : $self->encoded_ref($newval)
518 Function: Gives the encoded_ref line. No attempt is made to parse the encoded_ref line
519 (this is added for reading PDB records (REFN record), where this contains
520 ISBN/ISSN/ASTM code)
521 Example :
522 Returns : value of encoded_ref
523 Args : newvalue (optional)
526 =cut
528 sub encoded_ref {
529 my ($self,$value) = @_;
530 if( defined $value) {
531 $self->{'encoded_ref'} = $value;
533 return $self->{'encoded_ref'};
536 =head2 doi
538 Title : doi
539 Usage : $self->doi($newval)
540 Function: Gives the DOI (Digital Object Identifier) from the International
541 DOI Foundation (http://www.doi.org/), which can be used to resolve
542 URL links for the full-text documents using:
544 http://dx.doi.org/<doi>
546 Example :
547 Returns : value of doi
548 Args : newvalue (optional)
550 =cut
552 sub doi {
553 my ($self,$value) = @_;
554 if( defined $value) {
555 $self->{'doi'} = $value;
557 return $self->{'doi'};
560 =head2 consortium
562 Title : consortium
563 Usage : $self->consortium($newval)
564 Function: Gives the consortium line. No attempt is made to parse the consortium line
565 Example :
566 Returns : value of consortium
567 Args : newvalue (optional)
570 =cut
572 sub consortium{
573 my ($self,$value) = @_;
574 if( defined $value) {
575 $self->{'consortium'} = $value;
577 return $self->{'consortium'};
580 =head2 gb_reference
582 Title : gb_reference
583 Usage : $obj->gb_reference($newval)
584 Function: Gives the generic GenBank REFERENCE line. This is GenBank-specific.
585 If set, this includes everything on the reference line except
586 the REFERENCE tag and the reference count. This is mainly a
587 fallback for the few instances when REFERENCE lines have unusual
588 additional information such as split sequence locations, feature
589 references, etc. See Bug 2020 in Bugzilla for more information.
590 Example :
591 Returns : value of gb_reference (a scalar)
592 Args : on set, new value (a scalar or undef, optional)
595 =cut
597 sub gb_reference{
598 my ($self,$value) = @_;
599 if( defined $value) {
600 $self->{'gb_reference'} = $value;
602 return $self->{'gb_reference'};