EnsEMBL/CoordSystem.pm untested

filter: Statementstmt 0.0% 0 / 87 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 14 Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 10 totaltotal 0.0% 0 / 169 CC 22 SCAR 46.3
CC
22
Cov
0%
new
240.0
equals
20.0
alias_to
20.0
CRAP 102.6
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::CoordSystem
34  
35 =head1 SYNOPSIS
36  
37 my $db = Bio::EnsEMBL::DBSQL::DBAdaptor->new(...);
38  
39 my $csa = $db->get_CoordSystemAdaptor();
40  
41 #
42 # Get all coord systems in the database:
43 #
44 foreach my $cs ( @{ $csa->fetch_all() } ) {
45 my $str = join ':', $cs->name(), $cs->version(), $cs->dbID();
46 print "$str\n";
47 }
48  
49 =head1 DESCRIPTION
50  
51 This is a simple object which contains a few coordinate system attributes:
52 name, internal identifier, version. A coordinate system is uniquely defined
53 by its name and version. A version of a coordinate system applies to all
54 sequences within a coordinate system. This should not be confused with
55 individual sequence versions.
56  
57 Take for example the Human assembly. The version 'NCBI33' applies to
58 to all chromosomes in the NCBI33 assembly (that is the entire 'chromosome'
59 coordinate system). The 'clone' coordinate system in the same database would
60 have no version however. Although the clone sequences have their own sequence
61 versions, there is no version which applies to the entire set of clones.
62  
63 Coordinate system objects are immutable. Their name and version, and other
64 attributes may not be altered after they are created.
65  
66 =head1 METHODS
67  
68 =cut
69  
70  
71 use strict;
72 use warnings;
73  
74 package Bio::EnsEMBL::CoordSystem;
75 $Bio::EnsEMBL::CoordSystem::VERSION = '114.0.0_50'; # TRIAL
76 $Bio::EnsEMBL::CoordSystem::VERSION = '114.0.050';
77 use Bio::EnsEMBL::Storable;
78  
79 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
80 use Bio::EnsEMBL::Utils::Exception qw(throw);
81  
82 use vars qw(@ISA);
83  
84 @ISA = qw(Bio::EnsEMBL::Storable);
85  
86  
87 =head2 new
88  
89 Arg [..] : List of named arguments:
90 -NAME - The name of the coordinate system
91 -VERSION - (optional) The version of the coordinate system.
92 Note that if the version passed in is undefined,
93 it will be set to the empty string in the
94 resulting CoordSystem object.
95 -RANK - The rank of the coordinate system. The highest
96 level coordinate system should have rank 1, the
97 second highest rank 2 and so on. An example of
98 a high level coordinate system is 'chromosome' an
99 example of a lower level coordinate system is
100 'clone'.
101 -TOP_LEVEL - (optional) Sets whether this is a top-level coord
102 system. Default = 0. This should only be set to
103 true if you are creating an artificial toplevel
104 coordsystem by the name of 'toplevel'
105 -SEQUENCE_LEVEL - (optional) Sets whether this is a sequence
106 level coordinate system. Default = 0
107 -DEFAULT - (optional)
108 Whether this is the default version of the
109 coordinate systems of this name. Default = 0
110 -DBID - (optional) The internal identifier of this
111 coordinate system
112 -ADAPTOR - (optional) The adaptor which provides database
113 interaction for this object
114 -ALIAS_TO - (optional) Sets an alias for a coordsystem. If set
115 it should only be set to 'chromosome'
116 Example : $cs = Bio::EnsEMBL::CoordSystem->new(-NAME => 'chromosome',
117 -VERSION => 'NCBI33',
118 -RANK => 1,
119 -DBID => 1,
120 -ADAPTOR => adaptor,
121 -DEFAULT => 1,
122 -SEQUENCE_LEVEL => 0);
123 Description: Creates a new CoordSystem object representing a coordinate
124 system.
125 Returntype : Bio::EnsEMBL::CoordSystem
126 Exceptions : none
127 Caller : general
128 Status : Stable
129  
130 =cut
131  
132 sub new {
133 my $caller = shift;
134 my $class = ref($caller) || $caller;
135  
136 my $self = $class->SUPER::new(@_);
137  
138 my ( $name, $version, $top_level, $sequence_level, $default, $rank, $alias_to ) =
139 rearrange( [ 'NAME', 'VERSION',
140 'TOP_LEVEL', 'SEQUENCE_LEVEL',
141 'DEFAULT', 'RANK',
142 'ALIAS_TO' ],
143 @_ );
144  
145 $top_level = ($top_level) ? 1 : 0;
146 $sequence_level = ($sequence_level) ? 1 : 0;
147 $default = ($default) ? 1 : 0;
148 $rank ||= 0;
149  
150 if ( $top_level == 1 ) {
151 if ( $rank != 0 ) {
152 throw('RANK argument must be 0 if TOP_LEVEL is 1');
153 }
154  
155 if ( defined($name) ) {
156 if ( $name ne 'toplevel' ) {
157 throw('The NAME argument must be "toplevel" if TOP_LEVEL is 1');
158 }
159 } else {
160 $name = 'toplevel';
161 }
162  
163 if ( $sequence_level == 1 ) {
164 throw("SEQUENCE_LEVEL argument must be 0 if TOP_LEVEL is 1");
165 }
166  
167 $default = 0;
168  
169 } else {
170  
171 if ( $rank == 0 ) {
172 throw("RANK argument must be non-zero unless TOP_LEVEL is 1");
173 }
174  
175 if ( !defined($name) ) {
176 throw('The NAME argument is required');
177 } elsif ( $name eq 'toplevel' ) {
178 throw( "Cannot name coord system 'toplevel' "
179 . "unless TOP_LEVEL is 1" );
180 }
181  
182 }
183  
184 if ( $rank !~ /^\d+$/ ) {
185 throw('The RANK argument must be a positive integer');
186 }
187  
188 if ( defined($alias_to) ) {
189 throw("The ALIAS_TO argument can only be defined as 'chromosome'") unless $alias_to eq "chromosome";
190 }
191  
192 $self->{'version'} = $version;
193 $self->{'name'} = $name;
194 $self->{'top_level'} = $top_level;
195 $self->{'sequence_level'} = $sequence_level;
196 $self->{'default'} = $default;
197 $self->{'rank'} = $rank;
198 $self->{'alias_to'} = $alias_to;
199  
200 return $self;
201 } ## end sub new
202  
203  
204 =head2 name
205  
206 Arg [1] : (optional) string $name
207 Example : print $coord_system->name();
208 Description: Getter for the name of this coordinate system
209 Returntype : string
210 Exceptions : none
211 Caller : general
212 Status : Stable
213  
214 =cut
215  
216 sub name {
217 my $self = shift;
218 return $self->{'name'};
219 }
220  
221  
222  
223 =head2 version
224  
225 Arg [1] : none
226 Example : print $coord->version();
227 Description: Getter for the version of this coordinate system. This
228 will return an empty string if no version is defined for this
229 coordinate system.
230 Returntype : string
231 Exceptions : none
232 Caller : general
233 Status : Stable
234  
235 =cut
236  
237 sub version {
238 my $self = shift;
239  
240 return '' unless defined $self->{'version'};
241 return $self->{'version'};
242 }
243  
244  
245  
246 =head2 species
247  
248 Arg [1] : none
249 Example : print $coord->species();
250 Description: Shortcut method to get the species this CoordSystem refers to.
251 Returntype : string
252 Exceptions : none
253 Caller : general
254 Status : Stable
255  
256 =cut
257  
258 sub species {
259 my $self = shift;
260 return $self->adaptor->db->species;
261 }
262  
263  
264  
265 =head2 equals
266  
267 Arg [1] : Bio::EnsEMBL::CoordSystem $cs
268 The coord system to compare to for equality.
269 Example : if($coord_sys->equals($other_coord_sys)) { ... }
270 Description: Compares 2 coordinate systems and returns true if they are
271 equivalent. The definition of equivalent is sharing the same
272 name and version.
273 Returntype : string
274 Exceptions : none
275 Caller : general
276 Status : Stable
277  
278 =cut
279  
280 sub equals {
281 my $self = shift;
282 my $cs = shift;
283  
284 if(!$cs || !ref($cs) || !$cs->isa('Bio::EnsEMBL::CoordSystem')) {
285 if ($cs->isa('Bio::EnsEMBL::ExternalData::DAS::CoordSystem')) {
286 return $cs->equals($self);
287 }
288 throw('Argument must be a CoordSystem');
289 }
290  
291 if($self->version() eq $cs->version() && $self->{'name'} eq $cs->name()) {
292 return 1;
293 }
294  
295 return 0;
296 }
297  
298  
299  
300  
301 =head2 is_top_level
302  
303 Arg [1] : none
304 Example : if($coord_sys->is_top_level()) { ... }
305 Description: Returns true if this is the toplevel pseudo coordinate system.
306 The toplevel coordinate system is not a real coordinate system
307 which is stored in the database, but it is a placeholder that
308 can be used to request transformations or retrievals to/from
309 the highest defined coordinate system in a given region.
310 Returntype : 1 or 0
311 Exceptions : none
312 Caller : general
313 Status : Stable
314  
315 =cut
316  
317 sub is_top_level {
318 my $self = shift;
319 return $self->{'top_level'};
320 }
321  
322  
323 =head2 is_sequence_level
324  
325 Arg [1] : none
326 Example : if($coord_sys->is_sequence_level()) { ... }
327 Description: Returns true if this is a sequence level coordinate system
328 Returntype : 1 or 0
329 Exceptions : none
330 Caller : general
331 Status : Stable
332  
333 =cut
334  
335 sub is_sequence_level {
336 my $self = shift;
337 return $self->{'sequence_level'};
338 }
339  
340  
341 =head2 is_default
342  
343 Arg [1] : none
344 Example : if($coord_sys->is_default()) { ... }
345 Description: Returns true if this coordinate system is the default
346 version of the coordinate system of this name.
347 Returntype : 1 or 0
348 Exceptions : none
349 Caller : general
350 Status : Stable
351  
352 =cut
353  
354 sub is_default {
355 my $self = shift;
356 return $self->{'default'};
357 }
358  
359  
360  
361  
362 =head2 rank
363  
364 Arg [1] : none
365 Example : if($cs1->rank() < $cs2->rank()) {
366 print $cs1->name(), " is a higher level coord system than",
367 $cs2->name(), "\n";
368 }
369 Description: Returns the rank of this coordinate system. A lower number
370 is a higher coordinate system. The highest level coordinate
371 system has a rank of 1 (e.g. 'chromosome'). The toplevel
372 pseudo coordinate system has a rank of 0.
373 Returntype : int
374 Exceptions : none
375 Caller : general
376 Status : Stable
377  
378 =cut
379  
380 sub rank {
381 my $self = shift;
382 return $self->{'rank'};
383 }
384  
385  
386  
387 =head2 alias_to
388  
389 Arg [1] : string
390 Example : $coord->alias_to('chromosome');
391 Description: Getter/Setter for the alias of this coordinate system.
392 Returntype : Bio::EnsEMBL::CoordSystem
393 Exceptions : none
394 Caller : general
395 Status : Stable
396  
397 =cut
398  
399 sub alias_to {
400 my ($self, $alias_to) = @_;
401 if (defined($alias_to)) {
402 throw("The alias can only be set to 'chromosome'") unless $alias_to eq "chromosome";
403 }
404 $self->{'alias_to'} = $alias_to if defined $alias_to;
405 return $self->{'alias_to'};
406 }
407  
408  
409 1;