forked from Ensembl/VEP_plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHGVSshift.pm
200 lines (141 loc) · 5.97 KB
/
HGVSshift.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
=head1 LICENSE
Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=head1 CONTACT
Will McLaren <[email protected]>
=cut
=head1 NAME
HGVSshift
=head1 SYNOPSIS
mv HGVSshift.pm ~/.vep/Plugins
perl variant_effect_predictor.pl -i variations.vcf --cache --plugin HGVSshift
=head1 DESCRIPTION
This is a plugin for the Ensembl Variant Effect Predictor (VEP) that
reports the "opposite" 3'-shifted HGVS notation to the main HGVSc and
HGVSp VEP notations, i.e.
a) If using "--shift_hgvs 1" (default), "unshifted" HGVS notations
will be reported as HGVSc_unshifted and HGVSp_unshifted.
b) If using "--shift_hgvs 0", "shifted" HGVS notations will be
reported as HGVSc_shifted and HGVSp_shifted
New notations are only reported if they differ from the main notations, and
are reported in addition to, not instead of, the main notations.
=cut
package HGVSshift;
use strict;
use warnings;
use Bio::EnsEMBL::Variation::Utils::BaseVepPlugin;
use Bio::EnsEMBL::Variation::DBSQL::TranscriptVariationAdaptor;
use Bio::EnsEMBL::Variation::DBSQL::DBAdaptor;
use Bio::EnsEMBL::Variation::TranscriptVariationAllele;
use base qw(Bio::EnsEMBL::Variation::Utils::BaseVepPlugin);
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
# check config is OK
# FASTA file defined, optimal
if(!defined($self->{config}->{fasta})) {
# offline mode won't work without FASTA
die("ERROR: Cannot generate HGVS without either a FASTA file (--fasta) or a database connection (--cache or --database)\n") if defined($self->{config}->{offline}) and !defined($self->{config}->{quiet});
# cache mode will work, but DB will be accessed
warn("WARNING: Database will be accessed using this plugin; use a FASTA file (--fasta) for optimal performance\n") if defined($self->{config}->{cache}) and !defined($self->{config}->{quiet});
}
#
if(!defined($self->{config}->{hgvs})) {
warn("WARNING: Plugin is enabling --hgvs\n") unless defined($self->{config}->{quiet});
$self->{config}->{hgvs} = 1;
}
$self->{remove_transcript_ID} = $self->params->[0];
return $self;
}
sub feature_types {
return ['Transcript'];
}
sub variant_feature_types {
return ['VariationFeature'];
}
sub get_header_info {
my $self = shift;
my $prefix = $self->shifting_enabled ? 'Uns' : 'S';
return {
'HGVSc_'.lc($prefix).'hifted' => $prefix.'hifted HGVS transcript notation',
'HGVSp_'.lc($prefix).'hifted' => $prefix.'hifted HGVS protein notation',
};
}
sub run {
my ($self, $tva) = @_;
# check var class, shifting only happens to insertions and deletions
my $var_class = $tva->variation_feature->var_class();
return {} unless $var_class eq 'insertion' || $var_class eq 'deletion';
# find out config status
my $shifting_enabled = $self->shifting_enabled;
my $hgvs = {};
# shifting enabled (default from e!80 onwards)
if($shifting_enabled) {
# we only want to report unshifted if this one has been shifted
if($tva->can('hgvs_offset') && $tva->hgvs_offset) {
$self->reset_hgvs($tva);
$self->switch_shifting_state($tva, 0);
$hgvs->{HGVSc_unshifted} = $tva->hgvs_transcript;
$hgvs->{HGVSp_unshifted} = $tva->hgvs_protein;
$self->switch_shifting_state($tva, 1);
}
}
# shifting disabled
else {
# get the original ones so we don't report the same thing twice
# unfortunately we do have to calculate it twice...
my ($original_hgvsc, $original_hgvsp) = ($tva->hgvs_transcript, $tva->hgvs_protein);
$self->reset_hgvs($tva);
$self->switch_shifting_state($tva, 1);
my ($new_hgvsc, $new_hgvsp) = ($tva->hgvs_transcript, $tva->hgvs_protein);
$hgvs->{HGVSc_shifted} = $new_hgvsc if $new_hgvsc && $original_hgvsc && $new_hgvsc ne $original_hgvsc;
$hgvs->{HGVSp_shifted} = $new_hgvsp if $new_hgvsp && $original_hgvsp && $new_hgvsp ne $original_hgvsp;
$self->switch_shifting_state($tva, 0);
}
# delete empty keys
delete $hgvs->{$_} for grep {!$hgvs->{$_}} keys %$hgvs;
return $hgvs;
}
sub shifting_enabled {
my $self = shift;
if(!exists($self->{shifting_enabled})) {
my $shifting_enabled;
my $config = $self->{config};
if(defined($config->{shift_hgvs})) {
$shifting_enabled = $config->{shift_hgvs};
}
elsif(defined($Bio::EnsEMBL::Variation::DBSQL::TranscriptVariationAdaptor::DEFAULT_SHIFT_HGVS_VARIANTS_3PRIME)) {
$shifting_enabled = $Bio::EnsEMBL::Variation::DBSQL::TranscriptVariationAdaptor::DEFAULT_SHIFT_HGVS_VARIANTS_3PRIME;
}
elsif(defined($Bio::EnsEMBL::Variation::DBSQL::DBAdaptor::DEFAULT_SHIFT_HGVS_VARIANTS_3PRIME)) {
$shifting_enabled = $Bio::EnsEMBL::Variation::DBSQL::DBAdaptor::DEFAULT_SHIFT_HGVS_VARIANTS_3PRIME;
}
$self->{shifting_enabled} = $shifting_enabled;
}
return $self->{shifting_enabled};
}
sub switch_shifting_state {
my $self = shift;
my $tva = shift;
my $newval = shift;
my $tv = $tva->transcript_variation;
$tv->adaptor->db->shift_hgvs_variants_3prime($newval) if defined $tv->adaptor() && UNIVERSAL::can($tv->adaptor, 'isa');
no warnings 'once';
$Bio::EnsEMBL::Variation::DBSQL::TranscriptVariationAdaptor::DEFAULT_SHIFT_HGVS_VARIANTS_3PRIME = $newval;
no warnings 'once';
$Bio::EnsEMBL::Variation::DBSQL::DBAdaptor::DEFAULT_SHIFT_HGVS_VARIANTS_3PRIME = $newval;
}
sub reset_hgvs {
my $self = shift;
my $tva = shift;
delete $tva->{$_} for grep {/^hgvs/} keys %$tva;
}
1;