EnsEMBL/Operon.pm untested

filter: Statementstmt 0.0% 0 / 100 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 18 Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 12 totaltotal 0.0% 0 / 183 CC 18 SCAR 23.2
CC
18
Cov
0%
stable_id_version
20.0
get_all_Attributes
20.0
get_all_DBEntries
20.0
CRAP 10.2
1 =head1 LICENSE
2  
3 See the NOTICE file distributed with this work for additional information
4 regarding copyright ownership.
5  
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9  
10 http://www.apache.org/licenses/LICENSE-2.0
11  
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17  
18 =cut
19  
20  
21  
22 =head1 CONTACT
23  
24 Please email comments or questions to the public Ensembl
25 developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
26  
27 Questions may also be sent to the Ensembl help desk at
28 <http://www.ensembl.org/Help/Contact>.
29  
30 =cut
31  
32 =head1 NAME
33  
34 Bio::EnsEMBL::Operon - Object representing an operon
35  
36 =head1 SYNOPSIS
37  
38 my $operon = Bio::EnsEMBL::Operon->new(
39 -START => 123,
40 -END => 1045,
41 -STRAND => 1,
42 -SLICE => $slice,
43 -DISPLAY_LABEL => $name
44 );
45  
46 # print operon information
47 print("operon start:end:strand is "
48 . join( ":", map { $operon->$_ } qw(start end strand) )
49 . "\n" );
50  
51 =head1 DESCRIPTION
52  
53 A representation of an Operon within the Ensembl system.
54 An operon is a collection of one or more polycistronic transcripts which contain one or more genes.
55  
56 =head1 METHODS
57  
58 =cut
59  
60 package Bio::EnsEMBL::Operon;
61 $Bio::EnsEMBL::Operon::VERSION = '114.0.0_50'; # TRIAL
62 $Bio::EnsEMBL::Operon::VERSION = '114.0.050';
63 use strict;
64 use warnings;
65  
66 use Bio::EnsEMBL::Feature;
67 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
68 use Bio::EnsEMBL::Utils::Exception qw(throw warning);
69 use Bio::EnsEMBL::Utils::Scalar qw(assert_ref);
70  
71 use vars qw(@ISA);
72 @ISA = qw(Bio::EnsEMBL::Feature);
73  
74 =head2 new
75  
76 Arg [-START] :
77 int - start postion of the operon
78 Arg [-END] :
79 int - end position of the operon
80 Arg [-STRAND] :
81 int - 1,-1 the strand the operon is on
82 Arg [-SLICE] :
83 Bio::EnsEMBL::Slice - the slice the operon is on
84 Arg [-STABLE_ID] :
85 string - the stable identifier of this operon
86 Arg [-VERSION] :
87 int - the version of the stable identifier of this operon
88 Arg [-DISPLAY_LABEL]:
89 A name/label for this operon
90 Arg [-CREATED_DATE]:
91 string - the date the operon was created
92 Arg [-MODIFIED_DATE]:
93 string - the date the operon was last modified
94  
95 Example : $gene = Bio::EnsEMBL::Operon->new(...);
96 Description: Creates a new operon object
97 Returntype : Bio::EnsEMBL::Operon
98 Exceptions : none
99 Caller : general
100 Status : Stable
101  
102 =cut
103  
104 sub new {
105 my $caller = shift;
106  
107 my $class = ref($caller) || $caller;
108 my $self = $class->SUPER::new(@_);
109 my ( $stable_id, $version, $created_date, $modified_date,$display_label) =
110 rearrange( [ 'STABLE_ID', 'VERSION',
111 'CREATED_DATE', 'MODIFIED_DATE',
112 'DISPLAY_LABEL' ],
113 @_ );
114  
115 $self->stable_id($stable_id);
116 $self->version($version);
117 $self->{'created_date'} = $created_date;
118 $self->{'modified_date'} = $modified_date;
119 $self->display_label($display_label);
120  
121 return $self;
122 }
123  
124 =head2 created_date
125  
126 Arg [1] : (optional) String - created date to set (as a UNIX time int)
127 Example : $gene->created_date('1141948800');
128 Description: Getter/setter for attribute created_date
129 Returntype : String
130 Exceptions : none
131 Caller : general
132 Status : Stable
133  
134 =cut
135  
136 sub created_date {
137 my $self = shift;
138 $self->{'created_date'} = shift if ( @_ );
139 return $self->{'created_date'};
140 }
141  
142  
143 =head2 modified_date
144  
145 Arg [1] : (optional) String - modified date to set (as a UNIX time int)
146 Example : $gene->modified_date('1141948800');
147 Description: Getter/setter for attribute modified_date
148 Returntype : String
149 Exceptions : none
150 Caller : general
151 Status : Stable
152  
153 =cut
154  
155 sub modified_date {
156 my $self = shift;
157 $self->{'modified_date'} = shift if ( @_ );
158 return $self->{'modified_date'};
159 }
160  
161  
162 =head2 display_label
163  
164 Arg [1] : (optional) String - the name/label to set
165 Example : $operon->name('accBCD');
166 Description: Getter/setter for attribute name.
167 Returntype : String or undef
168 Exceptions : none
169 Caller : general
170 Status : Stable
171  
172 =cut
173  
174 sub display_label {
175 my $self = shift;
176 $self->{'display_label'} = shift if (@_);
177 return $self->{'display_label'};
178 }
179  
180 =head2 stable_id
181  
182 Arg [1] : (optional) String - the stable ID to set
183 Example : $operon->stable_id("accR2");
184 Description: Getter/setter for stable id for this operon.
185 Returntype : String
186 Exceptions : none
187 Caller : general
188 Status : Stable
189  
190 =cut
191  
192 sub stable_id {
193 my $self = shift;
194 $self->{'stable_id'} = shift if (@_);
195 return $self->{'stable_id'};
196 }
197  
198 =head2 version
199  
200 Arg [1] : (optional) Int - the stable ID version to set
201 Example : $operon->version(1);
202 Description: Getter/setter for stable id version for this operon.
203 Returntype : Int
204 Exceptions : none
205 Caller : general
206 Status : Stable
207  
208 =cut
209 sub version {
210 my $self = shift;
211 $self->{'version'} = shift if(@_);
212 return $self->{'version'};
213 }
214  
215 =head2 stable_id_version
216  
217 Arg [1] : (optional) String - the stable ID with version to set
218 Example : $operon->stable_id("accR2.3");
219 Description: Getter/setter for stable id with version for this operon.
220 Returntype : String
221 Exceptions : none
222 Caller : general
223 Status : Stable
224  
225 =cut
226  
227 sub stable_id_version {
228 my $self = shift;
229 if(my $stable_id = shift) {
230 # See if there's an embedded period, assume that's a
231 # version, might not work for some species but you
232 # should use ->stable_id() and version() if you're worried
233 # about ambiguity
234 my $vindex = rindex($stable_id, '.');
235 # Set the stable_id and version pair depending on if
236 # we found a version delimiter in the stable_id
237 ($self->{stable_id}, $self->{version}) = ($vindex > 0 ?
238 (substr($stable_id,0,$vindex), substr($stable_id,$vindex+1)) :
239 $stable_id, undef);
240 }
241 return $self->{stable_id} . ($self->{version} ? ".$self->{version}" : '');
242 }
243  
244 =head2 get_all_OperonTranscripts
245  
246 Example : my $ots = $operon->get_all_OperonTranscripts();
247 Description: Retrieve all operon transcripts belonging to this operon
248 Returntype : Arrayref of Bio::EnsEMBL::OperonTranscript
249 Exceptions : none
250 Caller : general
251 Status : Stable
252  
253 =cut
254 sub get_all_OperonTranscripts {
255 my $self = shift;
256 if ( !exists $self->{'_operon_transcript_array'} ) {
257 if ( defined $self->adaptor() ) {
258 my $ta = $self->adaptor()->db()->get_OperonTranscriptAdaptor();
259 my $transcripts = $ta->fetch_all_by_Operon($self);
260 $self->{'_operon_transcript_array'} = $transcripts;
261 }
262 }
263 return $self->{'_operon_transcript_array'};
264 }
265  
266 =head2 add_OperonTranscript
267  
268 Arg [1] : Bio::EnsEMBL::OperonTranscript - operon transcript to attach to this operon
269 Example : $operon->add_OperonTranscript($ot);
270 Description: Attach a polycistronic operon transcript to this operon
271 Exceptions : if argument is not Bio::EnsEMBL::OperonTranscript
272 Caller : general
273 Status : Stable
274  
275 =cut
276 sub add_OperonTranscript {
277 my ( $self, $trans ) = @_;
278  
279 assert_ref($trans,"Bio::EnsEMBL::OperonTranscript");
280  
281 $self->{'_operon_transcript_array'} ||= [];
282 push( @{ $self->{'_operon_transcript_array'} }, $trans );
283  
284 #$self->recalculate_coordinates();
285 return;
286 }
287  
288 =head2 add_DBEntry
289  
290 Arg [1] : Bio::EnsEMBL::DBEntry $dbe
291 The dbEntry to be added
292 Example : my $dbe = Bio::EnsEMBL::DBEntery->new(...);
293 $operon->add_DBEntry($dbe);
294 Description: Associates a DBEntry with this operon. Note that adding DBEntries
295 will prevent future lazy-loading of DBEntries for this operon
296 (see get_all_DBEntries).
297 Returntype : none
298 Exceptions : thrown on incorrect argument type
299 Caller : general
300 Status : Stable
301  
302 =cut
303  
304 sub add_DBEntry {
305 my $self = shift;
306 my $dbe = shift;
307  
308 unless($dbe && ref($dbe) && $dbe->isa('Bio::EnsEMBL::DBEntry')) {
309 throw('Expected DBEntry argument');
310 }
311  
312 $self->{'dbentries'} ||= [];
313 push @{$self->{'dbentries'}}, $dbe;
314 }
315  
316  
317 =head2 get_all_Attributes
318  
319 Arg [1] : (optional) String $attrib_code
320 The code of the attribute type to retrieve values for
321 Example : my ($author) = @{ $operon->get_all_Attributes('author') };
322 my @operon_attributes = @{ $operon->get_all_Attributes };
323 Description: Gets a list of Attributes of this operon.
324 Optionally just get Attributes for given code.
325 Returntype : Listref of Bio::EnsEMBL::Attribute
326 Exceptions : warning if gene does not have attached adaptor and attempts lazy
327 load.
328 Caller : general
329 Status : Stable
330  
331 =cut
332  
333 sub get_all_Attributes {
334 my $self = shift;
335 my $attrib_code = shift;
336  
337 if ( !exists $self->{'attributes'} ) {
338 if ( !$self->adaptor() ) {
339 return [];
340 }
341  
342 my $attribute_adaptor = $self->adaptor->db->get_AttributeAdaptor();
343 $self->{'attributes'} = $attribute_adaptor->fetch_all_by_Operon($self);
344 }
345  
346 if ( defined $attrib_code ) {
347 my @results =
348 grep { uc( $_->code() ) eq uc($attrib_code) }
349 @{ $self->{'attributes'} };
350 return \@results;
351 } else {
352 return $self->{'attributes'};
353 }
354 }
355  
356 =head2 get_all_DBEntries
357  
358 Arg [1] : (optional) String, external database name
359  
360 Arg [2] : (optional) String, external_db type
361  
362 Example : @dbentries = @{ $gene->get_all_DBEntries() };
363  
364 Description: Retrieves DBEntries (xrefs) for this operon. This does
365 *not* include DBEntries that are associated with the
366 transcripts and corresponding translations of this
367 gene (see get_all_DBLinks()).
368  
369 This method will attempt to lazy-load DBEntries
370 from a database if an adaptor is available and no
371 DBEntries are present on the gene (i.e. they have not
372 already been added or loaded).
373  
374 Return type: Listref of Bio::EnsEMBL::DBEntry objects
375 Exceptions : none
376 Caller : get_all_DBLinks, OperonAdaptor::store
377 Status : Stable
378  
379 =cut
380  
381 sub get_all_DBEntries {
382 my ( $self, $db_name_exp, $ex_db_type ) = @_;
383  
384 my $cache_name = 'dbentries';
385  
386 if ( defined($db_name_exp) ) {
387 $cache_name .= $db_name_exp;
388 }
389  
390 if ( defined($ex_db_type) ) {
391 $cache_name .= $ex_db_type;
392 }
393  
394 # if not cached, retrieve all of the xrefs for this gene
395 if ( !defined( $self->{$cache_name} ) && defined( $self->adaptor() ) ) {
396 $self->{$cache_name} =
397 $self->adaptor()->db()->get_DBEntryAdaptor()
398 ->fetch_all_by_Operon( $self, $db_name_exp, $ex_db_type );
399 }
400  
401 $self->{$cache_name} ||= [];
402  
403 return $self->{$cache_name};
404 }
405  
406 1;
407