4 See the NOTICE file distributed with
this work
for additional information
5 regarding copyright ownership.
7 Licensed under the Apache License, Version 2.0 (the
"License");
8 you may not use
this file except in compliance with the License.
9 You may obtain a copy of the License at
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an
"AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License
for the specific language governing permissions and
17 limitations under the License.
23 Please email comments or questions to the
public Ensembl
24 developers list at <http:
26 Questions may also be sent to the Ensembl help desk at
34 between RNA-product types used in the Ensembl database and respective
39 The purpose of
this class is to hide from the users the mappings
40 between classes representing various mature RNA products
41 (e.g. generic, miRNA, circRNA etc.) and their respective identifiers
42 in the Ensembl database. In principle there should be no need for
43 users to call the mapper directly; it is invoked internally whenever
44 such mappings are needed (e.g. in
RNAProduct constructor or in
47 Note that the type_code<->class_name mappings are hardcoded here,
48 specifically in the constructor, instead of being fetched from the
49 database. This is so that it is not possible
for someone to trigger
50 construction of arbitrary objects by having modified
class names
51 stored in the database.
58 my $type_code = $rpt_mapper->class_to_type_code(
'Bio::EnsEMBL::MicroRNA' );
62 package Bio::EnsEMBL::Utils::RNAProductTypeMapper;
78 reusing an existing one should it exist.
87 if ( !defined($type_mapper) ) {
97 Description: Constructor. Creates a
new RNAProductTypeMapper
object.
98 Not particularly useful
for end users because all
99 RNAProductTypeMapper objects are identical; use mapper()
101 Returntype :
Bio::
EnsEMBL::Utils::RNAProductTypeMapper
110 my $class = ref( $caller ) || $caller;
112 # Declare this here rather than in the package scope so that the map
113 # cannot be modified (we do not presently use Readonly in the Core
114 # API code), accidentally or otherwise.
115 my $class_attribute_cache_map = {
116 'Bio::EnsEMBL::RNAProduct' => { },
117 'Bio::EnsEMBL::MicroRNA' => {
118 'arm' =>
'mirna_arm',
121 my $type_to_class_map = {
122 'generic' =>
'Bio::EnsEMBL::RNAProduct',
123 'miRNA' =>
'Bio::EnsEMBL::MicroRNA',
127 'class_attribute_cache_map' => $class_attribute_cache_map,
128 'type_to_class_map' => $type_to_class_map,
129 'class_to_type_map' => undef,
136 =head2 class_attribute_cache_map
138 Arg [1] :
string $class_name - fully qualified RNA-product
class name
139 Example : my $attr_cache_map
140 = $mapper->class_attribute_cache_map( 'Bio::EnsEMBL::MicroRNA' );
141 Description: For the given name of a class representing a mature RNA
142 product, returns the
map indicating which local members variables
143 should be synchronised with which Attributes.
145 Exceptions : throw if the class does not represent known RNA-product type
151 sub class_attribute_cache_map {
152 my ( $self, $class_name ) = @_;
154 my %
map = %{ $self->{
'class_attribute_cache_map'} };
155 if ( !exists $map{$class_name} ) {
156 throw(
"Unknown RNA-product class name " . $class_name );
159 return $map{$class_name};
163 =head2 class_to_type_code
165 Arg [1] :
string $class_name - fully qualified RNA-product
class name
166 Example : my $type_code
167 = $mapper->class_to_type_code( 'Bio::EnsEMBL::MicroRNA' );
168 Description: For the given name of a class representing a mature RNA
169 product, returns the type code used to represent it in the
172 Exceptions : throw if the class does not represent known RNA-product type
178 sub class_to_type_code {
179 my ( $self, $class_name ) = @_;
181 if ( !defined( $self->{
'class_to_type_map'} ) ) {
182 $self->_generate_reverse_map();
185 my %
map = %{ $self->{
'class_to_type_map'} };
186 if ( !exists $map{$class_name} ) {
187 throw(
"Unknown RNA-product class name " . $class_name );
190 return $map{$class_name};
194 =head2 type_code_to_class
196 Arg [1] :
string $type_code - type code of RNA product
197 Example : my $class_name = $mapper->class_to_type_code( 1 );
198 Description: For the type code representing a mature RNA product in the
199 Ensembl database,
return its API
class name
201 Exceptions : throw if the code does not represent known RNA-product type
207 sub type_code_to_class {
208 my ( $self, $type_code ) = @_;
210 my %
map = %{ $self->{
'type_to_class_map'} };
211 if ( !exists $map{$type_code} ) {
212 throw(
"Unknown RNA-product type ID " . $type_code );
215 return $map{$type_code};
219 =head2 _generate_reverse_map
221 Description: PRIVATE generates class_name->type_code
map from the
222 type_code->class_name one.
230 sub _generate_reverse_map {
233 # Safe to use reverse because both keys and values are unique
234 my %reversed_map = reverse %{$self->{
'type_to_class_map'}};
235 $self->{
'class_to_type_map'} = \%reversed_map;