GenomeInfoAdaptor.pm
Go to the documentation of this file.
00001 
00002 =head1 LICENSE
00003 
00004 Copyright [1999-2014] EMBL-European Bioinformatics Institute
00005 
00006 Licensed under the Apache License, Version 2.0 (the "License");
00007 you may not use this file except in compliance with the License.
00008 You may obtain a copy of the License at
00009 
00010      http://www.apache.org/licenses/LICENSE-2.0
00011 
00012 Unless required by applicable law or agreed to in writing, software
00013 distributed under the License is distributed on an "AS IS" BASIS,
00014 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 See the License for the specific language governing permissions and
00016 limitations under the License.
00017 
00018 =cut
00019 
00020 =pod
00021 
00022 =head1 NAME
00023 
00024 Bio::EnsEMBL::MetaData::DBSQL::GenomeInfoAdaptor
00025 
00026 =head1 SYNOPSIS
00027 
00028 # metadata_db is an instance of MetaDataDBAdaptor
00029 my $adaptor = $metadata_db->get_GenomeInfoAdaptor();
00030 my $md = $gdba->fetch_by_name("homo_sapiens");
00031 
00032 =head1 DESCRIPTION
00033 
00034 Adaptor for storing and retrieving GenomeInfo objects from MySQL ensembl_metadata database
00035 
00036 To start working with an adaptor:
00037 
00038 # getting an adaptor
00039 ## adaptor for latest public Ensembl release
00040 my $gdba = Bio::EnsEMBL::MetaData::DBSQL::GenomeInfoAdaptor->build_ensembl_adaptor();
00041 ## adaptor for specified public Ensembl release
00042 my $gdba = Bio::EnsEMBL::MetaData::DBSQL::GenomeInfoAdaptor->build_ensembl_adaptor(83);
00043 ## adaptor for latest public EG release
00044 my $gdba = Bio::EnsEMBL::MetaData::DBSQL::GenomeInfoAdaptor->build_ensembl_genomes_adaptor();
00045 ## adaptor for specified public EG release
00046 my $gdba = Bio::EnsEMBL::MetaData::DBSQL::GenomeInfoAdaptor->build_ensembl_genome_adaptor(30);
00047 ## manually specify a given database
00048 my $gdba = Bio::EnsEMBL::MetaData::DBSQL::GenomeInfoAdaptor->new(-USER=>'anonymous',
00049 -PORT=>4157,
00050 -HOST=>'mysql-eg-publicsql.ebi.ac.uk',
00051 -DBNAME=>'ensembl_metadata');
00052 
00053 To find genomes, use the fetch methods. These will work with the release set on the adaptor
00054 which is the latest Ensembl release by default.
00055 
00056 # find a genome by name
00057 my $genome = $gdba->fetch_by_name('homo_sapiens');
00058 
00059 # find and iterate over all genomes
00060 for my $genome (@{$gdba->fetch_all()}) {
00061     print $genome->name()."\n";
00062 }
00063 
00064 # find and iterate over all genomes with variation
00065 for my $genome (@{$gdba->fetch_all_with_variation()}) {
00066     print $genome->name()."\n";
00067 }
00068 
00069 # to change the release
00070 $gdba->set_ensembl_release(82);
00071 $gdba->set_ensembl_genomes_release(82);
00072 
00073 my $genome = $gdba->fetch_by_name('arabidopsis_thaliana');
00074 
00075 # find and iterate over all genomes from plants
00076 for my $genome (@{$gdba->fetch_all_by_division('EnsemblPlants')}) {
00077     print $genome->name()."\n";
00078 }
00079 
00080 # find all comparas for the division of interest
00081 my $comparas = $gdba->fetch_all_compara_by_division('EnsemblPlants');
00082 
00083 # find the peptide compara
00084 my ($compara) = grep {$_->is_peptide_compara()} @$comparas;
00085 print $compara->division()." ".$compara->method()."(".$compara->dbname().")\n";
00086 
00087 # print out all the genomes in this compara
00088 for my $genome (@{$compara->genomes()}) {
00089     print $genome->name()."\n";
00090 }
00091 
00092 =head1 SEE ALSO
00093 
00094 Bio::EnsEMBL::MetaData::GenomeInfo
00095 Bio::EnsEMBL::MetaData::GenomeComparaInfo
00096 Bio::EnsEMBL::MetaData::GenomeAssemblyInfo
00097 Bio::EnsEMBL::MetaData::GenomeOrganismInfo
00098 
00099 =head1 Author
00100 
00101 Dan Staines
00102 
00103 =cut
00104 
00105 package Bio::EnsEMBL::MetaData::DBSQL::GenomeInfoAdaptor;
00106 
00107 use strict;
00108 use warnings;
00109 
00110 use base qw/Bio::EnsEMBL::MetaData::DBSQL::BaseInfoAdaptor/;
00111 
00112 use Carp qw(cluck croak);
00113 use Bio::EnsEMBL::Utils::Argument qw( rearrange );
00114 use Bio::EnsEMBL::MetaData::GenomeInfo;
00115 use Data::Dumper;
00116 use Scalar::Util qw(looks_like_number refaddr);
00117 use Bio::EnsEMBL::Utils::PublicMySQLServer qw/e_args eg_args/;
00118 use Bio::EnsEMBL::Utils::Exception qw/throw/;
00119 use Bio::EnsEMBL::MetaData::DBSQL::MetaDataDBAdaptor;
00120 
00121 =head1 METHODS
00122 
00123 =head2 build_ensembl_adaptor
00124   Arg        : (optional) Ensembl release number - default is latest
00125   Description: Build an adaptor for the public Ensembl metadata database
00126   Returntype : Bio::EnsEMBL::MetaData::DBSQL::GenomeInfoAdaptor
00127   Exceptions : none
00128   Caller     : general
00129   Status     : Stable
00130 =cut
00131 
00132 sub build_ensembl_adaptor {
00133   my ( $self, $release ) = @_;
00134   my $args = e_args();
00135   $args->{-DBNAME} = 'ensembl_metadata';
00136   my $adaptor =
00137     Bio::EnsEMBL::MetaData::DBSQL::GenomeInfoAdaptor->new(
00138                 Bio::EnsEMBL::MetaData::DBSQL::MetaDataDBAdaptor->new(%$args) );
00139   if ( defined $release ) {
00140     $adaptor->set_ensembl_release($release);
00141   }
00142   return $adaptor;
00143 }
00144 
00145 =head2 build_ensembl_genomes_adaptor
00146   Arg        : (optional) EG release number  - default is latest
00147   Description: Build an adaptor for the public Ensembl Genomes metadata database
00148   Returntype : Bio::EnsEMBL::MetaData::DBSQL::GenomeInfoAdaptor
00149   Exceptions : none
00150   Caller     : general
00151   Status     : Stable
00152 =cut
00153 
00154 sub build_ensembl_genomes_adaptor {
00155   my ( $self, $release ) = @_;
00156   my $args = eg_args();
00157   $args->{-DBNAME} = 'ensembl_metadata';
00158   my $adaptor =
00159     Bio::EnsEMBL::MetaData::DBSQL::GenomeInfoAdaptor->new(
00160                 Bio::EnsEMBL::MetaData::DBSQL::MetaDataDBAdaptor->new(%$args) );
00161   $adaptor->set_ensembl_genomes_release($release);
00162   return $adaptor;
00163 }
00164 
00165 =head2 set_release
00166   Arg        : Ensembl release number
00167   Description: Set release to use when querying 
00168   Returntype : None
00169   Exceptions : none
00170   Caller     : general
00171   Status     : Stable
00172 =cut
00173 
00174 sub set_ensembl_release {
00175   my ( $self, $release ) = @_;
00176   my $release_info =
00177     $self->db()->get_DataReleaseInfoAdaptor()
00178     ->fetch_by_ensembl_release($release);
00179   if ( !defined $release_info ) {
00180     throw "Could not find Ensembl release $release";
00181   }
00182   else {
00183     $self->data_release($release_info);
00184   }
00185   return;
00186 }
00187 
00188 =head2 set_ensembl_genomes_release
00189   Arg        : Ensembl Genomes release number
00190   Description: Set release to use when querying 
00191   Returntype : None
00192   Exceptions : none
00193   Caller     : general
00194   Status     : Stable
00195 =cut
00196 
00197 sub set_ensembl_genomes_release {
00198   my ( $self, $release ) = @_;
00199   my $release_info;
00200   if ( !defined $release ) {
00201     $release_info =
00202       $self->db()->get_DataReleaseInfoAdaptor()
00203       ->fetch_current_ensembl_genomes_release($release);
00204   }
00205   else {
00206     $release_info =
00207       $self->db()->get_DataReleaseInfoAdaptor()
00208       ->fetch_by_ensembl_genomes_release($release);
00209   }
00210   if ( !defined $release_info ) {
00211     throw "Could not find Ensembl Genomes release $release";
00212   }
00213   else {
00214     $self->data_release($release_info);
00215   }
00216   return;
00217 }
00218 
00219 =head2 data_release
00220   Arg        : Bio::EnsEMBL::MetaData::DataReleaseInfo
00221   Description: Default release to use when querying 
00222   Returntype : None
00223   Exceptions : none
00224   Caller     : general
00225   Status     : Stable
00226 =cut
00227 
00228 sub data_release {
00229   my ( $self, $release ) = @_;
00230   if ( defined $release ) {
00231     # replace release if we've been given something different
00232     if ( !defined $self->{data_release} ||
00233          refaddr($release) != refaddr( $self->{data_release} ) )
00234     {
00235       $self->{data_release} = $release;
00236       $self->db()->get_GenomeComparaInfoAdaptor()->data_release($release);
00237     }
00238   }
00239   if ( !defined $self->{data_release} ) {
00240     # default to current Ensembl release
00241     $self->{data_release} =
00242       $self->db()->get_DataReleaseInfoAdaptor()
00243       ->fetch_current_ensembl_release();
00244     if ( defined $self->{data_release} ) {
00245       $self->db()->get_GenomeComparaInfoAdaptor()
00246         ->data_release( $self->{data_release} );
00247     }
00248   }
00249   if ( !defined $self->{data_release}->dbID() ) {
00250     $self->db()->get_DataReleaseInfoAdaptor()->store( $self->{data_release} );
00251   }
00252   return $self->{data_release};
00253 } ## end sub data_release
00254 
00255 =head2 store
00256   Arg        : Bio::EnsEMBL::MetaData::GenomeInfo
00257   Description: Stores the supplied object and all associated child objects (includes other genomes attached by compara if not already stored)
00258   Returntype : None
00259   Exceptions : none
00260   Caller     : general
00261   Status     : Stable
00262 =cut
00263 
00264 sub store {
00265   my ( $self, $genome ) = @_;
00266   if ( !defined $genome->data_release() ) {
00267     $genome->data_release( $self->data_release() );
00268   }
00269   if ( !defined $genome->data_release()->dbID() ) {
00270     $self->db()->get_DataReleaseInfoAdaptor()->store( $genome->data_release() );
00271   }
00272   if ( !defined $genome->assembly() ) {
00273     throw("Genome must be associated with an assembly");
00274   }
00275   if ( !defined $genome->assembly()->dbID() ) {
00276     $self->db()->get_GenomeAssemblyInfoAdaptor()->store( $genome->assembly() );
00277   }
00278   if ( !defined $genome->dbID() ) {
00279     # find out if genome exists first
00280     my ($dbID) =
00281       @{
00282       $self->dbc()->sql_helper()->execute_simple(
00283         -SQL =>
00284 "select genome_id from genome where data_release_id=? and assembly_id=?",
00285         -PARAMS =>
00286           [ $genome->data_release()->dbID(), $genome->assembly()->dbID() ] ) };
00287 
00288     if ( defined $dbID ) {
00289       $genome->dbID($dbID);
00290       $genome->adaptor($self);
00291     }
00292   }
00293 
00294   if ( defined $genome->dbID() ) {
00295     return $self->update($genome);
00296   }
00297   $self->db()->get_GenomeAssemblyInfoAdaptor()->store( $genome->assembly() );
00298   $self->dbc()->sql_helper()->execute_update(
00299     -SQL => q/insert into genome(division_id,
00300 genebuild,has_pan_compara,has_variations,has_peptide_compara,
00301 has_genome_alignments,has_synteny,has_other_alignments,assembly_id,organism_id,data_release_id)
00302         values(?,?,?,?,?,?,?,?,?,?,?)/,
00303     -PARAMS => [ $self->_get_division_id( $genome->division() ),
00304                  $genome->genebuild(),
00305                  $genome->has_pan_compara(),
00306                  $genome->has_variations(),
00307                  $genome->has_peptide_compara(),
00308                  $genome->has_genome_alignments(),
00309                  $genome->has_synteny(),
00310                  $genome->has_other_alignments(),
00311                  $genome->assembly()->dbID(),
00312                  $genome->assembly()->organism()->dbID(),
00313                  $genome->data_release()->dbID() ],
00314     -CALLBACK => sub {
00315       my ( $sth, $dbh, $rv ) = @_;
00316       $genome->dbID( $dbh->{mysql_insertid} );
00317     } );
00318   $genome->adaptor($self);
00319   $self->_store_databases($genome);
00320   $self->_store_annotations($genome);
00321   $self->_store_features($genome);
00322   $self->_store_variations($genome);
00323   $self->_store_alignments($genome);
00324   $self->_store_compara($genome);
00325   $self->_store_cached_obj($genome);
00326   return;
00327 } ## end sub store
00328 
00329 =head2 update
00330   Arg        : Bio::EnsEMBL::MetaData::GenomeInfo
00331   Description: Updates the supplied object and all associated child objects (includes other genomes attached by compara if not already stored)
00332   Returntype : None
00333   Exceptions : none
00334   Caller     : general
00335   Status     : Stable
00336 =cut
00337 
00338 sub update {
00339   my ( $self, $genome ) = @_;
00340   if ( !defined $genome->dbID() ) {
00341     croak "Cannot update an object that has not already been stored";
00342   }
00343   $self->db()->get_GenomeAssemblyInfoAdaptor()->update( $genome->assembly() );
00344   $self->dbc()->sql_helper()->execute_update(
00345     -SQL => q/update genome set division_id=?,
00346 genebuild=?,has_pan_compara=?,has_variations=?,has_peptide_compara=?,
00347 has_genome_alignments=?,has_synteny=?,has_other_alignments=?,assembly_id=?,organism_id=?,data_release_id=? where genome_id=?/
00348     ,
00349     -PARAMS => [ $self->_get_division_id( $genome->division() ),
00350                  $genome->genebuild(),
00351                  $genome->has_pan_compara(),
00352                  $genome->has_variations(),
00353                  $genome->has_peptide_compara(),
00354                  $genome->has_genome_alignments(),
00355                  $genome->has_synteny(),
00356                  $genome->has_other_alignments(),
00357                  $genome->assembly()->dbID(),
00358                  $genome->assembly()->organism()->dbID(),
00359                  $genome->data_release()->dbID(),
00360                  $genome->dbID() ] );
00361   $genome->adaptor($self);
00362   $self->_store_databases($genome);
00363   $self->_store_annotations($genome);
00364   $self->_store_features($genome);
00365   $self->_store_variations($genome);
00366   $self->_store_alignments($genome);
00367   $self->_store_compara($genome);
00368   return;
00369 } ## end sub update
00370 
00371 =head2 update_booleans
00372   Description: Updates boolean genome attributes for all genomes
00373   Returntype : None
00374   Exceptions : none
00375   Caller     : internal
00376   Status     : Stable
00377 =cut
00378 
00379 sub update_booleans {
00380   my ($self) = @_;
00381 
00382   #has_peptide_compara
00383   $self->dbc()->sql_helper()->execute_update(
00384     -SQL => q/update genome g join genome_compara_analysis gc using (genome_id) 
00385       join compara_analysis c using (compara_analysis_id) 
00386       set g.has_peptide_compara=1 where c.division<>'EnsemblPan' and
00387       c.method='PROTEIN_TREES'/
00388   );
00389 
00390   #has_pan_compara
00391   $self->dbc()->sql_helper()->execute_update(
00392     -SQL => q/update genome g join genome_compara_analysis gc using (genome_id) 
00393       join compara_analysis c using (compara_analysis_id) 
00394       set g.has_pan_compara=1 where c.division='EnsemblPan' and
00395       c.method='PROTEIN_TREES'/
00396   );
00397 
00398   #has_genome_alignments
00399   $self->dbc()->sql_helper()->execute_update(
00400     -SQL => q/update genome g join genome_compara_analysis gc using (genome_id) 
00401       join compara_analysis c using (compara_analysis_id) 
00402       set g.has_genome_alignments=1 where c.method in 
00403       ('TRANSLATED_BLAT_NET','LASTZ_NET','TBLAT','ATAC','BLASTZ_NET')/
00404   );
00405 
00406   #has_synteny
00407   $self->dbc()->sql_helper()->execute_update(
00408     -SQL => q/update genome g join genome_compara_analysis gc using (genome_id) 
00409       join compara_analysis c using (compara_analysis_id) 
00410       set g.has_synteny=1 where c.method='SYNTENY'/
00411   );
00412 
00413   #has_other_alignments
00414   $self->dbc()->sql_helper()->execute_update(
00415     -SQL => q/update genome g join genome_alignment a using (genome_id) 
00416       set g.has_other_alignments=1/
00417   );
00418 
00419   #has_variations
00420   $self->dbc()->sql_helper()->execute_update(
00421     -SQL => q/update genome g join genome_variation a using (genome_id)
00422       set g.has_variations=1/
00423   );
00424 
00425   return;
00426 } ## end sub update_booleans
00427 
00428 =head2 fetch_databases 
00429   Arg        : release (optional)
00430   Description: Fetch all genome-associated databases for the specified release
00431   Returntype : Arrayref of strings
00432   Exceptions : none
00433   Caller     : general
00434   Status     : Stable
00435 =cut
00436 
00437 sub fetch_databases {
00438   my ( $self, $release ) = @_;
00439   if ( !defined $release ) {
00440     $release = $self->data_release();
00441   }
00442   return $self->dbc()->sql_helper()->execute_simple(
00443     -SQL => q/select distinct dbname from genome_database
00444       join genome using (genome_id) where data_release_id=?/,
00445     -PARAMS => [ $release->dbID() ] );
00446 }
00447 
00448 =head2 fetch_division_databases 
00449   Arg        : division
00450   Arg        : release (optional)
00451   Description: Fetch all genome-associated databases for the specified release
00452   Returntype : Arrayref of strings
00453   Exceptions : none
00454   Caller     : general
00455   Status     : Stable
00456 =cut
00457 
00458 sub fetch_division_databases {
00459   my ( $self, $division, $release ) = @_;
00460   if ( !defined $release ) {
00461     $release = $self->data_release();
00462   }
00463   return $self->dbc()->sql_helper()->execute_simple(
00464     -SQL => q/select distinct gd.dbname from genome_database gd
00465       join genome g using (genome_id)
00466       join division d using (division_id)
00467       where data_release_id=? and (d.name=? OR d.short_name=?)/,
00468     -PARAMS => [ $release->dbID(), $division, $division ] );
00469 }
00470 
00471 =head2 fetch_by_organism 
00472   Arg        : Bio::EnsEMBL::MetaData::GenomeOrganismInfo
00473   Arg        : (optional) if 1, expand children of genome info
00474   Description: Fetch genome info for specified organism
00475   Returntype : Bio::EnsEMBL::MetaData::GenomeInfo
00476   Exceptions : none
00477   Caller     : general
00478   Status     : Stable
00479 =cut
00480 
00481 sub fetch_by_organism {
00482   my ( $self, $organism, $keen ) = @_;
00483   if ( ref($organism) eq 'Bio::EnsEMBL::MetaData::GenomeOrganismInfo' ) {
00484     $organism = $organism->dbID();
00485   }
00486   return $self->_first_element(
00487        $self->_fetch_generic_with_args( { 'organism_id', $organism }, $keen ) );
00488 }
00489 
00490 =head2 fetch_all_by_organisms
00491   Arg        : Array ref of Bio::EnsEMBL::MetaData::GenomeOrganismInfo
00492   Arg        : (optional) if 1, expand children of genome info
00493   Description: Fetch genome info for specified organisms
00494   Returntype : Bio::EnsEMBL::MetaData::GenomeInfo
00495   Exceptions : none
00496   Caller     : general
00497   Status     : Stable
00498 =cut
00499 
00500 sub fetch_all_by_organisms {
00501   my ( $self, $organisms, $keen ) = @_;
00502   if ( !defined $organisms || scalar($organisms) == 0 ) {
00503     return [];
00504   }
00505   return
00506     $self->_fetch_generic_with_args( { 'organism_id',
00507                                        [ map { $_->dbID() } @$organisms ] },
00508                                      $keen );
00509 }
00510 
00511 =head2 fetch_by_taxonomy_id
00512   Arg        : Taxonomy ID
00513   Arg        : (optional) if 1, expand children of genome info
00514   Description: Fetch genome info for specified taxonomy node
00515   Returntype : arrayref of Bio::EnsEMBL::MetaData::GenomeOrganismInfo
00516   Exceptions : none
00517   Caller     : general
00518   Status     : Stable
00519 =cut
00520 
00521 sub fetch_all_by_taxonomy_id {
00522   my ( $self, $id, $keen ) = @_;
00523   return $self->fetch_all_by_organisms(
00524                    $self->_organism_adaptor()->fetch_all_by_taxonomy_id($id) );
00525 }
00526 
00527 =head2 fetch_by_taxonomy_ids
00528   Arg        : Arrayref of Taxonomy ID
00529   Description: Fetch genome info for specified taxonomy nodes (batch)
00530   Returntype : arrayref of Bio::EnsEMBL::MetaData::GenomeOrganismInfo
00531   Exceptions : none
00532   Caller     : general
00533   Status     : Stable
00534 =cut
00535 
00536 sub fetch_all_by_taxonomy_ids {
00537   my ( $self, $ids ) = @_;
00538   return $self->fetch_all_by_organisms(
00539                   $self->_organism_adaptor()->fetch_all_by_taxonomy_ids($ids) );
00540 }
00541 
00542 =head2 fetch_all_by_taxonomy_branch
00543   Arg        : Bio::EnsEMBL::TaxonomyNode
00544   Description: Fetch organism info for specified taxonomy node and its children
00545   Returntype : arrayref of Bio::EnsEMBL::MetaData::GenomeOrganismInfo
00546   Exceptions : none
00547   Caller     : general
00548   Status     : Stable
00549 =cut
00550 
00551 sub fetch_all_by_taxonomy_branch {
00552   my ( $self, $root, $keen ) = @_;
00553   return $self->fetch_all_by_organisms(
00554       $self->_organism_adaptor()->fetch_all_by_taxonomy_branch( $root, $keen ) )
00555     ;
00556 }
00557 
00558 =head2 fetch_by_assembly 
00559   Arg        : Bio::EnsEMBL::MetaData::GenomeAssemblyInfo
00560   Arg        : (optional) if 1, expand children of genome info
00561   Description: Fetch genome info for specified assembly
00562   Returntype : Bio::EnsEMBL::MetaData::GenomeInfo
00563   Exceptions : none
00564   Caller     : general
00565   Status     : Stable
00566 =cut
00567 
00568 sub fetch_by_assembly {
00569   my ( $self, $assembly, $keen ) = @_;
00570   if ( ref($assembly) eq 'Bio::EnsEMBL::MetaData::GenomeAssemblyInfo' ) {
00571     $assembly = $assembly->dbID();
00572   }
00573   return $self->_first_element(
00574        $self->_fetch_generic_with_args( { 'assembly_id', $assembly }, $keen ) );
00575 }
00576 
00577 =head2 fetch_all_by_assemblies 
00578   Arg        : array of Bio::EnsEMBL::MetaData::GenomeAssemblyInfo
00579   Arg        : (optional) if 1, expand children of genome info
00580   Description: Fetch genome info for specified assembly
00581   Returntype : Bio::EnsEMBL::MetaData::GenomeInfo
00582   Exceptions : none
00583   Caller     : general
00584   Status     : Stable
00585 =cut
00586 
00587 sub fetch_all_by_assemblies {
00588   my ( $self, $assemblies, $keen ) = @_;
00589   if ( !defined $assemblies || scalar(@$assemblies) == 0 ) {
00590     return [];
00591   }
00592   return
00593     $self->_fetch_generic_with_args( { 'assembly_id',
00594                                        [ map { $_->dbID() } @$assemblies ] },
00595                                      $keen );
00596 }
00597 
00598 =head2 fetch_all_by_sequence_accession
00599   Arg        : INSDC sequence accession e.g. U00096.1 or U00096
00600   Arg        : (optional) if 1, expand children of genome info
00601   Description: Fetch genome info for specified sequence accession
00602   Returntype : Bio::EnsEMBL::MetaData::GenomeInfo
00603   Exceptions : none
00604   Caller     : general
00605   Status     : Stable
00606 =cut
00607 
00608 sub fetch_all_by_sequence_accession {
00609   my ( $self, $id, $keen ) = @_;
00610   my $ass =
00611     $self->_assembly_adaptor()->fetch_all_by_sequence_accession_versioned($id);
00612   my $infos = $self->fetch_all_by_assemblies( $ass, $keen );
00613   if ( !defined $infos || scalar(@$infos) == 0 ) {
00614     $ass =
00615       $self->_assembly_adaptor()
00616       ->fetch_all_by_sequence_accession_unversioned($id);
00617     $infos = $self->fetch_all_by_assemblies( $ass, $keen );
00618   }
00619   return $infos;
00620 }
00621 
00622 =head2 fetch_all_by_sequence_accession_unversioned
00623   Arg        : INSDC sequence accession e.g. U00096
00624   Arg        : (optional) if 1, expand children of genome info
00625   Description: Fetch genome info for specified sequence accession
00626   Returntype : Bio::EnsEMBL::MetaData::GenomeInfo
00627   Exceptions : none
00628   Caller     : general
00629   Status     : Stable
00630 =cut
00631 
00632 sub fetch_all_by_sequence_accession_unversioned {
00633   my ( $self, $id, $keen ) = @_;
00634   my $ass =
00635     $self->_assembly_adaptor()->fetch_all_sequence_accession_unversioned($id);
00636   return $self->fetch_all_by_assemblies( $ass, $keen );
00637 }
00638 
00639 =head2 fetch_all_by_sequence_accession_versioned
00640   Arg        : INSDC sequence accession e.g. U00096.1
00641   Arg        : (optional) if 1, expand children of genome info
00642   Description: Fetch genome info for specified sequence accession
00643   Returntype : Bio::EnsEMBL::MetaData::GenomeInfo
00644   Exceptions : none
00645   Caller     : general
00646   Status     : Stable
00647 =cut
00648 
00649 sub fetch_all_by_sequence_accession_versioned {
00650   my ( $self, $id, $keen ) = @_;
00651   my $ass =
00652     $self->_assembly_adaptor()->fetch_all_sequence_accession_versioned($id);
00653   return $self->fetch_all_by_assemblies( $ass, $keen );
00654 }
00655 
00656 =head2 fetch_by_assembly_accession
00657   Arg        : INSDC assembly accession
00658   Arg        : (optional) if 1, expand children of genome info
00659   Description: Fetch genome info for specified assembly ID (versioned or unversioned)
00660   Returntype : Bio::EnsEMBL::MetaData::GenomeInfo
00661   Exceptions : none
00662   Caller     : general
00663   Status     : Stable
00664 =cut
00665 
00666 sub fetch_by_assembly_accession {
00667   my ( $self, $id, $keen ) = @_;
00668   my $ass = $self->_assembly_adaptor()->fetch_by_assembly_accession($id);
00669   return $self->fetch_by_assembly( $ass, $keen );
00670 }
00671 
00672 =head2 fetch_all_by_assembly_set_chain
00673   Arg        : INSDC assembly set chain (unversioned accession)
00674   Arg        : (optional) if 1, expand children of genome info
00675   Description: Fetch genome info for specified assembly set chain
00676   Returntype : Bio::EnsEMBL::MetaData::GenomeInfo
00677   Exceptions : none
00678   Caller     : general
00679   Status     : Stable
00680 =cut
00681 
00682 sub fetch_all_by_assembly_set_chain {
00683   my ( $self, $id, $keen ) = @_;
00684   my $ass = $self->_assembly_adaptor()->fetch_all_by_assembly_set_chain($id);
00685   return $self->fetch_all_by_assemblies( $ass, $keen );
00686 }
00687 
00688 =head2 fetch_all_by_division
00689   Arg        : Name of division
00690   Arg        : (optional) if 1, expand children of genome info
00691   Description: Fetch genome infos for specified division
00692   Returntype : Arrayref of Bio::EnsEMBL::MetaData::GenomeInfo
00693   Exceptions : none
00694   Caller     : general
00695   Status     : Stable
00696 =cut
00697 
00698 sub fetch_all_by_division {
00699   my ( $self, $division, $keen ) = @_;
00700   return $self->_fetch_generic_with_args( { 'division', $division }, $keen );
00701 }
00702 
00703 =head2 fetch_by_display_name
00704   Arg        : Production name of genome 
00705   Arg        : (optional) if 1, expand children of genome info
00706   Description: Fetch genome info for specified species
00707   Returntype : Bio::EnsEMBL::MetaData::GenomeInfo
00708   Exceptions : none
00709   Caller     : general
00710   Status     : Stable
00711 =cut
00712 
00713 sub fetch_by_display_name {
00714   my ( $self, $name, $keen ) = @_;
00715   my $org = $self->_organism_adaptor()->fetch_by_display_name($name);
00716   return $self->fetch_by_organism( $org, $keen );
00717 }
00718 
00719 =head2 fetch_by_name
00720   Arg        : Display name of genome 
00721   Arg        : (optional) if 1, expand children of genome info
00722   Description: Fetch genome info for specified species
00723   Returntype : Bio::EnsEMBL::MetaData::GenomeInfo
00724   Exceptions : none
00725   Caller     : general
00726   Status     : Stable
00727 =cut
00728 
00729 sub fetch_by_name {
00730   my ( $self, $name, $keen ) = @_;
00731   my $org = $self->_organism_adaptor()->fetch_by_name($name);
00732   return $self->fetch_by_organism( $org, $keen );
00733 }
00734 
00735 =head2 fetch_by_any_name
00736   Arg        : Name of genome (display, species, alias etc)
00737   Arg        : (optional) if 1, expand children of genome info
00738   Description: Fetch genome info for specified species
00739   Returntype : Bio::EnsEMBL::MetaData::GenomeInfo
00740   Exceptions : none
00741   Caller     : general
00742   Status     : Stable
00743 =cut
00744 
00745 sub fetch_by_any_name {
00746   my ( $self, $name, $keen ) = @_;
00747   my $org = $self->_organism_adaptor()->fetch_by_name($name);
00748   if ( !defined $org ) {
00749     $org = $self->_organism_adaptor()->fetch_by_alias($name);
00750   }
00751   return $self->fetch_by_organism( $org, $keen );
00752 }
00753 
00754 =head2 fetch_all_by_dbname
00755   Arg        : Name of database
00756   Arg        : (optional) if 1, expand children of genome info
00757   Description: Fetch genome info for specified database
00758   Returntype : arrayref of Bio::EnsEMBL::MetaData::GenomeInfo
00759   Exceptions : none
00760   Caller     : general
00761   Status     : Stable
00762 =cut
00763 
00764 sub fetch_all_by_dbname {
00765   my ( $self, $name, $keen ) = @_;
00766   return $self->_fetch_generic_with_args( { 'dbname', $name }, $keen );
00767 }
00768 
00769 =head2 fetch_all_by_name_pattern
00770   Arg        : Regular expression matching of genome
00771   Arg        : (optional) if 1, expand children of genome info
00772   Description: Fetch genome info for specified species
00773   Returntype : Arrayref of Bio::EnsEMBL::MetaData::GenomeInfo
00774   Exceptions : none
00775   Caller     : general
00776   Status     : Stable
00777 =cut
00778 
00779 sub fetch_all_by_name_pattern {
00780   my ( $self, $name, $keen ) = @_;
00781   my $orgs = $self->_organism_adaptor()->fetch_all_by_name_pattern($name);
00782   return $self->fetch_all_by_organisms( $orgs, $keen );
00783 }
00784 
00785 =head2 fetch_by_alias
00786   Arg        : Alias of genome
00787   Arg        : (optional) if 1, expand children of genome info
00788   Description: Fetch genome info for specified species
00789   Returntype : Bio::EnsEMBL::MetaData::GenomeInfo
00790   Exceptions : none
00791   Caller     : general
00792   Status     : Stable
00793 =cut
00794 
00795 sub fetch_by_alias {
00796   my ( $self, $name, $keen ) = @_;
00797   my $org = $self->_organism_adaptor()->fetch_all_by_name_pattern($name);
00798   return $self->fetch_by_organism( $org, $keen );
00799 }
00800 
00801 =head2 fetch_all_with_variation
00802   Arg        : (optional) if 1, expand children of genome info
00803   Description: Fetch all genome info that have variation data
00804   Returntype : arrayref of Bio::EnsEMBL::MetaData::GenomeInfo
00805   Exceptions : none
00806   Caller     : general
00807   Status     : Stable
00808 =cut
00809 
00810 sub fetch_all_with_variation {
00811   my ( $self, $keen ) = @_;
00812   return $self->_fetch_generic_with_args( { 'has_variations' => '1' }, $keen );
00813 }
00814 
00815 =head2 fetch_all_with_peptide_compara
00816   Arg        : (optional) if 1, expand children of genome info
00817   Description: Fetch all genome info that have peptide compara data
00818   Returntype : arrayref of Bio::EnsEMBL::MetaData::GenomeInfo
00819   Exceptions : none
00820   Caller     : general
00821   Status     : Stable
00822 =cut
00823 
00824 sub fetch_all_with_peptide_compara {
00825   my ( $self, $keen ) = @_;
00826   return $self->_fetch_generic_with_args( { 'has_peptide_compara' => '1' },
00827                                           $keen );
00828 }
00829 
00830 =head2 fetch_all_with_pan_compara
00831   Arg        : (optional) if 1, expand children of genome info
00832   Description: Fetch all genome info that have pan comapra data
00833   Returntype : arrayref of Bio::EnsEMBL::MetaData::GenomeInfo
00834   Exceptions : none
00835   Caller     : general
00836   Status     : Stable
00837 =cut
00838 
00839 sub fetch_all_with_pan_compara {
00840   my ( $self, $keen ) = @_;
00841   return $self->_fetch_generic_with_args( { 'has_pan_compara' => '1' }, $keen );
00842 }
00843 
00844 =head2 fetch_all_with_genome_alignments
00845   Arg        : (optional) if 1, expand children of genome info
00846   Description: Fetch all genome info that have whole genome alignment data
00847   Returntype : arrayref of Bio::EnsEMBL::MetaData::GenomeInfo
00848   Exceptions : none
00849   Caller     : general
00850   Status     : Stable
00851 =cut
00852 
00853 sub fetch_all_with_genome_alignments {
00854   my ( $self, $keen ) = @_;
00855   return $self->_fetch_generic_with_args( { 'has_genome_alignments' => '1' },
00856                                           $keen );
00857 }
00858 
00859 =head2 fetch_all_with_compara
00860   Arg        : (optional) if 1, expand children of genome info
00861   Description: Fetch all genome info that have any compara or whole genome alignment data
00862   Returntype : arrayref of Bio::EnsEMBL::MetaData::GenomeInfo
00863   Exceptions : none
00864   Caller     : general
00865   Status     : Stable
00866 =cut
00867 
00868 sub fetch_all_with_compara {
00869   my ( $self, $keen ) = @_;
00870   return $self->_fetch_generic( $self->_get_base_sql() .
00871 q/ where has_genome_alignments=1 or has_pan_compara=1 or has_peptide_compara=1/
00872   );
00873 }
00874 
00875 =head2 fetch_with_other_alignments
00876   Arg        : (optional) if 1, expand children of genome info
00877   Description: Fetch all genome info that have other alignment data
00878   Returntype : arrayref of Bio::EnsEMBL::MetaData::GenomeInfo
00879   Exceptions : none
00880   Caller     : general
00881   Status     : Stable
00882 =cut
00883 
00884 sub fetch_all_with_other_alignments {
00885   my ( $self, $keen ) = @_;
00886   return $self->_fetch_generic_with_args( { 'has_other_alignments' => '1' },
00887                                           $keen );
00888 }
00889 
00890 =head1 INTERNAL METHODS
00891 =head2 _fetch_assembly
00892   Arg        : Bio::EnsEMBL::MetaData::GenomeInfo 
00893   Description: Add assembly to supplied object
00894   Returntype : none
00895   Exceptions : none
00896   Caller     : internal
00897   Status     : Stable
00898 =cut
00899 
00900 sub _fetch_assembly {
00901   my ( $self, $genome ) = @_;
00902   if ( defined $genome->{assembly_id} ) {
00903     $genome->assembly( $self->db()->get_GenomeAssemblyInfoAdaptor()
00904                        ->fetch_by_dbID( $genome->{assembly_id} ) );
00905   }
00906   return;
00907 }
00908 
00909 =head2 _fetch_data_release
00910   Arg        : Bio::EnsEMBL::MetaData::GenomeInfo 
00911   Description: Add data release to supplied object
00912   Returntype : none
00913   Exceptions : none
00914   Caller     : internal
00915   Status     : Stable
00916 =cut
00917 
00918 sub _fetch_data_release {
00919   my ( $self, $genome ) = @_;
00920   if ( defined $genome->{data_release_id} ) {
00921     $genome->data_release( $self->db()->get_DataReleaseInfoAdaptor()
00922                            ->fetch_by_dbID( $genome->{data_release_id} ) );
00923   }
00924   return;
00925 }
00926 
00927 =head2 _fetch_variations
00928   Arg        : Bio::EnsEMBL::MetaData::GenomeInfo 
00929   Description: Add variations to supplied object
00930   Returntype : none
00931   Exceptions : none
00932   Caller     : internal
00933   Status     : Stable
00934 =cut
00935 
00936 sub _fetch_variations {
00937   my ( $self, $genome ) = @_;
00938   croak
00939     "Cannot fetch variations for a GenomeInfo object that has not been stored"
00940     if !defined $genome->dbID();
00941   my $variations = {};
00942   $self->dbc()->sql_helper()->execute_no_return(
00943     -SQL => 'select type,name,count from genome_variation where genome_id=?',
00944     -CALLBACK => sub {
00945       my @row = @{ shift @_ };
00946       $variations->{ $row[0] }->{ $row[1] } = $row[2];
00947       return;
00948     },
00949     -PARAMS => [ $genome->dbID() ] );
00950   $genome->variations($variations);
00951   $genome->has_variations();
00952   return;
00953 }
00954 
00955 =head2 _fetch_databases
00956   Arg        : Bio::EnsEMBL::MetaData::GenomeInfo 
00957   Description: Add databases to supplied object
00958   Returntype : none
00959   Exceptions : none
00960   Caller     : internal
00961   Status     : Stable
00962 =cut
00963 
00964 sub _fetch_databases {
00965   my ( $self, $genome ) = @_;
00966   croak
00967     "Cannot fetch databases for a GenomeInfo object that has not been stored"
00968     if !defined $genome->dbID();
00969   $genome->{databases} =
00970     $self->db()->get_DatabaseInfoAdaptor()->fetch_databases($genome);
00971   return;
00972 }
00973 
00974 =head2 _fetch_other_alignments
00975   Arg        : Bio::EnsEMBL::MetaData::GenomeInfo 
00976   Description: Add other_alignments to supplied object
00977   Returntype : none
00978   Exceptions : none
00979   Caller     : internal
00980   Status     : Stable
00981 =cut
00982 
00983 sub _fetch_other_alignments {
00984   my ( $self, $genome ) = @_;
00985   croak
00986     "Cannot fetch alignments for a GenomeInfo object that has not been stored"
00987     if !defined $genome->dbID();
00988   my $alignments = {};
00989   $self->dbc()->sql_helper()->execute_no_return(
00990     -SQL => 'select type,name,count from genome_alignment where genome_id=?',
00991     -CALLBACK => sub {
00992       my @row = @{ shift @_ };
00993       $alignments->{ $row[0] }->{ $row[1] } = $row[2];
00994       return;
00995     },
00996     -PARAMS => [ $genome->dbID() ] );
00997   $genome->other_alignments($alignments);
00998   $genome->has_other_alignments();
00999   return;
01000 }
01001 
01002 =head2 _fetch_annotations
01003   Arg        : Bio::EnsEMBL::MetaData::GenomeInfo 
01004   Description: Add annotations to supplied object
01005   Returntype : none
01006   Exceptions : none
01007   Caller     : internal
01008   Status     : Stable
01009 =cut
01010 
01011 sub _fetch_annotations {
01012   my ( $self, $genome ) = @_;
01013   croak
01014     "Cannot fetch annotations for a GenomeInfo object that has not been stored"
01015     if !defined $genome->dbID();
01016   my $annotations = {};
01017   $self->dbc()->sql_helper()->execute_no_return(
01018     -SQL      => 'select type,count from genome_annotation where genome_id=?',
01019     -CALLBACK => sub {
01020       my @row = @{ shift @_ };
01021       $annotations->{ $row[0] } = $row[1];
01022       return;
01023     },
01024     -PARAMS => [ $genome->dbID() ] );
01025   $genome->annotations($annotations);
01026   return;
01027 }
01028 
01029 =head2 _fetch_features
01030   Arg        : Bio::EnsEMBL::MetaData::GenomeInfo 
01031   Description: Add features to supplied object
01032   Returntype : none
01033   Exceptions : none
01034   Caller     : internal
01035   Status     : Stable
01036 =cut
01037 
01038 sub _fetch_features {
01039   my ( $self, $genome ) = @_;
01040   croak
01041     "Cannot fetch features  for a GenomeInfo object that has not been stored"
01042     if !defined $genome->dbID();
01043   my $features = {};
01044   $self->dbc()->sql_helper()->execute_no_return(
01045     -SQL => 'select type,analysis,count from genome_feature where genome_id=?',
01046     -CALLBACK => sub {
01047       my @row = @{ shift @_ };
01048       $features->{ $row[0] }->{ $row[1] } = $row[2];
01049       return;
01050     },
01051     -PARAMS => [ $genome->dbID() ] );
01052   $genome->features($features);
01053   return;
01054 }
01055 
01056 =head2 _fetch_comparas
01057   Arg        : Bio::EnsEMBL::MetaData::GenomeInfo 
01058   Description: Add compara info to supplied object
01059   Returntype : none
01060   Exceptions : none
01061   Caller     : internal
01062   Status     : Stable
01063 =cut
01064 
01065 sub _fetch_comparas {
01066   my ( $self, $genome ) = @_;
01067   my $comparas = [];
01068   for my $id (
01069     @{$self->dbc()->sql_helper()->execute_simple(
01070         -SQL => q/select distinct compara_analysis_id from compara_analysis 
01071   join genome_compara_analysis using (compara_analysis_id)
01072   where genome_id=? and method in ('BLASTZ_NET','LASTZ_NET','TRANSLATED_BLAT_NET', 'PROTEIN_TREES', 'ATAC')/,
01073         -PARAMS => [ $genome->dbID() ] ) } )
01074   {
01075     push @$comparas,
01076       $self->db()->get_GenomeComparaInfoAdaptor()->fetch_by_dbID($id);
01077   }
01078   $genome->compara($comparas);
01079   $genome->has_pan_compara();
01080   $genome->has_genome_alignments();
01081   $genome->has_peptide_compara();
01082   return;
01083 }
01084 
01085 =head2 _fetch_children
01086   Arg        : Arrayref of Bio::EnsEMBL::MetaData::GenomeInfo
01087   Description: Fetch all children of specified genome info object
01088   Returntype : none
01089   Exceptions : none
01090   Caller     : internal
01091   Status     : Stable
01092 =cut
01093 
01094 sub _fetch_children {
01095   my ( $self, $genome ) = @_;
01096   $self->_fetch_databases($genome);
01097   $self->_fetch_assembly($genome);
01098   $self->_fetch_data_release($genome);
01099   $self->_fetch_variations($genome);
01100   $self->_fetch_annotations($genome);
01101   $self->_fetch_other_alignments($genome);
01102   $self->_fetch_comparas($genome);
01103   return;
01104 }
01105 
01106 =head2 _store_features
01107   Arg        : Bio::EnsEMBL::MetaData::GenomeInfo
01108   Description: Stores the features for the supplied object
01109   Returntype : None
01110   Exceptions : none
01111   Caller     : internal
01112   Status     : Stable
01113 =cut
01114 
01115 sub _store_features {
01116   my ( $self, $genome ) = @_;
01117 
01118   $self->dbc()->sql_helper()->execute_update(
01119                         -SQL => q/delete from genome_feature where genome_id=?/,
01120                         -PARAMS => [ $genome->dbID() ] );
01121 
01122   while ( my ( $type, $f ) = each %{ $genome->features() } ) {
01123     while ( my ( $analysis, $count ) = each %$f ) {
01124       $self->dbc()->sql_helper()->execute_update(
01125         -SQL => q/insert into genome_feature(genome_id,type,analysis,count)
01126         values(?,?,?,?)/,
01127         -PARAMS => [ $genome->dbID(), $type, $analysis, $count ] );
01128     }
01129   }
01130   return;
01131 }
01132 
01133 =head2 _store_databases
01134   Arg        : Bio::EnsEMBL::MetaData::GenomeInfo
01135   Description: Stores the databases for the supplied object
01136   Returntype : None
01137   Exceptions : none
01138   Caller     : internal
01139   Status     : Stable
01140 =cut
01141 
01142 sub _store_databases {
01143   my ( $self, $genome ) = @_;
01144   for my $database ( @{ $genome->databases() } ) {
01145     $self->db()->get_DatabaseInfoAdaptor()->store($database);
01146   }
01147   return;
01148 }
01149 
01150 =head2 _store_annotations
01151   Arg        : Bio::EnsEMBL::MetaData::GenomeInfo
01152   Description: Stores the annotations for the supplied object
01153   Returntype : None
01154   Exceptions : none
01155   Caller     : internal
01156   Status     : Stable
01157 =cut
01158 
01159 sub _store_annotations {
01160   my ( $self, $genome ) = @_;
01161 
01162   $self->dbc()->sql_helper()->execute_update(
01163                      -SQL => q/delete from genome_annotation where genome_id=?/,
01164                      -PARAMS => [ $genome->dbID() ] );
01165 
01166   while ( my ( $type, $count ) = each %{ $genome->annotations() } ) {
01167     $self->dbc()->sql_helper()->execute_update(
01168       -SQL => q/insert into genome_annotation(genome_id,type,count)
01169         values(?,?,?)/,
01170       -PARAMS => [ $genome->dbID(), $type, $count ] );
01171   }
01172   return;
01173 }
01174 
01175 =head2 _store_variations
01176   Arg        : Bio::EnsEMBL::MetaData::GenomeInfo
01177   Description: Stores the variations for the supplied object
01178   Returntype : None
01179   Exceptions : none
01180   Caller     : internal
01181   Status     : Stable
01182 =cut
01183 
01184 sub _store_variations {
01185   my ( $self, $genome ) = @_;
01186 
01187   $self->dbc()->sql_helper()->execute_update(
01188                       -SQL => q/delete from genome_variation where genome_id=?/,
01189                       -PARAMS => [ $genome->dbID() ] );
01190 
01191   while ( my ( $type, $f ) = each %{ $genome->variations() } ) {
01192     while ( my ( $key, $count ) = each %$f ) {
01193       $self->dbc()->sql_helper()->execute_update(
01194         -SQL => q/insert into genome_variation(genome_id,type,name,count)
01195         values(?,?,?,?)/,
01196         -PARAMS => [ $genome->dbID(), $type, $key, $count ] );
01197     }
01198   }
01199   return;
01200 }
01201 
01202 =head2 _store_alignments
01203   Arg        : Bio::EnsEMBL::MetaData::GenomeInfo
01204   Description: Stores the alignments for the supplied object
01205   Returntype : None
01206   Exceptions : none
01207   Caller     : internal
01208   Status     : Stable
01209 =cut
01210 
01211 sub _store_alignments {
01212   my ( $self, $genome ) = @_;
01213 
01214   $self->dbc()->sql_helper()->execute_update(
01215                       -SQL => q/delete from genome_alignment where genome_id=?/,
01216                       -PARAMS => [ $genome->dbID() ] );
01217 
01218   while ( my ( $type, $f ) = each %{ $genome->other_alignments() } ) {
01219     while ( my ( $key, $count ) = each %$f ) {
01220       $self->dbc()->sql_helper()->execute_update(
01221         -SQL => q/insert into genome_alignment(genome_id,type,name,count)
01222         values(?,?,?,?)/,
01223         -PARAMS => [ $genome->dbID(), $type, $key, $count ] );
01224     }
01225   }
01226   return;
01227 }
01228 
01229 =head2 _store_compara
01230   Arg        : Bio::EnsEMBL::MetaData::GenomeInfo
01231   Description: Stores the compara analyses for the supplied object
01232   Returntype : None
01233   Exceptions : none
01234   Caller     : internal
01235   Status     : Stable
01236 =cut
01237 
01238 sub _store_compara {
01239   my ( $self, $genome ) = @_;
01240 
01241   $self->dbc()->sql_helper()->execute_update(
01242                -SQL => q/delete from genome_compara_analysis where genome_id=?/,
01243                -PARAMS => [ $genome->dbID() ] );
01244   if ( defined $genome->compara() ) {
01245     for my $compara ( @{ $genome->compara() } ) {
01246       if ( !defined $compara->dbID() ) {
01247         $self->db()->get_GenomeComparaInfoAdaptor()->store($compara);
01248       }
01249       $self->dbc()->sql_helper()->execute_update(
01250         -SQL =>
01251 q/insert into genome_compara_analysis(genome_id,compara_analysis_id) values(?,?)/,
01252         -PARAMS => [ $genome->dbID(), $compara->dbID() ] );
01253     }
01254   }
01255   return;
01256 
01257 }
01258 
01259 my $base_genome_fetch_sql =
01260   q/select genome_id as dbID, division.name as division, genebuild, 
01261 has_pan_compara, has_variations, has_peptide_compara, 
01262 has_genome_alignments, has_synteny, has_other_alignments, 
01263 assembly_id, data_release_id
01264 from genome join division using (division_id)/;
01265 
01266 sub _get_base_sql {
01267   return $base_genome_fetch_sql;
01268 }
01269 
01270 sub _get_id_field {
01271   return 'genome_id';
01272 }
01273 
01274 sub _get_obj_class {
01275   return 'Bio::EnsEMBL::MetaData::GenomeInfo';
01276 }
01277 
01278 # override to add release clause
01279 sub _args_to_sql {
01280   my ( $self, $sql_in, $args ) = @_;
01281   if ( !defined $args->{ _get_id_field() } ) {
01282     # if we're not searching by dbID, add release as a clause
01283     if ( defined $self->data_release()->dbID() ) {
01284       $args->{data_release_id} = $self->data_release()->dbID();
01285     }
01286   }
01287   return $self->SUPER::_args_to_sql( $sql_in, $args );
01288 }
01289 
01290 sub _organism_adaptor {
01291   my ($self) = @_;
01292   if ( !defined $self->{organism_adaptor} ) {
01293     $self->{organism_adaptor} = $self->db()->get_GenomeOrganismInfoAdaptor();
01294   }
01295   return $self->{organism_adaptor};
01296 }
01297 
01298 sub _assembly_adaptor {
01299   my ($self) = @_;
01300   if ( !defined $self->{assembly_adaptor} ) {
01301     $self->{assembly_adaptor} = $self->db()->get_GenomeAssemblyInfoAdaptor();
01302   }
01303   return $self->{assembly_adaptor};
01304 }
01305 
01306 1;