Skip to content

Commit

Permalink
fixed bug when getting md5 data set where function is null / empty st…
Browse files Browse the repository at this point in the history
…ring
  • Loading branch information
Travis Harrison committed Sep 20, 2012
1 parent aca30c5 commit 0f6767f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/Babel/lib/Babel.pm
Expand Up @@ -181,17 +181,29 @@ sub md5s2sets {
return [];
}

my $sql = qq(select d.id, d.md5, f.name, o.name, s.name
from md5_protein d, functions f, organisms_ncbi o, sources s
where d.function = f._id and d.organism = o._id and d.source = s._id);
# need to handle case of function being null
my $sql = qq(select d.id, d.md5, d.function, o.name, s.name
from md5_protein d, organisms_ncbi o, sources s
where d.organism = o._id and d.source = s._id);
if (@$md5s == 1) {
$sql .= " and d.md5 = " . $self->dbh->quote($md5s->[0]);
} else {
$sql .= " and d.md5 in (" . join(",", map {$self->dbh->quote($_)} @$md5s) . ")";
}

my $rows = $self->dbh->selectall_arrayref($sql);
return ($rows && ref($rows)) ? $rows : [];
if ($rows && (@$rows > 0)) {
my %funcs = map { $_->[2], 1 } grep { $_->[2] } @$rows;
my $fmap = {};
if (scalar(keys %funcs) > 0) {
my $fsql = "select d.function, f.name from md5_protein d, functions f where d.function=f._id and d.function in (".join(",", keys %funcs).")";
%$fmap = map { $_->[0], $_->[1] } @{ $self->dbh->selectall_arrayref($fsql) };
}
map { $_->[2] = ($_->[2] && exists($fmap->{$_->[2]})) ? $fmap->{$_->[2]} : 'unknown' } @$rows;
return $rows
} else {
return [];
}
}

sub md52org {
Expand Down
2 changes: 1 addition & 1 deletion src/Babel/m5nr_rest.cgi
Expand Up @@ -32,7 +32,7 @@ my @rest = split m#/#, $rest;

map {$rest[$_] =~ s#forwardslash#/#gi} (0 .. $#rest);

if ( $ENV{'REQUEST_METHOD'} =~ /post/i ) {
if ( $ENV{'REQUEST_METHOD'} && ($ENV{'REQUEST_METHOD'} =~ /post/i) ) {
print $cgi->header('text/plain');
print "ERROR: POST is not supported by this version";
exit 0;
Expand Down

0 comments on commit 0f6767f

Please sign in to comment.