diff --git a/modules/Bio/EnsEMBL/Registry.pm b/modules/Bio/EnsEMBL/Registry.pm index ae6beea380adbd674a28164f3977a325cfb0b27d..76f4eabfa3bcf3649250a5dc722ca1a27e9aeecb 100644 --- a/modules/Bio/EnsEMBL/Registry.pm +++ b/modules/Bio/EnsEMBL/Registry.pm @@ -131,8 +131,8 @@ use vars qw(%registry_register); my $API_VERSION = 54; -# This is a map from group names to Ensembl DB adaptors. -#Used by load_all and reset_DBAdaptor +# This is a map from group names to Ensembl DB adaptors. Used by +# load_all() and reset_DBAdaptor(). my %group2adaptor = ( 'blast' => 'Bio::EnsEMBL::External::BlastAdaptor', @@ -1322,7 +1322,8 @@ sub load_registry_from_db { @args ); - my $go_version = 0; + my $go_version = 0; + my $ontology_version = 0; $user ||= "ensro"; if ( !defined($port) ) { @@ -1373,8 +1374,12 @@ sub load_registry_from_db { if ( $1 eq $software_version ) { $go_version = $1; } + } elsif ( $db =~ /^(ensembl_ontology)_(\d+)/ ) { + if ( $2 eq $software_version ) { + $ontology_version = $2; + } } elsif ( - $db =~ /^([a-z]+_[a-z]+_[a-z]+(?:_\d+)?)_(\d+)_(\d+[a-z]*)/) + $db =~ /^([a-z]+_[a-z]+_[a-z]+(?:_\d+)?)_(\d+)_(\d+[a-z]*)/ ) { if ( $2 eq $software_version ) { $temp{$1} = $2 . "_" . $3; @@ -1746,6 +1751,31 @@ sub load_registry_from_db { print("No GO database found\n"); } + # Ontology + + if ( $ontology_version != 0 ) { + require Bio::EnsEMBL::DBSQL::OntologyDBAdaptor; + + my $ontology_db = + sprintf( "ensembl_ontology_%d", $ontology_version ); + + my $dba = Bio::EnsEMBL::DBSQL::OntologyDBAdaptor->new( + '-species' => 'multi', + '-group' => 'ontology', + '-host' => $host, + '-port' => $port, + '-user' => $user, + '-pass' => $pass, + '-dbname' => $ontology_db, + ); + + if ($verbose) { + printf( "%s loaded\n", $ontology_db ); + } + } elsif ($verbose) { + print("No ontology database found\n"); + } + # Hard coded aliases for the different species my @aliases = ( 'chimp', 'PanTro1', 'Pan', 'P_troglodytes' ); @@ -2036,6 +2066,10 @@ sub load_registry_from_db { -alias => \@aliases ); + Bio::EnsEMBL::Utils::ConfigRegistry->add_alias( + -species => 'multi', + -alias => ['ontology'] ); + # Register aliases as found in adaptor meta tables. $self->find_and_add_aliases( '-handle' => $dbh ); $dbh->disconnect(); @@ -2044,12 +2078,17 @@ sub load_registry_from_db { =head2 find_and_add_aliases + Arg [DBH] : (optional) DBI handle + A connected DBI database handle. Used instead + of the database handles stored in the DBAdaptor + objects. Bypasses the use of MetaContainer. + Arg [ADAPTOR] : (optional) Bio::EnsEMBL::DBSQL::DBAdaptor The adaptor to use to retrieve aliases from. Arg [GROUP] : (optional) string - The group you want to find aliases for. If not given - assumes all types. + The group you want to find aliases for. If not + given assumes all types. Arg [HANDLE] : (optional) DBI database handle A connected database handle to use instead of the @@ -2127,7 +2166,6 @@ sub find_and_add_aliases { if ( defined( $dba->dbc() ) ) { $dba->dbc()->disconnect_if_idle(); } - } foreach my $alias (@aliases) { @@ -2297,50 +2335,73 @@ sub no_version_check { =cut -sub version_check{ - my ($self, $dba) = @_; - +sub version_check { + my ( $self, $dba ) = @_; + # Check the datbase and versions match # give warning if they do not. my $check = no_version_check(); - if( (defined($ENV{HOME}) and (-e $ENV{HOME}."/.ensemblapi_no_version_check")) - or (defined($check) and ($check != 0))){ + + if ( ( + defined( $ENV{HOME} ) + and ( -e $ENV{HOME} . "/.ensemblapi_no_version_check" ) ) + or ( defined($check) and ( $check != 0 ) ) ) + { return 1; } - my $mca = $self->get_adaptor($dba->species(),$dba->group(),"MetaContainer"); + + my $mca = + $self->get_adaptor( $dba->species(), $dba->group(), + "MetaContainer" ); + my $database_version = 0; - if(defined($mca)){ + if ( defined($mca) ) { $database_version = $mca->get_schema_version(); } - if($database_version == 0){ + + if ( $database_version == 0 ) { # Try to work out the version - if($dba->dbc->dbname() =~ /^_test_db_/){ + if ( $dba->dbc()->dbname() =~ /^_test_db_/ ) { return 1; } - if($dba->dbc->dbname() =~ /(\d+)_\S+$/){ + if ( $dba->dbc()->dbname() =~ /(\d+)_\S+$/ ) { $database_version = $1; - } - elsif($dba->dbc->dbname() =~ /ensembl_compara_(\d+)/){ + } elsif ( $dba->dbc()->dbname() =~ /ensembl_compara_(\d+)/ ) { $database_version = $1; - } - elsif($dba->dbc->dbname() =~ /ensembl_go_(\d+)/){ + } elsif ( $dba->dbc()->dbname() =~ /ensembl_go_(\d+)/ ) { $database_version = $1; - } - elsif($dba->dbc->dbname() =~ /ensembl_help_(\d+)/){ + } elsif ( $dba->dbc()->dbname() =~ /ensembl_help_(\d+)/ ) { $database_version = $1; + } elsif ( $dba->dbc()->dbname() =~ /ensembl_ontology_(\d+)/ ) { + $database_version = $1; + } else { + warn( + sprintf( + "No database version for database %s " + . ". You must be using a pre version 34 database " + . "with version 34 or later code.\n" + . "You need to update your database " + . "or use the appropriate Ensembl software release " + . "to ensure your script does not crash\n", + $dba->dbc()->dbname() ) ); } - else{ - warn("No database version for database ".$dba->dbc->dbname().". You must be using a pre version 34 database with version 34 or later code. You need to update your database or use the appropriate ensembl software release to ensure your script does not crash\n"); - } - } - if($database_version != $API_VERSION){ - warn("For ".$dba->dbc->dbname()." there is a difference in the software release (".$API_VERSION.") and the database release (".$database_version."). You should change one of these to ensure your script does not crash.\n"); + } ## end if ( $database_version... + + if ( $database_version != $API_VERSION ) { + warn( + sprintf( + "For %s there is a difference in the software release (%s) " + . "and the database release (%s). " + . "You should update one of these to ensure that your script " + . "does not crash.\n", + $dba->dbc()->dbname(), + $API_VERSION, $database_version + ) ); return 0; } - else { - return 1; - } -} + + return 1; # Ok +} ## end sub version_check =head2 get_species_and_object_type diff --git a/modules/Bio/EnsEMBL/Utils/ConfigRegistry.pm b/modules/Bio/EnsEMBL/Utils/ConfigRegistry.pm index 66bd1d37522c9d4d2d873a29eb5cb0fb85cbd095..f3ca596e06592fb6c70fa3ff2e00ef4511009ef3 100644 --- a/modules/Bio/EnsEMBL/Utils/ConfigRegistry.pm +++ b/modules/Bio/EnsEMBL/Utils/ConfigRegistry.pm @@ -125,6 +125,12 @@ sub gen_load{ } $config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_funcgen; } + elsif ( $dba->isa('Bio::Ensembl::DBSQL::OntologyTermAdaptor') ) { + if ( !defined( $dba->group() ) ) { + $dba->group('ontology'); + } + $config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_ontology; + } elsif($dba->isa('Bio::EnsEMBL::DBSQL::DBAdaptor')){ #vega uses the core DBAdaptor so test if vega is in the dbname if(!defined($dba->group())){ @@ -192,37 +198,37 @@ sub gen_load{ -sub find_unique_species{ - my ($species, $group) = @_; +sub find_unique_species { + my ( $species, $group ) = @_; - $reg->add_alias($species,$species); + $reg->add_alias( $species, $species ); - my $i = 0; - my $free =0; - while(!$free){ - if($i == 0){ - if(!defined($reg->get_DBAdaptor($species, $group))){ - $free =1; - $i =""; + my $i = 0; + my $free = 0; + + while ( !$free ) { + if ( $i == 0 ) { + if ( !defined( $reg->get_DBAdaptor( $species, $group ) ) ) { + $free = 1; + $i = ""; + } else { + $i = 1; } - else{ - $i = 1; - } - } - else{ - $reg->add_alias($species.$i,$species.$i); #set needed self alias - if(!defined($reg->get_DBAdaptor($species.$i, $group))){ - $free =1; - } - else{ - $i++; + } else { + # set needed self alias + $reg->add_alias( $species . $i, $species . $i ); + + if ( !defined( $reg->get_DBAdaptor( $species . $i, $group ) ) ) { + $free = 1; + } else { + $i++; } } } - + $species .= $i; return ($species); -} +} ## end sub find_unique_species @@ -231,9 +237,9 @@ sub load_adaptors { my %pairs = %{ $dba->get_available_adaptors() }; - foreach my $key ( keys %pairs ) { - Bio::EnsEMBL::Registry->add_adaptor( $dba->species, $dba->group, - $key, $pairs{$key} ); + while ( my ( $key, $value ) = each(%pairs) ) { + Bio::EnsEMBL::Registry->add_adaptor( $dba->species(), $dba->group(), + $key, $value ); } } @@ -241,9 +247,8 @@ sub load_and_attach_dnadb_to_core { my ($dba) = @_; load_adaptors($dba); - - $reg->add_DNAAdaptor( $dba->species, $dba->group, - $dba->species, "core" ); + $reg->add_DNAAdaptor( $dba->species(), $dba->group(), $dba->species(), + 'core' ); } @@ -256,6 +261,7 @@ sub load_SNP { load_adaptors(@_) } sub load_variation { load_and_attach_dnadb_to_core(@_) } sub load_funcgen { load_and_attach_dnadb_to_core(@_) } sub load_haplotype { load_adaptors(@_) } +sub load_ontology { load_adaptors(@_) } # these that need to attach to the core to get the sequense data @@ -265,20 +271,21 @@ sub load_otherfeatures { load_and_attach_dnadb_to_core(@_) } sub load_vega { load_and_attach_dnadb_to_core(@_) } -sub add_alias{ - my ($class, @args) = @_; - my ($species, $aliases) = rearrange([qw(SPECIES ALIAS)],@args); +sub add_alias { + my ( $class, @args ) = @_; - #make sure it exists itself - Bio::EnsEMBL::Registry->add_alias($species,$species); + my ( $species, $aliases ) = rearrange( [qw(SPECIES ALIAS)], @args ); - if($aliases){ - foreach my $ali (@$aliases){ - Bio::EnsEMBL::Registry->add_alias($species,$ali); + # Make sure it exists itself + Bio::EnsEMBL::Registry->add_alias( $species, $species ); + + if ( defined($aliases) ) { + foreach my $ali (@$aliases) { + Bio::EnsEMBL::Registry->add_alias( $species, $ali ); } } - } + # # overwrite/load new types. Done this way to enable no changes to CVS for # external users. External users should add there own "GROUPS" in the file