Commit 008321d0 authored by Ian Longden's avatar Ian Longden
Browse files

moving around of code elements for reg stuff

parent 277f5fc6
......@@ -78,105 +78,38 @@ my $reg = "Bio::EnsEMBL::Registry";
sub new {
my($class, @args) = @_;
#call superclass constructor
my $self ={};
bless $self,$class;
my ($species, $group, $dbname) =
rearrange([qw(SPECIES GROUP DBNAME)], @args);
$self->dbc(new Bio::EnsEMBL::DBSQL::DBConnection(@args));
my ($species, $group, $con, $dnadb) =
rearrange([qw(SPECIES GROUP DBCONN DNADB)], @args);
my ($spec,$gro) = $reg->check_if_already_there(@args);
if($spec){
$self = $reg->get_DBAdaptor($spec,$gro);
$self->species($species);
$self->group($group);
return $self;
if(defined($con)){
$self->dbc($con);
}
my $config_sub;
if(defined($species)and defined($group)){ # NEW style usage of registry
$self = $reg->get_DBAdaptor($species,$group);
else{
$self->dbc(new Bio::EnsEMBL::DBSQL::DBConnection(@args));
}
if(defined($species)){
$self->species($species);
$self->group($group);
}
else{ # OLD style, so mimic by adding to registry
my $free=0;
if(!defined($species)){
$species= "DEFAULT";
}
if($class->isa('Bio::EnsEMBL::Compara::DBSQL::DBAdaptor')){
$group = "compara";
$config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_compara;
}
elsif($class->isa('Bio::EnsEMBL::Lite::DBAdaptor')){
$group = 'lite';
$config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_lite;
}
elsif($class->isa('Bio::EnsEMBL::External::BlastAdaptor')){
$group = 'blast';
$config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_blast;
}
elsif($class->isa('Bio::EnsEMBL::ExternalData::SNPSQL::DBAdaptor')){
$group = "SNP";
$config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_SNP;
}
elsif($class->isa('Bio::EnsEMBL::Pipeline::DBSQL::DBAdaptor')){
$group = "pipeline";
$config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_pipeline;
}
elsif($class->isa('Bio::EnsEMBL::Hive::DBSQL::DBAdaptor')){
$group = "hive";
$config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_hive;
}
elsif($class->isa('Bio::EnsEMBL::DBSQL::DBAdaptor')){
$group = "core";
$config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_core;
}
else{
throw("Unknown DBAdaptor type $class\n");
}
$reg->add_alias($species,$species);
my $i = 0;
while(!$free){
if($i == 0){
if(!defined($reg->get_DBAdaptor($species, $group))){
$free =1;
$i ="";
}
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++;
}
}
}
$species .= $i;
push (@args, '-species');
push (@args, $species);
&{$config_sub}($class,@args);
$self = $reg->get_DBAdaptor($species,$group);
else{
$self->species("DEFAULT");
}
if(defined($group)){
$self->group($group);
}
my ( $dnadb ) = rearrange([qw(DNADB)],@args);
Bio::EnsEMBL::Utils::ConfigRegistry::gen_load($self);
if(defined $dnadb) {
$self->dnadb($dnadb);
}
return $self;
}
......
......@@ -111,35 +111,13 @@ use Bio::EnsEMBL::Utils::Argument qw(rearrange);
sub new {
my $class = shift;
my ($db,$host,$driver,$user,$password,$port, $inactive_disconnect, $dbconn, $species, $group, $dnadb) =
rearrange([qw(DBNAME HOST DRIVER USER PASS PORT
DISCONNECT_WHEN_INACTIVE DBCONN SPECIES GROUP DNADB)], @_);
my ($db,$host,$driver,$user,$password,$port, $inactive_disconnect, $dbconn, $dnadb) =
rearrange([qw(DBNAME HOST DRIVER USER PASS PORT
DISCONNECT_WHEN_INACTIVE DBCONN DNADB)], @_);
my $self = {};
bless $self, $class;
# make sure the register can find the species name in the alias list as itself.
if(!defined($species)){
$species= "DEFAULT";
$group = "core";
Bio::EnsEMBL::Registry->add_alias($species,$species); #set needed self alias
my $free=0;
my $i = 1;
while(!$free){
Bio::EnsEMBL::Registry->add_alias($species.$i,$species.$i); #set needed self alias
if(!defined(Bio::EnsEMBL::Registry->get_DBAdaptor($species.$i, $group))){
$free =1;
}
else{
$i++;
}
}
$species .= $i;
}
if($dbconn) {
if($db || $host || $driver || $password || $port || $inactive_disconnect
|| $dnadb) {
......@@ -152,10 +130,6 @@ sub new {
$self->password($dbconn->password());
$self->port($dbconn->port());
$self->driver($dbconn->driver());
$self->species($dbconn->species());
$self->group($dbconn->group());
# $self->connect();
if($dbconn->disconnect_when_inactive()) {
$self->disconnect_when_inactive(1);
......@@ -186,18 +160,18 @@ sub new {
# $self->connect();
if($species){
# print "setting species to $species\n";
Bio::EnsEMBL::Registry->add_alias($species,$species);
$self->species($species);
# if($species){
# print "setting species to $species\n";
}
else{
throw("No species specified\n");
}
if($group){
$self->group($group);
}
# Bio::EnsEMBL::Registry->add_alias($species,$species);
# $self->species($species);
## print "setting species to $species\n";
# }
# else{
# throw("No species specified\n");
# }
# if($group){
# $self->group($group);
# }
if($inactive_disconnect) {
......@@ -257,6 +231,23 @@ sub connect {
return;
}
=head2 equals
=cut
sub equals{
my ($self, $dbc) = @_;
if($dbc->host() eq $self->host and $dbc->dbname() eq $self->dbname
and $dbc->driver() eq $self->driver and $dbc->port() eq $self->port){
return 1;
}
return 0;
}
=head2 driver
......
......@@ -173,23 +173,26 @@ sub load_all{
=cut
sub check_if_already_there{
my ($class) = shift;
my ($dbname,$host,$driver,$port ) =
rearrange([qw(DBNAME HOST DRIVER PORT )], @_);
if(defined($registry_register{'_DBA'})){
foreach my $db (@{$registry_register{'_DBA'}}){
my $dbc= $db->db();
if($dbc->host() eq $host and $dbc->dbname() eq $dbname
and $dbc->driver() eq $driver and $dbc->port() eq $port){
return ($db->species(),$db->group());
}
}
}
return 0;
}
#sub check_if_already_there{
# my ($class) = shift;
#
# my ($dbname,$host,$driver,$port,$species, $group ) =
# rearrange([qw(DBNAME HOST DRIVER PORT SPECIES GROUP)], @_);
#
# if(defined($registry_register{'_DBA'})){
# foreach my $db (@{$registry_register{'_DBA'}}){
# my $dbc= $db->db();
# if($dbc->host() eq $host and $dbc->dbname() eq $dbname
# and $dbc->driver() eq $driver and $dbc->port() eq $port){
# if(defined($species) and defined($group) and
# $db->species eq $species and $db->group eq $group){
# return ($db->species(),$db->group());
# }
# }
# }
# }
# return 0;
#}
#
......@@ -262,8 +265,8 @@ sub get_all_db_adaptors{
my ($class,$db) = @_;
my %ret=();
foreach my $key (keys %{$registry_register{$db->species()}{$db->group()}{'_special'}}){
$ret{$key} = $registry_register{$db->species()}{$db->group()}{'_special'}{$key};
foreach my $key (keys %{$registry_register{$class->get_alias($db->species())}{$db->group()}{'_special'}}){
$ret{$key} = $registry_register{$class->get_alias($db->species())}{$db->group()}{'_special'}{$key};
}
return \%ret;
......@@ -289,9 +292,6 @@ sub add_DBAdaptor{
my ($class, $species, $group, $adap) = @_;
$species = $class->get_alias($species);
# if(defined($registry_register{$species}{$group}{'_DB'}) && warn_on_duplicates()){
# warning("Overwriting DBAdaptor in Registry for $species $group $adap\n");
# }
$registry_register{$species}{$group}{'_DB'} = $adap;
......@@ -364,9 +364,6 @@ sub add_DNAAdaptor{
my ($class, $species, $group, $adap) = @_;
$species = $class->get_alias($species);
# if(defined($registry_register{$species}{$group}{'_DNA'}) && warn_on_duplicates()){
# warning("Overwriting DNAAdaptor in Registry for $species $group $adap\n");
# }
$registry_register{$species}{$group}{'_DNA'} = $adap;
......@@ -474,7 +471,7 @@ sub add_adaptor{
sub set_get_via_dnadb_if_set{
my ($class,$species,$type) = @_;
$registry_register{$species}{$type}{'DNADB'} = 1;
$registry_register{$class->get_alias($species)}{$type}{'DNADB'} = 1;
}
=head2 get_adaptor
......@@ -590,12 +587,7 @@ sub get_alias{
my ($class, $key, $no_throw) = @_;
if(!defined($registry_register{'_ALIAS'}{$key})){
if(defined($no_throw)){
return undef;
}
else{
throw("Unknown species $key has it been mistyped??\n");
}
return $key;
}
return $registry_register{'_ALIAS'}{$key};
}
......
......@@ -50,6 +50,7 @@ package Bio::EnsEMBL::Utils::ConfigRegistry;
#use Exporter;
use Bio::EnsEMBL::Registry;
my $reg = "Bio::EnsEMBL::Registry";
use Bio::EnsEMBL::Utils::Argument qw(rearrange);
use Bio::EnsEMBL::DBSQL::DBConnection;
use Bio::EnsEMBL::DBSQL::DBAdaptor;
......@@ -104,26 +105,101 @@ use Bio::EnsEMBL::Utils::Exception qw(warning throw deprecate stack_trace_dump)
=cut
sub load_core{
my ($class, @args) = @_;
sub gen_load{
my ($dba) = @_;
my $config_sub;
if($dba->isa('Bio::EnsEMBL::Compara::DBSQL::DBAdaptor')){
$dba->group('compara');
$config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_compara;
}
elsif($dba->isa('Bio::EnsEMBL::Lite::DBAdaptor')){
$dba->group('lite');
$config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_lite;
}
elsif($dba->isa('Bio::EnsEMBL::External::BlastAdaptor')){
$dba->group('blast');
$config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_blast;
}
elsif($dba->isa('Bio::EnsEMBL::ExternalData::SNPSQL::DBAdaptor')){
$dba->group('SNP');
$config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_SNP;
}
elsif($dba->isa('Bio::EnsEMBL::Pipeline::DBSQL::DBAdaptor')){
$dba->group('pipeline');
$config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_pipeline;
}
elsif($dba->isa('Bio::EnsEMBL::Hive::DBSQL::DBAdaptor')){
$dba->group('hive');
$config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_hive;
}
elsif($dba->isa('Bio::EnsEMBL::DBSQL::DBAdaptor')){
$dba->group('core');
$config_sub = \&Bio::EnsEMBL::Utils::ConfigRegistry::load_core;
}
else{
throw("Unknown DBAdaptor type $dba\n");
}
# return if the connection and species, group are the same
my $db_reg;
if($reg->get_alias($dba->species,"no throw")){
$db_reg = $reg->get_DBAdaptor($dba->species,$dba->group);
}
if(defined($db_reg)){
if($dba->dbc->equals($db_reg)){
return $db_reg;
}
else{ # diff conn details
$dba->species(find_unique_species($dba->species,$dba->group));
}
}
Bio::EnsEMBL::Registry->add_DBAdaptor($dba->species(), $dba->group(), $dba);
&{$config_sub}($dba);
return $dba;
}
my ($species) = rearrange([qw(SPECIES)],@args);
# print STDERR "species is $species\n";
my $group = 'core';
push (@args, '-group');
push (@args, $group);
sub find_unique_species{
my ($species, $group) = @_;
my ($spec,$gro) = Bio::EnsEMBL::Registry->check_if_already_there(@args);
if($spec){
return;
$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 ="";
}
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++;
}
}
}
my $dbc = new Bio::EnsEMBL::DBSQL::DBConnection(@args);
$species .= $i;
return ($species);
}
my $dba = new_fast Bio::EnsEMBL::DBSQL::DBAdaptor('-con' => $dbc);
sub load_core{
my ($dba) = @_;
Bio::EnsEMBL::Registry->add_DBAdaptor($species, $group, $dba);
my %pairs = ( 'Analysis' => 'Bio::EnsEMBL::DBSQL::AnalysisAdaptor',
'ArchiveStableId' => 'Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor',
......@@ -167,76 +243,53 @@ sub load_core{
foreach my $key (keys %pairs){
Bio::EnsEMBL::Registry->add_adaptor($species, $group, $key, $pairs{$key});
Bio::EnsEMBL::Registry->add_adaptor($dba->species, $dba->group, $key, $pairs{$key});
}
foreach my $type (qw(Sequence AssemblyMapper KaryotypeBand RepeatFeature CoordSystem AssemblyExceptionFeature)){
Bio::EnsEMBL::Registry->set_get_via_dnadb_if_set($species,$type);
Bio::EnsEMBL::Registry->set_get_via_dnadb_if_set($dba->species,$type);
}
}
sub load_lite{
my ($class, @args) = @_;
require Bio::EnsEMBL::Lite::DBAdaptor;
my ($species) = rearrange([qw(SPECIES)],@args);
my $group = 'lite';
push (@args, '-group');
push (@args, $group);
my ($dba) = @_;
my $dbc = new Bio::EnsEMBL::DBSQL::DBConnection(@args);
my $dba = new_fast Bio::EnsEMBL::Lite::DBAdaptor('-con' => $dbc);
Bio::EnsEMBL::Registry->add_DBAdaptor($species, $group, $dba);
# Bio::EnsEMBL::Registry->add_DBAdaptor($dba->species, $dba->group, $dba);
eval "require Bio::EnsEMBL::Lite::SNPAdaptor";
my $adap = Bio::EnsEMBL::Lite::SNPAdaptor->new($dba);
my $prim_adap = Bio::EnsEMBL::DBSQL::ProxySNPAdaptor->new($dba,$adap);
Bio::EnsEMBL::Registry->add_adaptor($species, $group, $group, $adap);
Bio::EnsEMBL::Registry->add_adaptor($species, $group, "ProxySNP", $prim_adap);
Bio::EnsEMBL::Registry->add_adaptor($dba->species, $dba->group, $dba->group, $adap);
Bio::EnsEMBL::Registry->add_adaptor($dba->species, $dba->group, "ProxySNP", $prim_adap);
}
sub load_SNP{
my ($class, @args) = @_;
require Bio::EnsEMBL::ExternalData::SNPSQL::DBAdaptor;
my ($dba) = @_;
# require Bio::EnsEMBL::ExternalData::SNPSQL::DBAdaptor;
require Bio::EnsEMBL::ExternalData::SNPSQL::SNPAdaptor;
my ($species) = rearrange([qw(SPECIES)],@args);
my $group = 'SNP';
push (@args, '-group');
push (@args, $group);
my $dbc = new Bio::EnsEMBL::DBSQL::DBConnection(@args);
my $dba = new_fast Bio::EnsEMBL::ExternalData::SNPSQL::DBAdaptor('-con' => $dbc);
Bio::EnsEMBL::Registry->add_DBAdaptor($species, $group, $dba);
eval "require Bio::EnsEMBL::ExternalData::SNPSQL::DBAdaptor";
# eval "require Bio::EnsEMBL::ExternalData::SNPSQL::DBAdaptor";
my $adap = Bio::EnsEMBL::ExternalData::SNPSQL::SNPAdaptor->new($dba);
my $prim_adap = Bio::EnsEMBL::DBSQL::ProxySNPAdaptor->new($dba,$adap);
Bio::EnsEMBL::Registry->add_adaptor($species, $group, $group, $adap);
Bio::EnsEMBL::Registry->add_adaptor($dba->species, $dba->group, "SNP", $adap);
Bio::EnsEMBL::Registry->add_adaptor($species, $group, "ProxySNP", $prim_adap);
Bio::EnsEMBL::Registry->add_adaptor($dba->species, $dba->group, "ProxySNP", $prim_adap);
}
sub attach_database{
my ($class, $species, $core, $name1) = @_;
print STDERR "attach_databse called ".caller(). "\n";
my $first = Bio::EnsEMBL::Registry->get_DBAdaptor($species,$name1);
my $coredb = Bio::EnsEMBL::Registry->get_DBAdaptor($species,$core);
......@@ -246,6 +299,7 @@ sub attach_database{
sub attach_dna{
my ($class, $species, $main, $attach) = @_;
print STDERR "attach_dna called ".caller(). "\n";
my $no_seq = Bio::EnsEMBL::Registry->get_DBAdaptor($species,$main);
my $seq = Bio::EnsEMBL::Registry->get_DBAdaptor($species,$attach);
......@@ -255,27 +309,13 @@ sub attach_dna{
sub load_blast{
my ($class, @args) = @_;
my ($species) = rearrange([qw(SPECIES)],@args);
if(!defined($species)){
$species = 'NONE'; # NOT species dependent.
push (@args, '-species');
push (@args, $species);
}
my $group = 'blast';
push (@args, '-group');
push (@args, $group);
my ($dba) = @_;
eval "require Bio::EnsEMBL::External::BlastAdaptor";
my $dba = Bio::EnsEMBL::External::BlastAdaptor->new(@args);
my $dbc = $dba->db();
my $key = 'Blast';
my $objadap = Bio::EnsEMBL::External::BlastAdaptor->new($dba);
Bio::EnsEMBL::Registry->add_adaptor($species, $group, $key, $dba);
Bio::EnsEMBL::Registry->add_adaptor($dba->species, $dba->group, 'Blast', $objadap);
}
......@@ -301,19 +341,7 @@ sub add_blast_link{
sub load_estgene{
my ($class, @args) = @_;
my ($species) = rearrange([qw(SPECIES)],@args);
my $group = 'estgene';
push (@args, '-group');
push (@args, $group);
my $dbc = new Bio::EnsEMBL::DBSQL::DBConnection(@args);
my $dba = new_fast Bio::EnsEMBL::DBSQL::DBAdaptor('-con' => $dbc);
Bio::EnsEMBL::Registry->add_DBAdaptor($species, $group, $dba);
my ($dba) = @_;
my %pairs = ( 'Analysis' => 'Bio::EnsEMBL::DBSQL::AnalysisAdaptor',
'ArchiveStableId' => 'Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor',
......@@ -358,31 +386,19 @@ sub load_estgene{
foreach my $key (keys %pairs){
Bio::EnsEMBL::Registry->add_adaptor($species, $group, $key, $pairs{$key});
Bio::EnsEMBL::Registry->add_adaptor($dba->species, $dba->group, $key, $pairs{$key});
}
#if dnadb has been set then for the follwing use it.