forked from Ensembl/VEP_plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SameCodon.pm
147 lines (101 loc) · 4.28 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
=head1 LICENSE
Copyright (c) 1999-2012 The European Bioinformatics Institute and
Genome Research Limited. All rights reserved.
This software is distributed under a modified Apache license.
For license details, please see
http://www.ensembl.org/info/about/code_licence.html
=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);
$DB::single = 1;
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 = 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 {$_->[0]}
grep {
$_->[0] ne $vf->variation_name &&
$_->[1] <= $config->{failed} &&
$_->[2] != $vf_start &&
$_->[3] != $vf_end &&
scalar $mapper->genomic2cds($_->[2], $_->[3], 1) >= 1
}
@$existing_vars;
}
}
}
# 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;