Mercurial > repos > mahtabm > ensemb_rep_gvl
comparison variant_effect_predictor/Bio/Annotation/DBLink.pm @ 0:2bc9b66ada89 draft default tip
Uploaded
author | mahtabm |
---|---|
date | Thu, 11 Apr 2013 06:29:17 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:2bc9b66ada89 |
---|---|
1 # $Id: DBLink.pm,v 1.12 2002/10/23 18:07:49 lapp Exp $ | |
2 # | |
3 # BioPerl module for Bio::Annotation::Link | |
4 # | |
5 # Cared for by Ewan Birney <birney@ebi.ac.uk> | |
6 # | |
7 # Copyright Ewan Birney | |
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::DBLink - DESCRIPTION of Object | |
16 | |
17 =head1 SYNOPSIS | |
18 | |
19 $link1 = new Bio::Annotation::DBLink(-database => 'TSC', | |
20 -primary_id => 'TSC0000030' | |
21 ); | |
22 | |
23 #or | |
24 | |
25 $link2 = new Bio::Annotation::DBLink(); | |
26 $link2->database('dbSNP'); | |
27 $link2->primary_id('2367'); | |
28 | |
29 # DBLink is-a Bio::AnnotationI object, can be added to annotation | |
30 # collections, e.g. the one on features or seqs | |
31 $feat->annotation->add_Annotation('dblink', $link2); | |
32 | |
33 | |
34 =head1 DESCRIPTION | |
35 | |
36 Provides an object which represents a link from one object to something | |
37 in another database without prescribing what is in the other database | |
38 | |
39 =head1 AUTHOR - Ewan Birney | |
40 | |
41 Ewan Birney - birney@ebi.ac.uk | |
42 | |
43 =head1 APPENDIX | |
44 | |
45 The rest of the documentation details each of the object | |
46 methods. Internal methods are usually preceded with a _ | |
47 | |
48 =cut | |
49 | |
50 | |
51 # Let the code begin... | |
52 | |
53 package Bio::Annotation::DBLink; | |
54 use vars qw(@ISA); | |
55 use strict; | |
56 | |
57 use Bio::Root::Root; | |
58 use Bio::AnnotationI; | |
59 use Bio::IdentifiableI; | |
60 | |
61 @ISA = qw(Bio::Root::Root Bio::AnnotationI Bio::IdentifiableI); | |
62 | |
63 | |
64 sub new { | |
65 my($class,@args) = @_; | |
66 | |
67 my $self = $class->SUPER::new(@args); | |
68 | |
69 my ($database, $primary_id, $optional_id, $comment, $tag, $ns, $auth, $v) = | |
70 $self->_rearrange([qw(DATABASE | |
71 PRIMARY_ID | |
72 OPTIONAL_ID | |
73 COMMENT | |
74 TAGNAME | |
75 NAMESPACE | |
76 AUTHORITY | |
77 VERSION | |
78 )], @args); | |
79 | |
80 $database && $self->database($database); | |
81 $primary_id && $self->primary_id($primary_id); | |
82 $optional_id && $self->optional_id($optional_id); | |
83 $comment && $self->comment($comment); | |
84 $tag && $self->tagname($tag); | |
85 # Bio::IdentifiableI parameters: | |
86 $ns && $self->namespace($ns); # this will override $database | |
87 $auth && $self->authority($auth); | |
88 defined($v) && $self->version($v); | |
89 | |
90 return $self; | |
91 } | |
92 | |
93 =head1 AnnotationI implementing functions | |
94 | |
95 =cut | |
96 | |
97 | |
98 =head2 as_text | |
99 | |
100 Title : as_text | |
101 Usage : | |
102 Function: | |
103 Example : | |
104 Returns : | |
105 Args : | |
106 | |
107 | |
108 =cut | |
109 | |
110 sub as_text{ | |
111 my ($self) = @_; | |
112 | |
113 return "Direct database link to ".$self->primary_id." in database ".$self->database; | |
114 } | |
115 | |
116 =head2 hash_tree | |
117 | |
118 Title : hash_tree | |
119 Usage : | |
120 Function: | |
121 Example : | |
122 Returns : | |
123 Args : | |
124 | |
125 | |
126 =cut | |
127 | |
128 sub hash_tree{ | |
129 my ($self) = @_; | |
130 | |
131 my $h = {}; | |
132 $h->{'database'} = $self->database; | |
133 $h->{'primary_id'} = $self->primary_id; | |
134 if( defined $self->optional_id ) { | |
135 $h->{'optional_id'} = $self->optional_id; | |
136 } | |
137 if( defined $self->comment ) { | |
138 # we know that comments have hash_tree methods | |
139 $h->{'comment'} = $self->comment; | |
140 } | |
141 | |
142 return $h; | |
143 } | |
144 | |
145 =head2 tagname | |
146 | |
147 Title : tagname | |
148 Usage : $obj->tagname($newval) | |
149 Function: Get/set the tagname for this annotation value. | |
150 | |
151 Setting this is optional. If set, it obviates the need to | |
152 provide a tag to Bio::AnnotationCollectionI when adding | |
153 this object. When obtaining an AnnotationI object from the | |
154 collection, the collection will set the value to the tag | |
155 under which it was stored unless the object has a tag | |
156 stored already. | |
157 | |
158 Example : | |
159 Returns : value of tagname (a scalar) | |
160 Args : new value (a scalar, optional) | |
161 | |
162 | |
163 =cut | |
164 | |
165 sub tagname{ | |
166 my ($self,$value) = @_; | |
167 if( defined $value) { | |
168 $self->{'tagname'} = $value; | |
169 } | |
170 return $self->{'tagname'}; | |
171 } | |
172 | |
173 =head1 Specific accessors for DBLinks | |
174 | |
175 =cut | |
176 | |
177 =head2 database | |
178 | |
179 Title : database | |
180 Usage : $self->database($newval) | |
181 Function: set/get on the database string. Databases are just | |
182 a string here which can then be interpretted elsewhere | |
183 Example : | |
184 Returns : value of database | |
185 Args : newvalue (optional) | |
186 | |
187 =cut | |
188 | |
189 sub database{ | |
190 my ($self,$value) = @_; | |
191 | |
192 if( defined $value) { | |
193 $self->{'database'} = $value; | |
194 } | |
195 return $self->{'database'}; | |
196 | |
197 } | |
198 | |
199 =head2 primary_id | |
200 | |
201 Title : primary_id | |
202 Usage : $self->primary_id($newval) | |
203 Function: set/get on the primary id (a string) | |
204 The primary id is the main identifier used for this object in | |
205 the database. Good examples would be accession numbers. The id | |
206 is meant to be the main, stable identifier for this object | |
207 Example : | |
208 Returns : value of primary_id | |
209 Args : newvalue (optional) | |
210 | |
211 =cut | |
212 | |
213 sub primary_id{ | |
214 my ($self,$value) = @_; | |
215 if( defined $value) { | |
216 $self->{'primary_id'} = $value; | |
217 } | |
218 return $self->{'primary_id'}; | |
219 | |
220 } | |
221 | |
222 =head2 optional_id | |
223 | |
224 Title : optional_id | |
225 Usage : $self->optional_id($newval) | |
226 Function: get/set for the optional_id (a string) | |
227 | |
228 optional id is a slot for people to use as they wish. The | |
229 main issue is that some databases do not have a clean | |
230 single string identifier scheme. It is hoped that the | |
231 primary_id can behave like a reasonably sane "single string | |
232 identifier" of objects, and people can use/abuse optional | |
233 ids to their heart's content to provide precise mappings. | |
234 | |
235 Example : | |
236 Returns : value of optional_id | |
237 Args : newvalue (optional) | |
238 | |
239 =cut | |
240 | |
241 #' | |
242 | |
243 sub optional_id{ | |
244 my ($self,$value) = @_; | |
245 if( defined $value) { | |
246 $self->{'optional_id'} = $value; | |
247 } | |
248 return $self->{'optional_id'}; | |
249 | |
250 } | |
251 | |
252 =head2 comment | |
253 | |
254 Title : comment | |
255 Usage : $self->comment($newval) | |
256 Function: get/set of comments (comment object) | |
257 Sets or gets comments of this dblink, which is sometimes relevant | |
258 Example : | |
259 Returns : value of comment (Bio::Annotation::Comment) | |
260 Args : newvalue (optional) | |
261 | |
262 =cut | |
263 | |
264 sub comment { | |
265 my ($self,$value) = @_; | |
266 if( defined $value) { | |
267 $self->{'comment'} = $value; | |
268 } | |
269 return $self->{'comment'}; | |
270 } | |
271 | |
272 =head1 Methods for Bio::IdentifiableI compliance | |
273 | |
274 =head2 object_id | |
275 | |
276 Title : object_id | |
277 Usage : $string = $obj->object_id() | |
278 Function: a string which represents the stable primary identifier | |
279 in this namespace of this object. For DNA sequences this | |
280 is its accession_number, similarly for protein sequences | |
281 | |
282 This is aliased to primary_id(). | |
283 Returns : A scalar | |
284 | |
285 | |
286 =cut | |
287 | |
288 sub object_id { | |
289 return shift->primary_id(@_); | |
290 } | |
291 | |
292 =head2 version | |
293 | |
294 Title : version | |
295 Usage : $version = $obj->version() | |
296 Function: a number which differentiates between versions of | |
297 the same object. Higher numbers are considered to be | |
298 later and more relevant, but a single object described | |
299 the same identifier should represent the same concept | |
300 | |
301 Returns : A number | |
302 | |
303 =cut | |
304 | |
305 sub version{ | |
306 my ($self,$value) = @_; | |
307 if( defined $value) { | |
308 $self->{'_version'} = $value; | |
309 } | |
310 return $self->{'_version'}; | |
311 } | |
312 | |
313 | |
314 =head2 authority | |
315 | |
316 Title : authority | |
317 Usage : $authority = $obj->authority() | |
318 Function: a string which represents the organisation which | |
319 granted the namespace, written as the DNS name for | |
320 organisation (eg, wormbase.org) | |
321 | |
322 Returns : A scalar | |
323 | |
324 =cut | |
325 | |
326 sub authority { | |
327 my ($obj,$value) = @_; | |
328 if( defined $value) { | |
329 $obj->{'authority'} = $value; | |
330 } | |
331 return $obj->{'authority'}; | |
332 } | |
333 | |
334 =head2 namespace | |
335 | |
336 Title : namespace | |
337 Usage : $string = $obj->namespace() | |
338 Function: A string representing the name space this identifier | |
339 is valid in, often the database name or the name | |
340 describing the collection | |
341 | |
342 For DBLink this is the same as database(). | |
343 Returns : A scalar | |
344 | |
345 | |
346 =cut | |
347 | |
348 sub namespace{ | |
349 return shift->database(@_); | |
350 } | |
351 | |
352 1; |