Commit 969a3bce authored by Leo Gordon's avatar Leo Gordon
Browse files

some methods moved into proper Adaptors (extending the Core adaptors)

parent 27633e4a
=pod
=head1 NAME
Bio::EnsEMBL::Hive::DBSQL::AnalysisAdaptor
=head1 SYNOPSIS
$analysis_adaptor = $db_adaptor->get_AnalysisAdaptor;
=head1 DESCRIPTION
This module extends EnsEMBL Core's AnalysisAdaptor, adding some Hive-specific stuff.
=head1 CONTACT
Please contact ehive-users@ebi.ac.uk mailing list with questions/suggestions.
=cut
package Bio::EnsEMBL::Hive::DBSQL::AnalysisAdaptor;
use strict;
use base ('Bio::EnsEMBL::DBSQL::AnalysisAdaptor');
=head2 fetch_by_logic_name_or_url
Description: given a URL gets the analysis from URLFactory, otherwise fetches it from the db
=cut
sub fetch_by_logic_name_or_url {
my $self = shift @_;
my $logic_name_or_url = shift @_;
if($logic_name_or_url =~ m{^\w+://}) {
return Bio::EnsEMBL::Hive::URLFactory->fetch($logic_name_or_url, $self->db);
} else {
return $self->fetch_by_logic_name($logic_name_or_url);
}
}
=head2 fetch_by_url_query
Description: fetches the analysis either by logic_name or by dbID (either coming from the tail of the URL)
=cut
sub fetch_by_url_query {
my ($self, $field_name, $field_value) = @_;
if(!$field_name or !$field_value) {
return;
} elsif($field_name eq 'logic_name') {
return $self->fetch_by_logic_name($field_value);
} elsif($field_name eq 'dbID') {
return $self->fetch_by_dbID($field_value);
}
}
1;
......@@ -41,17 +41,19 @@ use Bio::EnsEMBL::DBSQL::DBConnection;
use base ('Bio::EnsEMBL::DBSQL::DBAdaptor');
sub get_Queen {
my $self = shift;
return $self->get_QueenAdaptor();
}
#sub get_Queen {
# my $self = shift;
#
# return $self->get_QueenAdaptor();
#}
sub get_available_adaptors {
my %pairs = (
'MetaContainer' => 'Bio::EnsEMBL::DBSQL::MetaContainer',
'Analysis' => 'Bio::EnsEMBL::DBSQL::AnalysisAdaptor',
# Core adaptors extended with Hive stuff:
'MetaContainer' => 'Bio::EnsEMBL::Hive::DBSQL::MetaContainer',
'Analysis' => 'Bio::EnsEMBL::Hive::DBSQL::AnalysisAdaptor',
# Hive adaptors:
'Queen' => 'Bio::EnsEMBL::Hive::Queen',
'AnalysisJob' => 'Bio::EnsEMBL::Hive::DBSQL::AnalysisJobAdaptor',
'AnalysisData' => 'Bio::EnsEMBL::Hive::DBSQL::AnalysisDataAdaptor',
......@@ -66,4 +68,3 @@ sub get_available_adaptors {
}
1;
=pod
=head1 NAME
Bio::EnsEMBL::Hive::DBSQL::MetaContainer
=head1 SYNOPSIS
$meta_container = $db_adaptor->get_MetaContainer;
=head1 DESCRIPTION
This module extends EnsEMBL Core's MetaContainer, adding some Hive-specific stuff.
=head1 CONTACT
Please contact ehive-users@ebi.ac.uk mailing list with questions/suggestions.
=cut
package Bio::EnsEMBL::Hive::DBSQL::MetaContainer;
use strict;
use Bio::EnsEMBL::Hive::Utils ('destringify'); # import both functions
use base ('Bio::EnsEMBL::DBSQL::MetaContainer');
=head2 get_param_hash
Description: returns the content of the 'meta' table as a hash
=cut
sub get_param_hash {
my $self = shift @_;
my %meta_params_hash = ();
# Here we are assuming that meta_keys are unique.
# If they are not, you'll be getting the value with the highest meta_id.
#
my $sth = $self->prepare("SELECT meta_key, meta_value FROM meta ORDER BY meta_id");
$sth->execute();
while (my ($meta_key, $meta_value)=$sth->fetchrow_array()) {
$meta_params_hash{$meta_key} = destringify($meta_value);
}
$sth->finish();
return \%meta_params_hash;
}
1;
......@@ -32,7 +32,6 @@ use strict;
use Bio::EnsEMBL::Utils::Exception;
use Bio::EnsEMBL::Analysis;
use Bio::EnsEMBL::DBSQL::DBConnection;
use Bio::EnsEMBL::DBSQL::AnalysisAdaptor;
use Bio::EnsEMBL::Hive::URLFactory;
#use Bio::EnsEMBL::Pipeline::RunnableDB;
#use Bio::EnsEMBL::Analysis::RunnableDB;
......@@ -130,35 +129,6 @@ sub Bio::EnsEMBL::Analysis::url
return $url;
}
sub Bio::EnsEMBL::DBSQL::AnalysisAdaptor::fetch_by_logic_name_or_url {
my $self = shift @_;
my $logic_name_or_url = shift @_;
if($logic_name_or_url =~ m{^\w+://}) {
return Bio::EnsEMBL::Hive::URLFactory->fetch($logic_name_or_url, $self->db);
} else {
return $self->fetch_by_logic_name($logic_name_or_url);
}
}
sub Bio::EnsEMBL::DBSQL::AnalysisAdaptor::fetch_by_url_query {
my ($self, $field_name, $field_value) = @_;
if(!$field_name or !$field_value) {
return;
} elsif($field_name eq 'logic_name') {
return $self->fetch_by_logic_name($field_value);
} elsif($field_name eq 'dbID') {
return $self->fetch_by_dbID($field_value);
}
}
=head2 Bio::EnsEMBL::Analysis::stats
......
......@@ -54,6 +54,7 @@ package Bio::EnsEMBL::Hive::ProcessWithParams;
use strict;
use Bio::EnsEMBL::Hive::Utils ('stringify', 'destringify'); # import both functions
use base ('Bio::EnsEMBL::Hive::Process');
......@@ -91,11 +92,11 @@ sub param_init { # normally will run automatically on the first execution of
my $defaults_hash = scalar(@_) ? { @_ } : {}; # module-wide built-in defaults have the lowest precedence (will always be the same for this module)
my $meta_params_hash = $self->_parse_meta(); # then come the pipeline-wide parameters from the 'meta' table (define things common to all modules in this pipeline)
my $meta_params_hash = $self->db->get_MetaContainer->get_param_hash(); # then come the pipeline-wide parameters from the 'meta' table (define things common to all modules in this pipeline)
my $parameters_hash = $self->_parse_string('parameters'); # analysis-wide 'parameters' are even more specific (can be defined differently for several occurence of the same module)
my $parameters_hash = $self->_parse_string( $self->parameters() ); # analysis-wide 'parameters' are even more specific (can be defined differently for several occurence of the same module)
my $input_id_hash = $self->_parse_string('input_id'); # job-specific 'input_id' parameters have the highest precedence
my $input_id_hash = $self->_parse_string( $self->input_id() ); # job-specific 'input_id' parameters have the highest precedence
$self->{'_param_hash'} = { %$defaults_hash, %$meta_params_hash, %$parameters_hash, %$input_id_hash };
}
......@@ -222,15 +223,13 @@ sub csvq { # another example stringification formatter
=cut
sub _parse_string {
my ($self, $method) = @_;
my $string = $self->$method();
my ($self, $string) = @_;
if($self->strict_hash_format() or $string=~/^\{.*\}$/) {
my $param_hash = eval($string) || {};
if($@ or (ref($param_hash) ne 'HASH')) {
die "The module '".ref($self)."' for analysis '".$self->analysis->logic_name()
."' assumes analysis.$method should evaluate into a {'param'=>'value'} hashref."
."' assumes both analysis.parameters and analysis_job.input_id should evaluate into a {'param'=>'value'} hashref."
." The current value is '$string'\n";
}
return $param_hash;
......@@ -239,29 +238,4 @@ sub _parse_string {
}
}
=head2 _parse_meta
Description: this is a private method that deals with parsing of parameters out of 'meta' table.
=cut
sub _parse_meta { # Unfortunately, MetaContainer is useless for us, as we need to load all the parameters in one go
my $self = shift @_;
my %meta_params_hash = ();
# Here we are assuming that meta_keys are unique.
# If they are not, you'll be getting the value with the highest meta_id.
#
my $sth = $self->db->dbc()->prepare("SELECT meta_key, meta_value FROM meta ORDER BY meta_id");
$sth->execute();
while (my ($meta_key, $meta_value)=$sth->fetchrow_array()) {
$meta_params_hash{$meta_key} = destringify($meta_value);
}
$sth->finish();
return \%meta_params_hash;
}
1;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment