Mercurial > repos > mahtabm > ensembl
comparison variant_effect_predictor/Bio/EnsEMBL/Variation/BaseVariationFeatureOverlapAllele.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 =head1 NAME | |
| 22 | |
| 23 Bio::EnsEMBL::Variation::BaseVariationFeatureOverlapAllele | |
| 24 | |
| 25 =head1 SYNOPSIS | |
| 26 | |
| 27 use Bio::EnsEMBL::Variation::BaseVariationFeatureOverlapAllele; | |
| 28 | |
| 29 my $bvfoa = Bio::EnsEMBL::Variation::BaseVariationFeatureOverlapAllele->new( | |
| 30 -base_variation_feature_overlap => $bvfo, | |
| 31 -is_reference => 0, | |
| 32 ); | |
| 33 | |
| 34 print "consequence SO terms: ", (join ",", map { $_->SO_term } @{ $bvfoa->get_all_OverlapConsequences }), "\n"; | |
| 35 | |
| 36 =head1 DESCRIPTION | |
| 37 | |
| 38 A BaseVariationFeatureOverlapAllele object represents a single allele of a | |
| 39 BaseVariationFeatureOverlap. It is the super-class of variation feature specific | |
| 40 classes such as VariationFeatureOverlapAllele and StructuralVariationOverlapAllele | |
| 41 and contains methods not specific to any particular variation feature type. | |
| 42 Ordinarily you will not create these objects yourself, but instead you would | |
| 43 create one of the more specific subclasses. | |
| 44 | |
| 45 =cut | |
| 46 | |
| 47 package Bio::EnsEMBL::Variation::BaseVariationFeatureOverlapAllele; | |
| 48 | |
| 49 use strict; | |
| 50 use warnings; | |
| 51 | |
| 52 use Bio::EnsEMBL::Utils::Argument qw(rearrange); | |
| 53 use Bio::EnsEMBL::Utils::Scalar qw(assert_ref); | |
| 54 use Bio::EnsEMBL::Utils::Exception qw(throw); | |
| 55 use Bio::EnsEMBL::Variation::Utils::Constants qw(%OVERLAP_CONSEQUENCES); | |
| 56 use Scalar::Util qw(weaken); | |
| 57 | |
| 58 =head2 new | |
| 59 | |
| 60 Arg [-BASE_VARIATION_FEATURE_OVERLAP] : | |
| 61 The Bio::EnsEMBL::BaseVariationFeatureOverlap with which this allele is | |
| 62 associated | |
| 63 | |
| 64 Arg [-IS_REFERENCE] : | |
| 65 A flag indicating if this allele is the reference allele or not | |
| 66 | |
| 67 Example : | |
| 68 my $bvfoa = Bio::EnsEMBL::Variation::BaseVariationFeatureOverlapAllele->new( | |
| 69 -base_variation_feature_overlap => $bvfo, | |
| 70 -is_reference => 0 | |
| 71 ); | |
| 72 | |
| 73 Description: Constructs a new BaseVariationFeatureOverlapAllele instance given a | |
| 74 BaseVariationFeatureOverlap and a flag indicating if this is the | |
| 75 reference allele | |
| 76 Returntype : A new Bio::EnsEMBL::Variation::BaseVariationFeatureOverlapAllele instance | |
| 77 Exceptions : throws unlessBASE_VARIATION_FEATURE_OVERLAP is supplied | |
| 78 Status : At Risk | |
| 79 | |
| 80 =cut | |
| 81 | |
| 82 sub new { | |
| 83 my $class = shift; | |
| 84 | |
| 85 my ( | |
| 86 $base_variation_feature_overlap, | |
| 87 $is_reference | |
| 88 ) = rearrange([qw( | |
| 89 BASE_VARIATION_FEATURE_OVERLAP | |
| 90 IS_REFERENCE | |
| 91 )], @_); | |
| 92 | |
| 93 assert_ref($base_variation_feature_overlap, 'Bio::EnsEMBL::Variation::BaseVariationFeatureOverlap'); | |
| 94 | |
| 95 my $self = bless { | |
| 96 base_variation_feature_overlap => $base_variation_feature_overlap, | |
| 97 is_reference => $is_reference, | |
| 98 }, $class; | |
| 99 | |
| 100 # avoid a memory leak, because the bvfo also has a reference to us | |
| 101 weaken $self->{base_variation_feature_overlap}; | |
| 102 | |
| 103 return $self; | |
| 104 } | |
| 105 | |
| 106 sub new_fast { | |
| 107 my ($class, $hashref) = @_; | |
| 108 my $self = bless $hashref, $class; | |
| 109 # avoid a memory leak, because the bvfo also has a reference to us | |
| 110 weaken $self->{base_variation_feature_overlap} if $self->{base_variation_feature_overlap}; | |
| 111 return $self; | |
| 112 } | |
| 113 | |
| 114 =head2 base_variation_feature_overlap | |
| 115 | |
| 116 Description: Get/set the associated BaseVariationFeatureOverlap | |
| 117 Returntype : Bio::EnsEMBL::Variation::BaseVariationFeatureOverlap | |
| 118 Exceptions : throws if the argument is the wrong type | |
| 119 Status : At Risk | |
| 120 | |
| 121 =cut | |
| 122 | |
| 123 sub base_variation_feature_overlap { | |
| 124 my ($self, $bvfo) = @_; | |
| 125 | |
| 126 if ($bvfo) { | |
| 127 assert_ref($bvfo, 'Bio::EnsEMBL::Variation::BaseVariationFeatureOverlap'); | |
| 128 $self->{base_variation_feature_overlap} = $bvfo; | |
| 129 # avoid a memory leak, because the bvfo also has a reference to us | |
| 130 weaken $self->{base_variation_feature_overlap}; | |
| 131 } | |
| 132 | |
| 133 return $self->{base_variation_feature_overlap}; | |
| 134 } | |
| 135 | |
| 136 =head2 base_variation_feature | |
| 137 | |
| 138 Description: Get the associated BaseVariationFeature | |
| 139 Returntype : Bio::EnsEMBL::Variation::BaseVariationFeature | |
| 140 Exceptions : none | |
| 141 Status : At Risk | |
| 142 | |
| 143 =cut | |
| 144 | |
| 145 sub base_variation_feature { | |
| 146 my $self = shift; | |
| 147 return $self->base_variation_feature_overlap->base_variation_feature(@_); | |
| 148 } | |
| 149 | |
| 150 =head2 feature | |
| 151 | |
| 152 Description: Get the associated Feature | |
| 153 Returntype : Bio::EnsEMBL::Feature (or relevant subclass) | |
| 154 Exceptions : none | |
| 155 Status : At Risk | |
| 156 | |
| 157 =cut | |
| 158 | |
| 159 sub feature { | |
| 160 my $self = shift; | |
| 161 return $self->base_variation_feature_overlap->feature(@_); | |
| 162 } | |
| 163 | |
| 164 =head2 is_reference | |
| 165 | |
| 166 Args [1] : A boolean value | |
| 167 Description: Get/set a flag indicating if this allele is the reference allele | |
| 168 Returntype : bool | |
| 169 Exceptions : none | |
| 170 Status : At Risk | |
| 171 | |
| 172 =cut | |
| 173 | |
| 174 sub is_reference { | |
| 175 my ($self, $is_reference) = @_; | |
| 176 $self->{is_reference} = $is_reference if defined $is_reference; | |
| 177 return $self->{is_reference}; | |
| 178 } | |
| 179 | |
| 180 =head2 get_all_OverlapConsequences | |
| 181 | |
| 182 Description: Get a list of all the OverlapConsequences of this allele, calculating them | |
| 183 on the fly if necessary | |
| 184 Returntype : listref of Bio::EnsEMBL::Variation::OverlapConsequence objects | |
| 185 Exceptions : none | |
| 186 Status : At Risk | |
| 187 | |
| 188 =cut | |
| 189 | |
| 190 sub get_all_OverlapConsequences { | |
| 191 my $self = shift; | |
| 192 | |
| 193 unless ($self->{overlap_consequences}) { | |
| 194 | |
| 195 # calculate consequences on the fly | |
| 196 | |
| 197 my $cons = []; | |
| 198 | |
| 199 my $assigned_tier; | |
| 200 | |
| 201 # loop over all the possible consequences | |
| 202 for my $oc (@{$self->get_sorted_OverlapConsequences}) { | |
| 203 | |
| 204 last if defined($assigned_tier) and $oc->tier > $assigned_tier; | |
| 205 | |
| 206 # check that this consequence applies to this type of variation feature | |
| 207 | |
| 208 if ($oc->variant_feature_class && $self->base_variation_feature->isa($oc->variant_feature_class)) { | |
| 209 | |
| 210 # check that this consequence applies to this type of feature | |
| 211 | |
| 212 if ($self->feature->isa($oc->feature_class)) { | |
| 213 | |
| 214 # if so, check if the predicate of this consequence holds for this bvfoa | |
| 215 my $check = $oc->predicate->($self); | |
| 216 | |
| 217 #print STDERR $self->base_variation_feature->variation_name." ".$oc->{SO_term}." ".$self->feature->stable_id. " $check\n"; | |
| 218 | |
| 219 if ($check) { | |
| 220 push @$cons, $oc; | |
| 221 $assigned_tier = $oc->tier; | |
| 222 } | |
| 223 } | |
| 224 } | |
| 225 } | |
| 226 | |
| 227 $self->{overlap_consequences} = $cons; | |
| 228 } | |
| 229 | |
| 230 return $self->{overlap_consequences}; | |
| 231 } | |
| 232 | |
| 233 =head2 add_OverlapConsequence | |
| 234 | |
| 235 Arg [1] : Bio::EnsEMBL::Variation::OverlapConsequence instance | |
| 236 Description: Add an OverlapConsequence to this allele's list | |
| 237 Returntype : none | |
| 238 Exceptions : throws if the argument is the wrong type | |
| 239 Status : At Risk | |
| 240 | |
| 241 =cut | |
| 242 | |
| 243 sub add_OverlapConsequence { | |
| 244 my ($self, $oc) = @_; | |
| 245 assert_ref($oc, 'Bio::EnsEMBL::Variation::OverlapConsequence'); | |
| 246 $self->{overlap_consequences} ||= []; | |
| 247 push @{ $self->{overlap_consequences} }, $oc; | |
| 248 } | |
| 249 | |
| 250 sub SO_isa { | |
| 251 my ($self, $query) = @_; | |
| 252 | |
| 253 if (my $adap = $self->base_variation_feature_overlap->{adaptor}) { | |
| 254 if (my $ota = $adap->db->dnadb->get_OntologyTermAdaptor) { | |
| 255 my $term = $ota->fetch_by_accession(); | |
| 256 my @parents = $ota->fetch_by_child_term($term); | |
| 257 } | |
| 258 } | |
| 259 | |
| 260 for my $cons (@{ $self->get_all_OverlapConsequences }) { | |
| 261 if ($cons->SO_term eq $query) { | |
| 262 return 1; | |
| 263 } | |
| 264 } | |
| 265 } | |
| 266 | |
| 267 sub get_sorted_OverlapConsequences { | |
| 268 my $self = shift; | |
| 269 | |
| 270 if(!defined($self->base_variation_feature_overlap->adaptor->{sorted_cons})) { | |
| 271 my @sorted = sort {$a->tier <=> $b->tier} values %OVERLAP_CONSEQUENCES; | |
| 272 $self->base_variation_feature_overlap->adaptor->{sorted_cons} = \@sorted; | |
| 273 } | |
| 274 | |
| 275 return $self->base_variation_feature_overlap->adaptor->{sorted_cons}; | |
| 276 } | |
| 277 | |
| 278 1; | |
| 279 |
