EnsEMBL/RNAProduct.pm untested

filter: Statementstmt 0.0% 0 / 212 Branchbran 0.0% 0 / 78 Conditioncond 0.0% 0 / 30 Subroutinesub 0.0% 0 / 39 Podpod 0.0% 0 / 29 totaltotal 0.0% 0 / 388 CC 40 SCAR 24.7
CC
40
Cov
0%
transcript
42.0
get_all_DBEntries
20.0
seq
20.0
CRAP 11.8
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 =head1 CONTACT
22  
23 Please email comments or questions to the public Ensembl
24 developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
25  
26 Questions may also be sent to the Ensembl help desk at
27 <http://www.ensembl.org/Help/Contact>.
28  
29 =cut
30  
31 =head1 NAME
32  
33 Bio::EnsEMBL::RNAProduct - A class representing the mature RNA product
34 of a transcript
35  
36 =head1 DESCRIPTION
37  
38 Objects of this class represent mature RNA products of
39 transcripts. Examples of such products include MicroRNA (miRNA),
40 circular RNA (circRNA) or piwi-interacting RNA (piRNA), and they
41 commonly play a role in gene expression.
42  
43 =head1 SYNOPSIS
44  
45 my $rnaproduct = Bio::EnsEMBL::RNAProduct->new(
46 -SEQ_START => 36,
47 -SEQ_END => 58
48 );
49  
50 # Stable-ID setter
51 $rnaproduct->stable_id('ENSS00090210');
52  
53 # Get start and end position in the precursor transcript
54 my $start = $rnaproduct->start();
55 my $end = $rnaproduct->end();
56  
57 =cut
58  
59  
60 package Bio::EnsEMBL::RNAProduct;
61 $Bio::EnsEMBL::RNAProduct::VERSION = '114.0.0_50'; # TRIAL
62 $Bio::EnsEMBL::RNAProduct::VERSION = '114.0.050';
63 use vars qw($AUTOLOAD);
64 use strict;
65 use warnings;
66  
67 use Bio::EnsEMBL::Utils::Exception qw(throw warning );
68 use Bio::EnsEMBL::Utils::Argument qw( rearrange );
69 use Bio::EnsEMBL::Utils::RNAProductTypeMapper;
70 use Bio::EnsEMBL::Utils::Scalar qw( assert_ref wrap_array );
71 use Scalar::Util qw(weaken);
72  
73 use Bio::EnsEMBL::Storable;
74  
75 use parent qw(Bio::EnsEMBL::Storable);
76  
77  
78 =head2 new
79  
80 Arg [-SEQ_START] : The offset in the Transcript indicating the start
81 position of the product sequence.
82 Arg [-SEQ_END] : The offset in the Transcript indicating the end
83 position of the product sequence.
84 Arg [-START_EXON] : The Exon object in which the RNAProduct starts
85 Arg [-END_EXON] : The Exon object in which the RNAProduct ends
86 Arg [-STABLE_ID] : The stable identifier for this RNAPRoduct
87 Arg [-VERSION] : The version of the stable identifier
88 Arg [-DBID] : The internal identifier of this RNAProduct
89 Arg [-ADAPTOR] : The RNAProductAdaptor for this RNAProduct
90 Arg [-SEQ] : Manually sets the nucleotide sequence of this
91 RNAProduct. May be useful if this RNAProduct is not
92 stored in a database.
93 Arg [-CREATED_DATE] : the date the RNAProduct was created
94 Arg [-MODIFIED_DATE]: the date the RNAProduct was modified
95 Example : my $rp = Bio::EnsEMBL::RNAProduct->new(
96 -SEQ_START => 36,
97 -SEQ_END => 58
98 );
99 Description: Constructor. Creates a new RNAProduct object
100 Returntype : Bio::EnsEMBL::RNAProduct
101 Exceptions : none
102 Caller : general
103 Status : In Development
104  
105 =cut
106  
107 # perlcritic doesn't know about rearrange(), silence it
108 sub new { ## no critic (Subroutines::RequireArgUnpacking)
109 my $caller = shift;
110  
111 my $class = ref($caller) || $caller;
112  
113 my $type_code = Bio::EnsEMBL::Utils::RNAProductTypeMapper::mapper()
114 ->class_to_type_code($class);
115  
116 my ($seq_start, $seq_end, $start_exon, $end_exon, $stable_id, $version, $dbID,
117 $adaptor, $seq, $created_date, $modified_date ) =
118 rearrange(["SEQ_START", "SEQ_END", "START_EXON", "END_EXON",
119 "STABLE_ID", "VERSION", "DBID", "ADAPTOR", "SEQ",
120 "CREATED_DATE", "MODIFIED_DATE"], @_);
121  
122 # For consistency between stable_id() and stable_id_version()
123 $stable_id //= '';
124  
125 # Default version
126 $version //= 1;
127  
128 my $self = bless {
129 'start' => $seq_start,
130 'end' => $seq_end,
131 'start_exon' => $start_exon,
132 'end_exon' => $end_exon,
133 'stable_id' => $stable_id,
134 'version' => $version,
135 'dbID' => $dbID,
136 'seq' => $seq,
137 'created_date' => $created_date,
138 'modified_date' => $modified_date,
139 'type_code' => $type_code,
140 }, $class;
141  
142 $self->adaptor($adaptor);
143  
144 return $self;
145 }
146  
147  
148 =head2 add_Attributes
149  
150 Arg [1..N] : Bio::EnsEMBL::Attribute $attribute
151 Attributes to add.
152 Example : $rnaproduct->add_Attributes($selenocysteine_attribute);
153 Description: Adds an Attribute to the RNAProduct.
154 If you add an attribute before you retrieve any from database,
155 lazy load will be disabled.
156 Returntype : none
157 Exceptions : throw on incorrect arguments
158 Caller : general
159 Status : Stable
160  
161 =cut
162  
163 sub add_Attributes {
164 my ($self, @attribs) = @_;
165  
166 if (! exists $self->{'attributes'}) {
167 $self->{'attributes'} = [];
168 }
169  
170 for my $attrib (@attribs) {
171 if (! $attrib->isa("Bio::EnsEMBL::Attribute")) {
172 throw("Argument to add_Attribute must be a Bio::EnsEMBL::Attribute");
173 }
174 push (@{$self->{'attributes'}}, $attrib);
175  
176 # Invalidate the current sequence string in case the new attribute is a SeqEdit
177 $self->{seq} = undef;
178 }
179  
180 return;
181 }
182  
183  
184 =head2 add_DBEntry
185  
186 Arg [1] : Bio::EnsEMBL::DBEntry $dbe
187 The dbEntry to be added
188 Example : $rnaproduct->add_DBEntry($xref);
189 Description: Associates a DBEntry with this RNAProduct. Note that adding
190 DBEntries will prevent future lazy-loading of DBEntries for this
191 RNAProduct (see get_all_DBEntries).
192 Returntype : none
193 Exceptions : thrown on incorrect argument type
194 Caller : general
195 Status : Stable
196  
197 =cut
198  
199 sub add_DBEntry {
200 my ($self, $dbe) = @_;
201  
202 if (!$dbe || !ref($dbe) || !$dbe->isa('Bio::EnsEMBL::DBEntry')) {
203 throw('Expected DBEntry argument');
204 }
205  
206 $self->{'dbentries'} ||= [];
207 push @{$self->{'dbentries'}}, $dbe;
208  
209 return;
210 }
211  
212  
213 =head2 cdna_end
214  
215 Example : $rnaproduct_cdna_end = $rnaproduct->cdna_end();
216 Description : Returns the end position of the RNAProduct in cDNA
217 coordinates.
218 Since RNAProducts do not span multiple exons, this is
219 simply an alias for end().
220 Return type : Integer
221 Caller : General
222 Status : Stable
223  
224 =cut
225  
226 sub cdna_end {
227 my $self = shift;
228  
229 return $self->end();
230 }
231  
232  
233 =head2 cdna_start
234  
235 Example : $rnaproduct_cdna_start = $rnaproduct->cdna_start();
236 Description : Returns the start position of the RNAProduct in cDNA
237 coordinates.
238 Since RNAProducts do not span multiple exons, this is
239 simply an alias for start().
240 Return type : Integer
241 Caller : General
242 Status : Stable
243  
244 =cut
245  
246 sub cdna_start {
247 my $self = shift;
248  
249 return $self->start();
250 }
251  
252  
253 =head2 created_date
254  
255 Arg [1] : (optional) string $created_date - created date to set
256 Example : $rnaproduct->created_date('2007-01-10 20:52:00');
257 Description: Getter/setter for attribute created_date
258 Returntype : string
259 Exceptions : none
260 Caller : general
261 Status : Stable
262  
263 =cut
264  
265 sub created_date {
266 my $self = shift;
267 if ( @_ ) {
268 $self->{'created_date'} = shift;
269 }
270 return $self->{'created_date'};
271 }
272  
273  
274 =head2 display_id
275  
276 Example : print $rnaproduct->display_id();
277 Description: This method returns a string that is considered to be
278 the 'display' identifier. For RNAProducts this is (depending on
279 availability and in this order) the stable ID, the dbID or an
280 empty string.
281 Returntype : string
282 Exceptions : none
283 Caller : web drawing code
284 Status : Stable
285  
286 =cut
287  
288 sub display_id {
289 my $self = shift;
290 return $self->stable_id() || $self->dbID() || '';
291 }
292  
293  
294 =head2 end
295  
296 Arg [1] : (optional) int $end - end position to set
297 Example : $rnaproduct->end(39);
298 Description: Getter/setter for the value of end, which is a position within
299 the precursor Transcript.
300 Returntype : int
301 Exceptions : none
302 Caller : general
303 Status : Stable
304  
305 =cut
306  
307 sub end {
308 my $self = shift;
309 if ( @_ ) {
310 $self->{'end'} = shift;
311 }
312 return $self->{'end'};
313 }
314  
315  
316 =head2 end_Exon
317  
318 Arg [1] : (optional) Bio::EnsEMBL::Exon || undef - start exon to assign
319 Example : $rnaproduct->end_Exon($exon1);
320 Description: Getter/setter for the value of end_Exon, which denotes the
321 exon at which RNAProduct ends.
322 Returntype : Bio::EnsEMBL::Exon
323 Exceptions : thrown on wrong argument type
324 Caller : general
325 Status : Stable
326  
327 =cut
328  
329 sub end_Exon {
330 my ($self, $exon) = @_;
331  
332 if (defined($exon)) {
333  
334 # Normal setter
335 assert_ref($exon, 'Bio::EnsEMBL::Exon');
336 $self->{'end_exon'} = $exon;
337  
338 }
339 elsif (@_ > 1) {
340 # User has explicitly passed undef. Break connection to exon.
341 delete( $self->{'end_exon'} );
342 }
343  
344 return $self->{'end_exon'};
345 }
346  
347  
348 =head2 genomic_end
349  
350 Args : None
351 Example : $rnaproduct_genomic_end = $rnaproduct->genomic_end();
352 Description : Returns the end position of the RNAProduct in genomic
353 coordinates on the forward strand.
354 Return type : Integer
355 Exceptions : None
356 Caller : General
357 Status : Stable
358  
359 =cut
360  
361 sub genomic_end {
362 my $self = shift;
363  
364 if (!exists $self->{'genomic_end'}) {
365 my $transcript = $self->transcript();
366  
367 if ($transcript->strand() >= 0) {
368 $self->{'genomic_end'} =
369 $transcript->start() + ($self->end() - 1);
370 } else {
371 $self->{'genomic_end'} =
372 $transcript->end() - ($self->start() - 1);
373 }
374 }
375  
376 return $self->{'genomic_end'};
377 }
378  
379  
380 =head2 genomic_start
381  
382 Args : None
383 Example : $rnaproduct_genomic_start = $rnaproduct->genomic_start();
384 Description : Returns the start position of the RNAProduct in
385 genomic coordinates on the forward strand.
386 Return type : Integer
387 Exceptions : None
388 Caller : General
389 Status : Stable
390  
391 =cut
392  
393 sub genomic_start {
394 my $self = shift;
395  
396 if (!exists $self->{'genomic_start'}) {
397 my $transcript = $self->transcript();
398  
399 if ($transcript->strand() >= 0) {
400 $self->{'genomic_start'} =
401 $transcript->start() + ($self->start() - 1);
402 } else {
403 $self->{'genomic_start'} =
404 $transcript->end() - ($self->end() - 1);
405 }
406 }
407  
408 return $self->{'genomic_start'};
409 }
410  
411  
412 =head2 get_all_Attributes
413  
414 Arg [1] : optional string $attrib_code
415 The code of the attribute type to retrieve values for.
416 Example : ($n_attr) = @{$tl->get_all_Attributes('note')};
417 @rp_attributes = @{$rnaproduct->get_all_Attributes()};
418 Description: Gets a list of Attributes of this RNAProduct.
419 Optionally just get Attributes for given code.
420 Returntype : listref Bio::EnsEMBL::Attribute
421 Exceptions : none
422 Caller : general
423 Status : Stable
424  
425 =cut
426  
427 sub get_all_Attributes {
428 my ($self, $attrib_code) = @_;
429  
430 # If not cached, retrieve all of the attributes for this RNAProduct
431 if (!defined($self->{'attributes'}) && defined($self->adaptor())) {
432 my $aa = $self->adaptor->db->get_AttributeAdaptor();
433 $self->{'attributes'} = $aa->fetch_all_by_RNAProduct($self);
434 }
435  
436 if (defined $attrib_code) {
437 my @results = grep { uc($_->code()) eq uc($attrib_code) }
438 @{$self->{'attributes'}};
439 return \@results;
440 } else {
441 return $self->{'attributes'};
442 }
443 }
444  
445  
446 =head2 get_all_DBEntries
447  
448 Arg [1] : (optional) String, external database name,
449 SQL wildcard characters (_ and %) can be used to
450 specify patterns.
451  
452 Arg [2] : (optional) String, external_db type,
453 ('ARRAY','ALT_TRANS','ALT_GENE','MISC','LIT','PRIMARY_DB_SYNONYM','ENSEMBL'),
454 SQL wildcard characters (_ and %) can be used to
455 specify patterns.
456  
457 Example : my @dbentries = @{ $rnaproduct->get_all_DBEntries() };
458 @dbentries = @{ $rnaproduct->get_all_DBEntries('Uniprot%') };
459 @dbentries = @{ $rnaproduct->get_all_DBEntries('%', 'ENSEMBL') };
460  
461 Description: Retrieves DBEntries (xrefs) for this RNAProduct.
462  
463 This method will attempt to lazy-load DBEntries
464 from a database if an adaptor is available and no
465 DBEntries are present on the RNAProduct (i.e. they
466 have not already been added or loaded).
467  
468 Returntype : Listref to Bio::EnsEMBL::DBEntry objects
469 Exceptions : none
470 Caller : ?
471 Status : Stable
472  
473 =cut
474  
475 sub get_all_DBEntries {
476 my ($self, $ex_db_exp, $ex_db_type) = @_;
477  
478 my $cache_name = 'dbentries';
479  
480 if (defined($ex_db_exp)) {
481 $cache_name .= $ex_db_exp;
482 }
483  
484 if (defined($ex_db_type)) {
485 $cache_name .= $ex_db_type;
486 }
487  
488 # If not cached, retrieve all of the xrefs for this RNAProduct
489 if (!defined($self->{$cache_name}) && defined($self->adaptor())) {
490 $self->{$cache_name} = $self->adaptor()->db()->get_DBEntryAdaptor()->
491 fetch_all_by_RNAProduct( $self, $ex_db_exp, $ex_db_type );
492 }
493  
494 $self->{$cache_name} ||= [];
495  
496 return $self->{$cache_name};
497 }
498  
499  
500  
501  
502  
503 =head2 get_all_DBLinks
504  
505 Arg [1] : (optional) String, database name
506 SQL wildcard characters (_ and %) can be used to
507 specify patterns.
508  
509 Arg [2] : (optional) String, external database type, can be one of
510 ('ARRAY','ALT_TRANS','ALT_GENE','MISC','LIT','PRIMARY_DB_SYNONYM','ENSEMBL'),
511 SQL wildcard characters (_ and %) can be used to
512 specify patterns.
513  
514 Example : my @dblinks = @{ $rnaproduct->get_all_DBLinks() };
515 @dblinks = @{ $rnaproduct->get_all_DBLinks('mirbase%') };
516 @dblinks = @{ $rnaproduct->get_all_DBLinks('%', 'ENSEMBL') };
517  
518 Description: This is here for consistancy with the Transcript
519 and Gene classes. It is a synonym for the
520 get_all_DBEntries() method.
521  
522 Return type: Listref to Bio::EnsEMBL::DBEntry objects
523 Exceptions : none
524 Caller : general
525 Status : Stable
526  
527 =cut
528  
529 # this is an alias, we do NOT want to unpack @_
530 sub get_all_DBLinks { ## no critic (Subroutines::RequireArgUnpacking)
531 my $self = shift;
532 return $self->get_all_DBEntries(@_);
533 }
534  
535  
536 =head2 get_all_object_xrefs
537  
538 Arg [1] : (optional) String, external database name
539  
540 Arg [2] : (optional) String, external_db type
541  
542 Example : @oxrefs = @{ $rnaproduct->get_all_object_xrefs() };
543  
544 Description: Retrieves xrefs for this RNAProduct.
545  
546 This method will attempt to lazy-load xrefs from a
547 database if an adaptor is available and no xrefs
548 are present on the RNAProduct (i.e. they have not
549 already been added or loaded).
550  
551 NB: This method is an alias for the
552 get_all_DBentries() method.
553  
554 Return type: Listref of Bio::EnsEMBL::DBEntry objects
555  
556 Status : Stable
557  
558 =cut
559  
560 # this is an alias, we do NOT want to unpack @_
561 sub get_all_object_xrefs { ## no critic (Subroutines::RequireArgUnpacking)
562 my $self = shift;
563 return $self->get_all_DBEntries(@_);
564 }
565  
566  
567 =head2 get_all_xrefs
568  
569 Arg [1] : String database name (optional)
570 SQL wildcard characters (_ and %) can be used to
571 specify patterns.
572  
573 Example : @xrefs = @{ $rnaproduct->get_all_xrefs() };
574 @xrefs = @{ $rnaproduct->get_all_xrefs('mirbase%') };
575  
576 Description: This method is here for consistancy with the Gene
577 and Transcript classes. It is an alias for the
578 get_all_DBLinks() method, which in turn directly
579 calls get_all_DBEntries().
580  
581 Return type: Listref of Bio::EnsEMBL::DBEntry objects
582  
583 Status : Stable
584  
585 =cut
586  
587 # this is an alias, we do NOT want to unpack @_
588 sub get_all_xrefs { ## no critic (Subroutines::RequireArgUnpacking)
589 my $self = shift;
590 return $self->get_all_DBLinks(@_);
591 }
592  
593  
594 =head2 modified_date
595  
596 Arg [1] : (optional) string $modified_date - modification date to set
597 Example : $rnaproduct->modified_date('2007-01-10 20:52:00');
598 Description: Getter/setter for attribute modified_date
599 Returntype : string
600 Exceptions : none
601 Caller : general
602 Status : Stable
603  
604 =cut
605  
606 sub modified_date {
607 my $self = shift;
608 if ( @_ ) {
609 $self->{'modified_date'} = shift;
610 }
611 return $self->{'modified_date'};
612 }
613  
614  
615 =head2 length
616  
617 Example : print "RNA length =", $rnaproduct->length();
618 Description: Retrieves the length of the nucleotide sequence represented
619 by this RNAProduct object.
620 Returntype : int
621 Exceptions : none
622 Caller : webcode (protview etc.)
623 Status : Stable
624  
625 =cut
626  
627 # PBP do allow homonyms as methods but perlcritic cannot, tell these
628 # apart from the forbidden ones, as stated in the documentation of the
629 # relevant policy
630 sub length { ## no critic (Subroutines::ProhibitBuiltinHomonyms)
631 my $self = shift;
632 my $seq = $self->seq();
633  
634 return ($seq) ? CORE::length($seq) : 0;
635 }
636  
637  
638 =head2 load
639  
640 Arg [1] : Boolean $load_xrefs
641 Load (or don't load) xrefs. Default is to load xrefs.
642 Example : $rnaproduct->load();
643 Description : The Ensembl API makes extensive use of
644 lazy-loading. Under some circumstances (e.g.,
645 when copying genes between databases), all data of
646 an object needs to be fully loaded. This method
647 loads the parts of the object that are usually
648 lazy-loaded.
649 Returns : none
650  
651 =cut
652  
653 sub load {
654 my ($self, $load_xrefs) = @_;
655  
656 if ( !defined $load_xrefs ) {
657 $load_xrefs = 1;
658 }
659  
660 $self->seq();
661  
662 $self->stable_id();
663 $self->get_all_Attributes();
664  
665 if ($load_xrefs) {
666 $self->get_all_DBEntries();
667 }
668  
669 return;
670 }
671  
672  
673 =head2 seq
674  
675 Example : print $rnaproduct->seq();
676 Description: Retrieves a string representation of the nucleotide sequence
677 of this RNAProduct. This retrieves the transcript from the
678 database and gets its sequence, or retrieves the sequence which
679 was set via the constructor/setter.
680 Returntype : string
681 Exceptions : warning if the sequence is not set and cannot be retrieved from
682 the database.
683 Caller : webcode (protview etc.)
684 Status : Stable
685  
686 =cut
687  
688 sub seq {
689 my ($self, $sequence) = @_;
690  
691 if (defined($sequence)) {
692  
693 $self->{'seq'} = $sequence;
694  
695 } elsif (!defined($self->{'seq'})) {
696  
697 my $tr_seq = $self->transcript()->seq();
698 if ($tr_seq->length() <= 0) {
699 throw('Got no or empty sequence from the database');
700 }
701 $self->{'seq'} = $tr_seq->subseq($self->{'start'}, $self->{'end'});
702  
703 }
704  
705 return ( $self->{'seq'} // q{} );
706 }
707  
708  
709 =head2 stable_id
710  
711 Arg [1] : (optional) string $stable_id - stable ID to set
712 Example : $rnaproduct->stable_id('ENSS00090210');
713 Description: Getter/setter for attribute stable_id.
714 Unlike stable_id_version(), setting a new stable ID does NOT
715 reset the version number.
716 Returntype : string
717 Exceptions : none
718 Caller : general
719 Status : Stable
720  
721 =cut
722  
723 sub stable_id {
724 my $self = shift;
725 if ( @_ ) {
726 $self->{'stable_id'} = shift;
727 }
728 return $self->{'stable_id'};
729 }
730  
731  
732 =head2 stable_id_version
733  
734 Arg [1] : (optional) String - the stable ID with version to set
735 Example : $rnaproduct->stable_id("ENSS0059890.3");
736 Description: Getter/setter for stable id with version for this RNAProduct.
737 If the input string omits the version part, the version gets reset
738 to undef; use stable_id() if you want to avoid this.
739 Returntype : String
740 Exceptions : none
741 Caller : general
742 Status : Stable
743  
744 =cut
745  
746 sub stable_id_version {
747 my $self = shift;
748  
749 if (my $stable_id = shift) {
750 # If there is at least one embedded period assume everything
751 # beyond the last one is the version number. This may not work for
752 # some species, if you are worried about ambiguity use stable_id() +
753 # version() explicitly.
754 my $vindex = rindex($stable_id, '.');
755 ($self->{stable_id},
756 $self->{version}) = ($vindex > 0 ?
757 (substr($stable_id, 0, $vindex),
758 substr($stable_id, $vindex + 1)) :
759 $stable_id, undef
760 );
761 }
762  
763 return $self->{stable_id} . ($self->{version} ? ".$self->{version}" : '');
764 }
765  
766  
767 =head2 start
768  
769 Arg [1] : (optional) int $start - start position to set
770 Example : $rnaproduct->start(17);
771 Description: Getter/setter for the value of start, which is a position within
772 the precursor Transcript.
773 Returntype : int
774 Exceptions : none
775 Caller : general
776 Status : Stable
777  
778 =cut
779  
780 sub start {
781 my $self = shift;
782 if ( @_ ) {
783 $self->{'start'} = shift;
784 }
785 return $self->{'start'};
786 }
787  
788  
789 =head2 start_Exon
790  
791 Arg [1] : (optional) Bio::EnsEMBL::Exon || undef - start exon to assign
792 Example : $rnaproduct->start_Exon($exon1);
793 Description: Getter/setter for the value of start_Exon, which denotes the
794 exon at which RNAProduct starts.
795 Returntype : Bio::EnsEMBL::Exon
796 Exceptions : thrown on wrong argument type
797 Caller : general
798 Status : Stable
799  
800 =cut
801  
802 sub start_Exon {
803 my ($self, $exon) = @_;
804  
805 if (defined($exon)) {
806  
807 # Normal setter
808 assert_ref($exon, 'Bio::EnsEMBL::Exon');
809 $self->{'start_exon'} = $exon;
810  
811 }
812 elsif (@_ > 1) {
813 # User has explicitly passed undef. Break connection to exon.
814 delete( $self->{'start_exon'} );
815 }
816  
817 return $self->{'start_exon'};
818 }
819  
820  
821 =head2 summary_as_hash
822  
823 Example : $rnaproduct_summary = $rnaproduct->summary_as_hash();
824 Description : Retrieves a textual summary of this RNAProduct.
825 Not inherited from Feature.
826 Returns : hashref of arrays of descriptive strings
827 Status : Intended for internal use
828  
829 =cut
830  
831 sub summary_as_hash {
832 my $self = shift;
833 my %summary;
834 my $id = $self->display_id;
835 if ($self->version) {
836 $id .= "." . $self->version;
837 }
838 $summary{'id'} = $id;
839 $summary{'rnaproduct_id'} = $id;
840 $summary{'genomic_start'} = $self->genomic_start;
841 $summary{'genomic_end'} = $self->genomic_end;
842 $summary{'length'} = $self->length;
843 my $transcript = $self->transcript;
844 $summary{'Parent'} = $transcript->display_id;
845 return \%summary;
846 }
847  
848  
849 =head2 synchronise_attributes
850  
851 Example : $rnaproduct->synchronise_attributes();
852 Description : Some RNAProduct attributes, e.g. stem-loop arm in case
853 of MicroRNA, use a local cache of their value for
854 convenience. Unless the corresponding setters update both
855 the cache value and the attribute (which would defeat
856 the convenience thing), we have to make sure the former
857 get propagated to the latter before storing the object
858 in the database:
859 - if no corresponding attribute exists, create one;
860 - if there is one, update its value.
861 Class-specific maps of attributes to synchronise are
862 provided by
863 RNAProductTypeMapper::class_attribute_cache_map() .
864 Returntype : none
865 Exceptions : throws if the object contains multiple attributes with the
866 given code and the choice which one to update is
867 ambiguous.
868 Caller : RNAProductAdaptor
869 Status : At Risk (In Development)
870  
871 =cut
872  
873 sub synchronise_attributes {
874 my ($self) = @_;
875  
876 my $attribute_cache_map = Bio::EnsEMBL::Utils::RNAProductTypeMapper::mapper()
877 ->class_attribute_cache_map(ref($self));
878  
879 while (my ($cache_key, $attr_code) = each %{$attribute_cache_map}) {
880 my $existing_attributes = $self->get_all_Attributes($attr_code);
881 my $n_existing_attrs = scalar @{$existing_attributes};
882 if ($n_existing_attrs > 0) {
883 # At the moment we do not support multiple occurrences of target
884 # attributes at all
885 if ($n_existing_attrs > 1) {
886 throw("Object has multiple '$attr_code' attributes and we do not know"
887 . " which one to update");
888 }
889 else {
890 $existing_attributes->[0]->value($self->{$cache_key});
891 }
892 }
893 else {
894 # No corresponding attribute exists, most likely because we are
895 # dealing with a newly created object which has never been pushed
896 # to the database.
897 $self->add_Attributes(Bio::EnsEMBL::Attribute->new(
898 -CODE => $attr_code,
899 -VALUE => $self->{$cache_key},
900 ));
901 }
902 }
903  
904 return;
905 }
906  
907  
908 =head2 transcript
909  
910 Arg [1] : Transcript object (optional)
911 Description : Sets or retrieves the transcript object associated
912 with this RNAProduct object.
913 Exceptions : Throws if there is no adaptor or no dbID defined for
914 the RNAProduct object.
915 Returntype : Bio::EnsEMBL::Transcript
916  
917 =cut
918  
919 sub transcript {
920 my ($self, $transcript) = @_;
921  
922 if (defined($transcript)) {
923  
924 # Normal setter
925 assert_ref($transcript, 'Bio::EnsEMBL::Transcript');
926 $self->{'transcript'} = $transcript;
927 weaken($self->{'transcript'}); # Avoid circular references.
928  
929 } elsif (@_ > 1) {
930  
931 # User has explicitly passed undef. Break connection to transcript.
932 delete( $self->{'transcript'} );
933  
934 } elsif (!defined($self->{'transcript'})) {
935 my $adaptor = $self->{'adaptor'};
936 if (!defined($adaptor)) {
937 throw("Adaptor not set for RNAProduct, cannot fetch its transcript");
938 }
939  
940 my $dbID = $self->{'dbID'};
941 if (!defined($dbID)) {
942 throw("dbID not set for RNAProduct, cannot fetch its transcript.");
943 }
944  
945 $self->{'transcript'} =
946 $adaptor->db()->get_TranscriptAdaptor()
947 ->fetch_by_rnaproduct_id($dbID);
948  
949 # Do not weaken the reference if we had to get the transcript from the
950 # database. The user is probably working on RNA products directly,
951 # not going through transcripts.
952 }
953  
954 return $self->{'transcript'};
955 }
956  
957  
958 =head2 type_code
959  
960 Example : my $rp_type_code = $rnaproduct->type_code();
961 Description: Getter for the RNAProduct type (e.g. miRNA, circRNA, ...).
962 The type is expressed as human-readable code.
963 This is somewhat redundant because similar information can
964 be obtained simply by looking at the class of the object,
965 indeed type_code is not meant to be modified independently
966 of the class. However, there are certain use cases when the
967 latter are more convenient than the former.
968 Returntype : string
969 Exceptions : none
970 Caller : ?
971 Status : In Development
972  
973 =cut
974  
975 sub type_code {
976 my $self = shift;
977 return $self->{'type_code'};
978 }
979  
980  
981 =head2 version
982  
983 Arg [1] : (optional) string $version - version to set
984 Example : $rnaproduct->version(2);
985 Description: Getter/setter for attribute version
986 Returntype : string
987 Exceptions : none
988 Caller : general
989 Status : Stable
990  
991 =cut
992  
993 sub version {
994 my $self = shift;
995 if ( @_ ) {
996 $self->{'version'} = shift;
997 }
998 return $self->{'version'};
999 }
1000  
1001 1;