FAST/Bio/Annotation/Reference.pm untested

filter: Statementstmt 0.0% 0 / 117 Branchbran 0.0% 0 / 44 Conditioncond 0.0% 0 / 47 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 24 Podpod 0.0% 0 / 22 totaltotal 0.0% 0 / 254 SCAR 63.1
CC
23
Cov
0%
hash_tree
20.0
primary_id
12.0
display_text
6.0
CRAP 552.0
1 #
2 # BioPerl module for FAST::Bio::Annotation::Reference
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 FAST::Bio::Annotation::Reference - Specialised DBLink object for Literature References
17  
18 =head1 SYNOPSIS
19  
20 $reg = FAST::Bio::Annotation::Reference->new( -title => 'title line',
21 -location => 'location line',
22 -authors => 'author line',
23 -medline => 998122 );
24  
25 =head1 DESCRIPTION
26  
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.
32  
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...
40  
41 =head1 AUTHOR - Ewan Birney
42  
43 Email birney@ebi.ac.uk
44  
45 =head1 APPENDIX
46  
47 The rest of the documentation details each of the object
48 methods. Internal methods are usually preceded with a _
49  
50 =cut
51  
52  
53 # Let the code begin...
54  
55 package FAST::Bio::Annotation::Reference;
56 use strict;
57  
58 use base qw(FAST::Bio::Annotation::DBLink);
59  
60 =head2 new
61  
62 Title : new
63 Usage : $ref = FAST::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 FAST::Bio::Annotation::Reference object
70 Args : a hash with optional title, authors, location, medline, pubmed,
71 start, end, consortium, rp and rg attributes
72  
73  
74 =cut
75  
76 sub new{
77 my ($class,@args) = @_;
78  
79 my $self = $class->SUPER::new(@args);
80  
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
91 RP
92 RG
93 DOI
94 )],@args);
95  
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;
108 }
109  
110  
111 =head1 AnnotationI implementing functions
112  
113 =cut
114  
115 =head2 as_text
116  
117 Title : as_text
118 Usage :
119 Function:
120 Example :
121 Returns :
122 Args :
123  
124  
125 =cut
126  
127 sub as_text{
128 my ($self) = @_;
129  
130 # this could get out of hand!
131 return "Reference: ".$self->title;
132 }
133  
134 =head2 display_text
135  
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.
140  
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
147  
148 =cut
149  
150 {
151 my $DEFAULT_CB = sub { $_[0]->title || ''};
152  
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);
158 }
159  
160 }
161  
162 =head2 hash_tree
163  
164 Title : hash_tree
165 Usage :
166 Function:
167 Example :
168 Returns :
169 Args :
170  
171  
172 =cut
173  
174 sub hash_tree{
175 my ($self) = @_;
176  
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;
183 }
184 if (defined $self->end) {
185 $h->{'end'} = $self->end;
186 }
187 $h->{'medline'} = $self->medline;
188 if (defined $self->pubmed) {
189 $h->{'pubmed'} = $self->pubmed;
190 }
191  
192 return $h;
193 }
194  
195 =head2 tagname
196  
197 Title : tagname
198 Usage : $obj->tagname($newval)
199 Function: Get/set the tagname for this annotation value.
200  
201 Setting this is optional. If set, it obviates the need to provide
202 a tag to FAST::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)
209  
210  
211 =cut
212  
213  
214 =head1 Specific accessors for References
215  
216 =cut
217  
218  
219 =head2 start
220  
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)
227  
228  
229 =cut
230  
231 sub start {
232 my ($self,$value) = @_;
233 if( defined $value) {
234 $self->{'start'} = $value;
235 }
236 return $self->{'start'};
237  
238 }
239  
240 =head2 end
241  
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)
248  
249  
250 =cut
251  
252 sub end {
253 my ($self,$value) = @_;
254 if( defined $value) {
255 $self->{'end'} = $value;
256 }
257 return $self->{'end'};
258 }
259  
260 =head2 rp
261  
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)
268  
269  
270 =cut
271  
272 sub rp{
273 my ($self,$value) = @_;
274 if( defined $value) {
275 $self->{'rp'} = $value;
276 }
277 return $self->{'rp'};
278 }
279  
280 =head2 rg
281  
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.
288  
289 Example :
290 Returns : value of rg (a scalar)
291 Args : on set, new value (a scalar or undef, optional)
292  
293  
294 =cut
295  
296 sub rg{
297 my $self = shift;
298  
299 return $self->{'rg'} = shift if @_;
300 return $self->{'rg'};
301 }
302  
303 =head2 authors
304  
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)
311  
312  
313 =cut
314  
315 sub authors{
316 my ($self,$value) = @_;
317 if( defined $value) {
318 $self->{'authors'} = $value;
319 }
320 return $self->{'authors'};
321  
322 }
323  
324 =head2 location
325  
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)
332  
333  
334 =cut
335  
336 sub location{
337 my ($self,$value) = @_;
338 if( defined $value) {
339 $self->{'location'} = $value;
340 }
341 return $self->{'location'};
342  
343 }
344  
345 =head2 title
346  
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)
353  
354  
355 =cut
356  
357 sub title{
358 my ($self,$value) = @_;
359 if( defined $value) {
360 $self->{'title'} = $value;
361 }
362 return $self->{'title'};
363  
364 }
365  
366 =head2 medline
367  
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)
374  
375  
376 =cut
377  
378 sub medline{
379 my ($self,$value) = @_;
380 if( defined $value) {
381 $self->{'medline'} = $value;
382 }
383 return $self->{'medline'};
384 }
385  
386 =head2 pubmed
387  
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)
395  
396  
397 =cut
398  
399 sub pubmed {
400 my ($self,$value) = @_;
401 if( defined $value) {
402 $self->{'pubmed'} = $value;
403 }
404 return $self->{'pubmed'};
405 }
406  
407 =head2 database
408  
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 :
417  
418  
419 =cut
420  
421 sub database{
422 my ($self, @args) = @_;
423 my $default = 'MEDLINE';
424 if (! defined $self->medline && defined $self->pubmed) {
425 $default = 'PUBMED';
426 }
427 return $self->SUPER::database(@args) || $default;
428 }
429  
430 =head2 primary_id
431  
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 :
439  
440  
441 =cut
442  
443 sub primary_id{
444 my ($self, @args) = @_;
445 if (@args) {
446 $self->medline(@args);
447 }
448 if (! defined $self->medline && defined $self->pubmed) {
449 return $self->pubmed;
450 }
451 return $self->medline;
452 }
453  
454 =head2 optional_id
455  
456 Title : optional_id
457 Usage :
458 Function: Overrides DBLink optional_id to provide the PubMed number.
459 Example :
460 Returns :
461 Args :
462  
463  
464 =cut
465  
466 sub optional_id{
467 my ($self, @args) = @_;
468  
469 return $self->pubmed(@args);
470 }
471  
472 =head2 publisher
473  
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)
480  
481  
482 =cut
483  
484 sub publisher {
485 my ($self,$value) = @_;
486 if( defined $value) {
487 $self->{'publisher'} = $value;
488 }
489 return $self->{'publisher'};
490 }
491  
492  
493 =head2 editors
494  
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)
501  
502  
503 =cut
504  
505 sub editors {
506 my ($self,$value) = @_;
507 if( defined $value) {
508 $self->{'editors'} = $value;
509 }
510 return $self->{'editors'};
511 }
512  
513  
514 =head2 encoded_ref
515  
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)
524  
525  
526 =cut
527  
528 sub encoded_ref {
529 my ($self,$value) = @_;
530 if( defined $value) {
531 $self->{'encoded_ref'} = $value;
532 }
533 return $self->{'encoded_ref'};
534 }
535  
536 =head2 doi
537  
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:
543  
544 http://dx.doi.org/<doi>
545  
546 Example :
547 Returns : value of doi
548 Args : newvalue (optional)
549  
550 =cut
551  
552 sub doi {
553 my ($self,$value) = @_;
554 if( defined $value) {
555 $self->{'doi'} = $value;
556 }
557 return $self->{'doi'};
558 }
559  
560 =head2 consortium
561  
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)
568  
569  
570 =cut
571  
572 sub consortium{
573 my ($self,$value) = @_;
574 if( defined $value) {
575 $self->{'consortium'} = $value;
576 }
577 return $self->{'consortium'};
578 }
579  
580 =head2 gb_reference
581  
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)
593  
594  
595 =cut
596  
597 sub gb_reference{
598 my ($self,$value) = @_;
599 if( defined $value) {
600 $self->{'gb_reference'} = $value;
601 }
602 return $self->{'gb_reference'};
603  
604 }
605  
606 1;