From c2be78dee78142b712331b99c35085ab1e707778 Mon Sep 17 00:00:00 2001 From: Andrew Yates <ayates@ebi.ac.uk> Date: Wed, 23 May 2012 15:02:58 +0000 Subject: [PATCH] Adding a registry version to CliHelper --- modules/Bio/EnsEMBL/Utils/CliHelper.pm | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/modules/Bio/EnsEMBL/Utils/CliHelper.pm b/modules/Bio/EnsEMBL/Utils/CliHelper.pm index c71085e160..7317a254c8 100644 --- a/modules/Bio/EnsEMBL/Utils/CliHelper.pm +++ b/modules/Bio/EnsEMBL/Utils/CliHelper.pm @@ -82,6 +82,7 @@ use Carp; use Data::Dumper; use Getopt::Long qw(:config auto_version no_ignore_case); +use Bio::EnsEMBL::Registry; use Bio::EnsEMBL::DBSQL::DBConnection; use Bio::EnsEMBL::DBSQL::DBAdaptor; @@ -251,4 +252,35 @@ sub get_dbas_for_opts { } return $dbas; } + +=head2 load_registry_for_opts + + Arg [1] : Hash of options (e.g. parsed from command line options by process_args()) + Arg [2] : Optional prefix to use when parsing e.g. dna or master + Description : Loads a Registry from the given options hash. If a C<registry> + option is given then the code will call C<load_all>. Otherwise + we use the database parameters given to call + C<load_registry_from_db()>. + Returntype : Integer of the number of DBAdaptors loaded + Status : Under development + +=cut + +sub load_registry_for_opts { + my ($self, $opts, $prefix) = @_; + $prefix ||= q{}; + if($opts->{registry}) { + my $location = $opts->{registry}; + return Bio::EnsEMBL::Registry->load_all($location); + } + my ( $host, $port, $user, $pass ) = map { $prefix . $_ } qw(host port user pass); + my %args = ( + -HOST => $opts->{$host}, + -PORT => $opts->{$port}, + -USER => $opts->{$user}, + ); + $args{-PASS} = $opts->{$pass}; + return Bio::EnsEMBL::Registry->load_registry_from_db(%args); +} + 1; -- GitLab