forked from Ensembl/VEP_plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SameCodon.pm
155 lines (108 loc) · 4.5 KB
/
SameCodon.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
=head1 LICENSE
Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
Copyright [2016] 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 <wm2@ebi.ac.uk>
=cut
=head1 NAME
Draw
=head1 SYNOPSIS
mv SameCodon.pm ~/.vep/Plugins
perl variant_effect_predictor.pl -i variations.vcf --plugin SameCodon
=head1 DESCRIPTION
A VEP plugin that reports existing variants that fall in the same codon.
=cut
package SameCodon;
use strict;
use warnings;
use Bio::EnsEMBL::Variation::Utils::BaseVepPlugin;
use Bio::EnsEMBL::Variation::Utils::VEP qw(load_dumped_variation_cache);
use base qw(Bio::EnsEMBL::Variation::Utils::BaseVepPlugin);
sub version {
return '2.5';
}
sub feature_types {
return ['Transcript'];
}
sub get_header_info {
return {
SameCodon => "Existing variant IDs that fall in the same codon",
};
}
sub run {
my ($self, $tva) = @_;
my $tv = $tva->transcript_variation;
my $vf = $tv->variation_feature;
my ($pep_start, $pep_end) = ($tv->translation_start, $tv->translation_end);
my ($vf_start, $vf_end) = ($vf->start, $vf->end);
return {} unless defined($pep_start) && defined($pep_end);
my $config = $self->{config};
# we need to map the TV start and end coords to the genome
# needs to be done through the mapper in case the codon spans exons
my $mapper = $tv->_mapper();
return {} unless defined($mapper);
my @coords = $mapper->pep2genomic($pep_start, $pep_end);
return {} unless scalar @coords;
return {} if grep {!$_->isa('Bio::EnsEMBL::Mapper::Coordinate')} @coords;
my @results;
# we might get multiple "slices" if the codon that the variant falls in spans exons
foreach my $coord(@coords) {
my ($slice_start, $slice_end) = ($coord->start, $coord->end);
# using cache?
if(defined($config->{cache})) {
# spoof region based on cache region size
my $size = $config->{cache_region_size};
my $s = (int ($vf_start / $size) * $size) + 1;
my $e = (int ($vf_end / $size) + 1) * $size;
my $c = $vf->{chr};
my $region = "$s\-$e";
my $vf_cache = $self->{_cache}->{$c}->{$region} || load_dumped_variation_cache($config, $c, $region);
foreach my $pos($slice_start..$slice_end) {
if(my $existing_vars = $vf_cache->{$c}->{$pos}) {
push @results,
map {$_->{variation_name}}
grep {
$_->{variation_name} ne $vf->variation_name &&
$_->{failed} <= $config->{failed} &&
$_->{start} != $vf_start &&
$_->{end} != $vf_end &&
scalar $mapper->genomic2cds($_->{start}, $_->{end}, 1) >= 1
}
@$existing_vars;
}
}
$self->{_cache} = {};
$self->{_cache}->{$c}->{$region} = $vf_cache;
}
# using DB
elsif(defined($config->{sa}) && defined($config->{vfa}) && defined($config->{vfa})) {
my $sub_slice = $vf->slice->sub_Slice($slice_start, $slice_end);
push @results,
map {$_->variation_name}
grep {
$_->variation_name ne $vf->variation_name &&
$_->seq_region_start != $vf_start &&
$_->seq_region_end != $vf_end &&
scalar $mapper->genomic2cds($_->seq_region_start, $_->seq_region_end, 1) >= 1
}
@{$sub_slice->get_all_VariationFeatures()};
}
else {
return {}
}
}
return {} unless scalar @results;
return {
SameCodon => join ",", @results
}
}
1;