Skip to content

Commit

Permalink
Added invalid and duplicate gene input handling for queries #709
Browse files Browse the repository at this point in the history
  • Loading branch information
NoorMuhammad1 committed Jun 14, 2024
1 parent 3b4336a commit b9b61a2
Show file tree
Hide file tree
Showing 2 changed files with 189 additions and 6 deletions.
114 changes: 108 additions & 6 deletions app/js/backbone-views.js
Original file line number Diff line number Diff line change
Expand Up @@ -2116,14 +2116,20 @@ var NeighborhoodQueryView = Backbone.View.extend({
document.getElementById("query-neighborhood-length-limit").focus();
return;
}

var queryURL =
"http://www.pathwaycommons.org/pc2/graph?format=SBGN&kind=NEIGHBORHOOD&limit=" +
self.currentQueryParameters.lengthLimit;

var geneSymbolsArray = geneSymbols
.replaceAll("\n", " ")
.replaceAll("\t", " ")
.split(" ");
// Check if duplicate symbols are given or not
if(handleDuplicateGenes(geneSymbolsArray,chiseInstance))return;

// Check if the gene symbols that are added even exist in the database or not
if(handleGeneDoesNotExist(geneSymbolsArray,chiseInstance))return;

var queryURL =
"http://www.pathwaycommons.org/pc2/graph?format=SBGN&kind=NEIGHBORHOOD&limit=" +
self.currentQueryParameters.lengthLimit;

var filename = "";
var sources = "";
Expand Down Expand Up @@ -2160,7 +2166,6 @@ var NeighborhoodQueryView = Backbone.View.extend({
cy,
"currentLayoutProperties"
);

$.ajax({
type: "get",
url: "/utilities/testURL",
Expand Down Expand Up @@ -2295,6 +2300,8 @@ var NeighborhoodQueryView = Backbone.View.extend({
},
});



/**
* Paths Between Query view for the Sample Application.
*/
Expand Down Expand Up @@ -2324,7 +2331,7 @@ var PathsBetweenQueryView = Backbone.View.extend({

$(document)
.off("click", "#save-query-pathsbetween")
.on("click", "#save-query-pathsbetween", function (evt) {
.on("click", "#save-query-pathsbetween",async function (evt) {
// use active chise instance
var chiseInstance = appUtilities.getActiveChiseInstance();

Expand Down Expand Up @@ -2361,6 +2368,19 @@ var PathsBetweenQueryView = Backbone.View.extend({
return;
}

var geneSymbolsArray = geneSymbols
.replaceAll("\n", " ")
.replaceAll("\t", " ")
.split(" ");

// Check if duplicate symbols are given or not
if(handleDuplicateGenes(geneSymbolsArray,chiseInstance))return;

// Check if the gene symbols that are added even exist in the database or not
if(handleGeneDoesNotExist(geneSymbolsArray,chiseInstance))return;



var queryURL =
"http://www.pathwaycommons.org/pc2/graph?format=SBGN&kind=PATHSBETWEEN&limit=" +
self.currentQueryParameters.lengthLimit;
Expand Down Expand Up @@ -4242,6 +4262,50 @@ var PromptEmptyQueryResultView = Backbone.View.extend({
},
});


var DuplicateGeneGiven = Backbone.View.extend({
initialize: function (options) {
var self = this;
self.template = _.template($("#prompt-duplicateGeneGiven-template").html());
},
render: function () {
var self = this;
self.template = _.template($("#prompt-duplicateGeneGiven-template").html());

$(self.el).html(self.template);
$(self.el).modal("show");
$(document)
.off("click", "#prompt-duplicateGeneGiven-confirm")
.on("click", "#prompt-duplicateGeneGiven-confirm", function (evt) {
$(self.el).modal("toggle");
});

return this;
},
});

var GeneNotExist = Backbone.View.extend({
initialize: function (options) {
var self = this;
self.template = _.template($("#prompt-geneNotExist-template").html());
this.gene = options.gene;
},
render: function () {
var self = this;
self.template = _.template($("#prompt-geneNotExist-template").html());

$(self.el).html(self.template({gene:this.gene}));
$(self.el).modal("show");
$(document)
.off("click", "#prompt-geneNotExist-confirm")
.on("click", "#prompt-geneNotExist-confirm", function (evt) {
$(self.el).modal("toggle");
});

return this;
},
});

var PromptInvalidLengthLimitView = Backbone.View.extend({
initialize: function () {
var self = this;
Expand Down Expand Up @@ -6884,6 +6948,44 @@ function bindColorPicker2GridColorInputs() {
}
}

function handleDuplicateGenes(geneSymbolsArray,chiseInstance){
const hasDuplicate=(array)=>new Set(array).size!==array.length;
if(hasDuplicate(geneSymbolsArray)){
new DuplicateGeneGiven({
el: "#prompt-duplicateGeneGiven-table",
gene:"",
}).render();
chiseInstance.endSpinner("paths-between-spinner");
document.getElementById("query-pathsbetween-gene-symbols").focus();
return true;
}
return false
}

async function handleGeneDoesNotExist (geneSymbolsArray,chiseInstance){
chiseInstance.startSpinner("paths-between-spinner");
for(gene of geneSymbolsArray){
let q = `https://www.pathwaycommons.org/pc2/search?q=${gene}`;

const data = await $.ajax({
type:'get',
url:'/utilities/testURL',
data:{url:q}
});
let {numHits} = JSON.parse(data.response.body);
if(numHits===0){
new GeneNotExist({
el: "#prompt-geneNotExist-table",
gene,
}).render();
chiseInstance.endSpinner("paths-between-spinner");
document.getElementById("query-pathsbetween-gene-symbols").focus();
return true;
}
}
return false;
}

module.exports = {
// BioGeneView: BioGeneView,
ChemicalView: ChemicalView,
Expand Down
81 changes: 81 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2474,6 +2474,24 @@
<!-- map type change confirmation dialog will be shown here-->
</div>

<div
id="prompt-duplicateGeneGiven-table"
tabindex="-1"
class="modal fade"
role="dialog"
>
<!-- map type change confirmation dialog will be shown here-->
</div>

<div
id="prompt-geneNotExist-table"
tabindex="-1"
class="modal fade"
role="dialog"
>
<!-- map type change confirmation dialog will be shown here-->
</div>

<div
id="prompt-emptyQueryResult-table"
tabindex="-1"
Expand Down Expand Up @@ -4100,6 +4118,69 @@ <h4 class="modal-title">Info</h4>
</div>
</script>

<!-- Duplicate Gene Given -->
<script type="text/template" id="prompt-duplicateGeneGiven-template">
<div class="modal-dialog sbgn-modal-dialog" style="width: 300px;">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Error</h4>
</div>
<div class="modal-body">
<table class="table-condensed layout-table dialog-table" style="margin: auto;">
<tbody>
<tr>
<th style="padding-left: 0px;" align="left">
<span class="add-on layout-text">Duplicate gene symbols are not allowed</span>
</th>
</tr>

<tr id="prompt-duplicateGeneGiven-buttons" style="padding-bottom: 0px; margin-bottom: 0px;">
<td>
</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer" style="text-align: center">
<button id="prompt-duplicateGeneGiven-confirm" class="btn btn-default">OK</button>
</div>
</div>
</div>
</script>

<!-- Gene Not Exist result -->
<script type="text/template" id="prompt-geneNotExist-template">
<div class="modal-dialog sbgn-modal-dialog" style="width: 300px;">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Error</h4>
</div>
<div class="modal-body">
<table class="table-condensed layout-table dialog-table" style="margin: auto;">
<tbody>
<tr>
<th style="padding-left: 0px;" align="left">
<span class="add-on layout-text">Gene <%= gene %> does not exist in the database</span>
</th>
</tr>

<tr id="prompt-geneNotExist-buttons" style="padding-bottom: 0px; margin-bottom: 0px;">
<td>
</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer" style="text-align: center">
<button id="prompt-geneNotExist-confirm" class="btn btn-default">OK</button>
</div>
</div>
</div>
</script>


<!-- Empty query result -->
<script type="text/template" id="prompt-emptyQueryResult-template">
<div class="modal-dialog sbgn-modal-dialog" style="width: 300px;">
Expand Down

0 comments on commit b9b61a2

Please sign in to comment.