Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/MGRAST/lib/Abundance.pm
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,11 @@ sub all_job_abundances {
}
};

my $total_md5 = 0;
while (my @row = $sth->fetchrow_array()) {
$md5s->{$row[0]} = $row[1];
$count++;
$total_md5++;
if ($count == $self->chunk) {
$add_annotations->();
$md5s = {};
Expand All @@ -195,7 +197,7 @@ sub all_job_abundances {
}
$self->end_query($sth);

return ($org_map, $fun_map, $ont_map);
return ($total_md5, $org_map, $fun_map, $ont_map);
}

sub all_job_md5sums {
Expand Down
5 changes: 4 additions & 1 deletion src/MGRAST/lib/resources/compute.pm
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,10 @@ sub species_diversity_compute {

my $chdl = $self->cassandra_m5nr_handle("m5nr_v".$ver, $Conf::cassandra_m5nr);
my $mgdb = MGRAST::Abundance->new($chdl, $ver);
my ($org_map, undef, undef) = $mgdb->all_job_abundances($job->{job_id}, [$level], 1, undef, undef);
my ($md5_num, $org_map, undef, undef) = $mgdb->all_job_abundances($job->{job_id}, [$level], 1, undef, undef);
if ($md5_num == 0) {
return ({"ERROR" => "no md5 hits available"}, 500);
}

if ($type eq "alphadiversity") {
$data->{data} = $mgdb->get_alpha_diversity($org_map->{$level});
Expand Down
43 changes: 27 additions & 16 deletions src/MGRAST/lib/resources/job.pm
Original file line number Diff line number Diff line change
Expand Up @@ -427,21 +427,28 @@ sub job_data {

# get data
my $data = {};
my ($org_map, $fun_map, $ont_map) = $mgdb->all_job_abundances($job->{job_id}, $taxa_set, $get_org, $get_fun, $get_ont);
if ($get_org) {
$data->{taxonomy} = {};
foreach my $t (keys %{$org_map}) {
$data->{taxonomy}{$t} = [ map { [ $_, $org_map->{$t}{$_} ] } keys %{$org_map->{$t}} ];
my ($md5_num, $org_map, $fun_map, $ont_map) = $mgdb->all_job_abundances($job->{job_id}, $taxa_set, $get_org, $get_fun, $get_ont);
if ($md5_num > 0) {
if ($get_org) {
$data->{taxonomy} = {};
foreach my $t (keys %{$org_map}) {
$data->{taxonomy}{$t} = [ map { [ $_, $org_map->{$t}{$_} ] } keys %{$org_map->{$t}} ];
}
}
}
if ($get_fun) {
$data->{function} = [ map { [ $_, $fun_map->{$_} ] } keys %{$fun_map} ];
}
if ($get_ont) {
$data->{ontology} = {};
foreach my $s (keys %{$ont_map}) {
$data->{ontology}{$s} = [ map { [ $_, $ont_map->{$s}{$_} ] } keys %{$ont_map->{$s}} ];
if ($get_fun) {
$data->{function} = [ map { [ $_, $fun_map->{$_} ] } keys %{$fun_map} ];
}
if ($get_ont) {
$data->{ontology} = {};
foreach my $s (keys %{$ont_map}) {
$data->{ontology}{$s} = [ map { [ $_, $ont_map->{$s}{$_} ] } keys %{$ont_map->{$s}} ];
}
}
} else {
$data = {
ERROR => "no md5 hits available",
STATUS => 500
};
}
$mgdb->DESTROY();

Expand Down Expand Up @@ -847,7 +854,8 @@ sub job_action {
$job = $jobj->[0];
my $jdata = $job->data();
my $jobid = $job->{job_id};
my $mgid = 'mgm'.$job->{metagenome_id};
my $mgid = 'mgm'.$job->{metagenome_id};
my $filename = $jobid.".".time.'.solr.json';

close STDERR;
close STDOUT;
Expand Down Expand Up @@ -927,7 +935,11 @@ sub job_action {
}
}
# get annotations from DB
my ($org_map, $fun_map, undef) = $mgdb->all_job_abundances($jobid, ['species'], $get_org, $get_fun, undef);
my ($md5_num, $org_map, $fun_map, undef) = $mgdb->all_job_abundances($jobid, ['species'], $get_org, $get_fun, undef);
if ($md5_num == 0) {
$self->put_shock_file($filename, qq({"ERROR": "no md5 hits available", "STATUS": 500}), $node->{id}, $self->mgrast_token, 1);
exit 0;
}
if ($get_org) {
$solr_data->{organism} = [ keys %{$org_map->{species}} ];
}
Expand Down Expand Up @@ -960,7 +972,6 @@ sub job_action {
}
# get content
print DEBUG "solr command\n" if $post->{debug};
my $filename = $jobid.".".time.'.solr.json';
my $solr_str = $self->json->encode({
delete => { id => $mgid },
commit => { expungeDeletes => "true" },
Expand Down
2 changes: 1 addition & 1 deletion src/MGRAST/lib/resources/matrix.pm
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ sub prepare_data {

# initialize analysis obj with mgids
unless (exists $self->{m5nr_version}{$version}) {
$self->return_data({"ERROR" => "invalid version was entered ($version). Please use one of: ".join(", ", keys %{$self->{m5nr_version}})}, 404);
return ({"ERROR" => "invalid version was entered ($version). Please use one of: ".join(", ", keys %{$self->{m5nr_version}})}, 404);
}
my $master = $self->connect_to_datasource();
my $chdl = $self->cassandra_m5nr_handle("m5nr_v".$version, $Conf::cassandra_m5nr);
Expand Down
13 changes: 13 additions & 0 deletions src/MGRAST/lib/resources/status.pm
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ sub instance {
if ($err) {
$self->return_data( {"ERROR" => "unable to retrieve data: ".$err}, 404 );
}
# handle error in content
my $data = undef;
eval {
$data = $self->json->decode($content);
}
if ($@ || (! $data)) {
$self->return_data( {"ERROR" => "invalid data format: ".$@}, 404 );
}
my $error = exists($data->{ERROR}) ? $data->{ERROR} : (exists($data->{error}) ? $data->{error} : undef);
if ($error) {
my $status = exists($data->{STATUS}) ? $data->{STATUS} : (exists($data->{status}) ? $data->{status} : 500);
$self->return_data( {"ERROR" => $error}, $status);
}
$obj->{data} = $self->json->decode($content);
}
}
Expand Down