Commit c431628a authored by Severine Duvaud's avatar Severine Duvaud
Browse files

Handle max length

parent 2e2a7906
......@@ -70,6 +70,20 @@ function checkPreconditions(params) {
};
}
if (!Number(params.length)) {
return {
hasError: true,
msg: "min. length not a number"
};
}
if (!Number(params.maxLength)) {
return {
hasError: true,
msg: "max length not a number"
};
}
//TODO add additional checks
return {
......@@ -82,14 +96,21 @@ function buildMongoQuery(params) {
var position = parseInt(params.start);
var length = 0;
var maxLength = 0;
if(params.alternateBases == 'DEL') {
if (typeof params.length != undefined && params.length != null && params.length != '')
if (typeof params.length != undefined && params.length != null && params.length != '') // min. length is provided
{
length = (params.length.length == 0 ? 0 : parseInt(params.length));
}
}
console.log("*** LENGTH: " + length);
if (typeof params.maxLength != undefined && params.maxLength != null && params.maxLength != '') // max length is provided
{
maxLength = (params.maxLength.length == 0 ? 0 : parseInt(params.maxLength));
if (length == 0) {
length++; // force min. length in case none is given
}
}
}
var andConditions = [];
var orConditions = [];
......@@ -111,12 +132,29 @@ function buildMongoQuery(params) {
var cond = {};
if (length > 0) {
cond[convertedReference] = {
'$elemMatch': {
'CHRO': params.referenceName,
'SEGTYPE': segType,
'SEGSIZE': length, // exact length
'SEGSTART': position // exact position
if (maxLength > 0) {
cond[convertedReference] = {
'$elemMatch': {
'CHRO': params.referenceName,
'SEGTYPE': segType,
'SEGSIZE': {
$gte: length,
$lte: maxLength
}, // min. and max lengths
'SEGSTART': position // exact position
}
}
}
else {
cond[convertedReference] = {
'$elemMatch': {
'CHRO': params.referenceName,
'SEGTYPE': segType,
'SEGSIZE': {
$gte: length
}, // min. length
'SEGSTART': position // exact position
}
}
}
}
......
......@@ -23,7 +23,8 @@ arrayMap.controller('BeaconController', ['$scope', '$location', function ($scope
"reference": "GRCh38",
"dataset": "all",
"alternateBases": "DEL",
"length": '1'
"length": '1',
"maxLength": ''
}
$scope.getNewApiUrl = function () {
......@@ -36,7 +37,8 @@ arrayMap.controller('BeaconController', ['$scope', '$location', function ($scope
"&assemblyId=" + conf.reference +
"&datasetIds=" + conf.dataset +
((conf.alternateBases === "") ? "all" : "&alternateBases=" + conf.alternateBases) +
"&length=" + conf.length;
"&length=" + conf.length +
((conf.maxLength === '') ? "" : "&maxLength=" + conf.maxLength);
};
$scope.getInfoUrl = function () {
......
......@@ -49,11 +49,19 @@
</div>
</div>
<div class="form-group">
<label for="position" class="col-sm-2 control-label">Minimal Length</label>
<label for="position" class="col-sm-2 control-label">Minimal length</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="length" ng-model="config.length">
</div>
</div>
<div class="form-group">
<label for="position" class="col-sm-2 control-label">Maximal length</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="maxLength" ng-model="config.maxLength">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-8">
<a target="beacon" ng-href="/v0.3/query?referenceName=11&start=34439881&assemblyId=GRCh38&datasetIds=8070/3&alternateBases=DEL">Example query</a>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment