Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ST
ga4gh-arraymap
Commits
24358fc4
Commit
24358fc4
authored
Jul 22, 2016
by
Severine Duvaud
Browse files
Added the frequency to the response as requested my Michael
parent
cc74f807
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/node-app/arraymap-beacon/v0.4/beacon-query.js
View file @
24358fc4
...
...
@@ -3,9 +3,14 @@ var info = require('./beacon-info.js').info;
// store all the dataset identifiers
// not used when a list of datasets is entered
// find a better place for this?
var
allDatasetIds
=
[];
var
allDatasets
=
[];
var
datasetObj
;
info
[
'
info
'
][
'
info
'
][
'
datasets
'
].
forEach
(
function
(
dataset
){
allDatasetIds
.
push
(
dataset
.
id
);
datasetObj
=
{
"
id
"
:
dataset
.
id
,
"
nbSamples
"
:
dataset
.
size
.
samples
};
allDatasets
.
push
(
datasetObj
);
});
var
referenceMap
=
{
...
...
@@ -71,7 +76,11 @@ function checkPreconditions(params) {
}
if
(
params
.
datasetIds
!=
'
all
'
)
{
var
error
=
checkDatasetIdentifiers
(
params
.
datasetIds
,
allDatasetIds
);
var
ids
=
[];
allDatasets
.
forEach
(
function
(
dataset
)
{
ids
.
push
(
dataset
.
id
);
});
var
error
=
checkDatasetIdentifiers
(
params
.
datasetIds
,
ids
);
if
(
error
.
length
>
0
)
{
return
{
hasError
:
true
,
...
...
@@ -112,7 +121,7 @@ function checkPreconditions(params) {
}
/*
* Latest version of API v-0.
3
* Latest version of API v-0.
4
*
* BeaconAlleleRequest:
* referenceName
...
...
@@ -220,6 +229,7 @@ function checkResultAndGetResponse(params, datasets) {
"
exists
"
:
null
,
"
datasetId
"
:
null
,
"
sampleCount
"
:
0
,
"
frequency
"
:
0
,
"
error
"
:
{
errorCode
:
500
,
message
:
"
Internal error, DB returned a value but post check is not valid.
"
...
...
@@ -235,15 +245,19 @@ function checkResultAndGetResponse(params, datasets) {
"
error
"
:
null
,
"
note
"
:
null
,
"
datasetId
"
:
dataset
.
_id
,
"
sampleCount
"
:
0
"
sampleCount
"
:
0
,
"
frequency
"
:
0
};
}
else
{
var
totalSample
=
getTotalNbSample
(
dataset
.
_id
);
var
frequency
=
totalSample
>
1
?
(
dataset
.
observed
/
totalSample
).
toPrecision
(
3
)
:
0
;
response
=
{
"
exists
"
:
true
,
"
error
"
:
null
,
"
note
"
:
null
,
"
datasetId
"
:
dataset
.
_id
,
"
sampleCount
"
:
dataset
.
observed
"
sampleCount
"
:
dataset
.
observed
,
"
frequency
"
:
frequency
};
}
responses
.
push
(
response
);
...
...
@@ -255,6 +269,7 @@ function checkResultAndGetResponse(params, datasets) {
"
exists
"
:
false
,
"
datasetId
"
:
null
,
"
sampleCount
"
:
0
,
"
frequency
"
:
0
,
"
error
"
:
null
,
};
...
...
@@ -289,6 +304,16 @@ function checkResultAndGetResponse(params, datasets) {
};
}
function
getTotalNbSample
(
id
)
{
var
nbSamples
=
1
;
// and not 0: Division
allDatasets
.
forEach
(
function
(
dataset
){
if
(
dataset
.
id
==
id
)
{
nbSamples
=
dataset
.
nbSamples
;
}
});
return
nbSamples
;
}
// checks to be added!
// Pending for now!
function
checkResult
(
params
,
datasets
)
{
...
...
@@ -300,7 +325,10 @@ function checkResult(params, datasets) {
matchedIdentifiers
.
push
(
dataset
.
_id
);
});
var
submittedIdentifiers
=
allDatasetIds
;
var
submittedIdentifiers
=
[];
allDatasets
.
forEach
(
function
(
datasetId
){
submittedIdentifiers
.
push
(
datasetId
.
id
);
});
if
(
params
.
datasetIds
!=
'
all
'
)
{
submittedIdentifiers
=
params
.
datasetIds
.
split
(
'
,
'
);
}
...
...
@@ -311,7 +339,7 @@ function checkResult(params, datasets) {
var
missedObj
=
{
"
_id
"
:
missed
,
"
observed
"
:
0
}
}
;
allDatasets
.
push
(
missedObj
);
});
}
...
...
@@ -328,7 +356,7 @@ function checkDatasetIdentifiers(userDatasetIdentifiers, allDatasetIdentifiers)
if
(
all
==
id
)
{
found
=
true
;
}
})
})
;
if
(
!
found
)
{
error
.
push
(
id
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment