Commit 92310f88 authored by Steve Trevanion's avatar Steve Trevanion
Browse files

whitespace, remove old Glovar method!

parent 1fcf4a7e
......@@ -342,16 +342,16 @@ sub list_all_params {
$Text::Wrap::colums = 72;
my @params = $self->allowed_params;
foreach my $key (@params) {
my @vals = $self->param($key);
if (@vals) {
$txt .= Text::Wrap::wrap( sprintf(' %-21s', $key),
' 'x24,
join(", ", @vals)
) . "\n";
}
my @vals = $self->param($key);
if (@vals) {
$txt .= Text::Wrap::wrap( sprintf(' %-21s', $key),
' 'x24,
join(", ", @vals)
) . "\n";
}
$txt .= "\n";
return $txt;
}
$txt .= "\n";
return $txt;
}
=head2 create_commandline_options
......@@ -376,38 +376,37 @@ sub list_all_params {
=cut
sub create_commandline_options {
my ($self, $settings) = @_;
my %param_hash;
# get all allowed parameters
if ($settings->{'allowed_params'}) {
# exclude params explicitly stated
my %exclude = map { $_ => 1 } @{ $settings->{'exclude'} || [] };
foreach my $param ($self->allowed_params) {
unless ($exclude{$param}) {
my ($first, @rest) = $self->param($param);
next unless (defined($first));
if (@rest) {
$first = join(",", $first, @rest);
}
$param_hash{$param} = $first;
}
}
my ($self, $settings) = @_;
my %param_hash;
# get all allowed parameters
if ($settings->{'allowed_params'}) {
# exclude params explicitly stated
my %exclude = map { $_ => 1 } @{ $settings->{'exclude'} || [] };
foreach my $param ($self->allowed_params) {
unless ($exclude{$param}) {
my ($first, @rest) = $self->param($param);
next unless (defined($first));
if (@rest) {
$first = join(",", $first, @rest);
}
$param_hash{$param} = $first;
}
}
}
# replace values
foreach my $key (keys %{ $settings->{'replace'} || {} }) {
$param_hash{$key} = $settings->{'replace'}->{$key};
}
# replace values
foreach my $key (keys %{ $settings->{'replace'} || {} }) {
$param_hash{$key} = $settings->{'replace'}->{$key};
}
# create the commandline options string
my $options_string;
foreach my $param (keys %param_hash) {
$options_string .= sprintf("--%s %s ", $param, $param_hash{$param});
}
return $options_string;
# create the commandline options string
my $options_string;
foreach my $param (keys %param_hash) {
$options_string .= sprintf("--%s %s ", $param, $param_hash{$param});
}
return $options_string;
}
=head2 check_required_params
......@@ -423,15 +422,15 @@ sub create_commandline_options {
=cut
sub check_required_params {
my ($self, @params) = @_;
my @missing = ();
foreach my $param (@params) {
push @missing, $param unless $self->param($param);
}
if (@missing) {
throw("Missing parameters: @missing.\nYou must specify them on the commandline or in your conffile.\n");
}
return(1);
my ($self, @params) = @_;
my @missing = ();
foreach my $param (@params) {
push @missing, $param unless $self->param($param);
}
if (@missing) {
throw("Missing parameters: @missing.\nYou must specify them on the commandline or in your conffile.\n");
}
return(1);
}
=head2 user_proceed
......@@ -455,20 +454,20 @@ sub check_required_params {
=cut
sub user_proceed {
my ($self, $text) = @_;
if ($self->param('interactive')) {
print "$text\n" if $text;
print "[y/N] ";
my $input = lc(<>);
chomp $input;
unless ($input eq 'y') {
print "Skipping.\n";
return(0);
}
my ($self, $text) = @_;
if ($self->param('interactive')) {
print "$text\n" if $text;
print "[y/N] ";
my $input = lc(<>);
chomp $input;
unless ($input eq 'y') {
print "Skipping.\n";
return(0);
}
}
return(1);
return(1);
}
=head2 user_confirm
......@@ -478,8 +477,8 @@ sub user_proceed {
=cut
sub user_confirm {
my $self = shift;
exit unless $self->user_proceed("Continue?");
my $self = shift;
exit unless $self->user_proceed("Continue?");
}
=head2 read_user_input
......@@ -499,14 +498,14 @@ sub user_confirm {
=cut
sub read_user_input {
my ($self, $text) = @_;
my ($self, $text) = @_;
if ($self->param('interactive')) {
print "$text\n" if $text;
my $input = <>;
chomp $input;
return $input;
}
if ($self->param('interactive')) {
print "$text\n" if $text;
my $input = <>;
chomp $input;
return $input;
}
}
=head2 comma_to_list
......@@ -524,12 +523,12 @@ sub read_user_input {
=cut
sub comma_to_list {
my $self = shift;
foreach my $param (@_) {
$self->param($param,
split (/,/, join (',', $self->param($param))));
}
return(1);
my $self = shift;
foreach my $param (@_) {
$self->param($param,
split (/,/, join (',', $self->param($param))));
}
return(1);
}
=head2 list_or_file
......@@ -545,24 +544,24 @@ sub comma_to_list {
=cut
sub list_or_file {
my ($self, $param) = @_;
my @vals = $self->param($param);
return unless (@vals);
my $firstval = $vals[0];
if (scalar(@vals) == 1 && -e $firstval) {
# we didn't get a list of values, but a file to read values from
@vals = ();
open(IN, $firstval) or throw("Cannot open $firstval for reading: $!");
while(<IN>){
chomp;
push(@vals, $_);
}
close(IN);
$self->param($param, @vals);
my ($self, $param) = @_;
my @vals = $self->param($param);
return unless (@vals);
my $firstval = $vals[0];
if (scalar(@vals) == 1 && -e $firstval) {
# we didn't get a list of values, but a file to read values from
@vals = ();
open(IN, $firstval) or throw("Cannot open $firstval for reading: $!");
while(<IN>){
chomp;
push(@vals, $_);
}
$self->comma_to_list($param);
return(1);
close(IN);
$self->param($param, @vals);
}
$self->comma_to_list($param);
return(1);
}
=head2 param
......@@ -582,31 +581,31 @@ sub list_or_file {
=cut
sub param {
my $self = shift;
my $name = shift or throw("You must supply a parameter name");
# setter
if (@_) {
if (scalar(@_) == 1) {
# single value
$self->{'_param'}->{$name} = shift;
} else {
# list of values
undef $self->{'_param'}->{$name};
@{ $self->{'_param'}->{$name} } = @_;
}
}
my $self = shift;
my $name = shift or throw("You must supply a parameter name");
# getter
if (ref($self->{'_param'}->{$name}) eq 'ARRAY') {
# list parameter
return @{ $self->{'_param'}->{$name} };
} elsif (defined($self->{'_param'}->{$name})) {
# single-value parameter
return $self->{'_param'}->{$name};
# setter
if (@_) {
if (scalar(@_) == 1) {
# single value
$self->{'_param'}->{$name} = shift;
} else {
return ();
# list of values
undef $self->{'_param'}->{$name};
@{ $self->{'_param'}->{$name} } = @_;
}
}
# getter
if (ref($self->{'_param'}->{$name}) eq 'ARRAY') {
# list parameter
return @{ $self->{'_param'}->{$name} };
} elsif (defined($self->{'_param'}->{$name})) {
# single-value parameter
return $self->{'_param'}->{$name};
} else {
return ();
}
}
=head2 error
......@@ -622,9 +621,9 @@ sub param {
=cut
sub error {
my $self = shift;
$self->{'_error'} = shift if (@_);
return $self->{'_error'};
my $self = shift;
$self->{'_error'} = shift if (@_);
return $self->{'_error'};
}
=head2 warnings
......@@ -639,8 +638,8 @@ sub error {
=cut
sub warnings {
my $self = shift;
return $self->{'_warnings'};
my $self = shift;
return $self->{'_warnings'};
}
=head2 serverroot
......@@ -657,9 +656,9 @@ sub warnings {
=cut
sub serverroot {
my $self = shift;
$self->{'_serverroot'} = shift if (@_);
return $self->{'_serverroot'};
my $self = shift;
$self->{'_serverroot'} = shift if (@_);
return $self->{'_serverroot'};
}
=head2 get_database
......@@ -677,54 +676,52 @@ sub serverroot {
=cut
sub get_database {
my $self = shift;
my $database = shift or throw("You must provide a database");
my $prefix = shift || '';
$self->check_required_params(
"${prefix}host",
"${prefix}port",
"${prefix}user",
# "${prefix}pass", not required since might be empty
"${prefix}dbname",
);
my %adaptors = (
core => 'Bio::EnsEMBL::DBSQL::DBAdaptor',
ensembl => 'Bio::EnsEMBL::DBSQL::DBAdaptor',
evega => 'Bio::EnsEMBL::DBSQL::DBAdaptor',
otter => 'Bio::Otter::DBSQL::DBAdaptor',
vega => 'Bio::Otter::DBSQL::DBAdaptor',
compara => 'Bio::EnsEMBL::DBSQL::DBAdaptor',
loutre => 'Bio::Vega::DBSQL::DBAdaptor',
);
throw("Unknown database: $database") unless $adaptors{$database};
$self->dynamic_use($adaptors{$database});
my $dba = $adaptors{$database}->new(
-host => $self->param("${prefix}host"),
-port => $self->param("${prefix}port"),
-user => $self->param("${prefix}user"),
-pass => $self->param("${prefix}pass") || '',
-dbname => $self->param("${prefix}dbname"),
-group => $database,
);
#can use this approach to get dna from another db
# my $dna_db = $adaptors{$database}->new(
# -host => 'otterlive',
# -port => '3301',
# -user => $self->param("${prefix}user"),
# -pass => $self->param("${prefix}pass"),
# -dbname => 'loutre_human',
# );
# $dba->dnadb($dna_db);
# otherwise explicitely set the dnadb to itself - by default the Registry assumes
# a group 'core' for this now
$dba->dnadb($dba);
$self->{'_dba'}->{$database} = $dba;
$self->{'_dba'}->{'default'} = $dba unless $self->{'_dba'}->{'default'};
return $self->{'_dba'}->{$database};
my $self = shift;
my $database = shift or throw("You must provide a database");
my $prefix = shift || '';
$self->check_required_params(
"${prefix}host",
"${prefix}port",
"${prefix}user",
"${prefix}dbname",
);
my %adaptors = (
core => 'Bio::EnsEMBL::DBSQL::DBAdaptor',
ensembl => 'Bio::EnsEMBL::DBSQL::DBAdaptor',
evega => 'Bio::EnsEMBL::DBSQL::DBAdaptor',
otter => 'Bio::Otter::DBSQL::DBAdaptor',
vega => 'Bio::Otter::DBSQL::DBAdaptor',
compara => 'Bio::EnsEMBL::DBSQL::DBAdaptor',
loutre => 'Bio::Vega::DBSQL::DBAdaptor',
);
throw("Unknown database: $database") unless $adaptors{$database};
$self->dynamic_use($adaptors{$database});
my $dba = $adaptors{$database}->new(
-host => $self->param("${prefix}host"),
-port => $self->param("${prefix}port"),
-user => $self->param("${prefix}user"),
-pass => $self->param("${prefix}pass") || '',
-dbname => $self->param("${prefix}dbname"),
-group => $database,
);
#can use this approach to get dna from another db
# my $dna_db = $adaptors{$database}->new(
# -host => 'otterlive',
# -port => '3301',
# -user => $self->param("${prefix}user"),
# -pass => $self->param("${prefix}pass"),
# -dbname => 'loutre_human',
# );
# $dba->dnadb($dna_db);
# otherwise explicitely set the dnadb to itself - by default the Registry assumes
# a group 'core' for this now
$dba->dnadb($dba);
$self->{'_dba'}->{$database} = $dba;
$self->{'_dba'}->{'default'} = $dba unless $self->{'_dba'}->{'default'};
return $self->{'_dba'}->{$database};
}
......@@ -780,60 +777,6 @@ sub get_dbconnection {
}
=head2 get_glovar_database
Example : my $dba = $support->get_glovar_database;
Description : Connects to the Glovar database.
Return type : Bio::EnsEMBL::ExternalData::Glovar::DBAdaptor
Exceptions : thrown if no connection to a core db exists
Caller : general
=cut
sub get_glovar_database {
my $self = shift;
$self->check_required_params(qw(
glovarhost
glovarport
glovaruser
glovarpass
glovardbname
oracle_home
ld_library_path
glovar_snp_consequence_exp
));
# check for core dbadaptor
my $core_db = $self->dba;
unless ($core_db && (ref($core_db) =~ /Bio::.*::DBSQL::DBAdaptor/)) {
$self->log_error("You have to connect to a core db before you can get a glovar dbadaptor.\n");
exit;
}
# setup Oracle environment
$ENV{'ORACLE_HOME'} = $self->param('oracle_home');
$ENV{'LD_LIBRARY_PATH'} = $self->param('ld_library_path');
# connect to Glovar db
$self->dynamic_use('Bio::EnsEMBL::ExternalData::Glovar::DBAdaptor');
my $dba = Bio::EnsEMBL::ExternalData::Glovar::DBAdaptor->new(
-host => $self->param("glovarhost"),
-port => $self->param("glovarport"),
-user => $self->param("glovaruser"),
-pass => $self->param("glovarpass"),
-dbname => $self->param("glovardbname"),
-group => 'glovar',
);
# setup adaptor inter-relationships
$dba->dnadb($core_db);
$self->dynamic_use('Bio::EnsEMBL::ExternalData::Glovar::GlovarSNPAdaptor');
my $glovar_snp_adaptor = $dba->get_GlovarSNPAdaptor;
$glovar_snp_adaptor->consequence_exp($self->param('glovar_snp_consequence_exp'));
$core_db->add_ExternalFeatureAdaptor($glovar_snp_adaptor);
return $dba;
}
=head2 dba
......@@ -848,8 +791,8 @@ sub get_glovar_database {
=cut
sub dba {
my ($self, $database) = shift;
return $self->{'_dba'}->{$database} || $self->{'_dba'}->{'default'};
my ($self, $database) = shift;
return $self->{'_dba'}->{$database} || $self->{'_dba'}->{'default'};
}
=head2 dynamic_use
......@@ -866,19 +809,18 @@ sub dba {
=cut
sub dynamic_use {
my ($self, $classname) = @_;
my ($parent_namespace, $module) = $classname =~/^(.*::)(.*)$/ ?
($1,$2) : ('::', $classname);
no strict 'refs';
# return if module has already been imported
return 1 if $parent_namespace->{$module.'::'} && %{ $parent_namespace->{$module.'::'}||{} };
eval "require $classname";
throw("Failed to require $classname: $@") if ($@);
$classname->import();
return 1;
my ($self, $classname) = @_;
my ($parent_namespace, $module) = $classname =~/^(.*::)(.*)$/ ? ($1,$2) : ('::', $classname);
no strict 'refs';
# return if module has already been imported
return 1 if $parent_namespace->{$module.'::'} && %{ $parent_namespace->{$module.'::'}||{} };
eval "require $classname";
throw("Failed to require $classname: $@") if ($@);
$classname->import();
return 1;
}
=head2 get_chrlength
......@@ -898,48 +840,48 @@ sub dynamic_use {
=cut
sub get_chrlength {
my ($self, $dba, $version,$type,$include_non_reference) = @_;
$dba ||= $self->dba;
$type ||= 'toplevel';
throw("get_chrlength should be passed a Bio::EnsEMBL::DBSQL::DBAdaptor\n")
unless ($dba->isa('Bio::EnsEMBL::DBSQL::DBAdaptor'));
my $sa = $dba->get_SliceAdaptor;
my @chromosomes = map { $_->seq_region_name }
@{ $sa->fetch_all($type, $version,$include_non_reference) };
my %chr = map { $_ => $sa->fetch_by_region($type, $_, undef, undef, undef, $version)->length } @chromosomes;
my @wanted = $self->param('chromosomes');
if (@wanted) {
# check if user supplied invalid chromosome names
foreach my $chr (@wanted) {
my $found = 0;
foreach my $chr_from_db (keys %chr) {
if ($chr_from_db eq $chr) {
$found = 1;
last;
}
}
unless ($found) {
warning("Didn't find chromosome $chr in database " .
$self->param('dbname'));
}
}
# filter to requested chromosomes only
HASH:
foreach my $chr_from_db (keys %chr) {
foreach my $chr (@wanted) {
if ($chr_from_db eq $chr) {
next HASH;
}
}
delete($chr{$chr_from_db});
}
my ($self, $dba, $version,$type,$include_non_reference) = @_;
$dba ||= $self->dba;
$type ||= 'toplevel';
throw("get_chrlength should be passed a Bio::EnsEMBL::DBSQL::DBAdaptor\n")
unless ($dba->isa('Bio::EnsEMBL::DBSQL::DBAdaptor'));
my $sa = $dba->get_SliceAdaptor;
my @chromosomes = map { $_->seq_region_name }
@{ $sa->fetch_all($type, $version,$include_non_reference) };
my %chr = map { $_ => $sa->fetch_by_region($type, $_, undef, undef, undef, $version)->length } @chromosomes;
my @wanted = $self->param('chromosomes');
if (@wanted) {
# check if user supplied invalid chromosome names
foreach my $chr (@wanted) {
my $found = 0;
foreach my $chr_from_db (keys %chr) {
if ($chr_from_db eq $chr) {
$found = 1;
last;
}
}
unless ($found) {