Mercurial > repos > mahtabm > ensembl
comparison variant_effect_predictor/Bio/Annotation/SimpleValue.pm @ 0:1f6dce3d34e0
Uploaded
| author | mahtabm |
|---|---|
| date | Thu, 11 Apr 2013 02:01:53 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:1f6dce3d34e0 |
|---|---|
| 1 # $Id: SimpleValue.pm,v 1.9.2.1 2003/03/10 22:04:56 lapp Exp $ | |
| 2 # | |
| 3 # BioPerl module for Bio::Annotation::SimpleValue | |
| 4 # | |
| 5 # Cared for by bioperl <bioperl-l@bio.perl.org> | |
| 6 # | |
| 7 # Copyright bioperl | |
| 8 # | |
| 9 # You may distribute this module under the same terms as perl itself | |
| 10 | |
| 11 # POD documentation - main docs before the code | |
| 12 | |
| 13 =head1 NAME | |
| 14 | |
| 15 Bio::Annotation::SimpleValue - A simple scalar | |
| 16 | |
| 17 =head1 SYNOPSIS | |
| 18 | |
| 19 use Bio::Annotation::SimpleValue; | |
| 20 use Bio::Annotation::Collection; | |
| 21 | |
| 22 my $col = new Bio::Annotation::Collection; | |
| 23 my $sv = new Bio::Annotation::SimpleValue(-value => 'someval'); | |
| 24 $col->add_Annotation('tagname', $sv); | |
| 25 | |
| 26 =head1 DESCRIPTION | |
| 27 | |
| 28 Scalar value annotation object | |
| 29 | |
| 30 =head1 FEEDBACK | |
| 31 | |
| 32 =head2 Mailing Lists | |
| 33 | |
| 34 User feedback is an integral part of the evolution of this and other | |
| 35 Bioperl modules. Send your comments and suggestions preferably to one | |
| 36 of the Bioperl mailing lists. Your participation is much appreciated. | |
| 37 | |
| 38 bioperl-l@bioperl.org - General discussion | |
| 39 http://bio.perl.org/MailList.html - About the mailing lists | |
| 40 | |
| 41 =head2 Reporting Bugs | |
| 42 | |
| 43 Report bugs to the Bioperl bug tracking system to help us keep track | |
| 44 the bugs and their resolution. Bug reports can be submitted via email | |
| 45 or the web: | |
| 46 | |
| 47 bioperl-bugs@bioperl.org | |
| 48 http://bugzilla.bioperl.org/ | |
| 49 | |
| 50 =head1 AUTHOR - bioperl | |
| 51 | |
| 52 Email bioperl-l@bio.perl.org | |
| 53 | |
| 54 Describe contact details here | |
| 55 | |
| 56 =head1 APPENDIX | |
| 57 | |
| 58 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _ | |
| 59 | |
| 60 =cut | |
| 61 | |
| 62 | |
| 63 # Let the code begin... | |
| 64 | |
| 65 | |
| 66 package Bio::Annotation::SimpleValue; | |
| 67 use vars qw(@ISA); | |
| 68 use strict; | |
| 69 | |
| 70 # Object preamble - inherits from Bio::Root::Root | |
| 71 | |
| 72 use Bio::AnnotationI; | |
| 73 #use Bio::Ontology::TermI; | |
| 74 use Bio::Root::Root; | |
| 75 | |
| 76 @ISA = qw(Bio::Root::Root Bio::AnnotationI); | |
| 77 | |
| 78 =head2 new | |
| 79 | |
| 80 Title : new | |
| 81 Usage : my $sv = new Bio::Annotation::SimpleValue; | |
| 82 Function: Instantiate a new SimpleValue object | |
| 83 Returns : Bio::Annotation::SimpleValue object | |
| 84 Args : -value => $value to initialize the object data field [optional] | |
| 85 -tagname => $tag to initialize the tagname [optional] | |
| 86 -tag_term => ontology term representation of the tag [optional] | |
| 87 | |
| 88 =cut | |
| 89 | |
| 90 sub new{ | |
| 91 my ($class,@args) = @_; | |
| 92 | |
| 93 my $self = $class->SUPER::new(@args); | |
| 94 | |
| 95 my ($value,$tag,$term) = | |
| 96 $self->_rearrange([qw(VALUE TAGNAME TAG_TERM)], @args); | |
| 97 | |
| 98 # set the term first | |
| 99 defined $term && $self->tag_term($term); | |
| 100 defined $value && $self->value($value); | |
| 101 defined $tag && $self->tagname($tag); | |
| 102 | |
| 103 return $self; | |
| 104 } | |
| 105 | |
| 106 | |
| 107 =head1 AnnotationI implementing functions | |
| 108 | |
| 109 =cut | |
| 110 | |
| 111 =head2 as_text | |
| 112 | |
| 113 Title : as_text | |
| 114 Usage : my $text = $obj->as_text | |
| 115 Function: return the string "Value: $v" where $v is the value | |
| 116 Returns : string | |
| 117 Args : none | |
| 118 | |
| 119 | |
| 120 =cut | |
| 121 | |
| 122 sub as_text{ | |
| 123 my ($self) = @_; | |
| 124 | |
| 125 return "Value: ".$self->value; | |
| 126 } | |
| 127 | |
| 128 =head2 hash_tree | |
| 129 | |
| 130 Title : hash_tree | |
| 131 Usage : my $hashtree = $value->hash_tree | |
| 132 Function: For supporting the AnnotationI interface just returns the value | |
| 133 as a hashref with the key 'value' pointing to the value | |
| 134 Returns : hashrf | |
| 135 Args : none | |
| 136 | |
| 137 | |
| 138 =cut | |
| 139 | |
| 140 sub hash_tree{ | |
| 141 my ($self) = @_; | |
| 142 | |
| 143 my $h = {}; | |
| 144 $h->{'value'} = $self->value; | |
| 145 } | |
| 146 | |
| 147 =head2 tagname | |
| 148 | |
| 149 Title : tagname | |
| 150 Usage : $obj->tagname($newval) | |
| 151 Function: Get/set the tagname for this annotation value. | |
| 152 | |
| 153 Setting this is optional. If set, it obviates the need to | |
| 154 provide a tag to AnnotationCollection when adding this | |
| 155 object. | |
| 156 | |
| 157 Example : | |
| 158 Returns : value of tagname (a scalar) | |
| 159 Args : new value (a scalar, optional) | |
| 160 | |
| 161 | |
| 162 =cut | |
| 163 | |
| 164 sub tagname{ | |
| 165 my $self = shift; | |
| 166 | |
| 167 # check for presence of an ontology term | |
| 168 if($self->{'_tag_term'}) { | |
| 169 # keep a copy in case the term is removed later | |
| 170 $self->{'tagname'} = $_[0] if @_; | |
| 171 # delegate to the ontology term object | |
| 172 return $self->tag_term->name(@_); | |
| 173 } | |
| 174 return $self->{'tagname'} = shift if @_; | |
| 175 return $self->{'tagname'}; | |
| 176 } | |
| 177 | |
| 178 | |
| 179 =head1 Specific accessors for SimpleValue | |
| 180 | |
| 181 =cut | |
| 182 | |
| 183 =head2 value | |
| 184 | |
| 185 Title : value | |
| 186 Usage : $obj->value($newval) | |
| 187 Function: Get/Set the value for simplevalue | |
| 188 Returns : value of value | |
| 189 Args : newvalue (optional) | |
| 190 | |
| 191 | |
| 192 =cut | |
| 193 | |
| 194 sub value{ | |
| 195 my ($self,$value) = @_; | |
| 196 | |
| 197 if( defined $value) { | |
| 198 $self->{'value'} = $value; | |
| 199 } | |
| 200 return $self->{'value'}; | |
| 201 } | |
| 202 | |
| 203 =head2 tag_term | |
| 204 | |
| 205 Title : tag_term | |
| 206 Usage : $obj->tag_term($newval) | |
| 207 Function: Get/set the L<Bio::Ontology::TermI> object representing | |
| 208 the tag name. | |
| 209 | |
| 210 This is so you can specifically relate the tag of this | |
| 211 annotation to an entry in an ontology. You may want to do | |
| 212 this to associate an identifier with the tag, or a | |
| 213 particular category, such that you can better match the tag | |
| 214 against a controlled vocabulary. | |
| 215 | |
| 216 This accessor will return undef if it has never been set | |
| 217 before in order to allow this annotation to stay | |
| 218 light-weight if an ontology term representation of the tag | |
| 219 is not needed. Once it is set to a valid value, tagname() | |
| 220 will actually delegate to the name() of this term. | |
| 221 | |
| 222 Example : | |
| 223 Returns : a L<Bio::Ontology::TermI> compliant object, or undef | |
| 224 Args : on set, new value (a L<Bio::Ontology::TermI> compliant | |
| 225 object or undef, optional) | |
| 226 | |
| 227 | |
| 228 =cut | |
| 229 | |
| 230 sub tag_term{ | |
| 231 my $self = shift; | |
| 232 | |
| 233 return $self->{'_tag_term'} = shift if @_; | |
| 234 return $self->{'_tag_term'}; | |
| 235 } | |
| 236 | |
| 237 1; |
