Bio/Annotation/SimpleValue.pm

filter: Statementstmt 73.1% 30 / 41 Branchbran 61.1% 11 / 18 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 70.0% 7 / 10 Podpod 100% 7 / 7 totaltotal 69.1% 56 / 81 CC 11 SCAR 12.4
CC
11
Cov
68%
tag_term
6.0
tagname
5.2
new
4.0
CRAP 3.5
« Bio/SeqFeature/Amplicon.pm ↑ Summary Bio/SeqFeature/FeaturePair.pm »
1 #
2 # BioPerl module for Bio::Annotation::SimpleValue
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by bioperl <bioperl-l@bioperl.org>
7 #
8 # Copyright bioperl
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::SimpleValue - A simple scalar
17  
18 =head1 SYNOPSIS
19  
20 use Bio::Annotation::SimpleValue;
21 use Bio::Annotation::Collection;
22  
23 my $col = Bio::Annotation::Collection->new();
24 my $sv = Bio::Annotation::SimpleValue->new(-value => 'someval');
25 $col->add_Annotation('tagname', $sv);
26  
27 =head1 DESCRIPTION
28  
29 Scalar value annotation object
30  
31 =head1 FEEDBACK
32  
33 =head2 Mailing Lists
34  
35 User feedback is an integral part of the evolution of this and other
36 Bioperl modules. Send your comments and suggestions preferably to one
37 of the Bioperl mailing lists. Your participation is much appreciated.
38  
39 bioperl-l@bioperl.org - General discussion
40 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
41  
42 =head2 Support
43  
44 Please direct usage questions or support issues to the mailing list:
45  
46 I<bioperl-l@bioperl.org>
47  
48 rather than to the module maintainer directly. Many experienced and
49 reponsive experts will be able look at the problem and quickly
50 address it. Please include a thorough description of the problem
51 with code and data examples if at all possible.
52  
53 =head2 Reporting Bugs
54  
55 Report bugs to the Bioperl bug tracking system to help us keep track
56 the bugs and their resolution. Bug reports can be submitted via
57 the web:
58  
59 https://github.com/bioperl/bioperl-live/issues
60  
61 =head1 AUTHOR - Ewan Birney
62  
63 Email birney@ebi.ac.uk
64  
65 =head1 APPENDIX
66  
67 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
68  
69 =cut
70  
71  
72 # Let the code begin...
73  
74  
75 package Bio::Annotation::SimpleValue;
76 318 $Bio::Annotation::SimpleValue::VERSION = '1.7.8';
77 318 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
78  
79 # Object preamble - inherits from Bio::Root::Root
80  
81 #use Bio::Ontology::TermI;
82  
83 318 ▶use base qw(Bio::Root::Root Bio::AnnotationI);
Subroutine BEGIN: called CC=1 SCAR=0.0
84  
85 =head2 new
86  
87 Title : new
88 Usage : my $sv = Bio::Annotation::SimpleValue->new();
89 Function: Instantiate a new SimpleValue object
90 Returns : Bio::Annotation::SimpleValue object
91 Args : -value => $value to initialize the object data field [optional]
92 -tagname => $tag to initialize the tagname [optional]
93 -tag_term => ontology term representation of the tag [optional]
94  
95 =cut
96  
97 3227 ▶sub new{
Subroutine new: called CC=4 SCAR=13.9
Pod documented
98 3227 my ($class,@args) = @_;
99  
100 3227 my $self = $class->SUPER::new(@args);
101  
102 3227 my ($value,$tag,$term) =
103 $self->_rearrange([qw(VALUE TAGNAME TAG_TERM)], @args);
104  
105 # set the term first
106 3227 ▶ defined $term && $self->tag_term($term);
Branch: 1 branch
BranchTrueFalseTotal
defined $term and $self->tag_term($term) 0 3227 3227
107 3227 ▶ defined $value && $self->value($value);
Branch: 1 branch
BranchTrueFalseTotal
defined $value and $self->value($value) 2361 866 3227
108 3227 ▶ defined $tag && $self->tagname($tag);
Branch: 1 branch
BranchTrueFalseTotal
defined $tag and $self->tagname($tag) 2053 1174 3227
109  
110 3227 return $self;
111 }
112  
113  
114 =head1 AnnotationI implementing functions
115  
116 =cut
117  
118 =head2 as_text
119  
120 Title : as_text
121 Usage : my $text = $obj->as_text
122 Function: return the string "Value: $v" where $v is the value
123 Returns : string
124 Args : none
125  
126  
127 =cut
128  
129 0 ▶sub as_text{
Subroutine as_text: not called CC=1 SCAR=6.9
Pod documented
130 0 my ($self) = @_;
131  
132 0 return "Value: ".$self->value;
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 32 ▶ my $DEFAULT_CB = sub { $_[0]->value};
Subroutine __ANON__: called CC=1 SCAR=0.0
153  
154 32 ▶ sub display_text {
Subroutine display_text: called CC=3 SCAR=12.0
Pod documented
155 32 my ($self, $cb) = @_;
156 32 ▶ $cb ||= $DEFAULT_CB;
Condition33%1/3
$cb ||= $DEFAULT_CB
l!l&&r!l&&!r
0320
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 32 ▶ $self->throw("Callback must be a code reference") if ref $cb ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $cb ne "CODE" 0 32 32
158 32 return $cb->($self);
159 }
160  
161 }
162  
163 =head2 hash_tree
164  
165 Title : hash_tree
166 Usage : my $hashtree = $value->hash_tree
167 Function: For supporting the AnnotationI interface just returns the value
168 as a hashref with the key 'value' pointing to the value
169 Returns : hashrf
170 Args : none
171  
172  
173 =cut
174  
175 318 ▶sub hash_tree{
Subroutine hash_tree: not called CC=1 SCAR=4.1
Pod documented
176 0 my $self = shift;
177  
178 0 my $h = {};
179 0 $h->{'value'} = $self->value;
180 0 return $h;
181 }
182  
183 =head2 tagname
184  
185 Title : tagname
186 Usage : $obj->tagname($newval)
187 Function: Get/set the tagname for this annotation value.
188  
189 Setting this is optional. If set, it obviates the need to
190 provide a tag to AnnotationCollection when adding this
191 object.
192  
193 Example :
194 Returns : value of tagname (a scalar)
195 Args : new value (a scalar, optional)
196  
197  
198 =cut
199  
200 7823 ▶sub tagname{
Subroutine tagname: called CC=4 SCAR=16.4
Pod documented
201 7823 my $self = shift;
202  
203 # check for presence of an ontology term
204 7823 ▶ if($self->{'_tag_term'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_tag_term"}) 0 7823 7823
205 # keep a copy in case the term is removed later
206 0 ▶ $self->{'tagname'} = $_[0] if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
207 # delegate to the ontology term object
208 0 return $self->tag_term->name(@_);
209 }
210 7823 ▶ return $self->{'tagname'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 3101 4722 7823
211 4722 return $self->{'tagname'};
212 }
213  
214  
215 =head1 Specific accessors for SimpleValue
216  
217 =cut
218  
219 =head2 value
220  
221 Title : value
222 Usage : $obj->value($newval)
223 Function: Get/Set the value for simplevalue
224 Returns : value of value
225 Args : newvalue (optional)
226  
227  
228 =cut
229  
230 4948 ▶sub value{
Subroutine value: called CC=2 SCAR=6.9
Pod documented
231 4948 my ($self,$value) = @_;
232  
233 4948 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 3170 1778 4948
234 3170 $self->{'value'} = $value;
235 }
236 4948 return $self->{'value'};
237 }
238  
239 =head2 tag_term
240  
241 Title : tag_term
242 Usage : $obj->tag_term($newval)
243 Function: Get/set the L<Bio::Ontology::TermI> object representing
244 the tag name.
245  
246 This is so you can specifically relate the tag of this
247 annotation to an entry in an ontology. You may want to do
248 this to associate an identifier with the tag, or a
249 particular category, such that you can better match the tag
250 against a controlled vocabulary.
251  
252 This accessor will return undef if it has never been set
253 before in order to allow this annotation to stay
254 light-weight if an ontology term representation of the tag
255 is not needed. Once it is set to a valid value, tagname()
256 will actually delegate to the name() of this term.
257  
258 Example :
259 Returns : a L<Bio::Ontology::TermI> compliant object, or undef
260 Args : on set, new value (a L<Bio::Ontology::TermI> compliant
261 object or undef, optional)
262  
263  
264 =cut
265  
266 0 ▶sub tag_term{
Subroutine tag_term: not called CC=2 SCAR=17.9
Pod documented
267 0 my $self = shift;
268  
269 0 ▶ return $self->{'_tag_term'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
270 0 return $self->{'_tag_term'};
271 }
272  
273 318 1;
« Bio/SeqFeature/Amplicon.pm ↑ Summary Bio/SeqFeature/FeaturePair.pm »