EnsEMBL/DBSQL/GenomeContainer.pm untested

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