EnsEMBL/DBSQL/GenomeContainer.pm untested

filter: Statementstmt 0.0% 0 / 383 Branchbran 0.0% 0 / 164 Conditioncond 0.0% 0 / 3 Subroutinesub 0.0% 0 / 61 Podpod 0.0% 0 / 53 totaltotal 0.0% 0 / 664 CC 83 SCAR 24.6
CC
83
Cov
0%
is_high_coverage
42.0
store
20.0
update
12.0
CRAP 11.7
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 =head1 NAME
34  
35 Bio::EnsEMBL::DBSQL::GenomeContainer - Encapsulates all access to
36 genome related information
37  
38 =head1 SYNOPSIS
39  
40 use Bio::EnsEMBL::Registry;
41  
42 Bio::EnsEMBL::Registry->load_registry_from_db(
43 -host => 'ensembldb.ensembl.org',
44 -user => 'anonymous'
45 );
46  
47 $genome =
48 Bio::EnsEMBL::Registry->get_adaptor( "human", "core", "GenomeContainer" );
49  
50 my $version = $genome->get_version;
51  
52 my $ref_length = $genome->get_ref_length;
53  
54 my $coord_systems = $genome->get_coord_systems;
55  
56  
57  
58 =head1 DESCRIPTION
59  
60 This module is responsible for fetching and storing genome-wide information.
61 Genome is an abstract object which contains information linking the species, the assembly and the ensembl annotation.
62  
63 =head1 METHODS
64  
65 =cut
66  
67 package Bio::EnsEMBL::DBSQL::GenomeContainer;
68 $Bio::EnsEMBL::DBSQL::GenomeContainer::VERSION = '114.0.0_50'; # TRIAL
69 $Bio::EnsEMBL::DBSQL::GenomeContainer::VERSION = '114.0.050';
70 use strict;
71 use warnings;
72  
73 use Bio::EnsEMBL::Genome;
74 use Bio::EnsEMBL::DBSQL::DBAdaptor;
75 use Bio::EnsEMBL::DBSQL::BaseAdaptor;
76 use Bio::EnsEMBL::Utils::Exception qw( deprecate throw warning );
77 use Bio::EnsEMBL::Utils::Scalar qw( assert_ref );
78  
79 use vars qw(@ISA);
80  
81 @ISA = qw(Bio::EnsEMBL::DBSQL::BaseAdaptor);
82  
83  
84  
85 =head2 new
86  
87 Arg [...] : Superclass args. See Bio::EnsEMBL::DBSQL::BaseAdaptor
88 Description: Instantiates a Bio::EnsEMBL::DBSQL::GenomeContainer
89 Returntype : Bio::EnsEMBL::GenomeContainer
90 Exceptions : none
91 Caller : DBAdaptor
92 Status : Stable
93  
94 =cut
95  
96  
97 sub new {
98 my $class = shift;
99  
100 my $self = $class->SUPER::new(@_);
101  
102 # cache creation could go here
103 return $self;
104 }
105  
106  
107 =head2 store
108  
109 Arg [1] : Statistic
110 The type of statistic to store
111 Arg [2] : Value
112 The corresponding value for the statistic
113 Arg [3] : (optional) Attribute
114 If more than one value exists for the statistics, it will be distinguished by its attribute
115 Example : $genome_adaptor->store('coding_cnt', 20769);
116 Description: Stores a genome statistic in the database
117 Returntype : The database identifier (dbID) of the newly stored genome statistic
118 Exceptions :
119 Caller : general
120 Status : Stable
121  
122 =cut
123  
124 sub store {
125 my ($self, $statistic, $value, $attribute) = @_;
126  
127 my $stats_id = $self->fetch_by_statistic($statistic, $attribute)->dbID;
128  
129 if (defined $stats_id) {
130 $self->update($statistic, $value, $attribute);
131 } else {
132 my $db = $self->db();
133 my $species_id = $db->species_id();
134  
135 my $store_genome_sql = q{
136 INSERT INTO genome_statistics
137 SET statistic = ?,
138 value = ?,
139 species_id = ?,
140 timestamp = now()
141 };
142  
143 if (defined $attribute) {
144 $store_genome_sql .= ", attrib_type_id = ?";
145 }
146  
147 my $sth = $self->prepare($store_genome_sql);
148 $sth->bind_param(1, $statistic, SQL_VARCHAR);
149 $sth->bind_param(2, $value, SQL_INTEGER);
150 $sth->bind_param(3, $species_id, SQL_INTEGER);
151  
152 if (defined $attribute) {
153 my $attribute_adaptor = $db->get_AttributeAdaptor();
154 my $attribute_object = Bio::EnsEMBL::Attribute->new(-code => $attribute);
155 my $attribute_type_id = $attribute_adaptor->_store_type($attribute_object);
156 $sth->bind_param(4, $attribute_type_id, SQL_VARCHAR);
157 }
158  
159 $sth->execute();
160 $sth->finish();
161  
162 $stats_id = $sth->{'mysql_insertid'};
163 }
164  
165 return $stats_id;
166  
167 }
168  
169  
170 =head2 update
171  
172 Arg [1] : Statistic
173 The type of statistic to update
174 Arg [2] : Value
175 The corresponding value for the statistic
176 Arg [3] : (optional) Attribute
177 If more than one value exists for the statistics, it will be distinguished by its attribute
178 Example : $genome_adaptor->update('coding_cnt', 20769);
179 Description: Updates an existing genome statistic in the database
180 Returntype : none
181 Exceptions :
182 Caller : general
183 Status : Stable
184  
185 =cut
186  
187 sub update {
188 my ($self, $statistic, $value, $attribute) = @_;
189  
190 my $db = $self->db();
191  
192 my $update_genome_sql = q{
193 UPDATE genome_statistics
194 SET value = ?,
195 timestamp = now()
196 };
197  
198 if (defined $attribute) {
199 $update_genome_sql .= ', attrib_type_id = ?';
200 }
201  
202 $update_genome_sql .= ' WHERE statistic = ? and species_id = ?';
203  
204 my $sth = $self->prepare($update_genome_sql);
205 $sth->bind_param(1, $value, SQL_INTEGER);
206  
207 my $increment = 2;
208 if (defined $attribute) {
209 my $attribute_adaptor = $db->get_AttributeAdaptor();
210 my $attribute_object = Bio::EnsEMBL::Attribute->new(-code => $attribute);
211 my $attribute_type_id = $attribute_adaptor->_store_type($attribute_object);
212 $sth->bind_param($increment, $attribute_type_id, SQL_VARCHAR);
213 $increment++;
214 }
215  
216 $sth->bind_param($increment++, $statistic, SQL_VARCHAR);
217 $sth->bind_param($increment, $db->species_id(), SQL_INTEGER);
218  
219 $sth->execute();
220 $sth->finish();
221 }
222  
223  
224 =head2 _meta_container
225  
226 Arg [1] : none
227 Example : $meta_container = $genome->_meta_container();
228 Description: Internal method to return a MetaContainer object for the genome
229 Returntype : Bio::EnsEMBL::DBSQL::MetaContainer
230 Exceptions : none
231 Caller : general
232 Status : Stable
233  
234 =cut
235  
236 sub _meta_container {
237 my $self = shift;
238 return $self->db->get_adaptor('MetaContainer');
239 }
240  
241  
242 =head2 get_version
243  
244 Arg [1] : (optional) assembly version
245 Example : $version = $genome->get_version();
246 Description: Getter/Setter for the assembly version
247  
248 Returntype : string
249 Exceptions : none
250 Caller : general
251 Status : Stable
252  
253 =cut
254  
255 sub get_version {
256 my ($self, $version) = @_;
257 if (defined $version) {
258 $self->{'version'} = $version;
259 }
260 if (!defined $self->{'version'}) {
261 my $csa = $self->db()->get_adaptor('CoordSystem');
262 $self->{'version'} = $csa->get_default_version;
263 }
264 return $self->{'version'};
265 }
266  
267 =head2 get_accession
268  
269 Arg [1] : (optional) assembly accession
270 Example : $accession = $genome->get_accession();
271 Description: Getter/setter for the accession of the assembly currently used
272  
273 Returntype : string
274 Exceptions : none
275 Caller : general
276 Status : Stable
277  
278 =cut
279  
280 sub get_accession {
281 my ($self, $accession) = @_;
282 if (defined $accession) {
283 $self->{'accession'} = $accession;
284 }
285 if (!defined $self->{'accession'}) {
286 $self->{'accession'} = $self->_meta_container->single_value_by_key('assembly.accession');
287 }
288 return $self->{'accession'};
289 }
290  
291  
292 =head2 get_assembly_name
293  
294 Arg [1] : (optional) assembly name
295 Example : $assembly_name = $genome->get_assembly_name();
296 Description: Getter/setter for the name of the assembly currently used
297  
298 Returntype : string
299 Exceptions : none
300 Caller : general
301 Status : Stable
302  
303 =cut
304  
305 sub get_assembly_name {
306 my ($self, $assembly_name) = @_;
307 if (defined $assembly_name) {
308 $self->{'assembly_name'} = $assembly_name;
309 }
310 if (!defined $self->{'assembly_name'}) {
311 $self->{'assembly_name'} = $self->_meta_container->single_value_by_key('assembly.name');
312 }
313 return $self->{'assembly_name'};
314 }
315  
316  
317 =head2 get_assembly_date
318  
319 Arg [1] : (optional) assembly date
320 Example : $assembly_date = $genome->get_assembly_date();
321 Description: Getter/setter for the date of the assembly currently used
322  
323 Returntype : string
324 Exceptions : none
325 Caller : general
326 Status : Stable
327  
328 =cut
329  
330 sub get_assembly_date {
331 my ($self, $assembly_date) = @_;
332 if (defined $assembly_date) {
333 $self->{'assembly_date'} = $assembly_date;
334 }
335 if (!defined $self->{'assembly_date'}) {
336 $self->{'assembly_date'} = $self->_meta_container->single_value_by_key('assembly.date');
337 }
338 return $self->{'assembly_date'};
339 }
340  
341  
342 =head2 get_genebuild_start_date
343  
344 Arg [1] : (optional) genebuild start date
345 Example : $genebuild_start_date = $genome->get_genebuild_start_date();
346 Description: Getter/setter for the start date of the genebuild currently used
347  
348 Returntype : string
349 Exceptions : none
350 Caller : general
351 Status : Stable
352  
353 =cut
354  
355 sub get_genebuild_start_date {
356 my ($self, $genebuild_start_date) = @_;
357 if (defined $genebuild_start_date) {
358 $self->{'genebuild_start_date'} = $genebuild_start_date;
359 }
360 if (!defined $self->{'genebuild_start_date'}) {
361 $self->{'genebuild_start_date'} = $self->_meta_container->single_value_by_key('genebuild.start_date');
362 }
363 return $self->{'genebuild_start_date'};
364 }
365  
366  
367 =head2 get_genebuild_method
368  
369 Arg [1] : (optional) genebuild start date
370 Example : $genebuild_method = $genome->get_genebuild_method();
371 Description: Getter/setter for the method of the genebuild currently used
372  
373 Returntype : string
374 Exceptions : none
375 Caller : general
376 Status : Stable
377  
378 =cut
379  
380 sub get_genebuild_method {
381 my ($self, $genebuild_method) = @_;
382 if (defined $genebuild_method) {
383 $self->{'genebuild_method'} = $genebuild_method;
384 }
385 if (!defined $self->{'genebuild_method'}) {
386 $self->{'genebuild_method'} = $self->_meta_container->single_value_by_key('genebuild.method');
387 }
388 return $self->{'genebuild_method'};
389 }
390  
391  
392 =head2 get_genebuild_initial_release_date
393  
394 Arg [1] : (optional) genebuild initial release date
395 Example : $genebuild_initial_release_date = $genome->get_initial_release_date();
396 Description: Getter/setter for the initial release date of the genebuild currently used
397  
398 Returntype : string
399 Exceptions : none
400 Caller : general
401 Status : Stable
402  
403 =cut
404  
405 sub get_genebuild_initial_release_date {
406 my ($self, $genebuild_initial_release_date) = @_;
407 if (defined $genebuild_initial_release_date) {
408 $self->{'genebuild_initial_release_date'} = $genebuild_initial_release_date;
409 }
410 if (!defined $self->{'genebuild_initial_release_date'}) {
411 $self->{'genebuild_initial_release_date'} = $self->_meta_container->single_value_by_key('genebuild.initial_release_date');
412 }
413 return $self->{'genebuild_initial_release_date'};
414 }
415  
416  
417 =head2 get_genebuild_last_geneset_update
418  
419 Arg [1] : (optional) genebuild last geneset update
420 Example : $genebuild_last_geneset_update = $genome->get_last_geneset_update();
421 Description: Getter/setter for the last geneset update of the genebuild currently used
422  
423 Returntype : string
424 Exceptions : none
425 Caller : general
426 Status : Stable
427  
428 =cut
429  
430 sub get_genebuild_last_geneset_update {
431 my ($self, $genebuild_last_geneset_update) = @_;
432 if (defined $genebuild_last_geneset_update) {
433 $self->{'genebuild_last_geneset_update'} = $genebuild_last_geneset_update;
434 }
435 if (!defined $self->{'genebuild_last_geneset_update'}) {
436 $self->{'genebuild_last_geneset_update'} = $self->_meta_container->single_value_by_key('genebuild.last_geneset_update');
437 }
438 return $self->{'genebuild_last_geneset_update'};
439 }
440  
441  
442 =head2 _get_length
443  
444 Arg [1] : none
445 Example : $length = $genome->_get_length('toplevel');
446 Description: Internal method to return the length for a type of slices
447 Returntype : integer
448 Exceptions : none
449 Caller : general
450 Status : Stable
451  
452 =cut
453  
454 sub _get_length {
455 my ($self, $cs_name) = @_;
456 my $slice_adaptor = $self->db->get_adaptor('Slice');
457 my $seqlevel = $slice_adaptor->fetch_all($cs_name);
458 my $count;
459 foreach my $seq (@$seqlevel) {
460 $count += $seq->length();
461 }
462 return $count;
463 }
464  
465  
466  
467 =head2 get_ref_length
468  
469 Arg [1] : (optional) golden path length
470 Example : $ref_length = $genome->get_ref_length();
471 Description: Getter/setter for the golden path of the assembly currently used
472 Returntype : integer
473 Exceptions : none
474 Caller : general
475 Status : Stable
476  
477 =cut
478  
479 sub get_ref_length {
480 my ($self, $ref_length) = @_;
481 if (defined $ref_length) {
482 $self->{'ref_length'} = $ref_length;
483 }
484 if (!defined $self->{'ref_length'}) {
485 $self->{'ref_length'} = $self->fetch_by_statistic('ref_length')->value();
486 }
487 return $self->{'ref_length'};
488 }
489  
490 =head2 get_toplevel
491  
492 Arg [1] : none
493 Example : $toplevel = $genome->get_toplevel();
494 Description: Returns the toplevel for the assembly currently used
495  
496 Returntype : ListRef of Bio::EnsEMBL::Slice
497 Exceptions : none
498 Caller : general
499 Status : Stable
500  
501 =cut
502  
503 sub get_toplevel {
504 my ($self) = @_;
505 my $sa = $self->db->get_adaptor('Slice');
506 $self->{'toplevel'} = $sa->fetch_all('toplevel', undef, undef, 1);
507 return $self->{'toplevel'};
508 }
509  
510  
511 =head2 get_karyotype
512  
513 Arg [1] : none
514 Example : $karyotype = $genome->get_karyotype();
515 Description: Returns the karyotype for the assembly currently used
516  
517 Returntype : ListRef of Bio::EnsEMBL::Slice
518 Exceptions : none
519 Caller : general
520 Status : Stable
521  
522 =cut
523  
524 sub get_karyotype {
525 my ($self) = @_;
526 my $sa = $self->db->get_adaptor('Slice');
527 $self->{'karyotype'} = $sa->fetch_all_karyotype;
528 return $self->{'karyotype'};
529 }
530  
531 =head2 get_coord_systems
532  
533 Arg [1] : none
534 Example : $coord_systems = $genome->get_coord_systems();
535 Description: Returns the coord_systems for the assembly currently used
536  
537 Returntype : ListRef of Bio::EnsEMBL::CoordSystem
538 Exceptions : none
539 Caller : general
540 Status : Stable
541  
542 =cut
543  
544 sub get_coord_systems {
545 my ($self, $all) = @_;
546 my $csa = $self->db->get_adaptor('CoordSystem');
547 if (!$all) {
548 my $version = $self->get_version();
549 $self->{'coord_systems'} = $csa->fetch_all_by_version($version);
550 } else {
551 $self->{'coord_systems'} = $csa->fetch_all();
552 }
553 return $self->{'coord_systems'};
554 }
555  
556 =head2 _get_count
557  
558 Arg [1] : none
559 Example : $count = $genome->_get_count('coding_cnt');
560 Description: Internal method to return a count for a given attribute code
561 Returntype : integer
562 Exceptions : none
563 Caller : general
564 Status : Stable
565  
566 =cut
567  
568 sub _get_count {
569 my ($self, $code, $attribute) = @_;
570 my $statistic = $self->fetch_by_statistic($code, $attribute);
571 return $statistic->value();
572 }
573  
574 =head2 get_count
575  
576 Arg [1] : none
577 Example : $count = $genome->get_count('coding_cnt');
578 Description: Retrieve a count for a given attribute code
579 Returntype : integer
580 Exceptions : none
581 Caller : general
582 Status : Stable
583  
584 =cut
585  
586 sub get_count {
587 my ($self, $code, $attribute) = @_;
588 my $statistic = $self->fetch_by_statistic($code, $attribute);
589 return $statistic->value();
590 }
591  
592 =head2 fetch_all_statistics
593  
594 Arg [1] : none
595 Example : $list = $genome->fetch_all_statistics();
596 Description: Retrieve all entries stored in the genome_statistics table
597 Returntype : ArrayRef of Bio::EnsEMBL::Genome
598 Exceptions : none
599 Caller : general
600 Status : Stable
601  
602 =cut
603  
604 sub fetch_all_statistics {
605 my ($self) = @_;
606 my $db = $self->db;
607 my $species_id = $self->db->species_id();
608 my @results;
609 my $sql = q{
610 SELECT genome_statistics_id, statistic, value, species_id, code, name, description
611 FROM genome_statistics, attrib_type
612 WHERE genome_statistics.attrib_type_id = attrib_type.attrib_type_id
613 AND species_id=?
614 };
615  
616 my $sth = $self->prepare($sql);
617 $sth->bind_param(1, $species_id, SQL_INTEGER);
618 $sth->execute();
619 my $results = $self->_obj_from_sth($sth);
620 $sth->finish();
621  
622 return $results;
623 }
624  
625  
626 =head2 fetch_by_statistic
627  
628 Arg [1] : string $statistic
629 Example : $results = $genome->fetch_by_statistic('coding_cnt');
630 Description: Returns a Genome object for a given statistic
631 Returntype : Bio::EnsEMBL::Genome
632 Exceptions : none
633 Caller : general
634 Status : Stable
635  
636 =cut
637  
638 sub fetch_by_statistic {
639 my ($self, $statistic_name, $attribute) = @_;
640 my $db = $self->db;
641 my $fetch_sql = q{
642 SELECT genome_statistics_id, statistic, value, species_id, code, name, description
643 FROM genome_statistics, attrib_type
644 WHERE genome_statistics.attrib_type_id = attrib_type.attrib_type_id
645 AND statistic = ? AND species_id=?
646 };
647 if (defined $attribute) {
648 $fetch_sql .= " AND code = ?";
649 }
650  
651 my $sth = $self->prepare($fetch_sql);
652 $sth->bind_param(1, $statistic_name, SQL_VARCHAR);
653 $sth->bind_param(2, $self->db->species_id, SQL_INTEGER);
654 if (defined $attribute) {
655 $sth->bind_param(3, $attribute, SQL_VARCHAR);
656 }
657 $sth->execute();
658 my ($dbID, $statistic, $value, $species_id, $code, $name, $desc);
659 $sth->bind_columns(\$dbID, \$statistic, \$value, \$species_id, \$code, \$name, \$desc);
660  
661 my @results = $sth->fetchrow_array;
662 $sth->finish();
663  
664 return Bio::EnsEMBL::Genome->new_fast({'dbID' => $dbID,
665 'statistic' => $statistic,
666 'code' => $code,
667 'name' => $name,
668 'description' => $desc,
669 'value' => $value});
670  
671 }
672  
673 =head2 is_empty
674  
675 Arg [1] : none
676 Example : $results = $genome->is_empty;
677 Description: Boolean to check if there is data in the genome container
678 Returntype : Boolean
679 Exceptions : none
680 Caller : general
681 Status : Stable
682  
683 =cut
684  
685 sub is_empty {
686 my $self = shift;
687 my $db = $self->db;
688 my $species_id = $self->db->species_id();
689 my $is_empty = 1;
690 my $count_sql = q{
691 SELECT count(*) FROM genome_statistics
692 };
693  
694 my $sth = $self->prepare($count_sql);
695 $sth->execute();
696 if ($sth->fetchrow()) {
697 $is_empty = 0;
698 }
699 $sth->finish();
700 return $is_empty;
701 }
702  
703 =head2 get_attrib
704  
705 Arg [1] : statistic
706 Example : $results = $genome->_get_attrib('coding_cnt');
707 Description: Returns the attribute object for a given statistic
708 Returntype : Bio::EnsEMBL::Attrib
709 Exceptions : none
710 Caller : general
711 Status : Stable
712  
713 =cut
714  
715 sub get_attrib {
716 my ($self, $statistic) = @_;
717 my $db = $self->db();
718 my $attribute_adaptor = $db->get_adaptor('attribute');
719 my @attribs = @{ $attribute_adaptor->fetch_by_code($statistic) };
720 my $attrib = Bio::EnsEMBL::Attribute->new(
721 -code => $attribs[1],
722 -name => $attribs[2],
723 -description => $attribs[3]
724 );
725 return $attrib;
726 }
727  
728 =head2 get_coding_count
729  
730 Arg [1] : (optional) coding count
731 Example : $coding_count = $genome->get_coding_count();
732 Description: Getter/setter for the number of coding genes in the current build
733  
734 Returntype : integer
735 Exceptions : none
736 Caller : general
737 Status : Stable
738  
739 =cut
740  
741 sub get_coding_count {
742 my ($self, $coding_count) = @_;
743 if (defined $coding_count) {
744 $self->{'coding_count'} = $coding_count;
745 }
746 if (!defined $self->{'coding_count'}) {
747 $self->{'coding_count'} = $self->_get_count('coding_cnt');
748 }
749 return $self->{'coding_count'};
750 }
751  
752 =head2 get_rcoding_count
753  
754 Arg [1] : (optional) readthrough coding count
755 Example : $rcoding_count = $genome->get_rcoding_count();
756 Description: Getter/setter for the number of readthrough coding genes in the current build
757  
758 Returntype : integer
759 Exceptions : none
760 Caller : general
761 Status : Stable
762  
763 =cut
764  
765 sub get_rcoding_count {
766 my ($self, $rcoding_count) = @_;
767 if (defined $rcoding_count) {
768 $self->{'rcoding_count'} = $rcoding_count;
769 }
770 if (!defined $self->{'rcoding_count'}) {
771 $self->{'rcoding_count'} = $self->_get_count('coding_rcnt');
772 }
773 return $self->{'rcoding_count'};
774 }
775  
776  
777 =head2 get_snoncoding_count
778  
779 Arg [1] : (optional) short non coding count
780 Example : $snoncoding_count = $genome->get_snoncoding_count();
781 Description: Getter/setter for the number of short non coding genes in the current build
782  
783 Returntype : integer
784 Exceptions : none
785 Caller : general
786 Status : Stable
787  
788 =cut
789  
790 sub get_snoncoding_count {
791 my ($self, $snoncoding_count) = @_;
792 if (defined $snoncoding_count) {
793 $self->{'snoncoding_count'} = $snoncoding_count;
794 }
795 if (!defined $self->{'snoncoding_count'}) {
796 $self->{'snoncoding_count'} = $self->_get_count('noncoding_cnt_s');
797 }
798 return $self->{'snoncoding_count'};
799 }
800  
801 =head2 get_rsnoncoding_count
802  
803 Arg [1] : (optional) readthrough short non coding count
804 Example : $rsnoncoding_count = $genome->get_rsnoncoding_count();
805 Description: Getter/setter for the number of readthrough short non coding genes in the current build
806  
807 Returntype : integer
808 Exceptions : none
809 Caller : general
810 Status : Stable
811  
812 =cut
813  
814 sub get_rsnoncoding_count {
815 my ($self, $rsnoncoding_count) = @_;
816 if (defined $rsnoncoding_count) {
817 $self->{'rsnoncoding_count'} = $rsnoncoding_count;
818 }
819 if (!defined $self->{'rsnoncoding_count'}) {
820 $self->{'rsnoncoding_count'} = $self->_get_count('noncoding_rcnt_s');
821 }
822 return $self->{'rsnoncoding_count'};
823 }
824  
825 =head2 get_mnoncoding_count
826  
827 Arg [1] : (optional) miscellaneous non coding count
828 Example : $mnoncoding_count = $genome->get_mnoncoding_count();
829 Description: Getter/setter for the number of miscellaneous non coding genes in the current build
830  
831 Returntype : integer
832 Exceptions : none
833 Caller : general
834 Status : Stable
835  
836 =cut
837  
838 sub get_mnoncoding_count {
839 my ($self, $mnoncoding_count) = @_;
840 if (defined $mnoncoding_count) {
841 $self->{'mnoncoding_count'} = $mnoncoding_count;
842 }
843 if (!defined $self->{'mnoncoding_count'}) {
844 $self->{'mnoncoding_count'} = $self->_get_count('noncoding_cnt_m');
845 }
846 return $self->{'mnoncoding_count'};
847 }
848  
849 =head2 get_rmnoncoding_count
850  
851 Arg [1] : (optional) readthrough miscellaneous non coding count
852 Example : $rmnoncoding_count = $genome->get_rmnoncoding_count();
853 Description: Getter/setter for the number of readthrough miscellaneous non coding genes in the current build
854  
855 Returntype : integer
856 Exceptions : none
857 Caller : general
858 Status : Stable
859  
860 =cut
861  
862 sub get_rmnoncoding_count {
863 my ($self, $rmnoncoding_count) = @_;
864 if (defined $rmnoncoding_count) {
865 $self->{'rmnoncoding_count'} = $rmnoncoding_count;
866 }
867 if (!defined $self->{'rmnoncoding_count'}) {
868 $self->{'rmnoncoding_count'} = $self->_get_count('noncoding_rcnt_m');
869 }
870 return $self->{'rmnoncoding_count'};
871 }
872  
873  
874 =head2 get_lnoncoding_count
875  
876 Arg [1] : (optional) long non coding count
877 Example : $lnoncoding_count = $genome->get_lnoncoding_count();
878 Description: Getter/setter for the number of long non coding genes in the current build
879  
880 Returntype : integer
881 Exceptions : none
882 Caller : general
883 Status : Stable
884  
885 =cut
886  
887 sub get_lnoncoding_count {
888 my ($self, $lnoncoding_count) = @_;
889 if (defined $lnoncoding_count) {
890 $self->{'lnoncoding_count'} = $lnoncoding_count;
891 }
892 if (!defined $self->{'lnoncoding_count'}) {
893 $self->{'lnoncoding_count'} = $self->_get_count('noncoding_cnt_l');
894 }
895 return $self->{'lnoncoding_count'};
896 }
897  
898 =head2 get_rlnoncoding_count
899  
900 Arg [1] : (optional) readthrough long non coding count
901 Example : $rlnoncoding_count = $genome->get_rlnoncoding_count();
902 Description: Getter/setter for the number of readthrough long non coding genes in the current build
903  
904 Returntype : integer
905 Exceptions : none
906 Caller : general
907 Status : Stable
908  
909 =cut
910  
911 sub get_rlnoncoding_count {
912 my ($self, $rlnoncoding_count) = @_;
913 if (defined $rlnoncoding_count) {
914 $self->{'rlnoncoding_count'} = $rlnoncoding_count;
915 }
916 if (!defined $self->{'rlnoncoding_count'}) {
917 $self->{'rlnoncoding_count'} = $self->_get_count('noncoding_rcnt_l');
918 }
919 return $self->{'rlnoncoding_count'};
920 }
921  
922 =head2 get_pseudogene_count
923  
924 Arg [1] : (optional) pseudogene count
925 Example : $pseudogene_count = $genome->get_pseudogene_count();
926 Description: Getter/setter for the number of pseudogenes in the current build
927  
928 Returntype : integer
929 Exceptions : none
930 Caller : general
931 Status : Stable
932  
933 =cut
934  
935  
936 sub get_pseudogene_count {
937 my ($self, $pseudogene_count) = @_;
938 if (defined $pseudogene_count) {
939 $self->{'pseudogene_count'} = $pseudogene_count;
940 }
941 if (!defined $self->{'pseudogene_count'}) {
942 $self->{'pseudogene_count'} = $self->_get_count('pseudogene_cnt');
943 }
944 return $self->{'pseudogene_count'};
945 }
946  
947 =head2 get_rpseudogene_count
948  
949 Arg [1] : (optional) readthrough pseudogene count
950 Example : $rpseudogene_count = $genome->get_rpseudogene_count();
951 Description: Getter/setter for the number of readthrough pseudogenes in the current build
952  
953 Returntype : integer
954 Exceptions : none
955 Caller : general
956 Status : Stable
957  
958 =cut
959  
960  
961 sub get_rpseudogene_count {
962 my ($self, $rpseudogene_count) = @_;
963 if (defined $rpseudogene_count) {
964 $self->{'rpseudogene_count'} = $rpseudogene_count;
965 }
966 if (!defined $self->{'rpseudogene_count'}) {
967 $self->{'rpseudogene_count'} = $self->_get_count('pseudogene_rcnt');
968 }
969 return $self->{'rpseudogene_count'};
970 }
971  
972 =head2 get_alt_coding_count
973  
974 Arg [1] : (optional) alt coding count
975 Example : $alt_coding_count = $genome->get_alt_coding_count();
976 Description: Getter/setter for the number of coding genes on alternate sequences
977  
978 Returntype : integer
979 Exceptions : none
980 Caller : general
981 Status : Stable
982  
983 =cut
984  
985 sub get_alt_coding_count {
986 my ($self, $alt_coding_count) = @_;
987 if (defined $alt_coding_count) {
988 $self->{'alt_coding_count'} = $alt_coding_count;
989 }
990 if (!defined $self->{'alt_coding_count'}) {
991 $self->{'alt_coding_count'} = $self->_get_count('coding_acnt');
992 }
993 return $self->{'alt_coding_count'};
994 }
995  
996 =head2 get_alt_rcoding_count
997  
998 Arg [1] : (optional) alt readthrough coding count
999 Example : $alt_rcoding_count = $genome->get_alt_rcoding_count();
1000 Description: Getter/setter for the number of readthrough coding genes on alternate sequences
1001  
1002 Returntype : integer
1003 Exceptions : none
1004 Caller : general
1005 Status : Stable
1006  
1007 =cut
1008  
1009 sub get_alt_rcoding_count {
1010 my ($self, $alt_rcoding_count) = @_;
1011 if (defined $alt_rcoding_count) {
1012 $self->{'alt_rcoding_count'} = $alt_rcoding_count;
1013 }
1014 if (!defined $self->{'alt_rcoding_count'}) {
1015 $self->{'alt_rcoding_count'} = $self->_get_count('coding_racnt');
1016 }
1017 return $self->{'alt_rcoding_count'};
1018 }
1019  
1020  
1021 =head2 get_alt_snoncoding_count
1022  
1023 Arg [1] : (optional) alt short non coding count
1024 Example : $alt_snoncoding_count = $genome->get_alt_snoncoding_count();
1025 Description: Getter/setter for the number of short non coding genes on alternate sequences
1026  
1027 Returntype : integer
1028 Exceptions : none
1029 Caller : general
1030 Status : Stable
1031  
1032 =cut
1033  
1034 sub get_alt_snoncoding_count {
1035 my ($self, $alt_snoncoding_count) = @_;
1036 if (defined $alt_snoncoding_count) {
1037 $self->{'alt_snoncoding_count'} = $alt_snoncoding_count;
1038 }
1039 if (!defined $self->{'alt_snoncoding_count'}) {
1040 $self->{'alt_snoncoding_count'} = $self->_get_count('noncoding_acnt_s');
1041 }
1042 return $self->{'alt_snoncoding_count'};
1043 }
1044  
1045 =head2 get_alt_rsnoncoding_count
1046  
1047 Arg [1] : (optional) alt readthrough short non coding count
1048 Example : $alt_rsnoncoding_count = $genome->get_alt_rsnoncoding_count();
1049 Description: Getter/setter for the number of readthrough short non coding genes on alternate sequences
1050  
1051 Returntype : integer
1052 Exceptions : none
1053 Caller : general
1054 Status : Stable
1055  
1056 =cut
1057  
1058 sub get_alt_rsnoncoding_count {
1059 my ($self, $alt_rsnoncoding_count) = @_;
1060 if (defined $alt_rsnoncoding_count) {
1061 $self->{'alt_rsnoncoding_count'} = $alt_rsnoncoding_count;
1062 }
1063 if (!defined $self->{'alt_rsnoncoding_count'}) {
1064 $self->{'alt_rsnoncoding_count'} = $self->_get_count('noncoding_racnt_s');
1065 }
1066 return $self->{'alt_rsnoncoding_count'};
1067 }
1068  
1069 =head2 get_alt_mnoncoding_count
1070  
1071 Arg [1] : (optional) alt miscellaneous non coding count
1072 Example : $alt_mnoncoding_count = $genome->get_alt_mnoncoding_count();
1073 Description: Getter/setter for the number of miscellaneous non coding genes on alternate sequences
1074  
1075 Returntype : integer
1076 Exceptions : none
1077 Caller : general
1078 Status : Stable
1079  
1080 =cut
1081  
1082 sub get_alt_mnoncoding_count {
1083 my ($self, $alt_mnoncoding_count) = @_;
1084 if (defined $alt_mnoncoding_count) {
1085 $self->{'alt_mnoncoding_count'} = $alt_mnoncoding_count;
1086 }
1087 if (!defined $self->{'alt_mnoncoding_count'}) {
1088 $self->{'alt_mnoncoding_count'} = $self->_get_count('noncoding_acnt_m');
1089 }
1090 return $self->{'alt_mnoncoding_count'};
1091 }
1092  
1093 =head2 get_alt_rmnoncoding_count
1094  
1095 Arg [1] : (optional) alt readthrough miscellaneous non coding count
1096 Example : $alt_rmnoncoding_count = $genome->get_alt_rmnoncoding_count();
1097 Description: Getter/setter for the number of readthrough miscellaneous non coding genes on alternate sequences
1098  
1099 Returntype : integer
1100 Exceptions : none
1101 Caller : general
1102 Status : Stable
1103  
1104 =cut
1105  
1106 sub get_alt_rmnoncoding_count {
1107 my ($self, $alt_rmnoncoding_count) = @_;
1108 if (defined $alt_rmnoncoding_count) {
1109 $self->{'alt_rmnoncoding_count'} = $alt_rmnoncoding_count;
1110 }
1111 if (!defined $self->{'alt_rmnoncoding_count'}) {
1112 $self->{'alt_rmnoncoding_count'} = $self->_get_count('noncoding_racnt_m');
1113 }
1114 return $self->{'alt_rmnoncoding_count'};
1115 }
1116  
1117  
1118 =head2 get_alt_lnoncoding_count
1119  
1120 Arg [1] : (optional) alt long non coding count
1121 Example : $alt_lnoncoding_count = $genome->get_alt_lnoncoding_count();
1122 Description: Getter/setter for the number of long non coding genes on alternate sequences
1123  
1124 Returntype : integer
1125 Exceptions : none
1126 Caller : general
1127 Status : Stable
1128  
1129 =cut
1130  
1131 sub get_alt_lnoncoding_count {
1132 my ($self, $alt_lnoncoding_count) = @_;
1133 if (defined $alt_lnoncoding_count) {
1134 $self->{'alt_lnoncoding_count'} = $alt_lnoncoding_count;
1135 }
1136 if (!defined $self->{'alt_lnoncoding_count'}) {
1137 $self->{'alt_lnoncoding_count'} = $self->_get_count('noncoding_acnt_l');
1138 }
1139 return $self->{'alt_lnoncoding_count'};
1140 }
1141  
1142 =head2 get_alt_rlnoncoding_count
1143  
1144 Arg [1] : (optional) alt readthrough long non coding count
1145 Example : $alt_lnoncoding_count = $genome->get_alt_lnoncoding_count();
1146 Description: Getter/setter for the number of readthrough long non coding genes on alternate sequences
1147  
1148 Returntype : integer
1149 Exceptions : none
1150 Caller : general
1151 Status : Stable
1152  
1153 =cut
1154  
1155 sub get_alt_rlnoncoding_count {
1156 my ($self, $alt_rlnoncoding_count) = @_;
1157 if (defined $alt_rlnoncoding_count) {
1158 $self->{'alt_rlnoncoding_count'} = $alt_rlnoncoding_count;
1159 }
1160 if (!defined $self->{'alt_rlnoncoding_count'}) {
1161 $self->{'alt_rlnoncoding_count'} = $self->_get_count('noncoding_racnt_l');
1162 }
1163 return $self->{'alt_rlnoncoding_count'};
1164 }
1165  
1166  
1167  
1168 =head2 get_alt_pseudogene_count
1169  
1170 Arg [1] : (optional) alt pseudogene count
1171 Example : $alt_pseudogene_count = $genome->get_alt_pseudogene_count();
1172 Description: Getter/setter for the number of pseudogenes on alternate sequences
1173  
1174 Returntype : integer
1175 Exceptions : none
1176 Caller : general
1177 Status : Stable
1178  
1179 =cut
1180  
1181 sub get_alt_pseudogene_count {
1182 my ($self, $alt_pseudogene_count) = @_;
1183 if (defined $alt_pseudogene_count) {
1184 $self->{'alt_pseudogene_count'} = $alt_pseudogene_count;
1185 }
1186 if (!defined $self->{'alt_pseudogene_count'}) {
1187 $self->{'alt_pseudogene_count'} = $self->_get_count('pseudogene_acnt');
1188 }
1189 return $self->{'alt_pseudogene_count'};
1190 }
1191  
1192 =head2 get_alt_rpseudogene_count
1193  
1194 Arg [1] : (optional) alt readthrough pseudogene count
1195 Example : $alt_rpseudogene_count = $genome->get_alt_pseudogene_count();
1196 Description: Getter/setter for the number of readthrough pseudogenes on alternate sequences
1197  
1198 Returntype : integer
1199 Exceptions : none
1200 Caller : general
1201 Status : Stable
1202  
1203 =cut
1204  
1205 sub get_alt_rpseudogene_count {
1206 my ($self, $alt_rpseudogene_count) = @_;
1207 if (defined $alt_rpseudogene_count) {
1208 $self->{'alt_rpseudogene_count'} = $alt_rpseudogene_count;
1209 }
1210 if (!defined $self->{'alt_rpseudogene_count'}) {
1211 $self->{'alt_rpseudogene_count'} = $self->_get_count('pseudogene_racnt');
1212 }
1213 return $self->{'alt_rpseudogene_count'};
1214 }
1215  
1216 =head2 get_short_variation_count
1217  
1218 Arg [1] : (optional) short variation count
1219 Example : $short_variation_count = $genome->get_short_variation_count();
1220 Description: Getter/setter for the number of short variants in the current build
1221  
1222 Returntype : integer
1223 Exceptions : none
1224 Caller : general
1225 Status : Stable
1226  
1227 =cut
1228  
1229 sub get_short_variation_count {
1230 my ($self, $short_variation_count) = @_;
1231 if (defined $short_variation_count) {
1232 $self->{'short_variation_count'} = $short_variation_count;
1233 }
1234 if (!defined $self->{'short_variation_count'}) {
1235 $self->{'short_variation_count'} = $self->_get_count('SNPCount');
1236 }
1237 return $self->{'short_variation_count'};
1238 }
1239  
1240  
1241 =head2 get_prediction_count
1242  
1243 Arg [1] : (optional) logic_name
1244 Example : $prediction_count = $genome->get_prediction_count();
1245 Description: Getter for the number of predicted genes in the current build
1246 Can be restricted to a given analysis
1247  
1248 Returntype : integer
1249 Exceptions : none
1250 Caller : general
1251 Status : Stable
1252  
1253 =cut
1254  
1255 sub get_prediction_count {
1256 my ($self, $logic_name) = @_;
1257 return $self->_get_count('PredictionTranscript', $logic_name);
1258 }
1259  
1260  
1261 =head2 get_structural_variation_count
1262  
1263 Arg [1] : none
1264 Example : $structural_variation_count = $genome->get_structural_variation_count();
1265 Description: Return the number of structural variations in the current build
1266 Returntype : integer
1267 Exceptions : none
1268 Caller : general
1269 Status : Stable
1270  
1271 =cut
1272  
1273 sub get_structural_variation_count {
1274 my ($self, $structural_variation_count) = @_;
1275 if (defined $structural_variation_count) {
1276 $self->{'structural_variation_count'} = $structural_variation_count;
1277 }
1278 if (!defined $self->{'structural_variation_count'}) {
1279 $self->{'structural_variation_count'} = $self->_get_count('StructuralVariation');
1280 }
1281 return $self->{'structural_variation_count'};
1282 }
1283  
1284 =head2 get_transcript_count
1285  
1286 Arg [1] : (optional) transcript count
1287 Example : $transcript_count = $genome->get_transcript_count();
1288 Description: Getter/setter for the number of transcripts in the current build
1289 Returntype : integer
1290 Exceptions : none
1291 Caller : general
1292 Status : Stable
1293  
1294 =cut
1295  
1296 sub get_transcript_count {
1297 my ($self, $transcript_count) = @_;
1298 if (defined $transcript_count) {
1299 $self->{'transcript_count'} = $transcript_count;
1300 }
1301 if (!defined $self->{'transcript_count'}) {
1302 $self->{'transcript_count'} = $self->_get_count('transcript');
1303 }
1304 return $self->{'transcript_count'};
1305 }
1306  
1307 =head2 get_alt_transcript_count
1308  
1309 Arg [1] : (optional) alt transcript count
1310 Example : $alt_transcript_count = $genome->get_alt_transcript_count();
1311 Description: Getter/setter for the number of transcripts on alternate sequences in the current build
1312 Returntype : integer
1313 Exceptions : none
1314 Caller : general
1315 Status : Stable
1316  
1317 =cut
1318  
1319 sub get_alt_transcript_count {
1320 my ($self, $alt_transcript_count) = @_;
1321 if (defined $alt_transcript_count) {
1322 $self->{'alt_transcript_count'} = $alt_transcript_count;
1323 }
1324 if (!defined $self->{'alt_transcript_count'}) {
1325 $self->{'alt_transcript_count'} = $self->_get_count('alt_transcript');
1326 }
1327 return $self->{'alt_transcript_count'};
1328 }
1329  
1330  
1331 =head2 has_karyotype
1332  
1333 Arg : None
1334 Example : $has_karyotype = $genome->has_karyotype();
1335 Description: Boolean indicating whether a genome has a karyotype (ie chromosomes)
1336 or not
1337 Returntype : integer
1338 Exceptions : none
1339 Caller : general
1340 Status : Stable
1341  
1342 =cut
1343  
1344 sub has_karyotype {
1345 my $self = shift;
1346  
1347 my $db = $self->db();
1348 my $slice_adaptor = $db->get_SliceAdaptor();
1349 my $karyotype = $slice_adaptor->fetch_all_karyotype;
1350  
1351 return 0 unless scalar(@$karyotype);
1352  
1353 return 1;
1354 }
1355  
1356  
1357 =head2 is_high_coverage
1358  
1359 Arg : None
1360 Example : $is_high_coverage = $genome->is_high_coverage();
1361 Description: Boolean indicating whether an assembly is high coverage
1362 or not
1363 Returntype : integer
1364 Exceptions : none
1365 Caller : general
1366 Status : Stable
1367  
1368 =cut
1369  
1370 sub is_high_coverage {
1371 my $self = shift;
1372  
1373 my $coverage_depth = $self->_meta_container->single_value_by_key('assembly.coverage_depth');
1374  
1375 return 0 if !$coverage_depth;
1376 $coverage_depth = lc($coverage_depth);
1377  
1378 if ($coverage_depth eq 'high') {
1379 return 1;
1380 } elsif (($coverage_depth eq 'low') or ($coverage_depth eq 'medium')) {
1381 return 0;
1382 } elsif ($coverage_depth =~ /^([0-9]+)x$/) {
1383 return $1<6 ? 0 : 1;
1384 }
1385  
1386 return 0;
1387 }
1388  
1389 =head2 is_polyploid
1390  
1391 Arg : None
1392 Example : $is_polyploid = $genome->is_polyploid();
1393 Description: Returns whether the genome is or is not polyploid.
1394 Returntype : integer
1395 Exceptions : none
1396 Caller : general
1397 Status : Stable
1398  
1399 =cut
1400  
1401 sub is_polyploid {
1402 my $self = shift;
1403  
1404 my $polyploid = $self->_meta_container->single_value_by_key('ploidy');
1405  
1406 # polyploid could be not defined, meta_key is optional
1407 return 0 unless defined $polyploid;
1408  
1409 return $polyploid > 2;
1410 }
1411  
1412 =head2 get_genome_components
1413  
1414 Arg : None
1415 Example : $components = $genome->get_genome_components();
1416 Description: Returns the list of (diploid) components, for a
1417 polyploid genome
1418 Returntype : Arrayref
1419 Exceptions : none
1420 Caller : general
1421 Status : Stable
1422  
1423 =cut
1424  
1425 sub get_genome_components {
1426 my $self = shift;
1427  
1428 my $sql_helper = $self->dbc->sql_helper;
1429  
1430 my $sql =
1431 "SELECT DISTINCT value
1432 FROM seq_region_attrib JOIN attrib_type
1433 USING (attrib_type_id) WHERE attrib_type.code='genome_component'";
1434  
1435 return $sql_helper->execute_simple(-SQL => $sql);
1436 }
1437  
1438 sub _obj_from_sth {
1439 my $self = shift;
1440 my $sth = shift;
1441  
1442 my ($dbID, $statistic, $value, $species_id, $code, $name, $desc);
1443 $sth->bind_columns(\$dbID, \$statistic, \$value, \$species_id, \$code, \$name, \$desc);
1444  
1445 my @results;
1446 while ($sth->fetch()) {
1447 push @results,
1448 Bio::EnsEMBL::Genome->new_fast({'dbID' => $dbID,
1449 'statistic' => $statistic,
1450 'code' => $code,
1451 'name' => $name,
1452 'description' => $desc,
1453 'value' => $value});
1454 }
1455  
1456 return \@results;
1457 }
1458  
1459 1;