comparison variant_effect_predictor/Bio/EnsEMBL/Funcgen/FeatureSet.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 #
2 # Ensembl module for Bio::EnsEMBL::Funcgen::FeatureSet
3 #
4
5 =head1 LICENSE
6
7 Copyright (c) 1999-2011 The European Bioinformatics Institute and
8 Genome Research Limited. All rights reserved.
9
10 This software is distributed under a modified Apache license.
11 For license details, please see
12
13 http://www.ensembl.org/info/about/code_licence.html
14
15 =head1 CONTACT
16
17 Please email comments or questions to the public Ensembl
18 developers list at <ensembl-dev@ebi.ac.uk>.
19
20 Questions may also be sent to the Ensembl help desk at
21 <helpdesk@ensembl.org>.
22
23
24 =head1 NAME
25
26 Bio::EnsEMBL::FeatureSet - A module to represent FeatureSet.
27
28
29 =head1 SYNOPSIS
30
31 use Bio::EnsEMBL::Funcgen::FeatureSet;
32
33 my $result_set = Bio::EnsEMBL::Funcgen::FeatureSet->new(
34
35 );
36
37
38
39 =head1 DESCRIPTION
40
41 A FeatureSet object provides access to a set of feature predictions and their details, which may have been generated from a
42 single or multiple Experiments with potentially differing analyses. The FeatureSet itself will only have a single analysis
43 which may be one or a combination of programs but will be represented by one analysis record.
44
45 =cut
46
47 use strict;
48 use warnings;
49
50 package Bio::EnsEMBL::Funcgen::FeatureSet;
51
52 use Bio::EnsEMBL::Utils::Argument qw( rearrange );
53 use Bio::EnsEMBL::Utils::Exception qw( throw warning deprecate);
54 use Bio::EnsEMBL::Funcgen::Set;
55
56 use vars qw(@ISA);
57 @ISA = qw(Bio::EnsEMBL::Funcgen::Set);
58
59 my %valid_classes = ( annotated => undef,
60 regulatory => undef,
61 external => undef,
62 segmentation => undef, );
63
64 =head2 new
65
66 -name => $name,
67 -feature_type => $ftype,
68 -cell_type => $ctype,
69 -name => $name,
70 -description => 'Release 3.1',
71 -display_label => 'Short name',
72 -analysis => $analysis,
73 Arg [-EXPERIMENT_ID] : Experiment dbID
74 -dbid => $dbid,
75 Arg [-ADAPTOR]
76
77 Example : my $feature = Bio::EnsEMBL::Funcgen::FeatureSet->new(
78 -dbid => $dbid,
79 -analysis => $analysis,
80 -feature_type => $ftype,
81 -cell_type => $ctype,
82 -name => $name,
83 -feature_class => 'annotated',
84 -description => 'Release 3.1',
85 -display_label => 'Short name',
86 -input_set => $iset,
87 );
88 Description: Constructor for FeatureSet objects.
89 Returntype : Bio::EnsEMBL::Funcgen::FeatureSet
90 Exceptions : Throws if FeatureType defined
91 Caller : General
92 Status : At risk
93
94 =cut
95
96 sub new {
97 my $caller = shift;
98 my $class = ref($caller) || $caller;
99 my $self = $class->SUPER::new(@_);
100
101 my ( $desc, $dlabel, $iset_id, $iset, $exp_id, $exp ) =
102 rearrange( [
103 'DESCRIPTION', 'DISPLAY_LABEL',
104 'INPUT_SET_ID', 'INPUT_SET', 'EXPERIMENT_ID', 'EXPERIMENT'
105 ],
106 @_ );
107
108
109 if($exp_id || $exp){
110 throw('Passing an Experiment or an experiment_id is now deprecated,'.
111 ' please use -input_set or -input_set_id instead');
112 }
113
114 #Allow exp or exp_id to be passed to support storing and lazy loading
115
116 #Mandatory params checks here (setting done in Set.pm)
117 throw('Must provide a FeatureType')
118 if ( !defined $self->feature_type );
119
120 #explicit type check here to avoid invalid types being imported as NULL
121 #subsequently throwing errors on retrieval
122 my $type = $self->feature_class;
123
124 if ( !( $type && exists $valid_classes{$type} ) ) {
125 throw( 'You must define a valid FeatureSet type e.g. ' .
126 join( ', ', keys %valid_classes ) );
127 }
128
129 #Direct assignment to prevent need for set arg test in method
130
131 $self->{'description'} = $desc if defined $desc;
132 $self->{'display_label'} = $dlabel if defined $dlabel;
133 $self->{'input_set_id'} = $iset_id if defined $iset_id;
134
135 if ( defined $iset ) {
136 #Exp obj is only passed during object storing
137 #so let the adaptor do is_stored_and_valid
138 $self->{'input_set'} = $iset;
139 }
140
141 return $self;
142 } ## end sub new
143
144
145
146 =head2 new_fast
147
148 Args : Hashref with all internal attributes set
149 Example : none
150 Description: Quick and dirty version of new. Only works if the code is very
151 disciplined.
152 Returntype : Bio::EnsEMBL::Funcgen::FeatureSet
153 Exceptions : None
154 Caller : General
155 Status : At Risk
156
157 =cut
158
159
160 sub new_fast {
161 return bless ($_[1], $_[0]);
162 }
163
164
165 =head2 description
166
167 Example : print "Feature set description is:\t".$fset->description."\n";
168 Description: Getter for the description of this FeatureSet. e.g. Release 3.1
169 Returntype : String
170 Exceptions : None
171 Caller : General
172 Status : At Risk
173
174 =cut
175
176 sub description {
177 return $_[0]->{'description'};
178 }
179
180
181
182 =head2 display_label
183
184 Example : print $rset->display_label;
185 Description: Getter for the display_label attribute for this FeatureSet.
186 Returntype : String
187 Exceptions : None
188 Caller : General
189 Status : At Risk
190
191 =cut
192
193 sub display_label {
194 my $self = shift;
195
196 if ( !$self->{'display_label'} ) {
197
198 if ( $self->feature_type->class() eq 'Regulatory Feature' ) {
199 $self->{'display_label'} = $self->name;
200 }
201 else {
202 #This still fails here if we don't have a class or a cell_type set
203
204 $self->{'display_label'} =
205 $self->feature_type->name() . " - " . $self->cell_type->name() .
206 " Enriched Sites";
207 }
208 }
209
210 return $self->{'display_label'};
211 }
212
213
214
215
216 =head2 get_FeatureAdaptor
217
218 Example :
219 Description: Retrieves and caches FeatureAdaptor of feature_set type
220 Returntype : Bio::EnsEMBL::Funcgen::DBSQL::ucfirst($self->feature_class())FeatureAdaptor
221 Exceptions : None
222 Caller : General
223 Status : At Risk
224
225 =cut
226
227
228 sub get_FeatureAdaptor{
229 my $self = shift;
230
231 if(! exists $self->{'adaptor_refs'}){
232
233 foreach my $valid_class(keys %valid_classes){
234 my $method = 'get_'.ucfirst($valid_class).'FeatureAdaptor';
235
236 $self->{'adaptor_refs'}{$valid_class} = $self->adaptor->db->$method;
237 }
238 }
239
240 return $self->{'adaptor_refs'}->{$self->feature_class()};
241
242 }
243
244
245
246 =head2 get_Features_by_Slice
247
248 Example : my @features = @{$FeatureSet->get_Features_by_Slice($slice)};
249 Description: Retrieves all Features for this FeatureSet for a given Slice
250 Returntype : ARRAYREF containing Features of the feature_set type i.e. Annotated, Regulatory or Supporting;
251 Exceptions : None
252 Caller : General
253 Status : At Risk
254
255 =cut
256
257 sub get_Features_by_Slice{
258 my ($self, $slice) = @_;
259
260 return $self->get_FeatureAdaptor->fetch_all_by_Slice_FeatureSets($slice, [$self]);
261 }
262
263
264 =head2 get_Features_by_FeatureType
265
266 Arg[0] : Bio::EnsEMBL::Funcgen::FeatureType
267 Example : my @features = @{$FeatureSet->get_Features_by_FeatureType($ftype)};
268 Description: Retrieves all Features for this FeatureSet for a given FeatureType
269 or associated FeatureType. This is mainly used by external FeatureSets
270 which can sometimes have more than one associated FeatureType.
271 Returntype : ARRAYREF
272 Exceptions : None
273 Caller : General
274 Status : At Risk
275
276 =cut
277
278
279 sub get_Features_by_FeatureType{
280 my ($self, $type) = @_;
281
282 return $self->get_FeatureAdaptor->fetch_all_by_FeatureType_FeatureSets($type, [$self]);
283 }
284
285
286 =head2 get_all_Features
287
288 Example : my @features = @{$FeatureSet->get_all_Features};
289 Description: Retrieves all Features for this FeatureSet
290 Returntype : ARRAYREF
291 Exceptions : None
292 Caller : General
293 Status : At Risk
294
295 =cut
296
297 sub get_all_Features{
298 my $self = shift;
299
300 return $self->get_FeatureAdaptor->fetch_all_by_FeatureSets([$self]);
301 }
302
303
304
305
306 =head2 is_focus_set
307
308 Args : None
309 Example : if($fset->is_focus_set){ ... }
310 Description: Returns true if FeatureSet is a focus set used in the RegulatoryBuild
311 Returntype : Boolean
312 Exceptions : Throws if meta entry not present
313 Caller : General
314 Status : At Risk
315
316 =cut
317
318 sub is_focus_set{
319 my $self = shift;
320
321 if(! defined $self->{focus_set}){
322
323 if(! defined $self->cell_type){
324 warn "FeatureSet without an associated CellType cannot be a focus set:\t".$self->name;
325 $self->{focus_set} = 0;
326 }
327 else{
328 $self->{focus_set} = $self->adaptor->fetch_focus_set_config_by_FeatureSet($self);
329 }
330 }
331
332 return $self->{focus_set};
333 }
334
335
336 =head2 is_attribute_set
337
338 Args : None
339 Example : if($fset->is_attribute_set){ ... }
340 Description: Returns true if FeatureSet is a supporting/attribute(focus or not) set used in the RegulatoryBuild
341 Returntype : Boolean
342 Exceptions : Throws if meta entry not present
343 Caller : General
344 Status : At Risk
345
346 =cut
347
348 sub is_attribute_set{
349 my $self = shift;
350
351 if(! defined $self->{attribute_set}){
352
353 if(! defined $self->cell_type){
354 warn "FeatureSet without an associated CellType cannot be a attribute set:\t".$self->name;
355 $self->{attribute_set} = 0;
356 }
357 else{
358 $self->{attribute_set} = $self->adaptor->fetch_attribute_set_config_by_FeatureSet($self);
359 }
360 }
361
362 return $self->{attribute_set};
363 }
364
365
366 =head2 get_InputSet
367
368 Example : my $input_set = $FeatureSet->get_InputSet;
369 Description: Retrieves the InputSet for this FeatureSet
370 Returntype : Bio::EnsEMBL::Funcgen::InputSet
371 Exceptions : None
372 Caller : General
373 Status : At Risk
374
375 =cut
376
377 sub get_InputSet{
378 my $self = shift;
379
380 if( (! defined $self->{input_set}) &&
381 (defined $self->{input_set_id}) ){
382 $self->{input_set} = $self->adaptor->db->get_InputSetAdaptor->fetch_by_dbID($self->{input_set_id});
383 }
384
385 return $self->{input_set};
386 }
387
388
389
390 =head2 source_label
391
392 Example : my $source_label = $fset->source_label;
393 Description: Retrieves the source label this FeatureSet, used in zmenus
394 Returntype : Arrayref of Strings
395 Exceptions : None
396 Caller : Webcode zmenus
397 Status : At Risk - remove, to be done by webcode?
398
399 =cut
400
401 #These are used to link through to the experiment view based on feature_set_id
402
403 sub source_label{
404 my $self = shift;
405
406 if (! defined $self->{source_label}) {
407 my $input_set = $self->get_InputSet;
408 my @source_labels;
409
410 if ($input_set) {
411
412
413 foreach my $isset(@{$input_set->get_InputSubsets}){
414
415 if(defined $isset->archive_id){
416 push @source_labels, $isset->archive_id;
417 }
418 #Archive IDs e.g. SRX identifiers or undef.
419 }
420
421 #Append project name
422 my $exp_group = $input_set->get_Experiment->experimental_group;
423
424 if ($exp_group &&
425 $exp_group->is_project) {
426 push @source_labels, $exp_group->name;
427 }
428 }
429
430
431 $self->{source_label} = join(' ', @source_labels);
432 }
433
434 return $self->{source_label};
435 }
436
437
438
439
440 ### DEPRECATED ###
441
442 =head2 get_Experiment
443 #
444 # Example : my $exp = $FeatureSet->get_Experiment;
445 # Description: Retrieves the Experiment for this FeatureSet
446 # Returntype : Bio::EnsEMBL::Funcgen::Experiment
447 # Exceptions : None
448 # Caller : General
449 Status : DEPRECATED
450
451 =cut
452
453 sub get_Experiment{
454 throw('FeatureSet::get_Experiment is not longer supported, please use FeatureSet::get_InputSet');
455 }
456
457
458 1;