Skip to content

Commit

Permalink
Add support for WikiPathways Query
Browse files Browse the repository at this point in the history
Users can now make query by WPID to import corresponding pathway in SBGNf ormat
  • Loading branch information
hasanbalci committed Jul 9, 2024
1 parent 25612fc commit bfe3f87
Show file tree
Hide file tree
Showing 4 changed files with 336 additions and 239 deletions.
9 changes: 8 additions & 1 deletion app/js/app-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var _ = require('underscore');
module.exports = function() {
var dynamicResize = appUtilities.dynamicResize.bind(appUtilities);

var layoutPropertiesView, generalPropertiesView,neighborhoodQueryView, pathsBetweenQueryView, pathsFromToQueryView, commonStreamQueryView, pathsByURIQueryView, promptSaveView, promptConfirmationView,
var layoutPropertiesView, generalPropertiesView, neighborhoodQueryView, pathsBetweenQueryView, pathsFromToQueryView, commonStreamQueryView, pathsByURIQueryView, mapByWPIDQueryView, promptSaveView, promptConfirmationView,
promptMapTypeView, promptInvalidTypeWarning, promtErrorPD2AF, promptInvalidFileView, promptFileConversionErrorView, promptInvalidURIWarning, reactionTemplateView, gridPropertiesView, fontPropertiesView, fileSaveView,saveUserPreferencesView, loadUserPreferencesView, sifMapWarning;

function validateSBGNML(xml) {
Expand Down Expand Up @@ -150,6 +150,7 @@ module.exports = function() {
pathsFromToQueryView = appUtilities.pathsFromToQueryView = new BackboneViews.PathsFromToQueryView({el: '#query-pathsfromto-table'});
commonStreamQueryView = appUtilities.commonStreamQueryView = new BackboneViews.CommonStreamQueryView({el: '#query-commonstream-table'});
pathsByURIQueryView = appUtilities.pathsByURIQueryView = new BackboneViews.PathsByURIQueryView({el: '#query-pathsbyURI-table'});
mapByWPIDQueryView = appUtilities.mapByWPIDQueryView = new BackboneViews.MapByWPIDQueryView({el: '#query-mapbyWPID-table'});
//promptSaveView = appUtilities.promptSaveView = new BackboneViews.PromptSaveView({el: '#prompt-save-table'}); // see PromptSaveView in backbone-views.js
fileSaveView = appUtilities.fileSaveView = new BackboneViews.FileSaveView({el: '#file-save-table'});
saveUserPreferencesView = appUtilities.saveUserPreferencesView = new BackboneViews.SaveUserPreferencesView({el: '#user-preferences-save-table'});
Expand All @@ -166,7 +167,9 @@ module.exports = function() {
fontPropertiesView = appUtilities.fontPropertiesView = new BackboneViews.FontPropertiesView({el: '#font-properties-table'});
infoboxPropertiesView = appUtilities.infoboxPropertiesView = new BackboneViews.InfoboxPropertiesView({el: '#infobox-properties-table'});
promptInvalidURIView = appUtilities.promptInvalidURIView = new BackboneViews.PromptInvalidURIView({el: '#prompt-invalidURI-table'});
promptInvalidWPIDView = appUtilities.promptInvalidWPIDView = new BackboneViews.PromptInvalidWPIDView({el: '#prompt-invalidWPID-table'});
promptInvalidURIWarning = appUtilities.promptInvalidURIWarning = new BackboneViews.PromptInvalidURIWarning({el: '#prompt-invalidURI-table'});
promptInvalidWPIDWarning = appUtilities.promptInvalidWPIDWarning = new BackboneViews.PromptInvalidWPIDWarning({el: '#prompt-invalidWPID-table'});
promptInvalidURLWarning = appUtilities.promptInvalidURLWarning = new BackboneViews.PromptInvalidURLWarning({el: '#prompt-invalidURL-table'});
promptInvalidImageWarning = appUtilities.promptInvalidImageWarning = new BackboneViews.PromptInvalidImageWarning({el: '#prompt-invalidImage-table'});
promptInvalidEdgeWarning = appUtilities.promptInvalidEdgeWarning = new BackboneViews.PromptInvalidEdgeWarning({el: '#prompt-invalidEdge-table'});
Expand Down Expand Up @@ -1314,6 +1317,10 @@ module.exports = function() {
pathsByURIQueryView.render();
});

$("#query-mapbyWPID").click(function (e) {
mapByWPIDQueryView.render();
});

$("#grid-properties").click(function (e) {
gridPropertiesView.render();
});
Expand Down
7 changes: 2 additions & 5 deletions app/js/app-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -3224,14 +3224,11 @@ appUtilities.launchWithModelFile = function() {
await promptConfirmationView.render(async function () {
await chiseInstance.loadSBGNMLText(data.message, false, filename, cy, paramObj);
});
chiseInstance.endSpinner('paths-byURL-spinner')

chiseInstance.endSpinner('paths-byURL-spinner');
}
else {
await chiseInstance.loadSBGNMLText(data.message, false, filename, cy, paramObj);
chiseInstance.endSpinner('paths-byURL-spinner')


chiseInstance.endSpinner('paths-byURL-spinner');
}
});
}
Expand Down
196 changes: 190 additions & 6 deletions app/js/backbone-views.js
Original file line number Diff line number Diff line change
Expand Up @@ -3107,12 +3107,8 @@ var PathsByURIQueryView = Backbone.View.extend({
cy,
"currentGeneralProperties"
);
var currentInferNestingOnLoad =
currentGeneralProperties.inferNestingOnLoad;
var currentLayoutProperties = appUtilities.getScratch(
cy,
"currentLayoutProperties"
);
var currentInferNestingOnLoad = currentGeneralProperties.inferNestingOnLoad;
var currentLayoutProperties = appUtilities.getScratch(cy, "currentLayoutProperties");

chiseInstance.startSpinner("paths-byURI-spinner");
$.ajax({
Expand Down Expand Up @@ -3194,6 +3190,146 @@ var PathsByURIQueryView = Backbone.View.extend({
},
});

/**
* Map By WPID Query view for the Sample Application.
*/
var MapByWPIDQueryView = Backbone.View.extend({
defaultQueryParameters: {
WPID: "",
},
currentQueryParameters: null,
initialize: function () {
var self = this;
self.copyProperties();
self.template = _.template($("#query-mapbyWPID-template").html());
self.template = self.template(self.currentQueryParameters);
},
copyProperties: function () {
this.currentQueryParameters = _.clone(this.defaultQueryParameters);
},
render: function () {
var self = this;
self.template = _.template($("#query-mapbyWPID-template").html());
self.template = self.template(self.currentQueryParameters);
$(self.el).html(self.template);

$(self.el).modal("show");

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

// use the associated cy instance
var cy = chiseInstance.getCy();

self.currentQueryParameters.WPID = document.getElementById(
"query-mapbyWPID-WPID"
).value;
var wpid = self.currentQueryParameters.WPID.trim();

if (wpid.length === 0) {
document.getElementById("query-mapbyWPID-WPID").focus();
return;
}
// wpid is cleaned up from undesired characters such as #,$,! etc. and spaces put before and after the string
wpid = wpid.replace(/[^a-zA-Z0-9:/.\-\n\t ]/g, "").trim();
if (wpid.length === 0) {
$(self.el).modal("toggle");
new PromptInvalidWPIDView({ el: "#prompt-invalidWPID-table" }).render();
return;
}

var queryURL = "https://www.wikipathways.org/wikipathways-assets/pathways/" + wpid + "/" + wpid + ".gpml";

var filename = "";

if (filename == "") {
filename = wpid;
} else {
filename = filename + "_" + wpid;
}
filename = filename + ".nwt";

var sendMapByWPIDQuery = function () {
var currentGeneralProperties = appUtilities.getScratch(cy, "currentGeneralProperties");
var currentInferNestingOnLoad = currentGeneralProperties.inferNestingOnLoad;

chiseInstance.startSpinner("map-byWPID-spinner");
$.ajax({
type: "get",
url: "/utilities/testURL",
data: { url: queryURL },
success: function (data) {
if (!data.error && data.response.statusCode == 200) {
if (data.response.body !== "") {
$(document).trigger("sbgnvizLoadFile", [filename, cy]);
currentGeneralProperties.inferNestingOnLoad = false;
chiseInstance.convertGpmlToSbgnml(data.response.body, async function (data) {
chiseInstance.loadSBGNMLText(data.message, false, filename, cy);
chiseInstance.endSpinner("map-byWPID-spinner");
});
currentGeneralProperties.inferNestingOnLoad = currentInferNestingOnLoad;
$(document).trigger("sbgnvizLoadFileEnd", [filename, cy]);
} else {
new PromptEmptyQueryResultView({
el: "#prompt-emptyQueryResult-table",
}).render();
}
} else if (data.error) {
let { code } = data.error;
if (code === "ESOCKETTIMEDOUT") {
new PromptRequestTimedOutView({
el: "#prompt-requestTimedOut-table",
}).render();
}
chiseInstance.endSpinner("map-byWPID-spinner");
}
else if (!data.error && data.response.statusCode == 500){
new InternalServerError({
el: "#prompt-internal-server-table",
}).render();
chiseInstance.endSpinner("map-byWPID-spinner");
}
else {
new PromptInvalidWPIDView({
el: "#prompt-invalidWPID-table",
}).render();
chiseInstance.endSpinner("map-byWPID-spinner");
}
},
error: function (xhr, options, err) {
new PromptInvalidWPIDView({
el: "#prompt-invalidWPID-table",
}).render();
chiseInstance.endSpinner("map-byWPID-spinner");
},
});

$(self.el).modal("toggle");
}

if (cy.nodes().length != 0) {
new PromptConfirmationView({
el: "#prompt-confirmation-table",
}).render(sendMapByWPIDQuery);
} else {
sendMapByWPIDQuery();
}

});

$(document)
.off("click", "#cancel-query-mapbyWPID")
.on("click", "#cancel-query-mapbyWPID", function (evt) {
$(self.el).modal("toggle");
});

return this;
},
});

/*
There was a side effect of using this modal prompt when clicking on New.
If the user would click on save, then the save box asking for the filename (FileSaveView) would appear
Expand Down Expand Up @@ -4358,6 +4494,29 @@ var PromptInvalidURIView = Backbone.View.extend({
},
});

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

$(self.el).html(self.template);
$(self.el).modal("show");

$(document)
.off("click", "#prompt-invalidWPID-confirm")
.on("click", "#prompt-invalidWPID-confirm", function (evt) {
$(self.el).modal("toggle");
appUtilities.mapByWPIDQueryView.render();
});

return this;
},
});

var PromptInvalidURIWarning = Backbone.View.extend({
initialize: function () {
var self = this;
Expand All @@ -4380,6 +4539,28 @@ var PromptInvalidURIWarning = Backbone.View.extend({
},
});

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

$(self.el).html(self.template);
$(self.el).modal("show");

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

return this;
},
});

var PromptInvalidFileView = Backbone.View.extend({
initialize: function () {
var self = this;
Expand Down Expand Up @@ -7043,6 +7224,7 @@ module.exports = {
PathsFromToQueryView: PathsFromToQueryView,
CommonStreamQueryView: CommonStreamQueryView,
PathsByURIQueryView: PathsByURIQueryView,
MapByWPIDQueryView: MapByWPIDQueryView,
PromptSaveView: PromptSaveView,
FileSaveView: FileSaveView,
SaveUserPreferencesView: SaveUserPreferencesView,
Expand All @@ -7062,7 +7244,9 @@ module.exports = {
AnnotationListView: AnnotationListView,
AnnotationElementView: AnnotationElementView,
PromptInvalidURIView: PromptInvalidURIView,
PromptInvalidWPIDView: PromptInvalidWPIDView,
PromptInvalidURIWarning: PromptInvalidURIWarning,
PromptInvalidWPIDWarning: PromptInvalidWPIDWarning,
PromptInvalidURLWarning: PromptInvalidURLWarning,
PromptInvalidImageWarning: PromptInvalidImageWarning,
PromptInvalidEdgeWarning: PromptInvalidEdgeWarning,
Expand Down
Loading

0 comments on commit bfe3f87

Please sign in to comment.