Commit ee7f17d0 authored by Web Group's avatar Web Group
Browse files

sb23: fixed get_species_and_object_type - check port as well as host. Also,...

sb23: fixed get_species_and_object_type - check port as well as host. Also, don't die. Die is bad. Why would you die when you can return undef and not totally break the web code?
parent 7951dff6
...@@ -2443,7 +2443,8 @@ my %stable_id_stmts = ( ...@@ -2443,7 +2443,8 @@ my %stable_id_stmts = (
. 'JOIN %1$s.coord_system USING (coord_system_id) ' . 'JOIN %1$s.coord_system USING (coord_system_id) '
. 'JOIN %1$s.meta m USING (species_id) ' . 'JOIN %1$s.meta m USING (species_id) '
. 'WHERE si.stable_id = ? ' . 'WHERE si.stable_id = ? '
. 'AND m.meta_key = "species.production_name"', . 'AND m.meta_key = "species.production_name"'
,
"transcript" => 'SELECT m.meta_value ' "transcript" => 'SELECT m.meta_value '
. 'FROM %1$s.transcript_stable_id si ' . 'FROM %1$s.transcript_stable_id si '
. 'JOIN %1$s.transcript USING (transcript_id) ' . 'JOIN %1$s.transcript USING (transcript_id) '
...@@ -2472,56 +2473,44 @@ my %stable_id_stmts = ( ...@@ -2472,56 +2473,44 @@ my %stable_id_stmts = (
); );
sub get_species_and_object_type { sub get_species_and_object_type {
my ( $self, $stable_id, $known_type ) = @_; my ($self, $stable_id, $known_type) = @_;
if ( defined($known_type) if (defined $known_type && !exists $stable_id_stmts{lc $known_type}) {
&& !exists( $stable_id_stmts{ lc($known_type) } ) ) warn "Got invalid known_type '$known_type'";
{ return;
throw( sprintf( "Got invalid known_type '%s'", $known_type ) );
} }
my @types = ( defined($known_type) my @types = defined $known_type ? ($known_type) : ('Gene', 'Transcript', 'Translation', 'Exon');
? ($known_type)
: ( 'Gene', 'Transcript', 'Translation', 'Exon' ) );
my @match;
my $dbc; my $dbc;
my $dbh; my $dbh;
OUTER: foreach my $dba (
foreach my $dba ( sort { $a->dbc()->host() cmp $b->dbc()->host() } sort { $a->dbc->host cmp $b->dbc->host || $a->dbc->port <=> $b->dbc->port }
@{ $self->get_all_DBAdaptors( '-group' => 'Core' ) } ) @{$self->get_all_DBAdaptors( '-group' => 'Core' )}
{ ) {
if ( !defined($dbc) unless (defined $dbc && $dbc->host eq $dba->dbc->host && $dbc->port eq $dba->dbc->port) {
|| $dbc->host() ne $dba->dbc()->host() ) $dbc = $dba->dbc;
{ $dbh = $dbc->db_handle;
$dbc = $dba->dbc();
$dbh = $dbc->db_handle();
} }
foreach my $type (@types) { foreach my $type (@types) {
my $statement = my $statement = sprintf $stable_id_stmts{lc $type}, $dba->dbc->dbname;
sprintf( $stable_id_stmts{ lc($type) }, $dba->dbc()->dbname() );
my $sth = $dbh->prepare($statement); my $sth = $dbh->prepare($statement);
$sth->bind_param( 1, $stable_id, SQL_VARCHAR ); $sth->bind_param(1, $stable_id, SQL_VARCHAR);
$sth->execute(); $sth->execute;
my $species = $sth->fetchall_arrayref()->[0][0]; my $species = $sth->fetchall_arrayref->[0][0];
$sth->finish(); $sth->finish;
if ( defined($species) ) { return ($species, $type, 'Core') if defined $species;
@match = ( $species, $type, 'Core' );
last OUTER;
}
} }
} ## end foreach my $dba ( sort { $a...}) } ## end foreach my $dba ( sort { $a...})
return @match; return;
} ## end sub get_species_and_object_type } ## end sub get_species_and_object_type
1; 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