Mercurial > repos > mahtabm > ensembl
comparison variant_effect_predictor/Bio/EnsEMBL/Variation/VariationSet.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::VariationSet | |
| 22 # | |
| 23 # Copyright (c) 2010 Ensembl | |
| 24 # | |
| 25 | |
| 26 =head1 NAME | |
| 27 | |
| 28 Bio::EnsEMBL::Variation::VariationSet - Ensembl representation of a set of | |
| 29 variations. | |
| 30 | |
| 31 =head1 SYNOPSIS | |
| 32 | |
| 33 use Bio::EnsEMBL::Variation::VariationSet; | |
| 34 | |
| 35 ... | |
| 36 | |
| 37 | |
| 38 | |
| 39 =head1 DESCRIPTION | |
| 40 | |
| 41 This is a class representing a set of variations that are grouped by e.g. | |
| 42 study, method, quality measure etc. | |
| 43 | |
| 44 =head1 METHODS | |
| 45 | |
| 46 =cut | |
| 47 | |
| 48 | |
| 49 use strict; | |
| 50 use warnings; | |
| 51 | |
| 52 package Bio::EnsEMBL::Variation::VariationSet; | |
| 53 | |
| 54 use Bio::EnsEMBL::Storable; | |
| 55 use Bio::EnsEMBL::Utils::Argument qw(rearrange); | |
| 56 use Bio::EnsEMBL::Utils::Exception qw(throw deprecate warning); | |
| 57 use Bio::EnsEMBL::Utils::Iterator; | |
| 58 | |
| 59 use vars qw(@ISA); | |
| 60 | |
| 61 @ISA = qw(Bio::EnsEMBL::Storable); | |
| 62 | |
| 63 | |
| 64 =head2 new | |
| 65 | |
| 66 Arg [dbID] : | |
| 67 int - unique internal identifier for this allele group | |
| 68 | |
| 69 Arg [ADAPTOR] : | |
| 70 Bio::EnsEMBL::Variation::DBSQL::VariationSetAdaptor | |
| 71 | |
| 72 Arg [NAME] : | |
| 73 string - the name of this variation set | |
| 74 | |
| 75 Arg [DESCRIPTION] : | |
| 76 string - A description explaining the charcteristics of this variation set | |
| 77 | |
| 78 Arg [SHORT_NAME] : | |
| 79 string - the short name of this variation set | |
| 80 | |
| 81 Example : | |
| 82 $ag = Bio::EnsEMBL::Variation::VariationSet->new | |
| 83 ( | |
| 84 -dbID => 12, | |
| 85 -adaptor => $var_set_adaptor, | |
| 86 -name => 'Phenotype-associated variations', | |
| 87 -description => 'Variations that have been associated with a phenotype', | |
| 88 -short_name => 'ph_variants' | |
| 89 ); | |
| 90 Description: Constructor. Instantiates a new VariationSet | |
| 91 Returntype : Bio::EnsEMBL::Variation::VariationSet | |
| 92 Exceptions : none | |
| 93 Caller : general | |
| 94 Status : At Risk | |
| 95 | |
| 96 =cut | |
| 97 | |
| 98 sub new { | |
| 99 my $class = shift; | |
| 100 | |
| 101 my ($dbID, $adaptor, $name, $description, $short_name) = | |
| 102 rearrange([qw(DBID ADAPTOR NAME DESCRIPTION SHORT_NAME)], @_); | |
| 103 | |
| 104 # Check that the dbID does not exceed the maximum dbID that can be stored in the variation_set_id SET construct in variation_set_variation | |
| 105 warn("Primary key variation_set_id $dbID for variation set '$name' exceeds " . $Bio::EnsEMBL::Variation::DBSQL::VariationSetAdaptor::MAX_VARIATION_SET_ID . ". Therefore, this variation set cannot be properly referenced in variation_set_variation") if ($dbID > $Bio::EnsEMBL::Variation::DBSQL::VariationSetAdaptor::MAX_VARIATION_SET_ID); | |
| 106 | |
| 107 return bless {'dbID' => $dbID, | |
| 108 'adaptor' => $adaptor, | |
| 109 'name' => $name, | |
| 110 'description' => $description, | |
| 111 'short_name' => $short_name}, $class; | |
| 112 } | |
| 113 | |
| 114 =head2 description | |
| 115 | |
| 116 Arg [1] : string $description | |
| 117 Example : print $vs->description(); | |
| 118 Description: Getter/Setter for the description of this VariationSet | |
| 119 Returntype : string | |
| 120 Exceptions : none | |
| 121 Caller : general | |
| 122 Status : At Risk | |
| 123 | |
| 124 =cut | |
| 125 | |
| 126 sub description { | |
| 127 my $self = shift; | |
| 128 my $desc = shift; | |
| 129 | |
| 130 $self->{'description'} = $desc if (defined($desc)); | |
| 131 | |
| 132 return $self->{'description'}; | |
| 133 } | |
| 134 | |
| 135 =head2 get_all_sub_VariationSets | |
| 136 Arg [1] : (optional) boolean $only_immediate | |
| 137 If true, will only get the direct subsets of this variation. The default behaviour is | |
| 138 to recursively get all subsets. | |
| 139 Example : print $vs->get_all_sub_VariationSets(); | |
| 140 Description: Recursively gets all variation sets that are subsets of this variation set. | |
| 141 Returntype : reference to list of Bio::EnsEMBL::Variation::VariationSet | |
| 142 Exceptions : none | |
| 143 Caller : general | |
| 144 Status : At Risk | |
| 145 | |
| 146 =cut | |
| 147 | |
| 148 sub get_all_sub_VariationSets { | |
| 149 my $self = shift; | |
| 150 my $only_immediate = shift; | |
| 151 | |
| 152 # A database adaptor must be attached to this object | |
| 153 if(!$self->adaptor()) { | |
| 154 warning('Cannot get sub variation sets without attached adaptor'); | |
| 155 return []; | |
| 156 } | |
| 157 | |
| 158 return $self->adaptor->fetch_all_by_super_VariationSet($self,$only_immediate); | |
| 159 } | |
| 160 | |
| 161 =head2 get_all_super_VariationSets | |
| 162 Arg [1] : (optional) boolean $only_immediate | |
| 163 If true, will only get the direct supersets of this variation. The default behaviour is | |
| 164 to recursively get all supersets. | |
| 165 Example : print $vs->get_all_super_VariationSets(); | |
| 166 Description: Recursively gets all variation sets that are above this variation set. | |
| 167 Returntype : reference to list of Bio::EnsEMBL::Variation::VariationSet | |
| 168 Exceptions : none | |
| 169 Caller : general | |
| 170 Status : At Risk | |
| 171 | |
| 172 =cut | |
| 173 | |
| 174 sub get_all_super_VariationSets { | |
| 175 my $self = shift; | |
| 176 my $only_immediate = shift; | |
| 177 | |
| 178 # A database adaptor must be attached to this object | |
| 179 if(!$self->adaptor()) { | |
| 180 warning('Cannot get super variation sets without attached adaptor'); | |
| 181 return []; | |
| 182 } | |
| 183 | |
| 184 return $self->adaptor->fetch_all_by_sub_VariationSet($self,$only_immediate); | |
| 185 } | |
| 186 | |
| 187 =head2 get_all_Variations | |
| 188 | |
| 189 Example : print $vs->get_all_Variations(); | |
| 190 Description: Gets all variations belonging to this variation set and all of its subsets. | |
| 191 Returntype : reference to list of Bio::EnsEMBL::Variation::Variation | |
| 192 Exceptions : none | |
| 193 Caller : general | |
| 194 Status : At Risk | |
| 195 | |
| 196 =cut | |
| 197 | |
| 198 sub get_all_Variations { | |
| 199 my $self = shift; | |
| 200 | |
| 201 # A database adaptor must be attached to this object | |
| 202 if(!$self->adaptor()) { | |
| 203 warning('Cannot get variations without attached adaptor'); | |
| 204 return []; | |
| 205 } | |
| 206 | |
| 207 # Call the method in VariationAdaptor that will handle this | |
| 208 my $variation_adaptor = $self->adaptor->db->get_VariationAdaptor(); | |
| 209 if(!$variation_adaptor) { | |
| 210 warning('Could not get variation adaptor from database'); | |
| 211 return []; | |
| 212 } | |
| 213 | |
| 214 # Get all variations from this set (and its subsets) | |
| 215 return $variation_adaptor->fetch_all_by_VariationSet($self); | |
| 216 } | |
| 217 | |
| 218 | |
| 219 =head2 get_all_StructuralVariations | |
| 220 | |
| 221 Example : print $vs->get_all_StructuralVariations(); | |
| 222 Description: Gets all structural variations belonging to this variation set and all of its subsets. | |
| 223 Returntype : reference to list of Bio::EnsEMBL::Variation::StructuralVariation | |
| 224 Exceptions : none | |
| 225 Caller : general | |
| 226 Status : At Risk | |
| 227 | |
| 228 =cut | |
| 229 | |
| 230 sub get_all_StructuralVariations { | |
| 231 my $self = shift; | |
| 232 | |
| 233 # A database adaptor must be attached to this object | |
| 234 if(!$self->adaptor()) { | |
| 235 warning('Cannot get structural variations without attached adaptor'); | |
| 236 return []; | |
| 237 } | |
| 238 | |
| 239 # Call the method in StructuralVariationAdaptor that will handle this | |
| 240 my $sv_adaptor = $self->adaptor->db->get_StructuralVariationAdaptor(); | |
| 241 if(!$sv_adaptor) { | |
| 242 warning('Could not get structural variation adaptor from database'); | |
| 243 return []; | |
| 244 } | |
| 245 | |
| 246 # Get all variations from this set (and its subsets) | |
| 247 return $sv_adaptor->fetch_all_by_VariationSet($self); | |
| 248 } | |
| 249 | |
| 250 | |
| 251 =head2 get_Variation_Iterator | |
| 252 | |
| 253 Example : my $var_iterator = $vs->get_Variation_Iterator; | |
| 254 Description: Gets an iterator over all variations belonging to this | |
| 255 variation set and all of its subsets. | |
| 256 Returntype : Bio::EnsEMBL::Utils::Iterator | |
| 257 Exceptions : none | |
| 258 Caller : general | |
| 259 Status : Experimental | |
| 260 | |
| 261 =cut | |
| 262 | |
| 263 sub get_Variation_Iterator { | |
| 264 my $self = shift; | |
| 265 | |
| 266 # A database adaptor must be attached to this object | |
| 267 unless ($self->adaptor) { | |
| 268 warning('Cannot get variations without attached adaptor'); | |
| 269 return Bio::EnsEMBL::Utils::Iterator->new; | |
| 270 } | |
| 271 | |
| 272 # Call the method in VariationAdaptor that will handle this | |
| 273 my $variation_adaptor = $self->adaptor->db->get_VariationAdaptor(); | |
| 274 | |
| 275 unless ($variation_adaptor) { | |
| 276 warning('Could not get variation adaptor from database'); | |
| 277 return Bio::EnsEMBL::Utils::Iterator->new; | |
| 278 } | |
| 279 | |
| 280 # Get an iterator over variations from this set (and its subsets) | |
| 281 return $variation_adaptor->fetch_Iterator_by_VariationSet($self); | |
| 282 } | |
| 283 | |
| 284 | |
| 285 =head2 get_StructuralVariation_Iterator | |
| 286 | |
| 287 Example : my $sv_iterator = $vs->get_StructuralVariation_Iterator; | |
| 288 Description: Gets an iterator over all structural variations belonging to this | |
| 289 variation set and all of its subsets. | |
| 290 Returntype : Bio::EnsEMBL::Utils::Iterator | |
| 291 Exceptions : none | |
| 292 Caller : general | |
| 293 Status : Experimental | |
| 294 | |
| 295 =cut | |
| 296 | |
| 297 sub get_StructuralVariation_Iterator { | |
| 298 my $self = shift; | |
| 299 | |
| 300 # A database adaptor must be attached to this object | |
| 301 unless ($self->adaptor) { | |
| 302 warning('Cannot get structural variations without attached adaptor'); | |
| 303 return Bio::EnsEMBL::Utils::Iterator->new; | |
| 304 } | |
| 305 | |
| 306 # Call the method in StructuralVariationAdaptor that will handle this | |
| 307 my $sv_adaptor = $self->adaptor->db->get_StructuralVariationAdaptor(); | |
| 308 | |
| 309 unless ($sv_adaptor) { | |
| 310 warning('Could not get dructural variation adaptor from database'); | |
| 311 return Bio::EnsEMBL::Utils::Iterator->new; | |
| 312 } | |
| 313 | |
| 314 # Get an iterator over Structural variations from this set (and its subsets) | |
| 315 return $sv_adaptor->fetch_Iterator_by_VariationSet($self); | |
| 316 } | |
| 317 | |
| 318 | |
| 319 =head2 get_all_VariationFeatures_by_Slice | |
| 320 | |
| 321 Arg [1] : Bio::EnsEMBL:Variation::Slice $slice | |
| 322 Example : my @vfs = | |
| 323 @{$vs->get_all_VariationFeatures_by_Slice($slice)}; | |
| 324 Description: Retrieves all variation features in a slice that belong to | |
| 325 this set. | |
| 326 Returntype : reference to list Bio::EnsEMBL::Variation::VariationFeature | |
| 327 Exceptions : throw on bad argument | |
| 328 Caller : general | |
| 329 Status : Stable | |
| 330 | |
| 331 =cut | |
| 332 | |
| 333 sub get_all_VariationFeatures_by_Slice { | |
| 334 my $self = shift; | |
| 335 my $slice = shift; | |
| 336 | |
| 337 if(!$self->adaptor()) { | |
| 338 warning('Cannot get variation features without attached adaptor'); | |
| 339 return []; | |
| 340 } | |
| 341 | |
| 342 my $vfa = $self->adaptor->db->get_VariationFeatureAdaptor(); | |
| 343 if(!$vfa) { | |
| 344 warning('Could not get variation feature adaptor from database'); | |
| 345 return []; | |
| 346 } | |
| 347 return $vfa->fetch_all_by_Slice_VariationSet($slice,$self); | |
| 348 } | |
| 349 | |
| 350 =head2 name | |
| 351 | |
| 352 Arg [1] : string $name | |
| 353 Example : print $vs->name(); | |
| 354 Description: Getter/Setter for the name of this VariationSet | |
| 355 Returntype : string | |
| 356 Exceptions : none | |
| 357 Caller : general | |
| 358 Status : At Risk | |
| 359 | |
| 360 =cut | |
| 361 | |
| 362 sub name { | |
| 363 my $self = shift; | |
| 364 my $name = shift; | |
| 365 | |
| 366 $self->{'name'} = $name if (defined($name)); | |
| 367 | |
| 368 return $self->{'name'}; | |
| 369 } | |
| 370 | |
| 371 =head2 short_name | |
| 372 | |
| 373 Arg [1] : string $short_name | |
| 374 Example : print $vs->short_name(); | |
| 375 Description: Getter/Setter for the short name of this VariationSet | |
| 376 Returntype : string | |
| 377 Exceptions : none | |
| 378 Caller : general | |
| 379 | |
| 380 =cut | |
| 381 | |
| 382 sub short_name { | |
| 383 my $self = shift; | |
| 384 my $short_name = shift; | |
| 385 | |
| 386 $self->{'short_name'} = $short_name if (defined($short_name)); | |
| 387 | |
| 388 return $self->{'short_name'}; | |
| 389 } | |
| 390 | |
| 391 # API-internal subroutine to get the bitvalue of this set's id and all of its subsets (unless specifically indicated not to) | |
| 392 sub _get_bitvalue { | |
| 393 my $self = shift; | |
| 394 my @args = @_; | |
| 395 | |
| 396 # If the subsets should be exluded, call the subroutine in the adaptor and return the result. No caching. | |
| 397 if (@args) { | |
| 398 return $self->adaptor->_get_bitvalue($self,@args); | |
| 399 } | |
| 400 | |
| 401 # Check if we have cached the bitvalue (including subsets), otherwise get it and cache it | |
| 402 unless (exists($self->{'_bitvalue'})) { | |
| 403 $self->{'_bitvalue'} = $self->adaptor->_get_bitvalue($self); | |
| 404 } | |
| 405 | |
| 406 # Return the cached value | |
| 407 return $self->{'_bitvalue'}; | |
| 408 } | |
| 409 | |
| 410 1; |
