This repository has been archived by the owner on May 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeaconinfo.cgi
executable file
·109 lines (77 loc) · 3.2 KB
/
beaconinfo.cgi
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/perl
# © 2000-2019 Michael Baudis: m@baud.is
use strict;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(param);
use File::Basename;
use JSON;
use MongoDB;
use MongoDB::MongoClient;
use Data::Dumper;
use BeaconPlus::ConfigLoader;
=podmd
The "beaconinfo.cgi" server application serves tw main functions
1. Called w/o parameters, it will return a standard Beacon information object.
2. Provided with
- `datasetIds` (optional)
- `querytext`
- `querytype` (optional)
it will return information about the matched identifiers from the collection(s)
selected through `datasetIds`.
=cut
my $config = BeaconPlus::ConfigLoader->new();
my $autoc = $config->{param}->{autocomplete}->[0];
if (! -t STDIN) { print 'Status: 200'."\n".'Content-type: application/json'."\n\n" }
if ($ENV{REQUEST_URI} =~ /service\-info/) {
print JSON::XS->new->pretty( 1 )->allow_blessed->convert_blessed->encode($config->{service_info})."\n";
exit;
}
=podmd
The counts for the collections (`variants`, `biosamples` etc.) of the different
datasets are retrieved from the daily updated `progenetix.dbstats` collection.
For the non-parametrized call of the application, just the basic information
including variant counts is returned.
=cut
my $dbClient = MongoDB::MongoClient->new();
my $cursor = $dbClient->get_database( 'progenetix' )->get_collection('dbstats')->find()->sort({_id => -1})->limit(1);
my $stats = ($cursor->all)[0];
my $beaconInfo = $config->{service_info};
foreach (qw(id name apiVersion version description welcomeUrl alternativeUrl createDateTime updateDateTime organization sampleAlleleRequests)) {
$beaconInfo->{$_} = $config->{$_};
}
foreach my $dataset ( @{ $config->{ datasets }}) {
my $counts = {
callCount => $stats->{$dataset->{id}.'__variants'}->{count},
variantCount => $stats->{$dataset->{id}.'__variants'}->{distincts_count_digest},
sampleCount => $stats->{$dataset->{id}.'__biosamples'}->{count},
};
if (grep{ $counts->{$_} > 0 } keys %$counts) {
my $dbconn = $dbClient->get_database( $dataset->{id} );
foreach (sort keys %$counts) {
if ($counts->{$_} > 0) {
$dataset->{$_} = $counts->{$_} }
}
=podmd
If the request contains an "ontologies" or "details" keyword, information about
the existing ontologies are provided, per dataset.
TODO: This may either be deprecated (since an alternative exists in `/api/`),
or be specified more clearly in the future, depending also on the development
of the Beacon v2 "filters" concept.
=cut
if ($ENV{REQUEST_URI} =~ /details|ontolog/) {
my $collName = 'biosubsets';
if ($ENV{REQUEST_URI} =~ /referenceid/) {
$collName = 'datacollections' }
my $cursor = $dbconn->get_collection($collName)->find( $config->{queries}->{biosamples} )->fields({ id => 1, label => 1, count => 1, _id => 0});
my @subsets = $cursor->all;
foreach my $sub (grep{ $_->{id} !~ /\+/ } @subsets) {
$sub->{count} *= 1;
push(@{ $dataset->{ info }->{ ontology_terms } }, $sub);
}
}
push(@{ $beaconInfo->{datasets} }, $dataset);
}
}
print JSON::XS->new->pretty( 1 )->allow_blessed->convert_blessed->canonical()->encode($beaconInfo)."\n";
exit;
1;