forked from TheSEED/app_service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tbr
57 lines (45 loc) · 1.69 KB
/
tbr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use strict;
use Bio::KBase::AppService::BinningReport;
use Bio::KBase::AppService::AppConfig qw(data_api_url db_host db_user db_pass db_name seedtk);
use DBI;
use Data::Dumper;
use JSON::XS;
use Bio::P3::Workspace::WorkspaceClientExt;
use IPC::Run 'run';
my $ws = Bio::P3::Workspace::WorkspaceClientExt->new();
my $dsn = "DBI:mysql:database=" . db_name . ";host=" . db_host;
my $dbh = DBI->connect($dsn, db_user, db_pass, { RaiseError => 1, AutoCommit => 0 });
my $job_id = '3d13b98a-fdd2-4085-9400-b4bd04883911';
my($params_txt) = $dbh->selectrow_array(qq(SELECT app_params
FROM JobGroup
WHERE parent_job = ?), undef, $job_id);
my $params = decode_json($params_txt);
my $qual_path = join("/", $params->{output_path}, "." . $params->{output_file}, "quality.json");
my $qual = load_workspace_json($ws, $qual_path);
my $ppr_path = join("/", $params->{output_path}, "." . $params->{output_file}, "ppr_report.json");
my $ppr = load_workspace_json($ws, $ppr_path);
my $bins_path = join("/", $params->{output_path}, "." . $params->{output_file}, "bins.json");
my $bins = load_workspace_json($ws, $bins_path);
Bio::KBase::AppService::BinningReport::write_report($job_id, $params, $qual, $ppr, $bins, \*STDOUT);
sub load_workspace_json
{
my($ws, $path) = @_;
my $str;
open(my $fh, ">", \$str) or die "Cannot open string reference filehandle: $!";
eval {
$ws->copy_files_to_handles(1, $ws->{token}, [[$path, $fh]]);
};
if ($@)
{
my($err) = $@ =~ /_ERROR_(.*)_ERROR_/;
$err //= $@;
die "load_workspace_json: failed to load $path: $err\n";
}
close($fh);
my $doc = eval { decode_json($str) };
if ($@)
{
die "Error parsing json: $@";
}
return $doc;
}