Mercurial > repos > mahtabm > ensembl
comparison variant_effect_predictor/Bio/EnsEMBL/Variation/Allele.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 =head1 LICENSE | |
2 | |
3 Copyright (c) 1999-2012 The European Bioinformatics Institute and | |
4 Genome Research Limited. All rights reserved. | |
5 | |
6 This software is distributed under a modified Apache license. | |
7 For license details, please see | |
8 | |
9 http://www.ensembl.org/info/about/code_licence.html | |
10 | |
11 =head1 CONTACT | |
12 | |
13 Please email comments or questions to the public Ensembl | |
14 developers list at <dev@ensembl.org>. | |
15 | |
16 Questions may also be sent to the Ensembl help desk at | |
17 <helpdesk@ensembl.org>. | |
18 | |
19 =cut | |
20 | |
21 # Ensembl module for Bio::EnsEMBL::Variation::Allele | |
22 # | |
23 # Copyright (c) 2004 Ensembl | |
24 # | |
25 | |
26 | |
27 =head1 NAME | |
28 | |
29 Bio::EnsEMBL::Variation::Allele - A single allele of a nucleotide variation. | |
30 | |
31 =head1 SYNOPSIS | |
32 | |
33 $allele = Bio::EnsEMBL::Variation::Allele->new | |
34 (-allele => 'A', | |
35 -frequency => 0.85, | |
36 -population => $population); | |
37 | |
38 $delete = Bio::EnsEMBL::Variation::Allele->new | |
39 (-allele => '-', | |
40 -frequency => 0.15, | |
41 -population => $population); | |
42 | |
43 ... | |
44 | |
45 $astr = $a->allele(); | |
46 $pop = $a->population(); | |
47 $freq = $a->frequency(); | |
48 | |
49 print $a->allele(); | |
50 if($a->populaton) { | |
51 print " found in population ", $allele->population->name(); | |
52 } | |
53 if(defined($a->frequency())) { | |
54 print " with frequency ", $a->frequency(); | |
55 } | |
56 print "\n"; | |
57 | |
58 | |
59 | |
60 =head1 DESCRIPTION | |
61 | |
62 This is a class representing a single allele of a variation. In addition to | |
63 the nucleotide(s) (or absence of) that representing the allele frequency | |
64 and population information may be present. | |
65 | |
66 =head1 METHODS | |
67 | |
68 =cut | |
69 | |
70 use strict; | |
71 use warnings; | |
72 | |
73 package Bio::EnsEMBL::Variation::Allele; | |
74 | |
75 use Bio::EnsEMBL::Storable; | |
76 use Bio::EnsEMBL::Utils::Argument qw(rearrange); | |
77 use Bio::EnsEMBL::Utils::Exception qw(throw deprecate warning); | |
78 use Bio::EnsEMBL::Utils::Scalar qw(assert_ref check_ref); | |
79 use Scalar::Util qw(weaken); | |
80 use Bio::EnsEMBL::Variation::Failable; | |
81 | |
82 our @ISA = ('Bio::EnsEMBL::Storable', 'Bio::EnsEMBL::Variation::Failable'); | |
83 | |
84 | |
85 =head2 new | |
86 | |
87 Arg [-dbID]: int - unique internal identifier for the Allele | |
88 Arg [-ADAPTOR]: Bio::EnsEMBL::Variation::DBSQL::AlleleAdaptor | |
89 Arg [-ALLELE]: string - the nucleotide string representing the allele | |
90 Arg [-FREQUENCY]: float - the frequency of the allele | |
91 Arg [-POPULATION]: Bio::EnsEMBL::Variation::Population - the population | |
92 in which the allele was recorded | |
93 Example : $allele = Bio::EnsEMBL::Variation::Allele->new | |
94 (-allele => 'A', | |
95 -frequency => 0.85, | |
96 -population => $pop); | |
97 | |
98 Description: Constructor. Instantiates a new Allele object. | |
99 Returntype : Bio::EnsEMBL::Variation::Allele | |
100 Exceptions : none | |
101 Caller : general | |
102 Status : At Risk | |
103 | |
104 =cut | |
105 | |
106 | |
107 sub new { | |
108 my $caller = shift; | |
109 my $class = ref($caller) || $caller; | |
110 | |
111 my ($dbID, $adaptor, $allele, $freq, $count, $pop, $ss_id, $variation_id, $population_id) = | |
112 rearrange(['dbID', 'ADAPTOR', 'ALLELE', 'FREQUENCY', 'COUNT', 'POPULATION', 'SUBSNP', 'VARIATION_ID', 'POPULATION_ID'], @_); | |
113 | |
114 # set subsnp_id to undefined if it's 0 in the DB | |
115 #$ss_id = undef if (defined $ss_id && $ss_id == 0); | |
116 | |
117 # add ss to the subsnp_id | |
118 $ss_id = 'ss'.$ss_id if defined $ss_id && $ss_id !~ /^ss/; | |
119 | |
120 # Check that we at least get a BaseAdaptor | |
121 assert_ref($adaptor,'Bio::EnsEMBL::Variation::DBSQL::BaseAdaptor'); | |
122 # If the adaptor is not an AlleleAdaptor, try to get it via the passed adaptor | |
123 unless (check_ref($adaptor,'Bio::EnsEMBL::Variation::DBSQL::AlleleAdaptor')) { | |
124 $adaptor = $adaptor->db->get_AlleleAdaptor(); | |
125 # Verify that we could get the AlleleAdaptor | |
126 assert_ref($adaptor,'Bio::EnsEMBL::Variation::DBSQL::AlleleAdaptor'); | |
127 } | |
128 | |
129 my $self = bless {}, $class; | |
130 | |
131 $self->dbID($dbID); | |
132 $self->adaptor($adaptor); | |
133 $self->allele($allele); | |
134 $self->frequency($freq); | |
135 $self->count($count); | |
136 $self->subsnp($ss_id); | |
137 $self->{'_variation_id'} = $variation_id; | |
138 $self->{'_population_id'} = $population_id; | |
139 $self->population($pop) if (defined($pop)); | |
140 | |
141 return $self; | |
142 } | |
143 | |
144 sub new_fast { | |
145 my $class = shift; | |
146 my $hashref = shift; | |
147 return bless $hashref, $class; | |
148 } | |
149 | |
150 | |
151 # An internal method for getting a unique hash key identifier, used by the Variation module | |
152 sub _hash_key { | |
153 my $self = shift; | |
154 | |
155 # By default, return the dbID | |
156 my $dbID = $self->dbID(); | |
157 return $dbID if (defined($dbID)); | |
158 | |
159 # If no dbID is specified, e.g. if we are creating a 'custom' object, return a fake dbID. This is necessary since e.g. Variation stores | |
160 # its alleles in a hash with dbID as key. To create fake dbIDs, use the string representing the memory address. | |
161 ($dbID) = sprintf('%s',$self) =~ m/\(([0-9a-fx]+)\)/i; | |
162 return $dbID; | |
163 } | |
164 | |
165 =head2 allele | |
166 | |
167 Arg [1] : string $newval (optional) | |
168 The new value to set the allele attribute to | |
169 Example : print $a->allele(); | |
170 $a1->allele('A'); | |
171 $a2->allele('-'); | |
172 Description: Getter/Setter for the allele attribute. The allele is a string | |
173 of nucleotide sequence, or a '-' representing the absence of | |
174 sequence (deletion). | |
175 Returntype : string | |
176 Exceptions : none | |
177 Caller : general | |
178 Status : At Risk | |
179 | |
180 =cut | |
181 | |
182 sub allele{ | |
183 my $self = shift; | |
184 return $self->{'allele'} = shift if(@_); | |
185 return $self->{'allele'}; | |
186 } | |
187 | |
188 | |
189 | |
190 | |
191 =head2 frequency | |
192 | |
193 Arg [1] : float $newval (optional) | |
194 The new value to set the frequency attribute to | |
195 Example : $frequency = $a->frequency(); | |
196 Description: Getter/Setter for the frequency attribute. The frequency is | |
197 the frequency of the occurance of the allele. If the population | |
198 attribute it is the frequency of the allele within that | |
199 population. | |
200 Returntype : float | |
201 Exceptions : none | |
202 Caller : general | |
203 Status : At Risk | |
204 | |
205 =cut | |
206 | |
207 sub frequency{ | |
208 my $self = shift; | |
209 return $self->{'frequency'} = shift if(@_); | |
210 return $self->{'frequency'}; | |
211 } | |
212 | |
213 =head2 count | |
214 | |
215 Arg [1] : int $count (optional) | |
216 The new value to set the count attribute to | |
217 Example : $frequency = $allele->count() | |
218 Description: Getter/Setter for the observed count of this allele | |
219 within its associated population. | |
220 Returntype : string | |
221 Exceptions : none | |
222 Caller : general | |
223 Status : At Risk | |
224 | |
225 =cut | |
226 | |
227 sub count{ | |
228 my $self = shift; | |
229 return $self->{'count'} = shift if(@_); | |
230 return $self->{'count'}; | |
231 } | |
232 | |
233 | |
234 | |
235 =head2 population | |
236 | |
237 Arg [1] : Bio::EnsEMBL::Variation::Population $newval (optional) | |
238 The new value to set the population attribute to | |
239 Example : $population = $a->population(); | |
240 Description: Getter/Setter for the population attribute | |
241 Returntype : Bio::EnsEMBL::Variation::Population | |
242 Exceptions : throw on incorrect argument | |
243 Caller : general | |
244 Status : At Risk | |
245 | |
246 =cut | |
247 | |
248 sub population{ | |
249 my $self = shift; | |
250 | |
251 if(@_) { | |
252 assert_ref($_[0],'Bio::EnsEMBL::Variation::Population'); | |
253 $self->{'population'} = shift; | |
254 $self->{'_population_id'} = $self->{'population'}->dbID(); | |
255 } | |
256 | |
257 # Population can be lazy-loaded, so get it from the database if we have a sample_id but no cached object | |
258 if (!defined($self->{'population'}) && defined($self->{'_population_id'})) { | |
259 | |
260 # Check that an adaptor is attached | |
261 assert_ref($self->adaptor(),'Bio::EnsEMBL::Variation::DBSQL::AlleleAdaptor'); | |
262 | |
263 # Get a population object | |
264 my $population = $self->adaptor->db->get_PopulationAdaptor()->fetch_by_dbID($self->{'_population_id'}); | |
265 | |
266 # Set the population | |
267 $self->{'population'} = $population; | |
268 } | |
269 | |
270 return $self->{'population'}; | |
271 } | |
272 | |
273 | |
274 =head2 subsnp | |
275 | |
276 Arg [1] : string $newval (optional) | |
277 The new value to set the subsnp attribute to | |
278 Example : print $a->subsnp(); | |
279 Description: Getter/Setter for the subsnp attribute. | |
280 Returntype : string | |
281 Exceptions : none | |
282 Caller : general | |
283 Status : At Risk | |
284 | |
285 =cut | |
286 | |
287 sub subsnp{ | |
288 my $self = shift; | |
289 if(@_) { | |
290 $self->{'subsnp'} = shift; | |
291 } | |
292 | |
293 my $ssid = $self->{'subsnp'}; | |
294 if(defined($ssid)) { | |
295 $ssid = 'ss'.$ssid unless $ssid =~ /^ss/; | |
296 } | |
297 | |
298 return $ssid; | |
299 } | |
300 | |
301 | |
302 =head2 variation | |
303 | |
304 Arg [1] : Bio::EnsEMBL::Variation::Variation $newval (optional) | |
305 The new value to set the variation attribute to | |
306 Example : print $a->variation->name(); | |
307 Description: Getter/Setter for the variation attribute. | |
308 Returntype : Bio::EnsEMBL::Variation::Variation | |
309 Exceptions : throw on incorrect argument | |
310 Caller : general | |
311 | |
312 =cut | |
313 | |
314 sub variation { | |
315 my $self = shift; | |
316 my $variation = shift; | |
317 | |
318 # Set the dbID of the variation object on this allele | |
319 if(defined($variation)) { | |
320 assert_ref($variation,'Bio::EnsEMBL::Variation::Variation'); | |
321 $self->{'_variation_id'} = $variation->dbID(); | |
322 return $variation; | |
323 } | |
324 | |
325 # Load the variation from the database if we have a variation_id | |
326 if (defined($self->{'_variation_id'})) { | |
327 | |
328 # Check that an adaptor is attached | |
329 assert_ref($self->adaptor(),'Bio::EnsEMBL::Variation::DBSQL::BaseAdaptor'); | |
330 | |
331 # Get a variation object | |
332 $variation = $self->adaptor->db->get_VariationAdaptor()->fetch_by_dbID($self->{'_variation_id'}); | |
333 | |
334 $self->{variation} = $variation; | |
335 } | |
336 | |
337 # Return the variation object | |
338 return $self->{variation}; | |
339 } | |
340 | |
341 | |
342 =head2 subsnp_handle | |
343 | |
344 Arg [1] : string $newval (optional) | |
345 The new value to set the subsnp_handle attribute to | |
346 Example : print $a->subsnp_handle(); | |
347 Description: Getter/Setter for the subsnp_handle attribute. | |
348 Returntype : string | |
349 Exceptions : none | |
350 Caller : general | |
351 Status : At Risk | |
352 | |
353 =cut | |
354 | |
355 sub subsnp_handle{ | |
356 my $self = shift; | |
357 my $handle = shift; | |
358 | |
359 # if changing handle | |
360 if(defined($handle)) { | |
361 $self->{'subsnp_handle'} = $handle; | |
362 } | |
363 elsif (!defined($self->{'subsnp_handle'})) { | |
364 | |
365 # Check that this allele has an adaptor attached | |
366 assert_ref($self->adaptor(),'Bio::EnsEMBL::Variation::DBSQL::AlleleAdaptor'); | |
367 | |
368 $self->{'subsnp_handle'} = $self->adaptor->get_subsnp_handle($self); | |
369 } | |
370 | |
371 return $self->{'subsnp_handle'}; | |
372 } | |
373 | |
374 sub _weaken { | |
375 my $self = shift; | |
376 | |
377 # If the variation is not defined, do nothing | |
378 return unless (defined($self->variation())); | |
379 | |
380 # Weaken the link to the variation | |
381 weaken($self->{'variation'}); | |
382 } | |
383 | |
384 1; |