~ubuntu-branches/ubuntu/trusty/bioperl/trusty-proposed

« back to all changes in this revision

Viewing changes to Bio/Annotation/Reference.pm

  • Committer: Bazaar Package Importer
  • Author(s): Charles Plessy
  • Date: 2009-03-10 07:19:11 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090310071911-fukqzw54pyb1f0bd
Tags: 1.6.0-2
* Removed patch system (not used):
  - removed instuctions in debian/rules;
  - removed quilt from Build-Depends in debian/control.
* Re-enabled tests:
  - uncommented test command in debian/rules;
  - uncommented previously missing build-dependencies in debian/control.
  - Re-enabled tests and uncommented build-dependencies accordingly.
* Removed libmodule-build-perl and libtest-harness-perl from
  Build-Depends-Indep (provided by perl-modules).
* Better cleaning of empty directories using find -type d -empty -delete
  instead of rmdir in debian/rules (LP: #324001).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# $Id: Reference.pm,v 1.24.4.3 2006/10/02 23:10:12 sendu Exp $
 
1
# $Id: Reference.pm 14708 2008-06-10 00:08:17Z heikki $
2
2
#
3
3
# BioPerl module for Bio::Annotation::Reference
4
4
#
43
43
 
44
44
=head1 APPENDIX
45
45
 
46
 
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
 
46
The rest of the documentation details each of the object
 
47
methods. Internal methods are usually preceded with a _
47
48
 
48
49
=cut
49
50
 
52
53
 
53
54
package Bio::Annotation::Reference;
54
55
use strict;
55
 
use overload '""' => sub { $_[0]->title || ''};
56
 
use overload 'eq' => sub { "$_[0]" eq "$_[1]" };
57
 
 
58
 
use Bio::AnnotationI;
59
56
 
60
57
use base qw(Bio::Annotation::DBLink);
61
58
 
63
60
 
64
61
 Title   : new
65
62
 Usage   : $ref = Bio::Annotation::Reference->new( -title => 'title line',
66
 
                                                   -authors => 'author line',
67
 
                                                   -location => 'location line',
68
 
                                                   -medline => 9988812);
 
63
                           -authors => 'author line',
 
64
                           -location => 'location line',
 
65
                           -medline => 9988812);
69
66
 Function:
70
67
 Example :
71
68
 Returns : a new Bio::Annotation::Reference object
81
78
    my $self = $class->SUPER::new(@args);
82
79
 
83
80
    my ($start,$end,$authors,$consortium,$location,$title,$medline,
84
 
        $pubmed,$rp,$rg) =
85
 
        $self->_rearrange([qw(START
86
 
                              END
87
 
                              AUTHORS
88
 
                                  CONSORTIUM
89
 
                              LOCATION
90
 
                              TITLE
91
 
                              MEDLINE
92
 
                                  PUBMED
93
 
                                  RP
94
 
                                  RG
95
 
                              )],@args);
 
81
    $pubmed,$rp,$rg,$doi) =
 
82
    $self->_rearrange([qw(START
 
83
                  END
 
84
                  AUTHORS
 
85
                  CONSORTIUM
 
86
                  LOCATION
 
87
                  TITLE
 
88
                  MEDLINE
 
89
                  PUBMED
 
90
                  RP
 
91
                  RG
 
92
                                  DOI
 
93
                  )],@args);
96
94
 
97
95
    defined $start    && $self->start($start);
98
96
    defined $end      && $self->end($end);
99
97
    defined $authors  && $self->authors($authors);
100
 
        defined $consortium  && $self->consortium($consortium);
 
98
    defined $consortium  && $self->consortium($consortium);
101
99
    defined $location && $self->location($location);
102
100
    defined $title    && $self->title($title);
103
101
    defined $medline  && $self->medline($medline);
104
102
    defined $pubmed   && $self->pubmed($pubmed);
105
103
    defined $rp       && $self->rp($rp);
106
104
    defined $rg       && $self->rg($rg);
 
105
        defined $doi      && $self->doi($doi);
107
106
    return $self;
108
107
}
109
108
 
131
130
   return "Reference: ".$self->title;
132
131
}
133
132
 
 
133
=head2 display_text
 
134
 
 
135
 Title   : display_text
 
136
 Usage   : my $str = $ann->display_text();
 
137
 Function: returns a string. Unlike as_text(), this method returns a string
 
138
           formatted as would be expected for te specific implementation.
 
139
 
 
140
           One can pass a callback as an argument which allows custom text
 
141
           generation; the callback is passed the current instance and any text
 
142
           returned
 
143
 Example :
 
144
 Returns : a string
 
145
 Args    : [optional] callback
 
146
 
 
147
=cut
 
148
 
 
149
{
 
150
  my $DEFAULT_CB = sub { $_[0]->title || ''};
 
151
 
 
152
  sub display_text {
 
153
    my ($self, $cb) = @_;
 
154
    $cb ||= $DEFAULT_CB;
 
155
    $self->throw("Callback must be a code reference") if ref $cb ne 'CODE';
 
156
    return $cb->($self);
 
157
  }
 
158
 
 
159
}
134
160
 
135
161
=head2 hash_tree
136
162
 
145
171
=cut
146
172
 
147
173
sub hash_tree{
148
 
        my ($self) = @_;
149
 
 
150
 
        my $h = {};
151
 
        $h->{'title'}   = $self->title;
152
 
        $h->{'authors'} = $self->authors;
153
 
        $h->{'location'} = $self->location;
154
 
        if (defined $self->start) {
155
 
                $h->{'start'}   = $self->start;
156
 
        }
157
 
        if (defined $self->end) {
158
 
                $h->{'end'} = $self->end;
159
 
        }
160
 
        $h->{'medline'} = $self->medline;
161
 
        if (defined $self->pubmed) {
162
 
                $h->{'pubmed'} = $self->pubmed;
163
 
        }
164
 
 
165
 
        return $h;
 
174
    my ($self) = @_;
 
175
 
 
176
    my $h = {};
 
177
    $h->{'title'}   = $self->title;
 
178
    $h->{'authors'} = $self->authors;
 
179
    $h->{'location'} = $self->location;
 
180
    if (defined $self->start) {
 
181
        $h->{'start'}   = $self->start;
 
182
    }
 
183
    if (defined $self->end) {
 
184
        $h->{'end'} = $self->end;
 
185
    }
 
186
    $h->{'medline'} = $self->medline;
 
187
    if (defined $self->pubmed) {
 
188
        $h->{'pubmed'} = $self->pubmed;
 
189
    }
 
190
 
 
191
    return $h;
166
192
}
167
193
 
168
194
=head2 tagname
204
230
sub start {
205
231
    my ($self,$value) = @_;
206
232
    if( defined $value) {
207
 
        $self->{'start'} = $value;
 
233
    $self->{'start'} = $value;
208
234
    }
209
235
    return $self->{'start'};
210
236
 
225
251
sub end {
226
252
    my ($self,$value) = @_;
227
253
    if( defined $value) {
228
 
        $self->{'end'} = $value;
 
254
    $self->{'end'} = $value;
229
255
    }
230
256
    return $self->{'end'};
231
257
}
351
377
sub medline{
352
378
    my ($self,$value) = @_;
353
379
    if( defined $value) {
354
 
        $self->{'medline'} = $value;
 
380
    $self->{'medline'} = $value;
355
381
    }
356
382
    return $self->{'medline'};
357
383
}
372
398
sub pubmed {
373
399
    my ($self,$value) = @_;
374
400
    if( defined $value) {
375
 
        $self->{'pubmed'} = $value;
 
401
    $self->{'pubmed'} = $value;
376
402
    }
377
403
    return $self->{'pubmed'};
378
404
}
382
408
 Title   : database
383
409
 Usage   :
384
410
 Function: Overrides DBLink database to be hard coded to 'MEDLINE' (or 'PUBMED'
385
 
                   if only pubmed id has been supplied), unless the database has been
386
 
                   set explicitely before.
 
411
           if only pubmed id has been supplied), unless the database has been
 
412
           set explicitely before.
387
413
 Example :
388
414
 Returns :
389
415
 Args    :
392
418
=cut
393
419
 
394
420
sub database{
395
 
        my ($self, @args) = @_;
396
 
        my $default = 'MEDLINE';
397
 
        if (! defined $self->medline && defined $self->pubmed) {
398
 
                $default = 'PUBMED';
399
 
        }
400
 
        return $self->SUPER::database(@args) || $default;
 
421
    my ($self, @args) = @_;
 
422
    my $default = 'MEDLINE';
 
423
    if (! defined $self->medline && defined $self->pubmed) {
 
424
        $default = 'PUBMED';
 
425
    }
 
426
    return $self->SUPER::database(@args) || $default;
401
427
}
402
428
 
403
429
=head2 primary_id
414
440
=cut
415
441
 
416
442
sub primary_id{
417
 
        my ($self, @args) = @_;
418
 
        if (@args) {
419
 
                $self->medline(@args);
420
 
        }
421
 
        if (! defined $self->medline && defined $self->pubmed) {
422
 
                return $self->pubmed;
423
 
        }
424
 
        return $self->medline;
 
443
    my ($self, @args) = @_;
 
444
    if (@args) {
 
445
        $self->medline(@args);
 
446
    }
 
447
    if (! defined $self->medline && defined $self->pubmed) {
 
448
        return $self->pubmed;
 
449
    }
 
450
    return $self->medline;
425
451
}
426
452
 
427
453
=head2 optional_id
489
515
 Title   : encoded_ref
490
516
 Usage   : $self->encoded_ref($newval)
491
517
 Function: Gives the encoded_ref line. No attempt is made to parse the encoded_ref line
492
 
        (this is added for reading PDB records (REFN record), where this contains
493
 
         ISBN/ISSN/ASTM code)
 
518
    (this is added for reading PDB records (REFN record), where this contains
 
519
     ISBN/ISSN/ASTM code)
494
520
 Example :
495
521
 Returns : value of encoded_ref
496
522
 Args    : newvalue (optional)
506
532
   return $self->{'encoded_ref'};
507
533
}
508
534
 
 
535
=head2 doi
 
536
 
 
537
 Title   : doi
 
538
 Usage   : $self->doi($newval)
 
539
 Function: Gives the DOI (Digital Object Identifier) from the International
 
540
           DOI Foundation (http://www.doi.org/), which can be used to resolve
 
541
                   URL links for the full-text documents using:
 
542
 
 
543
                   http://dx.doi.org/<doi>
 
544
 
 
545
 Example :
 
546
 Returns : value of doi
 
547
 Args    : newvalue (optional)
 
548
 
 
549
=cut
 
550
 
 
551
sub doi {
 
552
   my ($self,$value) = @_;
 
553
   if( defined $value) {
 
554
      $self->{'doi'} = $value;
 
555
    }
 
556
    return $self->{'doi'};
 
557
}
 
558
 
509
559
=head2 consortium
510
560
 
511
561
 Title   : consortium
524
574
      $self->{'consortium'} = $value;
525
575
    }
526
576
    return $self->{'consortium'};
527
 
 
528
577
}
529
578
 
530
579
=head2 gb_reference
533
582
 Usage   : $obj->gb_reference($newval)
534
583
 Function: Gives the generic GenBank REFERENCE line. This is GenBank-specific.
535
584
           If set, this includes everything on the reference line except
536
 
           the REFERENCE tag and the reference count.  This is mainly a
537
 
           fallback for the few instances when REFERENCE lines have unusual
538
 
           additional information such as split sequence locations, feature
539
 
           references, etc.  See Bug 2020 in Bugzilla for more information.
 
585
                   the REFERENCE tag and the reference count.  This is mainly a
 
586
                   fallback for the few instances when REFERENCE lines have unusual
 
587
                   additional information such as split sequence locations, feature
 
588
                   references, etc.  See Bug 2020 in Bugzilla for more information.
540
589
 Example :
541
590
 Returns : value of gb_reference (a scalar)
542
591
 Args    : on set, new value (a scalar or undef, optional)