EnsEMBL/OperonTranscript.pm untested

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