Mercurial > repos > mahtabm > ensembl
comparison variant_effect_predictor/Bio/EnsEMBL/Variation/Variation.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::Variation | |
| 22 # | |
| 23 # Copyright (c) 2004 Ensembl | |
| 24 # | |
| 25 | |
| 26 | |
| 27 =head1 NAME | |
| 28 | |
| 29 Bio::EnsEMBL::Variation::Variation - Ensembl representation of a nucleotide variation. | |
| 30 | |
| 31 =head1 SYNOPSIS | |
| 32 | |
| 33 $v = Bio::EnsEMBL::Variation::Variation->new(-name => 'rs123', | |
| 34 -source => 'dbSNP'); | |
| 35 | |
| 36 # add additional synonyms for the same SNP | |
| 37 $v->add_synonym('dbSNP', 'ss3242'); | |
| 38 $v->add_synonym('TSC', '53253'); | |
| 39 | |
| 40 # add some validation states for this SNP | |
| 41 $v->add_validation_status('freq'); | |
| 42 $v->add_validation_status('cluster'); | |
| 43 | |
| 44 # add alleles associated with this SNP | |
| 45 $a1 = Bio::EnsEMBL::Allele->new(...); | |
| 46 $a2 = Bio::EnsEMBL::Allele->new(...); | |
| 47 $v->add_Allele($a1); | |
| 48 $v->add_Allele($a2); | |
| 49 | |
| 50 # set the flanking sequences | |
| 51 $v->five_prime_flanking_seq($seq); | |
| 52 $v->three_prime_flanking_seq($seq); | |
| 53 | |
| 54 | |
| 55 ... | |
| 56 | |
| 57 # print out the default name and source of the variation and the version | |
| 58 print $v->source(), ':',$v->name(), ".",$v->version,"\n"; | |
| 59 | |
| 60 # print out every synonym associated with this variation | |
| 61 @synonyms = @{$v->get_all_synonyms()}; | |
| 62 print "@synonyms\n"; | |
| 63 | |
| 64 # print out synonyms and their database associations | |
| 65 my $sources = $v->get_all_synonym_sources(); | |
| 66 foreach my $src (@$sources) { | |
| 67 @synonyms = $v->get_all_synonyms($src); | |
| 68 print "$src: @synonyms\n"; | |
| 69 } | |
| 70 | |
| 71 | |
| 72 # print out validation states | |
| 73 my @vstates = @{$v->get_all_validation_states()}; | |
| 74 print "@validation_states\n"; | |
| 75 | |
| 76 # print out flanking sequences | |
| 77 print "5' flanking: ", $v->five_prime_flanking_seq(), "\n"; | |
| 78 print "3' flanking: ", $v->three_prime_flanking_seq(), "\n"; | |
| 79 | |
| 80 | |
| 81 =head1 DESCRIPTION | |
| 82 | |
| 83 This is a class representing a nucleotide variation from the | |
| 84 ensembl-variation database. A variation may be a SNP a multi-base substitution | |
| 85 or an insertion/deletion. The objects Alleles associated with a Variation | |
| 86 object describe the nucleotide change that Variation represents. | |
| 87 | |
| 88 A Variation object has an associated identifier and 0 or more additional | |
| 89 synonyms. The position of a Variation object on the Genome is represented | |
| 90 by the B<Bio::EnsEMBL::Variation::VariationFeature> class. | |
| 91 | |
| 92 =head1 METHODS | |
| 93 | |
| 94 =cut | |
| 95 | |
| 96 | |
| 97 use strict; | |
| 98 use warnings; | |
| 99 | |
| 100 package Bio::EnsEMBL::Variation::Variation; | |
| 101 | |
| 102 use Bio::EnsEMBL::Storable; | |
| 103 use Bio::EnsEMBL::Utils::Argument qw(rearrange); | |
| 104 use Bio::EnsEMBL::Utils::Scalar qw(assert_ref wrap_array); | |
| 105 use Bio::EnsEMBL::Variation::Utils::Sequence qw(ambiguity_code SO_variation_class); | |
| 106 use Bio::EnsEMBL::Utils::Exception qw(throw deprecate warning); | |
| 107 use Bio::EnsEMBL::Variation::Utils::Sequence; | |
| 108 use Bio::EnsEMBL::Variation::Utils::Constants qw(%VARIATION_CLASSES); | |
| 109 use Bio::EnsEMBL::Variation::Failable; | |
| 110 use vars qw(@ISA); | |
| 111 use Scalar::Util qw(weaken); | |
| 112 | |
| 113 @ISA = qw(Bio::EnsEMBL::Storable Bio::EnsEMBL::Variation::Failable); | |
| 114 | |
| 115 =head2 new | |
| 116 | |
| 117 Arg [-dbID] : | |
| 118 int - unique internal identifier for snp | |
| 119 | |
| 120 Arg [-ADAPTOR] : | |
| 121 Bio::EnsEMBL::Variation::DBSQL::VariationAdaptor | |
| 122 Adaptor which provides database connectivity for this Variation object | |
| 123 | |
| 124 Arg [-NAME] : | |
| 125 string - the name of this SNP | |
| 126 | |
| 127 Arg [-SOURCE] : | |
| 128 string - the source of this SNP | |
| 129 | |
| 130 Arg [-SOURCE_DESCRIPTION] : | |
| 131 string - description of the SNP source | |
| 132 | |
| 133 Arg [-SOURCE_TYPE] : | |
| 134 string - the source type of this variant | |
| 135 | |
| 136 Arg [-SYNONYMS] : | |
| 137 reference to hash with list reference values - keys are source | |
| 138 names and values are lists of identifiers from that db. | |
| 139 e.g.: {'dbSNP' => ['ss1231', '1231'], 'TSC' => ['1452']} | |
| 140 | |
| 141 Arg [-ANCESTRAL_ALLELES] : | |
| 142 string - the ancestral allele of this SNP | |
| 143 | |
| 144 Arg [-ALLELES] : | |
| 145 reference to list of Bio::EnsEMBL::Variation::Allele objects | |
| 146 | |
| 147 Arg [-VALIDATION_STATES] : | |
| 148 reference to list of strings | |
| 149 | |
| 150 Arg [-MOLTYPE] : | |
| 151 string - the moltype of this SNP | |
| 152 | |
| 153 Arg [-FIVE_PRIME_FLANKING_SEQ] : | |
| 154 string - the five prime flanking nucleotide sequence | |
| 155 | |
| 156 Arg [-THREE_PRIME_FLANKING_SEQ] : | |
| 157 string - the three prime flanking nucleotide sequence | |
| 158 | |
| 159 Example : $v = Bio::EnsEMBL::Variation::Variation->new | |
| 160 (-name => 'rs123', | |
| 161 -source => 'dbSNP'); | |
| 162 | |
| 163 Description: Constructor. Instantiates a new Variation object. | |
| 164 Returntype : Bio::EnsEMBL::Variation::Variation | |
| 165 Exceptions : none | |
| 166 Caller : general | |
| 167 Status : At Risk | |
| 168 | |
| 169 =cut | |
| 170 | |
| 171 | |
| 172 sub new { | |
| 173 my $caller = shift; | |
| 174 my $class = ref($caller) || $caller; | |
| 175 | |
| 176 my ($dbID, $adaptor, $name, $class_so_term, $src, $src_desc, $src_url, $src_type, $is_somatic, $flipped, $syns, $ancestral_allele, | |
| 177 $alleles, $valid_states, $moltype, $five_seq, $three_seq, $flank_flag, $minor_allele, $minor_allele_frequency, $minor_allele_count, | |
| 178 $clinical_significance) = | |
| 179 rearrange([qw(dbID ADAPTOR NAME CLASS_SO_TERM SOURCE SOURCE_DESCRIPTION SOURCE_URL SOURCE_TYPE IS_SOMATIC | |
| 180 FLIPPED SYNONYMS ANCESTRAL_ALLELE ALLELES VALIDATION_STATES MOLTYPE FIVE_PRIME_FLANKING_SEQ | |
| 181 THREE_PRIME_FLANKING_SEQ FLANK_FLAG MINOR_ALLELE MINOR_ALLELE_FREQUENCY MINOR_ALLELE_COUNT | |
| 182 CLINICAL_SIGNIFICANCE)],@_); | |
| 183 | |
| 184 # convert the validation state strings into a bit field | |
| 185 # this preserves the same order and representation as in the database | |
| 186 # and filters out invalid states | |
| 187 my $vcode = Bio::EnsEMBL::Variation::Utils::Sequence::get_validation_code($valid_states); | |
| 188 | |
| 189 my $self = bless { | |
| 190 'dbID' => $dbID, | |
| 191 'adaptor' => $adaptor, | |
| 192 'name' => $name, | |
| 193 'class_SO_term' => $class_so_term, | |
| 194 'source' => $src, | |
| 195 'source_description' => $src_desc, | |
| 196 'source_url' => $src_url, | |
| 197 'source_type'=> $src_type, | |
| 198 'is_somatic' => $is_somatic, | |
| 199 'flipped' => $flipped, | |
| 200 'synonyms' => $syns || {}, | |
| 201 'ancestral_allele' => $ancestral_allele, | |
| 202 'validation_code' => $vcode, | |
| 203 'moltype' => $moltype, | |
| 204 'five_prime_flanking_seq' => $five_seq, | |
| 205 'three_prime_flanking_seq' => $three_seq, | |
| 206 'flank_flag' => $flank_flag, | |
| 207 'minor_allele' => $minor_allele, | |
| 208 'minor_allele_frequency' => $minor_allele_frequency, | |
| 209 'minor_allele_count' => $minor_allele_count, | |
| 210 'clinical_significance' => $clinical_significance, | |
| 211 }, $class; | |
| 212 | |
| 213 $self->add_Allele($alleles) if defined($alleles); | |
| 214 | |
| 215 return $self; | |
| 216 } | |
| 217 | |
| 218 sub new_fast { | |
| 219 my $class = shift; | |
| 220 my $hashref = shift; | |
| 221 return bless $hashref, $class; | |
| 222 } | |
| 223 | |
| 224 =head2 has_failed_subsnps | |
| 225 | |
| 226 Description: DEPRECATED: Use has_failed_alleles instead. | |
| 227 Status : DEPRECATED | |
| 228 | |
| 229 =cut | |
| 230 | |
| 231 sub has_failed_subsnps { | |
| 232 my $self = shift; | |
| 233 | |
| 234 deprecate("has_failed_subsnps should no longer be used, use has_failed_alleles instead\n"); | |
| 235 return $self->has_failed_alleles(); | |
| 236 } | |
| 237 | |
| 238 =head2 has_failed_alleles | |
| 239 | |
| 240 Example : print "Variation '" . $var->name() . "' has " . ($var->has_failed_alleles() ? "" : "no ") . " failed alleles\n"; | |
| 241 Description: Returns true if this variation has alleles that are flagged as failed | |
| 242 Returntype : int | |
| 243 Exceptions : none | |
| 244 Caller : general | |
| 245 Status : At risk | |
| 246 | |
| 247 =cut | |
| 248 | |
| 249 sub has_failed_alleles { | |
| 250 my $self = shift; | |
| 251 | |
| 252 map {return 1 if ($_->is_failed())} @{$self->get_all_Alleles()}; | |
| 253 return 0; | |
| 254 } | |
| 255 | |
| 256 | |
| 257 =head2 add_Allele | |
| 258 | |
| 259 Arg [1] : Bio::EnsEMBL::Variation::Allele $allele | |
| 260 Example : $v->add_allele(Bio::EnsEMBL::Variation::Allele->new(...)); | |
| 261 Description: Add an Allele to this variation. | |
| 262 Returntype : none | |
| 263 Exceptions : throw on incorrect argument | |
| 264 Caller : general | |
| 265 Status : At Risk | |
| 266 | |
| 267 =cut | |
| 268 | |
| 269 sub add_Allele { | |
| 270 my $self = shift; | |
| 271 my $allele = shift; | |
| 272 | |
| 273 # This method also accepts a list of alleles so wrap the argument in an array and treat as such | |
| 274 $allele = wrap_array($allele); | |
| 275 map {assert_ref($_,'Bio::EnsEMBL::Variation::Allele')} @{$allele}; | |
| 276 | |
| 277 # Store the allele in the private hash | |
| 278 $self->{alleles} = [] unless (exists($self->{alleles})); | |
| 279 push(@{$self->{alleles}},@{$allele}); | |
| 280 | |
| 281 } | |
| 282 | |
| 283 =head2 name | |
| 284 | |
| 285 Arg [1] : string $newval (optional) | |
| 286 The new value to set the name attribute to | |
| 287 Example : $name = $obj->name() | |
| 288 Description: Getter/Setter for the name attribute | |
| 289 Returntype : string | |
| 290 Exceptions : none | |
| 291 Caller : general | |
| 292 Status : Stable | |
| 293 | |
| 294 =cut | |
| 295 | |
| 296 sub name{ | |
| 297 my $self = shift; | |
| 298 return $self->{'name'} = shift if(@_); | |
| 299 return $self->{'name'}; | |
| 300 } | |
| 301 | |
| 302 | |
| 303 =head2 get_all_Genes | |
| 304 | |
| 305 Args : None | |
| 306 Example : $genes = $v->get_all_genes(); | |
| 307 Description : Retrieves all the genes where this Variation | |
| 308 has a consequence. | |
| 309 ReturnType : reference to list of Bio::EnsEMBL::Gene | |
| 310 Exceptions : None | |
| 311 Caller : general | |
| 312 Status : At Risk | |
| 313 | |
| 314 =cut | |
| 315 | |
| 316 sub get_all_Genes{ | |
| 317 my $self = shift; | |
| 318 my $genes; | |
| 319 if (defined $self->{'adaptor'}){ | |
| 320 my $UPSTREAM = 5000; | |
| 321 my $DOWNSTREAM = 5000; | |
| 322 my $vf_adaptor = $self->adaptor()->db()->get_VariationFeatureAdaptor(); | |
| 323 my $vf_list = $vf_adaptor->fetch_all_by_Variation($self); | |
| 324 #foreach vf, get the slice is on, us ethe USTREAM and DOWNSTREAM limits to get all the genes, and see if SNP is within the gene | |
| 325 my $new_slice; | |
| 326 my $gene_list; | |
| 327 my $gene_hash; | |
| 328 | |
| 329 foreach my $vf (@{$vf_list}){ | |
| 330 #expand the slice UPSTREAM and DOWNSTREAM | |
| 331 $new_slice = $vf->feature_Slice()->expand($UPSTREAM,$DOWNSTREAM); | |
| 332 #get the genes in the new slice | |
| 333 $gene_list = $new_slice->get_all_Genes(); | |
| 334 foreach my $gene (@{$gene_list}){ | |
| 335 if (($vf->start >= $gene->seq_region_start - $UPSTREAM) && ($vf->start <= $gene->seq_region_end + $DOWNSTREAM) && ($vf->end <= $gene->seq_region_end + $DOWNSTREAM)){ | |
| 336 #the vf is affecting the gene, add to the hash if not present already | |
| 337 if (!exists $gene_hash->{$gene->dbID}){ | |
| 338 $gene_hash->{$gene->dbID} = $gene; | |
| 339 } | |
| 340 } | |
| 341 } | |
| 342 } | |
| 343 #and return all the genes | |
| 344 push @{$genes}, values %{$gene_hash}; | |
| 345 } | |
| 346 return $genes; | |
| 347 } | |
| 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 =head2 get_all_VariationFeatures | |
| 353 | |
| 354 Args : None | |
| 355 Example : $vfs = $v->get_all_VariationFeatures(); | |
| 356 Description : Retrieves all VariationFeatures for this Variation | |
| 357 ReturnType : reference to list of Bio::EnsEMBL::Variation::VariationFeature | |
| 358 Exceptions : None | |
| 359 Caller : general | |
| 360 Status : At Risk | |
| 361 | |
| 362 =cut | |
| 363 | |
| 364 sub get_all_VariationFeatures{ | |
| 365 my $self = shift; | |
| 366 | |
| 367 if(defined $self->adaptor) { | |
| 368 | |
| 369 # get variation feature adaptor | |
| 370 my $vf_adaptor = $self->adaptor()->db()->get_VariationFeatureAdaptor(); | |
| 371 | |
| 372 return $vf_adaptor->fetch_all_by_Variation($self); | |
| 373 } | |
| 374 | |
| 375 else { | |
| 376 warn("No variation database attached"); | |
| 377 return []; | |
| 378 } | |
| 379 } | |
| 380 | |
| 381 =head2 get_VariationFeature_by_dbID | |
| 382 | |
| 383 Args : None | |
| 384 Example : $vf = $v->get_VariationFeature_by_dbID(); | |
| 385 Description : Retrieves a VariationFeature for this Variation by it's internal | |
| 386 database identifier | |
| 387 ReturnType : Bio::EnsEMBL::Variation::VariationFeature | |
| 388 Exceptions : None | |
| 389 Caller : general | |
| 390 Status : At Risk | |
| 391 | |
| 392 =cut | |
| 393 | |
| 394 sub get_VariationFeature_by_dbID{ | |
| 395 my $self = shift; | |
| 396 my $dbID = shift; | |
| 397 | |
| 398 throw("No dbID defined") unless defined $dbID; | |
| 399 | |
| 400 if(defined $self->adaptor) { | |
| 401 | |
| 402 # get variation feature adaptor | |
| 403 my $vf_adaptor = $self->adaptor()->db()->get_VariationFeatureAdaptor(); | |
| 404 | |
| 405 my $vf = $vf_adaptor->fetch_by_dbID($dbID); | |
| 406 | |
| 407 # check defined | |
| 408 if(defined($vf)) { | |
| 409 | |
| 410 # check it is the same variation ID | |
| 411 if($vf->{_variation_id} == $self->dbID) { | |
| 412 return $vf; | |
| 413 } | |
| 414 | |
| 415 else { | |
| 416 warn("Variation dbID for Variation Feature does not match this Variation's dbID"); | |
| 417 return undef; | |
| 418 } | |
| 419 } | |
| 420 | |
| 421 else { | |
| 422 return undef; | |
| 423 } | |
| 424 } | |
| 425 | |
| 426 else { | |
| 427 warn("No variation database attached"); | |
| 428 return undef; | |
| 429 } | |
| 430 } | |
| 431 | |
| 432 | |
| 433 | |
| 434 =head2 get_all_synonyms | |
| 435 | |
| 436 Arg [1] : (optional) string $source - the source of the synonyms to | |
| 437 return. | |
| 438 Example : @dbsnp_syns = @{$v->get_all_synonyms('dbSNP')}; | |
| 439 @all_syns = @{$v->get_all_synonyms()}; | |
| 440 Description: Retrieves synonyms for this Variation. If a source argument | |
| 441 is provided all synonyms from that source are returned, | |
| 442 otherwise all synonyms are returned. | |
| 443 Returntype : reference to list of strings | |
| 444 Exceptions : none | |
| 445 Caller : general | |
| 446 Status : At Risk | |
| 447 | |
| 448 =cut | |
| 449 | |
| 450 sub get_all_synonyms { | |
| 451 my $self = shift; | |
| 452 my $source = shift; | |
| 453 | |
| 454 if ($source) { | |
| 455 $source = [$source]; | |
| 456 } | |
| 457 else { | |
| 458 $source = $self->get_all_synonym_sources(); | |
| 459 } | |
| 460 | |
| 461 my @synonyms; | |
| 462 map {push(@synonyms,keys(%{$self->{synonyms}{$_}}))} @{$source}; | |
| 463 | |
| 464 return \@synonyms; | |
| 465 } | |
| 466 | |
| 467 | |
| 468 | |
| 469 =head2 get_all_synonym_sources | |
| 470 | |
| 471 Arg [1] : none | |
| 472 Example : my @sources = @{$v->get_all_synonym_sources()}; | |
| 473 Description: Retrieves a list of all the sources for synonyms of this | |
| 474 Variation. | |
| 475 Returntype : reference to a list of strings | |
| 476 Exceptions : none | |
| 477 Caller : general | |
| 478 Status : At Risk | |
| 479 | |
| 480 =cut | |
| 481 | |
| 482 sub get_all_synonym_sources { | |
| 483 my $self = shift; | |
| 484 my @sources = keys %{$self->{'synonyms'}}; | |
| 485 return \@sources; | |
| 486 } | |
| 487 | |
| 488 | |
| 489 | |
| 490 =head2 add_synonym | |
| 491 | |
| 492 Arg [1] : string $source | |
| 493 Arg [2] : string $syn | |
| 494 Example : $v->add_synonym('dbSNP', 'ss55331'); | |
| 495 Description: Adds a synonym to this variation. | |
| 496 Returntype : none | |
| 497 Exceptions : throw if $source argument is not provided | |
| 498 throw if $syn argument is not provided | |
| 499 Caller : general | |
| 500 Status : At Risk | |
| 501 | |
| 502 =cut | |
| 503 | |
| 504 sub add_synonym { | |
| 505 my $self = shift; | |
| 506 my $source = shift; | |
| 507 my $syn = shift; | |
| 508 | |
| 509 throw("source argument is required") if(!$source); | |
| 510 throw("syn argument is required") if(!$syn); | |
| 511 | |
| 512 $self->{'synonyms'}{$source}{$syn}++; | |
| 513 | |
| 514 return; | |
| 515 } | |
| 516 | |
| 517 | |
| 518 | |
| 519 =head2 get_all_validation_states | |
| 520 | |
| 521 Arg [1] : none | |
| 522 Example : my @vstates = @{$v->get_all_validation_states()}; | |
| 523 Description: Retrieves all validation states for this variation. Current | |
| 524 possible validation statuses are 'cluster','freq','submitter', | |
| 525 'doublehit', 'hapmap' | |
| 526 Returntype : reference to list of strings | |
| 527 Exceptions : none | |
| 528 Caller : general | |
| 529 Status : At Risk | |
| 530 | |
| 531 =cut | |
| 532 | |
| 533 sub get_all_validation_states { | |
| 534 my $self = shift; | |
| 535 | |
| 536 return Bio::EnsEMBL::Variation::Utils::Sequence::get_all_validation_states($self->{'validation_code'}); | |
| 537 } | |
| 538 | |
| 539 | |
| 540 | |
| 541 | |
| 542 =head2 add_validation_state | |
| 543 | |
| 544 Arg [1] : string $state | |
| 545 Example : $v->add_validation_state('cluster'); | |
| 546 Description: Adds a validation state to this variation. | |
| 547 Returntype : none | |
| 548 Exceptions : warning if validation state is not a recognised type | |
| 549 Caller : general | |
| 550 Status : At Risk | |
| 551 | |
| 552 =cut | |
| 553 | |
| 554 sub add_validation_state { | |
| 555 Bio::EnsEMBL::Variation::Utils::Sequence::add_validation_state(@_); | |
| 556 } | |
| 557 | |
| 558 | |
| 559 | |
| 560 =head2 source | |
| 561 | |
| 562 Arg [1] : string $source (optional) | |
| 563 The new value to set the source attribute to | |
| 564 Example : $source = $v->source() | |
| 565 Description: Getter/Setter for the source attribute | |
| 566 Returntype : string | |
| 567 Exceptions : none | |
| 568 Caller : general | |
| 569 Status : Stable | |
| 570 | |
| 571 =cut | |
| 572 | |
| 573 sub source{ | |
| 574 my $self = shift; | |
| 575 return $self->{'source'} = shift if(@_); | |
| 576 return $self->{'source'}; | |
| 577 } | |
| 578 | |
| 579 | |
| 580 =head2 source_type | |
| 581 | |
| 582 Arg [1] : string $source_type (optional) | |
| 583 The new value to set the source type attribute to | |
| 584 Example : $source_type = $v->source_type() | |
| 585 Description: Getter/Setter for the source type attribute | |
| 586 Returntype : string | |
| 587 Exceptions : none | |
| 588 Caller : general | |
| 589 Status : At risk | |
| 590 | |
| 591 =cut | |
| 592 | |
| 593 sub source_type{ | |
| 594 my $self = shift; | |
| 595 return $self->{'source_type'} = shift if(@_); | |
| 596 return $self->{'source_type'}; | |
| 597 } | |
| 598 | |
| 599 | |
| 600 =head2 source_description | |
| 601 | |
| 602 Arg [1] : string $source_description (optional) | |
| 603 The new value to set the source description attribute to | |
| 604 Example : $source_description = $v->source_description() | |
| 605 Description: Getter/Setter for the source description attribute | |
| 606 Returntype : string | |
| 607 Exceptions : none | |
| 608 Caller : general | |
| 609 Status : Stable | |
| 610 | |
| 611 =cut | |
| 612 | |
| 613 sub source_description{ | |
| 614 my $self = shift; | |
| 615 return $self->{'source_description'} = shift if(@_); | |
| 616 return $self->{'source_description'}; | |
| 617 } | |
| 618 | |
| 619 | |
| 620 | |
| 621 =head2 source_url | |
| 622 | |
| 623 Arg [1] : string $source_url (optional) | |
| 624 The new value to set the source URL attribute to | |
| 625 Example : $source_url = $v->source_url() | |
| 626 Description: Getter/Setter for the source URL attribute | |
| 627 Returntype : string | |
| 628 Exceptions : none | |
| 629 Caller : general | |
| 630 Status : Stable | |
| 631 | |
| 632 =cut | |
| 633 | |
| 634 sub source_url{ | |
| 635 my $self = shift; | |
| 636 return $self->{'source_url'} = shift if(@_); | |
| 637 return $self->{'source_url'}; | |
| 638 } | |
| 639 | |
| 640 =head2 is_somatic | |
| 641 | |
| 642 Arg [1] : boolean $is_somatic (optional) | |
| 643 The new value to set the is_somatic flag to | |
| 644 Example : $is_somatic = $v->is_somatic | |
| 645 Description: Getter/Setter for the is_somatic flag, which identifies this variation as either somatic or germline | |
| 646 Returntype : boolean | |
| 647 Exceptions : none | |
| 648 Caller : general | |
| 649 Status : Stable | |
| 650 | |
| 651 =cut | |
| 652 | |
| 653 sub is_somatic { | |
| 654 my ($self, $is_somatic) = @_; | |
| 655 $self->{is_somatic} = $is_somatic if defined $is_somatic; | |
| 656 return $self->{is_somatic}; | |
| 657 } | |
| 658 | |
| 659 =head2 flipped | |
| 660 | |
| 661 Arg [1] : boolean $flipped (optional) | |
| 662 The new value to set the flipped flag to | |
| 663 Example : $flipped = $v->flipped | |
| 664 Description: Getter/Setter for the flipped flag, which identifies if this | |
| 665 variation's strand has been flipped during the import process | |
| 666 Returntype : boolean | |
| 667 Exceptions : none | |
| 668 Caller : general | |
| 669 Status : Stable | |
| 670 | |
| 671 =cut | |
| 672 | |
| 673 sub flipped { | |
| 674 my ($self, $flipped) = @_; | |
| 675 $self->{flipped} = $flipped if defined $flipped; | |
| 676 return $self->{flipped}; | |
| 677 } | |
| 678 | |
| 679 =head2 get_all_Alleles | |
| 680 | |
| 681 Arg [1] : none | |
| 682 Example : @alleles = @{$v->get_all_Alleles()}; | |
| 683 Description: Retrieves all Alleles associated with this variation | |
| 684 Returntype : reference to list of Bio::EnsEMBL::Variation::Allele objects | |
| 685 Exceptions : none | |
| 686 Caller : general | |
| 687 Status : Stable | |
| 688 | |
| 689 =cut | |
| 690 | |
| 691 sub get_all_Alleles { | |
| 692 my $self = shift; | |
| 693 | |
| 694 # If the private hash key 'alleles' does not exist, no attempt has been made to load them, so do that | |
| 695 unless (exists($self->{alleles})) { | |
| 696 | |
| 697 # Get an AlleleAdaptor | |
| 698 assert_ref($self->adaptor(),'Bio::EnsEMBL::Variation::DBSQL::BaseAdaptor'); | |
| 699 my $allele_adaptor = $self->adaptor->db->get_AlleleAdaptor(); | |
| 700 | |
| 701 $self->add_Allele($allele_adaptor->fetch_all_by_Variation($self)); | |
| 702 } | |
| 703 | |
| 704 return $self->{alleles}; | |
| 705 } | |
| 706 | |
| 707 | |
| 708 | |
| 709 =head2 ancestral_allele | |
| 710 | |
| 711 Arg [1] : string $ancestral_allele (optional) | |
| 712 Example : $ancestral_allele = v->ancestral_allele(); | |
| 713 Description: Getter/Setter ancestral allele associated with this variation | |
| 714 Returntype : string | |
| 715 Exceptions : none | |
| 716 Caller : general | |
| 717 Status : At Risk | |
| 718 | |
| 719 =cut | |
| 720 | |
| 721 sub ancestral_allele { | |
| 722 my $self = shift; | |
| 723 return $self->{'ancestral_allele'} = shift if(@_); | |
| 724 return $self->{'ancestral_allele'}; | |
| 725 } | |
| 726 | |
| 727 =head2 moltype | |
| 728 | |
| 729 Arg [1] : string $moltype (optional) | |
| 730 The new value to set the moltype attribute to | |
| 731 Example : $moltype = v->moltype(); | |
| 732 Description: Getter/Setter moltype associated with this variation | |
| 733 Returntype : string | |
| 734 Exceptions : none | |
| 735 Caller : general | |
| 736 Status : At Risk | |
| 737 | |
| 738 =cut | |
| 739 | |
| 740 sub moltype { | |
| 741 my $self = shift; | |
| 742 return $self->{'moltype'} = shift if(@_); | |
| 743 return $self->{'moltype'}; | |
| 744 } | |
| 745 | |
| 746 | |
| 747 =head2 five_prime_flanking_seq | |
| 748 | |
| 749 Arg [1] : string $newval (optional) | |
| 750 The new value to set the five_prime_flanking_seq attribute to | |
| 751 Example : $five_prime_flanking_seq = $obj->five_prime_flanking_seq() | |
| 752 Description: Getter/Setter for the five_prime_flanking_seq attribute | |
| 753 Returntype : string | |
| 754 Exceptions : none | |
| 755 Caller : general | |
| 756 Status : Stable | |
| 757 | |
| 758 =cut | |
| 759 | |
| 760 sub five_prime_flanking_seq{ | |
| 761 my $self = shift; | |
| 762 | |
| 763 #setter of the flanking sequence | |
| 764 return $self->{'five_prime_flanking_seq'} = shift if(@_); | |
| 765 #lazy-load the flanking sequence from the database | |
| 766 if (!defined $self->{'five_prime_flanking_seq'} && $self->{'adaptor'}){ | |
| 767 my $variation_adaptor = $self->adaptor()->db()->get_VariationAdaptor(); | |
| 768 ($self->{'three_prime_flanking_seq'},$self->{'five_prime_flanking_seq'}) = @{$variation_adaptor->get_flanking_sequence($self->{'dbID'})}; | |
| 769 } | |
| 770 return $self->{'five_prime_flanking_seq'}; | |
| 771 } | |
| 772 | |
| 773 | |
| 774 | |
| 775 | |
| 776 =head2 three_prime_flanking_seq | |
| 777 | |
| 778 Arg [1] : string $newval (optional) | |
| 779 The new value to set the three_prime_flanking_seq attribute to | |
| 780 Example : $three_prime_flanking_seq = $obj->three_prime_flanking_seq() | |
| 781 Description: Getter/Setter for the three_prime_flanking_seq attribute | |
| 782 Returntype : string | |
| 783 Exceptions : none | |
| 784 Caller : general | |
| 785 Status : Stable | |
| 786 | |
| 787 =cut | |
| 788 | |
| 789 sub three_prime_flanking_seq{ | |
| 790 my $self = shift; | |
| 791 | |
| 792 #setter of the flanking sequence | |
| 793 return $self->{'three_prime_flanking_seq'} = shift if(@_); | |
| 794 #lazy-load the flanking sequence from the database | |
| 795 if (!defined $self->{'three_prime_flanking_seq'} && $self->{'adaptor'}){ | |
| 796 my $variation_adaptor = $self->adaptor()->db()->get_VariationAdaptor(); | |
| 797 ($self->{'three_prime_flanking_seq'},$self->{'five_prime_flanking_seq'}) = @{$variation_adaptor->get_flanking_sequence($self->{'dbID'})}; | |
| 798 } | |
| 799 return $self->{'three_prime_flanking_seq'}; | |
| 800 } | |
| 801 | |
| 802 | |
| 803 =head2 get_all_IndividualGenotypes | |
| 804 | |
| 805 Args : none | |
| 806 Example : $ind_genotypes = $var->get_all_IndividualGenotypes() | |
| 807 Description: Getter for IndividualGenotypes for this Variation, returns empty list if | |
| 808 there are none | |
| 809 Returntype : listref of IndividualGenotypes | |
| 810 Exceptions : none | |
| 811 Caller : general | |
| 812 Status : At Risk | |
| 813 | |
| 814 =cut | |
| 815 | |
| 816 sub get_all_IndividualGenotypes { | |
| 817 my $self = shift; | |
| 818 my $individual = shift; | |
| 819 if (defined ($self->{'adaptor'})){ | |
| 820 my $igtya = $self->{'adaptor'}->db()->get_IndividualGenotypeAdaptor(); | |
| 821 | |
| 822 return $igtya->fetch_all_by_Variation($self, $individual); | |
| 823 } | |
| 824 return []; | |
| 825 } | |
| 826 | |
| 827 =head2 get_all_PopulationGenotypes | |
| 828 | |
| 829 Args : none | |
| 830 Example : $pop_genotypes = $var->get_all_PopulationGenotypes() | |
| 831 Description: Getter for PopulationGenotypes for this Variation, returns empty list if | |
| 832 there are none. | |
| 833 Returntype : listref of PopulationGenotypes | |
| 834 Exceptions : none | |
| 835 Caller : general | |
| 836 Status : At Risk | |
| 837 | |
| 838 =cut | |
| 839 | |
| 840 sub get_all_PopulationGenotypes { | |
| 841 my $self = shift; | |
| 842 | |
| 843 #simulate a lazy-load on demand situation, used by the Glovar team | |
| 844 if (!defined($self->{'populationGenotypes'}) && defined ($self->{'adaptor'})){ | |
| 845 my $pgtya = $self->{'adaptor'}->db()->get_PopulationGenotypeAdaptor(); | |
| 846 | |
| 847 return $pgtya->fetch_all_by_Variation($self); | |
| 848 } | |
| 849 return $self->{'populationGenotypes'}; | |
| 850 | |
| 851 } | |
| 852 | |
| 853 | |
| 854 =head2 add_PopulationGenotype | |
| 855 | |
| 856 Arg [1] : Bio::EnsEMBL::Variation::PopulationGenotype | |
| 857 Example : $v->add_PopulationGenotype($pop_genotype) | |
| 858 Description : Adds another PopulationGenotype to the Variation object | |
| 859 Exceptions : thrown on bad argument | |
| 860 Caller : general | |
| 861 Status : At Risk | |
| 862 | |
| 863 =cut | |
| 864 | |
| 865 sub add_PopulationGenotype{ | |
| 866 my $self = shift; | |
| 867 | |
| 868 if (@_){ | |
| 869 if(!ref($_[0]) || !$_[0]->isa('Bio::EnsEMBL::Variation::PopulationGenotype')) { | |
| 870 throw("Bio::EnsEMBL::Variation::PopulationGenotype argument expected"); | |
| 871 } | |
| 872 #a variation can have multiple PopulationGenotypes | |
| 873 push @{$self->{'populationGenotypes'}},shift; | |
| 874 } | |
| 875 | |
| 876 } | |
| 877 | |
| 878 | |
| 879 =head2 ambig_code | |
| 880 | |
| 881 Args : None | |
| 882 Example : my $ambiguity_code = $v->ambig_code() | |
| 883 Description : Returns the ambigutiy code for the alleles in the Variation | |
| 884 ReturnType : String $ambiguity_code | |
| 885 Exceptions : none | |
| 886 Caller : General | |
| 887 Status : At Risk | |
| 888 | |
| 889 =cut | |
| 890 | |
| 891 sub ambig_code{ | |
| 892 my $self = shift; | |
| 893 | |
| 894 my $code; | |
| 895 | |
| 896 # first try via VF | |
| 897 if(my @vfs = @{$self->get_all_VariationFeatures}) { | |
| 898 if(scalar @vfs) { | |
| 899 $code = $vfs[0]->ambig_code; | |
| 900 } | |
| 901 } | |
| 902 | |
| 903 # otherwise get it via alleles attatched to this object already | |
| 904 if(!defined($code)) { | |
| 905 my $alleles = $self->get_all_Alleles(); #get all Allele objects | |
| 906 my %alleles; #to get all the different alleles in the Variation | |
| 907 map {$alleles{$_->allele}++} @{$alleles}; | |
| 908 my $allele_string = join "|",keys %alleles; | |
| 909 $code = &ambiguity_code($allele_string); | |
| 910 } | |
| 911 | |
| 912 return $code; | |
| 913 } | |
| 914 | |
| 915 =head2 var_class | |
| 916 | |
| 917 Args : None | |
| 918 Example : my $variation_class = $vf->var_class() | |
| 919 Description : returns the class for the variation, according to dbSNP classification | |
| 920 ReturnType : String $variation_class | |
| 921 Exceptions : none | |
| 922 Caller : General | |
| 923 Status : At Risk | |
| 924 | |
| 925 =cut | |
| 926 | |
| 927 sub var_class{ | |
| 928 my $self = shift; | |
| 929 | |
| 930 unless ($self->{class_display_term}) { | |
| 931 | |
| 932 unless ($self->{class_SO_term}) { | |
| 933 # work out the term from the alleles | |
| 934 | |
| 935 my $alleles = $self->get_all_Alleles(); #get all Allele objects | |
| 936 my %alleles; #to get all the different alleles in the Variation | |
| 937 map {$alleles{$_->allele}++} @{$alleles}; | |
| 938 my $allele_string = join '/',keys %alleles; | |
| 939 | |
| 940 $self->{class_SO_term} = SO_variation_class($allele_string); | |
| 941 } | |
| 942 | |
| 943 # convert the SO term to the ensembl display term | |
| 944 | |
| 945 $self->{class_display_term} = $self->is_somatic ? | |
| 946 $VARIATION_CLASSES{$self->{class_SO_term}}->{somatic_display_term} : | |
| 947 $VARIATION_CLASSES{$self->{class_SO_term}}->{display_term}; | |
| 948 } | |
| 949 | |
| 950 return $self->{class_display_term}; | |
| 951 } | |
| 952 | |
| 953 =head2 derived_allele_frequency | |
| 954 | |
| 955 Arg[1] : Bio::EnsEMBL::Variation::Population $population | |
| 956 Example : $daf = $variation->derived_allele_frequency($population); | |
| 957 Description: Gets the derived allele frequency for the population. | |
| 958 The DAF is the frequency of the reference allele that is | |
| 959 different from the allele in Chimp. If none of the alleles | |
| 960 is the same as the ancestral, will return reference allele | |
| 961 frequency | |
| 962 Returntype : float | |
| 963 Exceptions : none | |
| 964 Caller : general | |
| 965 Status : At Risk | |
| 966 | |
| 967 =cut | |
| 968 | |
| 969 sub derived_allele_frequency{ | |
| 970 my $self = shift; | |
| 971 my $population = shift; | |
| 972 my $daf; | |
| 973 | |
| 974 if(!ref($population) || !$population->isa('Bio::EnsEMBL::Variation::Population')) { | |
| 975 throw('Bio::EnsEMBL::Variation::Population argument expected.'); | |
| 976 } | |
| 977 my $ancestral_allele = $self->ancestral_allele(); | |
| 978 if (defined $ancestral_allele){ | |
| 979 #get reference allele | |
| 980 my $vf_adaptor = $self->adaptor->db->get_VariationFeatureAdaptor(); | |
| 981 my $vf = shift @{$vf_adaptor->fetch_all_by_Variation($self)}; | |
| 982 my $ref_freq; | |
| 983 #get allele in population | |
| 984 my $alleles = $self->get_all_Alleles(); | |
| 985 | |
| 986 foreach my $allele (@{$alleles}){ | |
| 987 next unless defined $allele->population; | |
| 988 | |
| 989 if (($allele->allele eq $vf->ref_allele_string) and ($allele->population->name eq $population->name)){ | |
| 990 $ref_freq = $allele->frequency; | |
| 991 } | |
| 992 } | |
| 993 | |
| 994 if(defined $ref_freq) { | |
| 995 if ($ancestral_allele eq $vf->ref_allele_string){ | |
| 996 $daf = 1 - $ref_freq | |
| 997 } | |
| 998 elsif ($ancestral_allele ne $vf->ref_allele_string){ | |
| 999 $daf = $ref_freq; | |
| 1000 } | |
| 1001 } | |
| 1002 } | |
| 1003 | |
| 1004 return $daf; | |
| 1005 } | |
| 1006 | |
| 1007 =head2 derived_allele | |
| 1008 | |
| 1009 Arg[1] : Bio::EnsEMBL::Variation::Population $population | |
| 1010 Example : $da = $variation->derived_allele($population); | |
| 1011 Description: Gets the derived allele for the population. | |
| 1012 Returntype : float | |
| 1013 Exceptions : none | |
| 1014 Caller : general | |
| 1015 Status : At Risk | |
| 1016 | |
| 1017 =cut | |
| 1018 | |
| 1019 sub derived_allele { | |
| 1020 my $self = shift(); | |
| 1021 my $population = shift(); | |
| 1022 | |
| 1023 my $population_dbID = $population->dbID(); | |
| 1024 my $ancestral_allele_str = $self->ancestral_allele(); | |
| 1025 | |
| 1026 if (not defined($ancestral_allele_str)) { | |
| 1027 return; | |
| 1028 } | |
| 1029 | |
| 1030 my $alleles = $self->get_all_Alleles(); | |
| 1031 | |
| 1032 my $derived_allele_str; | |
| 1033 | |
| 1034 foreach my $allele (@{$alleles}) { | |
| 1035 my $allele_population = $allele->population(); | |
| 1036 | |
| 1037 if (defined($allele_population) and | |
| 1038 $allele_population->dbID() == $population_dbID) | |
| 1039 { | |
| 1040 my $allele_str = $allele->allele(); | |
| 1041 | |
| 1042 if ($ancestral_allele_str ne $allele_str) { | |
| 1043 if (defined($derived_allele_str)) { | |
| 1044 return; | |
| 1045 } else { | |
| 1046 $derived_allele_str = $allele_str; | |
| 1047 } | |
| 1048 } | |
| 1049 } | |
| 1050 } | |
| 1051 return $derived_allele_str; | |
| 1052 } | |
| 1053 | |
| 1054 =head2 minor_allele | |
| 1055 | |
| 1056 Arg [1] : string $minor_allele (optional) | |
| 1057 The new minor allele string | |
| 1058 Example : $ma = $obj->minor_allele() | |
| 1059 Description: Get/set the minor allele of this variation, as reported by dbSNP | |
| 1060 Returntype : string | |
| 1061 Exceptions : none | |
| 1062 Caller : general | |
| 1063 Status : Stable | |
| 1064 | |
| 1065 =cut | |
| 1066 | |
| 1067 sub minor_allele { | |
| 1068 my ($self, $minor_allele) = @_; | |
| 1069 $self->{minor_allele} = $minor_allele if defined $minor_allele; | |
| 1070 return $self->{minor_allele} | |
| 1071 } | |
| 1072 | |
| 1073 =head2 minor_allele_frequency | |
| 1074 | |
| 1075 Arg [1] : float $minor_allele_frequency (optional) | |
| 1076 The new minor allele frequency | |
| 1077 Example : $maf = $obj->minor_allele_frequency() | |
| 1078 Description: Get/set the frequency of the minor allele of this variation, as reported by dbSNP | |
| 1079 Returntype : float | |
| 1080 Exceptions : none | |
| 1081 Caller : general | |
| 1082 Status : Stable | |
| 1083 | |
| 1084 =cut | |
| 1085 | |
| 1086 sub minor_allele_frequency { | |
| 1087 my ($self, $minor_allele_frequency) = @_; | |
| 1088 $self->{minor_allele_frequency} = $minor_allele_frequency if defined $minor_allele_frequency; | |
| 1089 return $self->{minor_allele_frequency} | |
| 1090 } | |
| 1091 | |
| 1092 =head2 minor_allele_count | |
| 1093 | |
| 1094 Arg [1] : int $minor_allele_count (optional) | |
| 1095 The new minor allele count | |
| 1096 Example : $maf_count = $obj->minor_allele_count() | |
| 1097 Description: Get/set the sample count of the minor allele of this variation, as reported by dbSNP | |
| 1098 Returntype : int | |
| 1099 Exceptions : none | |
| 1100 Caller : general | |
| 1101 Status : Stable | |
| 1102 | |
| 1103 =cut | |
| 1104 | |
| 1105 sub minor_allele_count { | |
| 1106 my ($self, $minor_allele_count) = @_; | |
| 1107 $self->{minor_allele_count} = $minor_allele_count if defined $minor_allele_count; | |
| 1108 return $self->{minor_allele_count} | |
| 1109 } | |
| 1110 | |
| 1111 =head2 clinical_significance | |
| 1112 | |
| 1113 Arg [1] : string $clinical_significance (optional) | |
| 1114 The new clinical significance string | |
| 1115 Example : $ma = $obj->clinical_significance() | |
| 1116 Description: Get/set the clinical significance of this variation, as reported by dbSNP. | |
| 1117 When available, this will be one of the following strings: | |
| 1118 unknown | |
| 1119 untested | |
| 1120 non-pathogenic | |
| 1121 probable-non-pathogenic | |
| 1122 probable-pathogenic | |
| 1123 pathogenic | |
| 1124 drug-response | |
| 1125 histocompatibility | |
| 1126 other | |
| 1127 Returntype : string | |
| 1128 Exceptions : none | |
| 1129 Caller : general | |
| 1130 Status : Stable | |
| 1131 | |
| 1132 =cut | |
| 1133 | |
| 1134 sub clinical_significance { | |
| 1135 my ($self, $clinical_significance) = @_; | |
| 1136 $self->{clinical_significance} = $clinical_significance if defined $clinical_significance; | |
| 1137 return $self->{clinical_significance} | |
| 1138 } | |
| 1139 | |
| 1140 =head2 get_all_VariationAnnotations | |
| 1141 | |
| 1142 Args : none | |
| 1143 Example : my $annotations = $var->get_all_VariationAnnotations() | |
| 1144 Description: Getter for VariationAnnotations for this Variation, returns empty list if | |
| 1145 there are none. | |
| 1146 Returntype : listref of VariationAnnotations | |
| 1147 Exceptions : none | |
| 1148 Caller : general | |
| 1149 | |
| 1150 =cut | |
| 1151 | |
| 1152 sub get_all_VariationAnnotations { | |
| 1153 my $self = shift; | |
| 1154 | |
| 1155 #ÊAssert the adaptor reference | |
| 1156 assert_ref($self->adaptor(),'Bio::EnsEMBL::Variation::DBSQL::BaseAdaptor'); | |
| 1157 | |
| 1158 # Get the annotations from the database | |
| 1159 return $self->adaptor->db->get_VariationAnnotationAdaptor()->fetch_all_by_Variation($self); | |
| 1160 | |
| 1161 } | |
| 1162 | |
| 1163 1; |
