Skip to content

Commit

Permalink
Expose registered analysis field results via the API.
Browse files Browse the repository at this point in the history
Closes #1024.
  • Loading branch information
kjolley committed Dec 19, 2024
1 parent 3b0f2f7 commit 6e65dc5
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lib/BIGSdb/REST/Routes/Isolates.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Written by Keith Jolley
#Copyright (c) 2014-2023, University of Oxford
#Copyright (c) 2014-2024, University of Oxford
#E-mail: [email protected]
#
#This file is part of Bacterial Isolate Genome Sequence Database (BIGSdb).
Expand Down Expand Up @@ -154,6 +154,8 @@ sub _get_isolate {
$values->{'history'} = request->uri_for("$subdir/db/$db/isolates/$id/history") if $has_history;
my $publications = _get_publications($id);
$values->{'publications'} = $publications if @$publications;
my $analysis = _get_analysis_results($id);
$values->{'analysis_results'} = $analysis if %$analysis;
my $seqbin_stats =
$self->{'datastore'}
->run_query( 'SELECT * FROM seqbin_stats WHERE isolate_id=?', $id, { fetch => 'row_hashref' } );
Expand Down Expand Up @@ -213,6 +215,25 @@ sub _get_publications {
return $publications;
}

sub _get_analysis_results {
my ($isolate_id) = @_;
my $self = setting('self');
my $results = $self->{'datastore'}->run_query(
'SELECT af.analysis_name,af.analysis_display_name,af.field_name,af.data_type,arc.value FROM '
. 'analysis_fields af JOIN analysis_results_cache arc ON (af.analysis_name,af.json_path)='
. '(arc.analysis_name,arc.json_path) WHERE arc.isolate_id=?',
$isolate_id,
{ fetch => 'all_arrayref', slice => {} }
);
my $values = {};
foreach my $result (@$results) {
my $analysis = $result->{'analysis_display_name'} // $result->{'analysis_name'};
my $value = $result->{'data_type'} eq 'integer' ? int( $result->{'value'} ) : $result->{'value'};
$values->{$analysis}->{ $result->{'field_name'} } = $value;
}
return $values;
}

sub _get_history {
my $self = setting('self');
my $params = params;
Expand Down

0 comments on commit 6e65dc5

Please sign in to comment.