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