EnsEMBL/OperonTranscript.pm untested

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