forked from Ensembl/VEP_plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Conservation.pm
222 lines (157 loc) · 6.74 KB
/
Conservation.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
=head1 LICENSE
Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
Copyright [2016-2018] 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
Ensembl <http://www.ensembl.org/info/about/contact/index.html>
=cut
=head1 NAME
Conservation
=head1 SYNOPSIS
mv Conservation.pm ~/.vep/Plugins
./vep -i variations.vcf --plugin Conservation,GERP_CONSERVATION_SCORE,mammals
=head1 DESCRIPTION
This is a plugin for the Ensembl Variant Effect Predictor (VEP) that
retrieves a conservation score from the Ensembl Compara databases
for variant positions. You can specify the method link type and
species sets as command line options, the default is to fetch GERP
scores from the EPO 35 way mammalian alignment (please refer to the
Compara documentation for more details of available analyses).
If a variant affects multiple nucleotides the average score for the
position will be returned, and for insertions the average score of
the 2 flanking bases will be returned.
The plugin requires the ensembl-compara API module to be installed;
see http://www.ensembl.org/info/docs/api/index.html
=cut
package Conservation;
use strict;
use warnings;
use Bio::EnsEMBL::Registry;
use Bio::EnsEMBL::Slice;
use base qw(Bio::EnsEMBL::Variation::Utils::BaseVepPlugin);
sub version {
return '2.3';
}
sub feature_types {
return ['Feature','Intergenic'];
}
sub get_header_info {
my $self = shift;
return {
Conservation => "The conservation score for this site (method_link_type=\"".
$self->{method_link_type}."\", species_set=\"".$self->{species_set}."\")",
};
}
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
my $params = $self->params;
# REST API passes 1 as first param
shift @$params if $params->[0] && $params->[0] eq '1';
$self->{method_link_type} = $params->[0] || 'GERP_CONSERVATION_SCORE';
$self->{species_set} = $params->[1] || 'mammals';
my $config = $self->{config};
my $reg = 'Bio::EnsEMBL::Registry';
# reconnect to DB without species param
if($config->{host}) {
$reg->load_registry_from_db(
-host => $config->{host},
-user => $config->{user},
-pass => $config->{password},
-port => $config->{port},
-db_version => $config->{db_version},
-no_cache => $config->{no_slice_cache},
);
}
my $mlss_adap = $config->{mlssa} ||= $reg->get_adaptor('Multi', 'compara', 'MethodLinkSpeciesSet')
or die "Failed to connect to compara database\n";
$self->{mlss} = $mlss_adap->fetch_by_method_link_type_species_set_name($self->{method_link_type}, $self->{species_set})
or die "Failed to fetch MLSS for ".$self->{method_link_type}." and ".$self->{species_set}."\n";
$self->{cs_adap} = $config->{cosa} ||= $reg->get_adaptor('Multi', 'compara', 'ConservationScore')
or die "Failed to fetch conservation adaptor\n";
return $self;
}
sub run {
my ($self, $bvfoa) = @_;
my $bvf = $bvfoa->base_variation_feature;
# we cache the score on the BaseVariationFeature so we don't have to
# fetch it multiple times if this variant overlaps multiple Features
unless (exists $bvf->{_conservation_score}) {
my $slice;
my $true_snp = 0;
if ($bvf->{end} >= $bvf->{start}) {
if ($bvf->{start} == $bvf->{end}) {
# work around a bug in the compara API that means you can't fetch
# conservation scores for 1bp slices by creating a 2bp slice for
# SNPs and then ignoring the score returned for the second position
my $s = $bvf->slice;
$slice = Bio::EnsEMBL::Slice->new(
-seq_region_name => $s->seq_region_name,
-seq_region_length => $s->seq_region_length,
-coord_system => $s->coord_system,
-start => $bvf->{start},
-end => $bvf->{end} + 1,
-strand => $bvf->{strand},
-adaptor => $s->adaptor
);
$true_snp = 1;
}
else {
# otherwise, just get a slice that covers our variant feature
$slice = $bvf->feature_Slice;
}
}
else {
# this is an insertion, we return the average score of the flanking
# bases, so we create a 2bp slice around the insertion site
my $s = $bvf->slice;
$slice = Bio::EnsEMBL::Slice->new(
-seq_region_name => $s->seq_region_name,
-seq_region_length => $s->seq_region_length,
-coord_system => $s->coord_system,
-start => $bvf->{end},
-end => $bvf->{start},
-strand => $bvf->{strand},
-adaptor => $s->adaptor
);
}
my $scores = $self->{cs_adap}->fetch_all_by_MethodLinkSpeciesSet_Slice(
$self->{mlss}, # our MLSS for the conservation metric and the set of species
$slice, # our slice
($slice->end - $slice->start + 1), # the number of scores we want back (one for each base)
);
if (@$scores > 0) {
# we use the simple average of the diff_scores as the overall score
pop @$scores if $true_snp; # get rid of our spurious second score for SNPs
if (@$scores > 0) {
my $tot_score = 0;
$tot_score += $_->diff_score for @$scores;
$tot_score /= @$scores;
$bvf->{_conservation_score} = sprintf "%.3f", $tot_score;
}
else {
$bvf->{_conservation_score} = undef;
}
}
else {
$bvf->{_conservation_score} = undef;
}
}
if (defined $bvf->{_conservation_score}) {
return {
Conservation => $bvf->{_conservation_score}
};
}
else {
return {};
}
}
1;