<commit_before>#
# BioPerl module for DBSQL::Obj
#
# Cared for by <NAME> <<EMAIL>>
#
# Copyright <NAME>
#
# You may distribute this module under the same terms as perl itself

# POD documentation - main docs before the code

=head1 NAME

Bio::EnsEMBL::Compara::DBSQL::DBAdaptor

=head1 SYNOPSIS

    $db = Bio::EnsEMBL::Compara::DBSQL::DBAdaptor->new(
        -user   => 'root',
        -dbname => 'pog',
        -host   => 'caldy',
        -driver => 'mysql',
        );


=head1 DESCRIPTION

This object represents the handle for a comparative DNA alignment database

=head1 CONTACT

Post questions the the EnsEMBL developer list: <<EMAIL>>

=cut


# Let the code begin...


package Bio::EnsEMBL::Compara::DBSQL::DBAdaptor;

use vars qw(@ISA);
use strict;

use Bio::EnsEMBL::DBSQL::DBConnection;
use Bio::EnsEMBL::DBSQL::DBAdaptor;

@ISA = qw( Bio::EnsEMBL::DBSQL::DBAdaptor );



=head2 new

  Arg [..]   : list of named arguments.  See Bio::EnsEMBL::DBConnection.
               [-CONF_FILE] optional name of a file containing configuration
               information for comparas genome databases.  If databases are
               not added in this way, then they should be added via the
               method add_DBAdaptor. An example of the conf file can be found
               in ensembl-compara/modules/Bio/EnsEMBL/Compara/Compara.conf.example
  Example    :  $db = new Bio::EnsEMBL::Compara::DBSQL::DBAdaptor(
						    -user   => 'root',
						    -dbname => 'pog',
						    -host   => 'caldy',
						    -driver => 'mysql',
                                                    -conf_file => 'conf.pl');
  Description: Creates a new instance of a DBAdaptor for the compara database.
  Returntype : Bio::EnsEMBL::Compara::DBSQL::DBAdaptor
  Exceptions : none
  Caller     : general

=cut

sub new {
  my ($class, @args) = @_;

  #call superclass constructor; this may actually return a container
  my $container = $class->SUPER::new(@args);

  my $self;
  if($container->isa('Bio::EnsEMBL::Container')) {
    $self = $container->_obj;
  } else {
    $self = $container;
  }

  my ($conf_file) = $self->_rearrange(['CONF_FILE'], @args);

  $self->{'genomes'} = {};

  if($conf_file) {
    #read configuration file from disk
    my @conf = @{do $conf_file};

    foreach my $genome (@conf) {
      my ($species, $assembly, $db_hash) = @$genome;
      my $db;

      my $module = $db_hash->{'module'};
      my $mod = $module;

      eval {
	# require needs /'s rather than colons
	if ( $mod =~ /::/ ) {
	  $mod =~ s/::/\//g;
	}
	require "${mod}.pm";

	$db = $module->new(-dbname => $db_hash->{'dbname'},
			   -host   => $db_hash->{'host'},
			   -user   => $db_hash->{'user'},
			   -pass   => $db_hash->{'pass'},
			   -port   => $db_hash->{'port'},
			   -driver => $db_hash->{'driver'});
      };

      if($@) {
        $self->throw("could not load module specified in configuration file:$@");
      }

      unless($db && ref $db && $db->isa('Bio::EnsEMBL::DBSQL::DBConnection')) {
        $self->throw("[$db] specified in conf file is not a " .
             "Bio::EnsEMBL::DBSQL::DBConnection");
      }

      #compara should hold onto the actual container objects
      #if($db->isa('Bio::EnsEMBL::DBSQL::Container')) {
      #	$db = $db->_obj;
      #      }

      $self->{'genomes'}->{"$species:".uc($assembly)} = $db;
    }
  }

  $self->add_CanonicalAdaptor('Analysis'  , 'Bio::EnsEMBL::Pipeline::DBSQL::AnalysisAdaptor');
  $self->add_CanonicalAdaptor('SimpleRule', 'Bio::EnsEMBL::Compara::DBSQL::SimpleRuleAdaptor');
  $self->add_CanonicalAdaptor('Domain'    , 'Bio::EnsEMBL::Compara::DBSQL::DomainAdaptor');
  $self->add_CanonicalAdaptor('Member'    , 'Bio::EnsEMBL::Compara::DBSQL::MemberAdaptor');
  $self->add_CanonicalAdaptor('Subset'    , 'Bio::EnsEMBL::Compara::DBSQL::SubsetAdaptor');

  #we want to return the container not the contained object
  return $container;
}



=head2 add_db_adaptor

  Arg [1]    : Bio::EnsEMBL::DBSQL::DBConnection
  Example    : $compara_db->add_db_adaptor($homo_sapiens_db);
  Description: Adds a genome-containing database to compara.  This database
               can be used by compara to obtain sequence for a genome on
               on which comparative analysis has been performed.  The database
               adaptor argument must define the get_MetaContainer argument
               so that species name and assembly type information can be
               extracted from the database.
  Returntype : none
  Exceptions : Thrown if the argument is not a Bio::EnsEMBL::DBConnection
               or if the argument does not implement a get_MetaContainer
               method.
  Caller     : general

=cut

sub add_db_adaptor {
  my ($self, $dba) = @_;

  unless($dba && ref $dba && $dba->isa('Bio::EnsEMBL::DBSQL::DBConnection')) {
    $self->throw("dba argument must be a Bio::EnsEMBL::DBSQL::DBConnection\n" .
		 "not a [$dba]");
  }

  #compara should hold onto the actual container objects...
  #  if($dba->isa('Bio::EnsEMBL::Container')) {
  #    $dba = $dba->_obj;
  #  }

  my $mc = $dba->get_MetaContainer;
  my $csa = $dba->get_CoordSystemAdaptor;
  
  my $species = $mc->get_Species->binomial;
  my ($cs) = @{$csa->fetch_all};
  my $assembly = $cs ? $cs->version : '';

  warn "ADDING GENOME DB $species $assembly $dba";
  $self->{'genomes'}->{"$species:".uc($assembly) } = $dba;
}

<commit_msg>added in called to DBConnection->disconnect_when_inactive for all connections to core databases.  Uses new auto-disconnect system<commit_after>#
# BioPerl module for DBSQL::Obj
#
# Cared for by <NAME> <<EMAIL>>
#
# Copyright <NAME>
#
# You may distribute this module under the same terms as perl itself

# POD documentation - main docs before the code

=head1 NAME

Bio::EnsEMBL::Compara::DBSQL::DBAdaptor

=head1 SYNOPSIS

    $db = Bio::EnsEMBL::Compara::DBSQL::DBAdaptor->new(
        -user   => 'root',
        -dbname => 'pog',
        -host   => 'caldy',
        -driver => 'mysql',
        );


=head1 DESCRIPTION

This object represents the handle for a comparative DNA alignment database

=head1 CONTACT

Post questions the the EnsEMBL developer list: <<EMAIL>>

=cut


# Let the code begin...


package Bio::EnsEMBL::Compara::DBSQL::DBAdaptor;

use vars qw(@ISA);
use strict;

use Bio::EnsEMBL::DBSQL::DBConnection;
use Bio::EnsEMBL::DBSQL::DBAdaptor;

@ISA = qw( Bio::EnsEMBL::DBSQL::DBAdaptor );



=head2 new

  Arg [..]   : list of named arguments.  See Bio::EnsEMBL::DBConnection.
               [-CONF_FILE] optional name of a file containing configuration
               information for comparas genome databases.  If databases are
               not added in this way, then they should be added via the
               method add_DBAdaptor. An example of the conf file can be found
               in ensembl-compara/modules/Bio/EnsEMBL/Compara/Compara.conf.example
  Example    :  $db = new Bio::EnsEMBL::Compara::DBSQL::DBAdaptor(
						    -user   => 'root',
						    -dbname => 'pog',
						    -host   => 'caldy',
						    -driver => 'mysql',
                                                    -conf_file => 'conf.pl');
  Description: Creates a new instance of a DBAdaptor for the compara database.
  Returntype : Bio::EnsEMBL::Compara::DBSQL::DBAdaptor
  Exceptions : none
  Caller     : general

=cut

sub new {
  my ($class, @args) = @_;

  #call superclass constructor; this may actually return a container
  my $container = $class->SUPER::new(@args);

  my $self;
  if($container->isa('Bio::EnsEMBL::Container')) {
    $self = $container->_obj;
  } else {
    $self = $container;
  }

  my ($conf_file) = $self->_rearrange(['CONF_FILE'], @args);

  $self->{'genomes'} = {};

  if($conf_file) {
    #read configuration file from disk
    my @conf = @{do $conf_file};

    foreach my $genome (@conf) {
      my ($species, $assembly, $db_hash) = @$genome;
      my $db;

      my $module = $db_hash->{'module'};
      my $mod = $module;

      eval {
	# require needs /'s rather than colons
	if ( $mod =~ /::/ ) {
	  $mod =~ s/::/\//g;
	}
	require "${mod}.pm";

	$db = $module->new(-dbname => $db_hash->{'dbname'},
			   -host   => $db_hash->{'host'},
			   -user   => $db_hash->{'user'},
			   -pass   => $db_hash->{'pass'},
			   -port   => $db_hash->{'port'},
			   -driver => $db_hash->{'driver'});
      };
      $db->disconnect_when_inactive(1);

      if($@) {
        $self->throw("could not load module specified in configuration file:$@");
      }

      unless($db && ref $db && $db->isa('Bio::EnsEMBL::DBSQL::DBConnection')) {
        $self->throw("[$db] specified in conf file is not a " .
             "Bio::EnsEMBL::DBSQL::DBConnection");
      }

      #compara should hold onto the actual container objects
      #if($db->isa('Bio::EnsEMBL::DBSQL::Container')) {
      #	$db = $db->_obj;
      #      }

      $self->{'genomes'}->{"$species:".uc($assembly)} = $db;
    }
  }

  $self->add_CanonicalAdaptor('Analysis'  , 'Bio::EnsEMBL::Pipeline::DBSQL::AnalysisAdaptor');
  $self->add_CanonicalAdaptor('SimpleRule', 'Bio::EnsEMBL::Compara::DBSQL::SimpleRuleAdaptor');
  $self->add_CanonicalAdaptor('Domain'    , 'Bio::EnsEMBL::Compara::DBSQL::DomainAdaptor');
  $self->add_CanonicalAdaptor('Member'    , 'Bio::EnsEMBL::Compara::DBSQL::MemberAdaptor');
  $self->add_CanonicalAdaptor('Subset'    , 'Bio::EnsEMBL::Compara::DBSQL::SubsetAdaptor');

  #we want to return the container not the contained object
  return $container;
}



=head2 add_db_adaptor

  Arg [1]    : Bio::EnsEMBL::DBSQL::DBConnection
  Example    : $compara_db->add_db_adaptor($homo_sapiens_db);
  Description: Adds a genome-containing database to compara.  This database
               can be used by compara to obtain sequence for a genome on
               on which comparative analysis has been performed.  The database
               adaptor argument must define the get_MetaContainer argument
               so that species name and assembly type information can be
               extracted from the database.
  Returntype : none
  Exceptions : Thrown if the argument is not a Bio::EnsEMBL::DBConnection
               or if the argument does not implement a get_MetaContainer
               method.
  Caller     : general

=cut

sub add_db_adaptor {
  my ($self, $dba) = @_;

  unless($dba && ref $dba && $dba->isa('Bio::EnsEMBL::DBSQL::DBConnection')) {
    $self->throw("dba argument must be a Bio::EnsEMBL::DBSQL::DBConnection\n" .
		 "not a [$dba]");
  }

  #compara should hold onto the actual container objects...
  #  if($dba->isa('Bio::EnsEMBL::Container')) {
  #    $dba = $dba->_obj;
  #  }
  $dba->disconnect_when_inactive(1);
  my $mc = $dba->get_MetaContainer;
  my $csa = $dba->get_CoordSystemAdaptor;
  
  my $species = $mc->get_Species->binomial;
  my ($cs) = @{$csa->fetch_all};
  my $assembly = $cs ? $cs->version : '';

  warn "ADDING GENOME DB $species $assembly $dba";
  $self->{'genomes'}->{"$species:".uc($assembly) } = $dba;
}


{'fraction_non_alphanumeric': 0.15327000365363536, 'fraction_numerical': 0.0014614541468761417, 'mean_word_length': 2.9641564083997105, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 126, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2003959', 'n_tokens_mistral': 3925, 'n_tokens_neox': 3697, 'n_words': 910}