Mercurial > repos > mahtabm > ensembl
comparison variant_effect_predictor/Bio/EnsEMBL/Variation/Utils/BaseVepPlugin.pm @ 0:1f6dce3d34e0
Uploaded
author | mahtabm |
---|---|
date | Thu, 11 Apr 2013 02:01:53 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1f6dce3d34e0 |
---|---|
1 =head1 LICENSE | |
2 | |
3 Copyright (c) 1999-2012 The European Bioinformatics Institute and | |
4 Genome Research Limited. All rights reserved. | |
5 | |
6 This software is distributed under a modified Apache license. | |
7 For license details, please see | |
8 | |
9 http://www.ensembl.org/info/about/code_licence.html | |
10 | |
11 =head1 CONTACT | |
12 | |
13 Please email comments or questions to the public Ensembl | |
14 developers list at <dev@ensembl.org>. | |
15 | |
16 Questions may also be sent to the Ensembl help desk at | |
17 <helpdesk@ensembl.org>. | |
18 | |
19 =cut | |
20 | |
21 =head1 NAME | |
22 | |
23 Bio::EnsEMBL::Variation::Utils::BaseVepPlugin | |
24 | |
25 =head1 SYNOPSIS | |
26 | |
27 package FunkyPlugin; | |
28 | |
29 use base qw(Bio::EnsEMBL::Variation::Utils::BaseVepPlugin); | |
30 | |
31 sub feature_types { | |
32 return ['Transcript']; | |
33 } | |
34 | |
35 sub get_header_info { | |
36 return { | |
37 FUNKY_PLUGIN => "Description of funky plugin" | |
38 }; | |
39 } | |
40 | |
41 sub run { | |
42 my ($self, $transcript_variation_allele) = @_; | |
43 | |
44 my $results = ... # do analysis | |
45 | |
46 return { | |
47 FUNKY_PLUGIN => $results | |
48 }; | |
49 } | |
50 | |
51 1; | |
52 | |
53 =head1 DESCRIPTION | |
54 | |
55 To make writing plugin modules for the VEP easier, get | |
56 your plugin to inherit from this class, override (at least) | |
57 the feature_types, get_header_info and run methods to behave | |
58 according to the documentation below, and then run the VEP | |
59 with your plugin using the --plugin <module name> command | |
60 line option. | |
61 | |
62 =cut | |
63 | |
64 package Bio::EnsEMBL::Variation::Utils::BaseVepPlugin; | |
65 | |
66 use strict; | |
67 use warnings; | |
68 | |
69 =head2 new | |
70 | |
71 Arg [1] : a VEP configuration hashref | |
72 Arg [>1] : any parameters passed on the VEP command line, will be stored as a listref in $self->{params} | |
73 Description: Creates and returns a new instance of this plugin | |
74 Returntype : Bio::EnsEMBL::Variation::Utils::BaseVepPlugin instance (most likely a user-defined subclass) | |
75 Status : Experimental | |
76 | |
77 =cut | |
78 | |
79 sub new { | |
80 my ($class, $config, @params) = @_; | |
81 | |
82 # default to the current VEP version, and analysing VariationFeatures and | |
83 # Transcripts (which we expect to be the most common usage, this means that | |
84 # the run method will be called with a TranscriptVariationAllele as the | |
85 # first argument) | |
86 | |
87 return bless { | |
88 version => '2.3', | |
89 feature_types => ['Transcript'], | |
90 variant_feature_types => ['VariationFeature'], | |
91 config => $config, | |
92 params => \@params, | |
93 }, $class; | |
94 } | |
95 | |
96 =head2 version | |
97 | |
98 Arg [1] : (optional) a version number string in the form N.N.N | |
99 Description: Get/set the version of this plugin. The version should | |
100 match the version of the VEP that this plugin works with | |
101 (at least in the major version number). This is used to | |
102 detect compatibility between the VEP and plugins. | |
103 Returntype : string | |
104 Status : Experimental | |
105 | |
106 =cut | |
107 | |
108 sub version { | |
109 my ($self, $version) = @_; | |
110 $self->{version} = $version if $version; | |
111 return $self->{version}; | |
112 } | |
113 | |
114 =head2 config | |
115 | |
116 Arg [1] : a VEP configuration hashref | |
117 Description: Get/set the VEP configuration hashref | |
118 Returntype : hashref | |
119 Status : Experimental | |
120 | |
121 =cut | |
122 | |
123 sub config { | |
124 my ($self, $config) = @_; | |
125 $self->{config} = $config if $config; | |
126 return $self->{config}; | |
127 } | |
128 | |
129 =head2 params | |
130 | |
131 Arg [1] : (optional) a listref of plugin parameters | |
132 Description: Get/set the parameters of this plugin, typically as passed on the VEP command line. | |
133 Returntype : listref | |
134 Status : Experimental | |
135 | |
136 =cut | |
137 | |
138 sub params { | |
139 my ($self, $params) = @_; | |
140 $self->{params} = $params if $params; | |
141 return $self->{params} || []; | |
142 } | |
143 | |
144 =head2 get_header_info | |
145 | |
146 Description: Return a hashref with any Extra column keys as keys and a description | |
147 of the data as a value, this will be included in the VEP output file | |
148 header to help explain the results of this plugin. Plugins that do | |
149 not want to include anything in the header should return undef. | |
150 Returntype : hashref or undef | |
151 Status : Experimental | |
152 | |
153 =cut | |
154 | |
155 sub get_header_info { | |
156 my ($self) = @_; | |
157 return undef; | |
158 } | |
159 | |
160 =head2 variant_feature_types | |
161 | |
162 Description: To indicate which types of variation features a plugin is interested | |
163 in, plugins should return a listref of the types of variation feature | |
164 they can deal with. Currently this list should include one or more of: | |
165 'VariationFeature' or 'StructuralVariationFeature' | |
166 Returntype : listref | |
167 Status : Experimental | |
168 | |
169 =cut | |
170 | |
171 sub variant_feature_types { | |
172 my ($self, $types) = @_; | |
173 $self->{variant_feature_types} = $types if $types; | |
174 return $self->{variant_feature_types}; | |
175 } | |
176 | |
177 =head2 feature_types | |
178 | |
179 Description: To indicate which types of genomic features a plugin is interested | |
180 in, plugins should return a listref of the types of feature they can deal | |
181 with. Currently this list should include one or more of: 'Transcript', | |
182 'RegulatoryFeature' and 'MotifFeature' | |
183 Returntype : listref | |
184 Status : Experimental | |
185 | |
186 =cut | |
187 | |
188 sub feature_types { | |
189 my ($self, $types) = @_; | |
190 $self->{feature_types} = $types if $types; | |
191 return $self->{feature_types}; | |
192 } | |
193 | |
194 sub _check_types { | |
195 my ($self, $type_type, $type) = @_; | |
196 | |
197 # if we're passed an object instead of a type string | |
198 # get the type of reference and use that | |
199 if (ref $type) { | |
200 $type = ref $type; | |
201 } | |
202 | |
203 # $type_type will either be 'variant_feature' or 'feature' | |
204 # so construct the method to call and the hash key to | |
205 # store the cached results under | |
206 | |
207 my $method = $type_type.'_types'; | |
208 my $hash_key = $method.'_wanted'; | |
209 | |
210 unless (defined $self->{$hash_key}->{$type}) { | |
211 | |
212 # cache the result so we don't have to loop each time | |
213 | |
214 $self->{$hash_key}->{$type} = 0; | |
215 | |
216 for my $wanted (@{ $self->$method }) { | |
217 | |
218 # special case the intergenic class | |
219 | |
220 if ($wanted eq 'Intergenic') { | |
221 if ($wanted eq $type) { | |
222 $self->{$hash_key}->{$type} = 1; | |
223 last; | |
224 } | |
225 } | |
226 else { | |
227 | |
228 # we are fairly relaxed about how the user describes features, it can | |
229 # be the fully qualified class name, or just the specific module name, | |
230 # (i.e. the text after the last '::') in which case we automatically | |
231 # fully qualify it | |
232 | |
233 if ($wanted !~ /::/) { | |
234 | |
235 if ($type_type eq 'feature') { | |
236 | |
237 if ($wanted eq 'RegulatoryFeature' || $wanted eq 'MotifFeature') { | |
238 $wanted = "Bio::EnsEMBL::Funcgen::$wanted"; | |
239 } | |
240 else { | |
241 $wanted = "Bio::EnsEMBL::$wanted"; | |
242 } | |
243 } | |
244 elsif ($type_type eq 'variant_feature') { | |
245 $wanted = "Bio::EnsEMBL::Variation::$wanted"; | |
246 } | |
247 } | |
248 | |
249 if ($type->isa($wanted)) { | |
250 $self->{$hash_key}->{$type} = 1; | |
251 last; | |
252 } | |
253 } | |
254 } | |
255 } | |
256 | |
257 return $self->{$hash_key}->{$type}; | |
258 } | |
259 | |
260 =head2 check_feature_type | |
261 | |
262 Arg[1] : the feature type as a string (or a reference to an object of the desired type) | |
263 Description: Check if this plugin is interested in a particular feature type | |
264 Returntype : boolean | |
265 Status : Experimental | |
266 | |
267 =cut | |
268 | |
269 sub check_feature_type { | |
270 my ($self, $type) = @_; | |
271 return $self->_check_types('feature', $type); | |
272 } | |
273 | |
274 =head2 check_variant_feature_type | |
275 | |
276 Arg[1] : the variant feature type as a string (or a reference to an object of the desired type) | |
277 Description: Check if this plugin is interested in a particular variant feature type | |
278 Returntype : boolean | |
279 Status : Experimental | |
280 | |
281 =cut | |
282 | |
283 sub check_variant_feature_type { | |
284 my ($self, $type) = @_; | |
285 return $self->_check_types('variant_feature', $type); | |
286 } | |
287 | |
288 =head2 run | |
289 | |
290 Arg[1] : An instance of a subclass of Bio::EnsEMBL::Variation::BaseVariationFeatureOverlapAllele | |
291 Arg[2] : A hashref containing all the data that will be printed on this line, keyed by column name | |
292 Description: Run this plugin, this is where most of the plugin logic should reside. | |
293 When the VEP is about to finish one line of output (for a given variation-allele-feature | |
294 combination) it will call this method, passing it a relevant subclass of a | |
295 Bio::EnsEMBL::Variation::BaseVariationFeatureOverlapAllele object according to | |
296 feature types it is interested in, as specified by the plugin's feature_types method: | |
297 | |
298 feature type argument type | |
299 | |
300 'Transcript' Bio::EnsEMBL::Variation::TranscriptVariationAllele | |
301 'RegulatoryFeature' Bio::EnsEMBL::Variation::RegulatoryFeatureVariationAllele | |
302 'MotifFeature' Bio::EnsEMBL::Variation::MotifFeatureVariationAllele | |
303 | |
304 Once the plugin has done its analysis it should return the results as a hashref | |
305 with a key for each type of data (which should match the keys described in | |
306 get_header_info) and a corresponding value for this particular object, or an empty | |
307 hash (*not* undef) if this plugin does not produce any annotation for this object. | |
308 Any edata will then be included in the Extra column in the VEP output file. | |
309 Please refer to the variation API documentation to see what methods are available | |
310 on each of the possible classes, bearing in mind that common functionality can be | |
311 found in the BaseVariationFeatureOverlapAllele superclass. | |
312 | |
313 If the plugin wants to filter this line out of the VEP output it can indicate | |
314 this by returning undef rather than a hashref. Using this mechanism a plugin | |
315 can act as a filter on the VEP output to limit lines to particular events | |
316 of interest. If you are writing a plugin to act as filter, consider subclassing | |
317 Bio::EnsEMBL::Variation::Utils::BaseVepFilterPlugin, a subclass of this class | |
318 which provides some convenient functionality for filter plugins. | |
319 | |
320 Returntype : hashref or undef if the plugin wants to filter out this line | |
321 Status : Experimental | |
322 | |
323 =cut | |
324 | |
325 sub run { | |
326 my ($self, $bvfoa, $line_hash) = @_; | |
327 warn "VEP plugins should implement the 'run' method\n"; | |
328 return {}; | |
329 } | |
330 | |
331 1; | |
332 |