Bio/Annotation/Reference.pm

filter: Statementstmt 70.9% 83 / 117 Branchbran 72.0% 49 / 68 Conditioncond 25.0% 3 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 76.0% 19 / 25 Podpod 100% 22 / 22 totaltotal 69.8% 176 / 252 CC 39 SCAR 19.0
CC
39
Cov
69%
primary_id
20.0
hash_tree
17.7
new
12.0
CRAP 6.7
« Bio/Tools/GuessSeqFormat.pm ↑ Summary Bio/SearchIO/Writer/ResultTableWriter.pm »
1 #
2 # BioPerl module for 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 Bio::Annotation::Reference - Specialised DBLink object for Literature References
17  
18 =head1 SYNOPSIS
19  
20 $reg = 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 Bio::Annotation::Reference;
56 36 $Bio::Annotation::Reference::VERSION = '1.7.8';
57 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
58  
59 36 ▶use base qw(Bio::Annotation::DBLink);
Subroutine BEGIN: called CC=1 SCAR=0.0
60  
61 =head2 new
62  
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
73  
74  
75 =cut
76  
77 931 ▶sub new{
Subroutine new: called CC=12 SCAR=24.8
Pod documented
78 931 my ($class,@args) = @_;
79  
80 931 my $self = $class->SUPER::new(@args);
81  
82 931 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
92 RP
93 RG
94 DOI
95 )],@args);
96  
97 931 ▶ defined $start && $self->start($start);
Branch: 1 branch
BranchTrueFalseTotal
defined $start and $self->start($start) 124 807 931
98 931 ▶ defined $end && $self->end($end);
Branch: 1 branch
BranchTrueFalseTotal
defined $end and $self->end($end) 123 808 931
99 931 ▶ defined $authors && $self->authors($authors);
Branch: 1 branch
BranchTrueFalseTotal
defined $authors and $self->authors($authors) 454 477 931
100 931 ▶ defined $consortium && $self->consortium($consortium);
Branch: 1 branch
BranchTrueFalseTotal
defined $consortium and $self->consortium($consortium) 26 905 931
101 931 ▶ defined $location && $self->location($location);
Branch: 1 branch
BranchTrueFalseTotal
defined $location and $self->location($location) 460 471 931
102 931 ▶ defined $title && $self->title($title);
Branch: 1 branch
BranchTrueFalseTotal
defined $title and $self->title($title) 429 502 931
103 931 ▶ defined $medline && $self->medline($medline);
Branch: 1 branch
BranchTrueFalseTotal
defined $medline and $self->medline($medline) 283 648 931
104 931 ▶ defined $pubmed && $self->pubmed($pubmed);
Branch: 1 branch
BranchTrueFalseTotal
defined $pubmed and $self->pubmed($pubmed) 243 688 931
105 931 ▶ defined $rp && $self->rp($rp);
Branch: 1 branch
BranchTrueFalseTotal
defined $rp and $self->rp($rp) 285 646 931
106 931 ▶ defined $rg && $self->rg($rg);
Branch: 1 branch
BranchTrueFalseTotal
defined $rg and $self->rg($rg) 16 915 931
107 931 ▶ defined $doi && $self->doi($doi);
Branch: 1 branch
BranchTrueFalseTotal
defined $doi and $self->doi($doi) 22 909 931
108 931 return $self;
109 }
110  
111  
112 =head1 AnnotationI implementing functions
113  
114 =cut
115  
116 =head2 as_text
117  
118 Title : as_text
119 Usage :
120 Function:
121 Example :
122 Returns :
123 Args :
124  
125  
126 =cut
127  
128 1 ▶sub as_text{
Subroutine as_text: called CC=1 SCAR=0.0
Pod documented
129 1 my ($self) = @_;
130  
131 # this could get out of hand!
132 1 return "Reference: ".$self->title;
133 }
134  
135 =head2 display_text
136  
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.
141  
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
148  
149 =cut
150  
151 {
152 22 ▶ my $DEFAULT_CB = sub { $_[0]->title || ''};
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->title or "" 20 2 22
153  
154 22 ▶ sub display_text {
Subroutine display_text: called CC=3 SCAR=12.0
Pod documented
155 22 my ($self, $cb) = @_;
156 22 ▶ $cb ||= $DEFAULT_CB;
Condition33%1/3
$cb ||= $DEFAULT_CB
l!l&&r!l&&!r
0220
MC/DC0%0/2
$cb ||= $DEFAULT_CB
$cb $DEFAULT_CB
Truth table33%1/3
A ||= B
A= $cbB= $DEFAULT_CB
ABresult
1X1
011
000
157 22 ▶ $self->throw("Callback must be a code reference") if ref $cb ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $cb ne "CODE" 0 22 22
158 22 return $cb->($self);
159 }
160  
161 }
162  
163 =head2 hash_tree
164  
165 Title : hash_tree
166 Usage :
167 Function:
168 Example :
169 Returns :
170 Args :
171  
172  
173 =cut
174  
175 36 ▶sub hash_tree{
Subroutine hash_tree: not called CC=4 SCAR=28.7
Pod documented
176 0 my ($self) = @_;
177  
178 0 my $h = {};
179 0 $h->{'title'} = $self->title;
180 0 $h->{'authors'} = $self->authors;
181 0 $h->{'location'} = $self->location;
182 0 ▶ if (defined $self->start) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->start) 0 0 0
183 0 $h->{'start'} = $self->start;
184 }
185 0 ▶ if (defined $self->end) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->end) 0 0 0
186 0 $h->{'end'} = $self->end;
187 }
188 0 $h->{'medline'} = $self->medline;
189 0 ▶ if (defined $self->pubmed) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->pubmed) 0 0 0
190 0 $h->{'pubmed'} = $self->pubmed;
191 }
192  
193 0 return $h;
194 }
195  
196 =head2 tagname
197  
198 Title : tagname
199 Usage : $obj->tagname($newval)
200 Function: Get/set the tagname for this annotation value.
201  
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)
210  
211  
212 =cut
213  
214  
215 =head1 Specific accessors for References
216  
217 =cut
218  
219  
220 =head2 start
221  
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)
228  
229  
230 =cut
231  
232 598 ▶sub start {
Subroutine start: called CC=2 SCAR=6.9
Pod documented
233 598 my ($self,$value) = @_;
234 598 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 408 190 598
235 408 $self->{'start'} = $value;
236 }
237 598 return $self->{'start'};
238  
239 }
240  
241 =head2 end
242  
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)
249  
250  
251 =cut
252  
253 551 ▶sub end {
Subroutine end: called CC=2 SCAR=6.9
Pod documented
254 551 my ($self,$value) = @_;
255 551 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 407 144 551
256 407 $self->{'end'} = $value;
257 }
258 551 return $self->{'end'};
259 }
260  
261 =head2 rp
262  
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)
269  
270  
271 =cut
272  
273 291 ▶sub rp{
Subroutine rp: called CC=2 SCAR=6.9
Pod documented
274 291 my ($self,$value) = @_;
275 291 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 285 6 291
276 285 $self->{'rp'} = $value;
277 }
278 291 return $self->{'rp'};
279 }
280  
281 =head2 rg
282  
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.
289  
290 Example :
291 Returns : value of rg (a scalar)
292 Args : on set, new value (a scalar or undef, optional)
293  
294  
295 =cut
296  
297 18 ▶sub rg{
Subroutine rg: called CC=2 SCAR=6.9
Pod documented
298 18 my $self = shift;
299  
300 18 ▶ return $self->{'rg'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 16 2 18
301 2 return $self->{'rg'};
302 }
303  
304 =head2 authors
305  
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)
312  
313  
314 =cut
315  
316 1723 ▶sub authors{
Subroutine authors: called CC=2 SCAR=6.9
Pod documented
317 1723 my ($self,$value) = @_;
318 1723 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 1272 451 1723
319 1272 $self->{'authors'} = $value;
320 }
321 1723 return $self->{'authors'};
322  
323 }
324  
325 =head2 location
326  
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)
333  
334  
335 =cut
336  
337 1017 ▶sub location{
Subroutine location: called CC=2 SCAR=6.9
Pod documented
338 1017 my ($self,$value) = @_;
339 1017 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 929 88 1017
340 929 $self->{'location'} = $value;
341 }
342 1017 return $self->{'location'};
343  
344 }
345  
346 =head2 title
347  
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)
354  
355  
356 =cut
357  
358 1758 ▶sub title{
Subroutine title: called CC=2 SCAR=6.9
Pod documented
359 1758 my ($self,$value) = @_;
360 1758 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 1258 500 1758
361 1258 $self->{'title'} = $value;
362 }
363 1758 return $self->{'title'};
364  
365 }
366  
367 =head2 medline
368  
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)
375  
376  
377 =cut
378  
379 563 ▶sub medline{
Subroutine medline: called CC=2 SCAR=6.9
Pod documented
380 563 my ($self,$value) = @_;
381 563 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 459 104 563
382 459 $self->{'medline'} = $value;
383 }
384 563 return $self->{'medline'};
385 }
386  
387 =head2 pubmed
388  
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)
396  
397  
398 =cut
399  
400 612 ▶sub pubmed {
Subroutine pubmed: called CC=2 SCAR=6.9
Pod documented
401 612 my ($self,$value) = @_;
402 612 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 460 152 612
403 460 $self->{'pubmed'} = $value;
404 }
405 612 return $self->{'pubmed'};
406 }
407  
408 =head2 database
409  
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 explicitly before.
415 Example :
416 Returns :
417 Args :
418  
419  
420 =cut
421  
422 1 ▶sub database{
Subroutine database: called CC=4 SCAR=17.2
Pod documented
423 1 my ($self, @args) = @_;
424 1 my $default = 'MEDLINE';
425 1 ▶ if (! defined $self->medline && defined $self->pubmed) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->medline and defined $self->pubmed) 0 1 1
Condition33%1/3
not defined $self->medline and defined $self->pubmed
!ll&&!rl&&r
010
MC/DC0%0/2
not defined $self->medline and defined $self->pubmed
not defined $self->medline defined $self->pubmed
Truth table33%1/3
not(A) and B
A= not defined $self->medlineB= defined $self->pubmed
ABresult
0X0
100
111
426 0 $default = 'PUBMED';
427 }
428 1 ▶ return $self->SUPER::database(@args) || $default;
Condition33%1/3
$self->SUPER::database(@args) || $default
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->SUPER::database(@args) || $default
$self->SUPER::database(@args) $default
Truth table33%1/3
A || B
A= $self->SUPER::database(@args)B= $default
ABresult
1X1
011
000
429 }
430  
431 =head2 primary_id
432  
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 :
440  
441  
442 =cut
443  
444 0 ▶sub primary_id{
Subroutine primary_id: not called CC=4 SCAR=30.0
Pod documented
445 0 my ($self, @args) = @_;
446 0 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 0 0 0
447 0 $self->medline(@args);
448 }
449 0 ▶ if (! defined $self->medline && defined $self->pubmed) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->medline and defined $self->pubmed) 0 0 0
Condition0%0/3
not defined $self->medline and defined $self->pubmed
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $self->medline and defined $self->pubmed
not defined $self->medline defined $self->pubmed
Truth table0%0/3
not(A) and B
A= not defined $self->medlineB= defined $self->pubmed
ABresult
0X0
100
111
450 0 return $self->pubmed;
451 }
452 0 return $self->medline;
453 }
454  
455 =head2 optional_id
456  
457 Title : optional_id
458 Usage :
459 Function: Overrides DBLink optional_id to provide the PubMed number.
460 Example :
461 Returns :
462 Args :
463  
464  
465 =cut
466  
467 0 ▶sub optional_id{
Subroutine optional_id: not called CC=1 SCAR=6.9
Pod documented
468 0 my ($self, @args) = @_;
469  
470 0 return $self->pubmed(@args);
471 }
472  
473 =head2 publisher
474  
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)
481  
482  
483 =cut
484  
485 0 ▶sub publisher {
Subroutine publisher: not called CC=2 SCAR=17.9
Pod documented
486 0 my ($self,$value) = @_;
487 0 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 0 0
488 0 $self->{'publisher'} = $value;
489 }
490 0 return $self->{'publisher'};
491 }
492  
493  
494 =head2 editors
495  
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)
502  
503  
504 =cut
505  
506 0 ▶sub editors {
Subroutine editors: not called CC=2 SCAR=17.9
Pod documented
507 0 my ($self,$value) = @_;
508 0 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 0 0
509 0 $self->{'editors'} = $value;
510 }
511 0 return $self->{'editors'};
512 }
513  
514  
515 =head2 encoded_ref
516  
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)
525  
526  
527 =cut
528  
529 0 ▶sub encoded_ref {
Subroutine encoded_ref: not called CC=2 SCAR=17.9
Pod documented
530 0 my ($self,$value) = @_;
531 0 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 0 0
532 0 $self->{'encoded_ref'} = $value;
533 }
534 0 return $self->{'encoded_ref'};
535 }
536  
537 =head2 doi
538  
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:
544  
545 http://dx.doi.org/<doi>
546  
547 Example :
548 Returns : value of doi
549 Args : newvalue (optional)
550  
551 =cut
552  
553 24 ▶sub doi {
Subroutine doi: called CC=2 SCAR=6.9
Pod documented
554 24 my ($self,$value) = @_;
555 24 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 22 2 24
556 22 $self->{'doi'} = $value;
557 }
558 24 return $self->{'doi'};
559 }
560  
561 =head2 consortium
562  
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)
569  
570  
571 =cut
572  
573 113 ▶sub consortium{
Subroutine consortium: called CC=2 SCAR=6.9
Pod documented
574 113 my ($self,$value) = @_;
575 113 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 59 54 113
576 59 $self->{'consortium'} = $value;
577 }
578 113 return $self->{'consortium'};
579 }
580  
581 =head2 gb_reference
582  
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)
594  
595  
596 =cut
597  
598 67 ▶sub gb_reference{
Subroutine gb_reference: called CC=2 SCAR=7.0
Pod documented
599 67 my ($self,$value) = @_;
600 67 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 67 0 67
601 67 $self->{'gb_reference'} = $value;
602 }
603 67 return $self->{'gb_reference'};
604  
605 }
606  
607 36 1;
« Bio/Tools/GuessSeqFormat.pm ↑ Summary Bio/SearchIO/Writer/ResultTableWriter.pm »