forked from Ensembl/VEP_plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProteinSeqs.pm
164 lines (105 loc) · 4.41 KB
/
ProteinSeqs.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
=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
Graham Ritchie <[email protected]>
=cut
=head1 NAME
ProteinSeqs
=head1 SYNOPSIS
mv ProteinSeqs.pm ~/.vep/Plugins
perl variant_effect_predictor.pl -i variations.vcf --plugin ProteinSeqs,reference.fa,mutated.fa
=head1 DESCRIPTION
This is a plugin for the Ensembl Variant Effect Predictor (VEP) that
prints out the reference and mutated protein sequences of any
proteins found with non-synonymous mutations in the input file.
You should supply the name of file where you want to store the
reference protein sequences as the first argument, and a file to
store the mutated sequences as the second argument.
Note that, for simplicity, where stop codons are gained the plugin
simply substitutes a '*' into the sequence and does not truncate the
protein. Where a stop codon is lost any new amino acids encoded by the
mutation are appended to the sequence, but the plugin does not attempt
to translate until the next downstream stop codon. Also, the protein
sequence resulting from each mutation is printed separately, no attempt
is made to apply multiple mutations to the same protein.
=cut
package ProteinSeqs;
use strict;
use warnings;
use base qw(Bio::EnsEMBL::Variation::Utils::BaseVepPlugin);
sub version {
return '2.4';
}
sub feature_types {
return ['Transcript'];
}
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
# use some default file names if none are supplied
my $ref_file = $self->params->[0] || 'reference.fa';
my $mut_file = $self->params->[1] || 'mutated.fa';
open $self->{ref_file}, ">$ref_file" or die "Failed to open $ref_file";
open $self->{mut_file}, ">$mut_file" or die "Failed to open $mut_file";
return $self;
}
sub run {
my ($self, $tva) = @_;
# check if we have a mutant amino acid, if not there isn't much we can do!
if (my $mut_aa = $tva->peptide) {
# get the peptide coordinates
my $tl_start = $tva->transcript_variation->translation_start;
my $tl_end = $tva->transcript_variation->translation_end;
# and our reference sequence
my $ref_seq = $tva->transcript_variation->_peptide;
# splice the mutant peptide sequence into the reference sequence
my $mut_seq = $ref_seq;
substr($mut_seq, $tl_start-1, $tl_end - $tl_start + 1) = $mut_aa;
# print out our reference and mutant sequences
my $translation_id = $tva->transcript->translation->stable_id;
# only print the reference sequence if we haven't printed it yet
$self->print_fasta($ref_seq, $translation_id, $self->{ref_file})
unless $self->{printed_ref}->{$translation_id}++;
# we always print the mutated sequence as each mutation may have
# a different consequence
$self->print_fasta($mut_seq, $tva->hgvs_protein, $self->{mut_file});
}
# return an empty hashref because we don't want to add
# anything to the VEP output file
return {};
}
sub print_fasta {
my ($self, $peptide, $id, $fh) = @_;
# break the sequence into 80 characters per line
$peptide =~ s/(.{80})/$1\n/g;
# get rid of any trailing newline
chomp $peptide;
# print the sequence
print $fh ">$id\n$peptide\n";
}
sub STORABLE_freeze {
my ($self, $cloning) = @_;
return if $cloning;
close $self->{ref_file};
close $self->{mut_file};
delete $self->{ref_file};
delete $self->{ref_file};
}
sub STORABLE_thaw {
my ($self, $cloning) = @_;
return if $cloning;
my $ref_file = $self->params->[0] || 'reference.fa';
my $mut_file = $self->params->[1] || 'mutated.fa';
open $self->{ref_file}, ">>$ref_file" or die "Failed to open $ref_file";
open $self->{mut_file}, ">>$mut_file" or die "Failed to open $mut_file";
}
1;