comparison variant_effect_predictor/Bio/EnsEMBL/Funcgen/Experiment.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 =head1 LICENSE
3
4 Copyright (c) 1999-2011 The European Bioinformatics Institute and
5 Genome Research Limited. All rights reserved.
6
7 This software is distributed under a modified Apache license.
8 For license details, please see
9
10 http://www.ensembl.org/info/about/code_licence.html
11
12 =head1 CONTACT
13
14 Please email comments or questions to the public Ensembl
15 developers list at <ensembl-dev@ebi.ac.uk>.
16
17 Questions may also be sent to the Ensembl help desk at
18 <helpdesk@ensembl.org>.
19
20
21 =head1 NAME
22
23 Bio::EnsEMBL::Funcgen::Experiment
24
25 =head1 SYNOPSIS
26
27 use Bio::EnsEMBL::Funcgen::Experiment;
28
29 my $exp = Bio::EnsEMBL::Funcgen::Experiment->new
30 (
31 -ADAPTOR => $self,
32 -NAME => $name,
33 -EXPERIMENTAL_GROUP => $experimental_group,
34 -DATE => $date,
35 -PRIMARY_DESIGN_TYPE => 'binding_site_indentification',
36 -DESCRIPTION => $description,
37 -ARCHIVE_ID => $archive_id,
38 );
39
40 my $db_adaptor = Bio::EnsEMBL::Funcgen::DBSQL::DBAdaptor->new(...);
41 my $exp_adaptor = $db_adaptor->get_ExperimentAdaptor();
42 my $exp = $exp_adaptor->fetch_by_name($exp_name)
43
44 =head1 DESCRIPTION
45
46 The Experiment class represents an instance of an experiment i.e. a discrete set of data
47
48 =cut
49
50
51 ################################################################################
52
53 package Bio::EnsEMBL::Funcgen::Experiment;
54
55 use warnings;
56 use strict;
57
58 use Bio::EnsEMBL::Utils::Argument qw( rearrange );
59 use Bio::EnsEMBL::Utils::Exception qw( throw warning deprecate );
60 use Bio::EnsEMBL::Funcgen::Storable;
61 use vars qw(@ISA);
62
63 @ISA = qw(Bio::EnsEMBL::Funcgen::Storable);
64
65
66
67 =head2 new
68
69 Arg [-NAME] : String - experiment name
70 Arg [-EXPERIMENTAL_GROUP] : Bio::EnsEMBL::Funcgen ExperimentalGroup associated with this experiment
71 Arg [-DATE] : String - Date of the experiment (YYYY-MM-DD)
72 Arg [-PRIMARY_DESIGN_TYPE] : String - MGED term for the primary design of teh experiment e.g. binding_site_identification
73 Arg [-DESCRIPTION] : String
74
75 Example : my $array = Bio::EnsEMBL::Funcgen::Experiment->new
76 (
77 -NAME => $name,
78 -EXPERIMENTAL_GROUP => $group,
79 -DATE => $date,
80 -PRIMARY_DESIGN_TYPE => $p_design_type,
81 -DESCRIPTION => $description,
82 );
83
84 Description: Creates a new Bio::EnsEMBL::Funcgen::Experiment object.
85 Returntype : Bio::EnsEMBL::Funcgen::Experiment
86 Exceptions : Throws if name not defined
87 Throws if ExperimentalGroup not valid
88 Caller : General
89 Status : Medium Risk
90
91 =cut
92
93 sub new {
94 my $caller = shift;
95
96 my $class = ref($caller) || $caller;
97
98 my $self = $class->SUPER::new(@_);
99
100 my ($name, $group, $date, $p_dtype, $desc, $archive_id, $data_url, $xml_id, $xml)
101 = rearrange( ['NAME', 'EXPERIMENTAL_GROUP', 'DATE', 'PRIMARY_DESIGN_TYPE',
102 'DESCRIPTION','ARCHIVE_ID', 'DATA_URL', 'MAGE_XML', 'MAGE_XML_ID'], @_ );
103
104
105 #Added in v68
106 #Remove in v69
107 if($data_url || $archive_id){
108 throw('The -data_url and -archive_id parameters have been moved to the InputSubSet class');
109 }
110
111
112 #Mandatory attr checks
113
114 if(ref($group) ne 'Bio::EnsEMBL::Funcgen::ExperimentalGroup'){
115 throw("Must pass a valid stored Bio::EnsEMBL::Funcgen::ExperimentalGroup object");
116 }
117
118 if(! defined $name){
119 throw('You must provide a name parameter');
120 }
121
122 #test date format here?
123
124
125 #Direct assignment here so we avoid setter test in methods
126 $self->{name} = $name;
127 $self->{group} = $group;
128 $self->{date} = $date if defined $date;
129 $self->{primary_design_type} = $p_dtype if defined $p_dtype; #MGED term for primary design type
130 $self->{description} = $desc if defined $desc;
131
132 #Maintain setter funcs here as these are populated after initialisation
133 $self->mage_xml_id($xml_id) if defined $xml_id;
134 $self->mage_xml($xml) if defined $xml;
135
136 return $self;
137 }
138
139
140 ### ACCESSOR METHODS ###
141
142 =head2 name
143
144 Example : my $exp_name = $exp->name;
145 Description : Getter for the experiment name
146 Returntype : String
147 Exceptions : None
148 Caller : General
149 Status : Stable
150
151 =cut
152
153 sub name{
154 return $_[0]->{'name'};
155 }
156
157
158 =head2 experimental_group
159
160 Example : my $exp_group_name = $exp->experimental_group()->name();
161 Description : Getter for the experimental group
162 Returntype : Bio::EnsEMBL::Funcgen::ExperimentalGroup
163 Exceptions : None
164 Caller : General
165 Status : At risk
166
167 =cut
168
169 sub experimental_group{
170 return $_[0]->{'group'};
171 }
172
173
174 =head2 date
175
176 Example : my $exp_date = $exp->date;
177 Description : Getter for the date
178 Returntype : String
179 Exceptions : None
180 Caller : General
181 Status : Stable
182
183 =cut
184
185 sub date{
186 return $_[0]->{'date'};
187 }
188
189
190 =head2 description
191
192 Example : my $exp_desc = $exp->description
193 Description : Getter for the experiment description
194 Returntype : String
195 Exceptions : None
196 Caller : General
197 Status : At risk - Not used, was stable until v64
198
199 =cut
200
201 sub description{
202 return $_[0]->{'description'};
203 }
204
205
206
207
208
209 =head2 primary_design_type
210
211 Example : my $pdt = $exp->primary_design_type;
212 Description : Getter for the primary design type
213 Returntype : String - MGED term
214 Exceptions : None
215 Caller : General
216 Status : At risk
217
218 =cut
219
220 sub primary_design_type{
221 return $_[0]->{'primary_design_type'};
222 }
223
224
225 # Accessor/Setter methods
226
227 =head2 mage_xml
228
229 Arg [1] : string(optional) - MAGE XML
230 Example : my $xml = $exp->mage_xml();
231 Description : Getter/Setter for the mage_xml attribute
232 Returntype : String
233 Exceptions : None
234 Caller : General
235 Status : at risk
236
237 =cut
238
239 sub mage_xml{
240 my ($self) = shift;
241
242 $self->{'mage_xml'} = shift if(@_);
243
244 #use fetch_attrs?
245 if(! exists $self->{'mage_xml'} && $self->mage_xml_id()){
246 $self->{'mage_xml'} = $self->adaptor->fetch_mage_xml_by_Experiment($self);
247 }
248
249 return (exists $self->{'mage_xml'}) ? $self->{'mage_xml'} : undef;
250 }
251
252
253 =head2 mage_xml_id
254
255 Arg [1] : int (optional) - mage_xml_id
256 Example : $exp->group_db_id('1');
257 Description : Getter/Setter for the mage_xml attribute
258 Returntype : String
259 Exceptions : None
260 Caller : General
261 Status : at risk
262
263 =cut
264
265 sub mage_xml_id{
266 my $self = shift;
267
268 $self->{'mage_xml_id'} = shift if @_;
269
270 return $self->{'mage_xml_id'};
271 }
272
273
274
275
276
277
278 #These convenience methods are to provide a registry for the experimental chips of the experiment
279
280 =head2 get_ExperimentalChips
281
282 Example : my $exp_chips = @{$exp->get_ExperimentalChips()}
283 Description : Retrieves all ExperiemntalChips
284 Returntype : Listref of ExperimentalChips
285 Exceptions : None
286 Caller : General
287 Status : At risk
288
289 =cut
290
291 sub get_ExperimentalChips{
292 my ($self) = shift;
293
294 #should this also store echips?
295
296 #Need to retrieve all from DB if not defined, then check whether already present and add and store if not
297 #what about immediate access to dbID
298 #should we separate and have add_ExperimentalChip?
299
300
301
302 if(! exists $self->{'experimental_chips'}){
303 $self->{'experimental_chips'} = {};
304
305 #need to warn about DBAdaptor here?
306
307 foreach my $echip(@{$self->adaptor->db->get_ExperimentalChipAdaptor->fetch_all_by_experiment_dbID($self->dbID())}){
308 $self->{'experimental_chips'}->{$echip->unique_id()} = $echip;
309 }
310 }
311
312 #is this returning a list or a listref?
313 return [values %{$self->{'experimental_chips'}}];
314 }
315
316 =head2 add_ExperimentalChip
317
318 Example : $exp_chip = $exp->add_ExperimentalChip($exp_chip)
319 Description : Adds and stores an ExperiemntalChip for this Experiment
320 Returntype : Bio::EnsEMBL::Funcgen::ExperimentalChip
321 Exceptions : Throws is not passed a valid stored Bio::EnsENBML::Funcgen::ExperimentalChip
322 Caller : General
323 Status : At risk
324
325 =cut
326
327 sub add_ExperimentalChip{
328 my ($self, $echip) = @_;
329
330
331 throw("Must pass a valid stored Bio::EnsEMBL::Funcgen::ExperimentalChip object")
332 if(! $echip->isa("Bio::EnsEMBL::Funcgen::ExperimentalChip") || ! $echip->dbID());
333
334 if(! exists $self->{'experimental_chips'}){
335 $self->get_ExperimentalChips();
336 $self->{'experimental_chips'}->{$echip->unique_id()} = $echip;
337 #do this here without checking to avoid probelm of retrieving first stored chip
338 }elsif(exists $self->{'experimental_chips'}->{$echip->unique_id()}){
339 warn("You cannot add the same ExperimentalChip(".$echip->unique_id().")to an Experiment more than once, check your code");
340 }else{
341 $self->{'experimental_chips'}->{$echip->unique_id()} = $echip;
342 }
343
344 return;
345 }
346
347 =head2 get_ExperimentalChip_by_unique_id
348
349 Example : $exp_chip = $exp->add_ExperimentalChip($exp_chip)
350 Description : Adds and stores an ExperiemntalChip for this Experiment
351 Returntype : Bio::EnsEMBL::Funcgen::ExperimentalChip
352 Exceptions : Throws if no uid supplied
353 Caller : General
354 Status : At risk
355
356 =cut
357
358 sub get_ExperimentalChip_by_unique_id{
359 my ($self, $uid) = @_;
360
361 my ($echip);
362
363 throw("Must supply a ExperimentalChip unque_id") if(! defined $uid);
364
365 $self->{'experimental_chips'} || $self->get_ExperimentalChips();
366
367 if(exists $self->{'experimental_chips'}->{$uid}){
368 $echip = $self->{'experimental_chips'}->{$uid};
369 }
370 #should we warn here if not exists?
371
372 return $echip;
373 }
374
375
376 =head2 get_ExperimentalChip_unique_ids
377
378 Example : foreach my $uid(@{$self->experiment->get_ExperimentalChip_unique_ids()}){ ... }
379 Description : retrieves all ExperimentalChip unique_ids
380 Returntype : ListRef
381 Exceptions : None
382 Caller : General
383 Status : At risk
384
385 =cut
386
387 sub get_ExperimentalChip_unique_ids{
388 my $self = shift;
389
390 $self->{'experimental_chips'} || $self->get_ExperimentalChips();
391
392 return [keys %{ $self->{'experimental_chips'}}];
393 }
394
395
396
397
398 ### Deprecated methods ###
399
400
401 sub group{
402 my $self = shift;
403
404 deprecate("group is deprecated experimental_group instead");
405 throw("You are trying to set a experimental group name using a deprecated method") if @_;
406 return $self->experimental_group()->name;
407 }
408
409
410
411 sub group_id{
412 my ($self) = shift;
413
414 deprecate("Experiment->group_id is deprecated. Use exp->experimental_group->dbID instead");
415 return $self->experimental_group()->dbID;
416 }
417
418
419
420 sub archive_id{ #deprecated in v68
421 #would deprecate, but no easy way of doing this reliably
422 throw("Use InputSubset->archive_id");
423 }
424
425
426 sub data_url{ #deprecated in v68
427 #would deprecate, but no easy way of doing this reliably
428 throw("Use InputSubset->display_url");
429 }
430
431
432 sub source_info{ #deprecated in v68
433 #would deprecate, but no easy way of doing this reliably
434 throw("Use InputSubset->source_info");
435 }
436
437
438 1;
439