Skip to content

Commit

Permalink
Switching between mines is working, with some problems #21
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianBZG committed Jul 18, 2018
1 parent faddec2 commit 3573393
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 32 deletions.
15 changes: 8 additions & 7 deletions package.json
Expand Up @@ -16,22 +16,19 @@
"author": "Adrian Rodriguez-Bazaga",
"contributors": [
"Yo Yehudi",
"Rachel Lyne"
"Rachel Lyne"
],
"repository": {
"type": "git",
"url": "https://github.com/AdrianBZG/InterMine-Data-Browser-Tool"
},
"dependencies": {
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"http-errors": "~1.6.2",
"morgan": "~1.9.0",
"pug": "2.0.0-beta11",
"bootstrap": "4.0.0",
"browser-sync": "2.23.6",
"chart.js": "2.7.1",
"cookie-parser": "~1.4.3",
"datatables.net-bs4": "1.10.16",
"debug": "~2.6.9",
"express": "^4.16.3",
"font-awesome": "4.7.0",
"gulp-clean-css": "3.9.2",
Expand All @@ -41,8 +38,12 @@
"gulp-rename": "^1.2.2",
"gulp-sass": "^3.1.0",
"gulp-uglify": "3.0.0",
"http-errors": "~1.6.2",
"jquery": "3.3.1",
"jquery.easing": "^1.4.1"
"jquery.easing": "^1.4.1",
"jsdom": "^11.11.0",
"morgan": "~1.9.0",
"pug": "2.0.0-beta11"
},
"devDependencies": {
"browser-sync": "2.23.6",
Expand Down
2 changes: 1 addition & 1 deletion public/javascripts/common.min.js

Large diffs are not rendered by default.

30 changes: 20 additions & 10 deletions routes/fetch.js
Expand Up @@ -2,13 +2,23 @@ var express = require('express');
var imjs = require('imjs');
var request = require('request');
var router = express.Router();
var jsdom = require("jsdom");
const {
JSDOM
} = jsdom;
const {
document
} = (new JSDOM('<!doctype html><html><body></body></html>')).window;
global.document = document;
global.window = document.defaultView;
var $ = require('jquery');

/**
* GET Pathway Names from HumanMine inside a class (parameter)
*/
router.get('/pathways/:mineUrl/:classname', function(req, res, next) {
var className = req.params.classname;
var mineUrl = req.params.mineUrl.replace(/_/g,":").replace(/-/g,"/");
var mineUrl = req.params.mineUrl.replace(/_/g, ":").replace(/-/g, "/");

if (className != "Protein" && className != "Gene") {
res.status(500).send('You need to specify a valid class: Protein, Gene');
Expand Down Expand Up @@ -43,7 +53,7 @@ router.get('/pathways/:mineUrl/:classname', function(req, res, next) {
*/
router.get('/proteinatlastissuenames/:mineUrl/:classname', function(req, res, next) {
var className = req.params.classname;
var mineUrl = req.params.mineUrl.replace(/_/g,":").replace(/-/g,"/");
var mineUrl = req.params.mineUrl.replace(/_/g, ":").replace(/-/g, "/");

if (className != "Protein" && className != "Gene") {
res.status(500).send('You need to specify a valid class: Protein, Gene');
Expand Down Expand Up @@ -77,7 +87,7 @@ router.get('/proteinatlastissuenames/:mineUrl/:classname', function(req, res, ne
*/
router.get('/proteinatlascelltypes/:mineUrl/:classname', function(req, res, next) {
var className = req.params.classname;
var mineUrl = req.params.mineUrl.replace(/_/g,":").replace(/-/g,"/");
var mineUrl = req.params.mineUrl.replace(/_/g, ":").replace(/-/g, "/");

if (className != "Protein" && className != "Gene") {
res.status(500).send('You need to specify a valid class: Protein, Gene');
Expand Down Expand Up @@ -111,7 +121,7 @@ router.get('/proteinatlascelltypes/:mineUrl/:classname', function(req, res, next
*/
router.get('/clinicalsignificance/:mineUrl/:classname', function(req, res, next) {
var className = req.params.classname;
var mineUrl = req.params.mineUrl.replace(/_/g,":").replace(/-/g,"/");
var mineUrl = req.params.mineUrl.replace(/_/g, ":").replace(/-/g, "/");

if (className != "Protein" && className != "Gene") {
res.status(500).send('You need to specify a valid class: Protein, Gene');
Expand Down Expand Up @@ -146,7 +156,7 @@ router.get('/clinicalsignificance/:mineUrl/:classname', function(req, res, next)
*/
router.get('/allelestype/:mineUrl/:classname', function(req, res, next) {
var className = req.params.classname;
var mineUrl = req.params.mineUrl.replace(/_/g,":").replace(/-/g,"/");
var mineUrl = req.params.mineUrl.replace(/_/g, ":").replace(/-/g, "/");

if (className != "Protein" && className != "Gene") {
res.status(500).send('You need to specify a valid class: Protein, Gene');
Expand Down Expand Up @@ -181,7 +191,7 @@ router.get('/allelestype/:mineUrl/:classname', function(req, res, next) {
*/
router.get('/diseases/:mineUrl/:classname', function(req, res, next) {
var className = req.params.classname;
var mineUrl = req.params.mineUrl.replace(/_/g,":").replace(/-/g,"/");
var mineUrl = req.params.mineUrl.replace(/_/g, ":").replace(/-/g, "/");

if (className != "Protein" && className != "Gene") {
res.status(500).send('You need to specify a valid class: Protein, Gene');
Expand Down Expand Up @@ -216,7 +226,7 @@ router.get('/diseases/:mineUrl/:classname', function(req, res, next) {
*/
router.get('/datasets/:mineUrl/:classname', function(req, res, next) {
var className = req.params.classname;
var mineUrl = req.params.mineUrl.replace(/_/g,":").replace(/-/g,"/");
var mineUrl = req.params.mineUrl.replace(/_/g, ":").replace(/-/g, "/");

if (className != "Protein" && className != "Gene") {
res.status(500).send('You need to specify a valid class: Protein, Gene');
Expand Down Expand Up @@ -250,7 +260,7 @@ router.get('/datasets/:mineUrl/:classname', function(req, res, next) {
*/
router.get('/ontologyterms/:mineUrl/:classname', function(req, res, next) {
var className = req.params.classname;
var mineUrl = req.params.mineUrl.replace(/_/g,":").replace(/-/g,"/");
var mineUrl = req.params.mineUrl.replace(/_/g, ":").replace(/-/g, "/");

if (className != "Protein" && className != "Gene") {
res.status(500).send('You need to specify a valid class: Protein, Gene');
Expand Down Expand Up @@ -306,7 +316,7 @@ router.get('/ontologyterms/:mineUrl/:classname', function(req, res, next) {
* GET Protein Domain Name from HumanMine
*/
router.get('/proteindomainname/:mineUrl', function(req, res, next) {
var mineUrl = req.params.mineUrl.replace(/_/g,":").replace(/-/g,"/");
var mineUrl = req.params.mineUrl.replace(/_/g, ":").replace(/-/g, "/");

var service = new imjs.Service({
root: mineUrl
Expand Down Expand Up @@ -338,7 +348,7 @@ router.get('/proteindomainname/:mineUrl', function(req, res, next) {
* GET Interaction Participant 2 Gene Symbol from HumanMine
*/
router.get('/participant2genesymbols/:mineUrl', function(req, res, next) {
var mineUrl = req.params.mineUrl.replace(/_/g,":").replace(/-/g,"/");
var mineUrl = req.params.mineUrl.replace(/_/g, ":").replace(/-/g, "/");

var service = new imjs.Service({
root: mineUrl
Expand Down
111 changes: 100 additions & 11 deletions src/js/common.js
Expand Up @@ -20,12 +20,12 @@ $(document).ready(function() {
[],
[],
[],
[]
[]
]; // 0 = GO annotation, 1 = Dataset Name, 2 = Pathway Name, 3 = Protein Domain Name, 4 = Disease Name

window.locationFilter = null;
window.interactionsFilter = null;
window.clinVarFilter = null;
window.clinVarFilter = null;
window.expressionFilter = null;
window.proteinLocalisationFilter = null;

Expand Down Expand Up @@ -79,6 +79,21 @@ function getColorsArray(size) {
return rainbow;
};

/**
* Method to get the different intermines names and URLs from the registry
* @returns {array} an array with the server response containing the different intermines with their URLs
*/
function getIntermines() {
return $.ajax({
url: 'http://registry.intermine.org/service/instances?mines=%27prod%27',
type: 'GET',
error: function(e) {
console.log(e);
},
success: function(data) {}
})
}

/**
* Method to get the different ontology terms inside a class in order to feed the typeahead
* @returns {array} an array with the server response containing the different ontology terms
Expand Down Expand Up @@ -321,8 +336,8 @@ function updateTableWithConstraints() {
});
}
}
// Disease Name

// Disease Name
if (window.imTableConstraint[4].length > 0) {
window.imTable.query.addConstraint({
"path": "diseases.name",
Expand Down Expand Up @@ -404,6 +419,80 @@ function showMoreDatasetNames() {
* @param {string} pieChartID: the div id of the pie chart, in order to update it
*/
function updateElements(constraints, pieChartID) {
if ($('#mineSelector option').length == 0) {
$.when(getIntermines()).done(function(result) {
$('#mineSelector').find('option').remove().end().append('<option value="http_--www.humanmine.org-humanmine-service">HumanMine</option>').val('http_--www.humanmine.org-humanmine-service');

for (var i = 0; i < result.instances.length; i++) {
if (result.instances[i].name == "HumanMine") continue;

var mineUrl = result.instances[i].url;
if (mineUrl[mineUrl.length - 1] == "/") {
mineUrl += "service";
} else {
mineUrl += "/service";
}

mineUrl = mineUrl.replace(/:/g, "_").replace(/\//g, "-");

$('#mineSelector').append('<option value="' + mineUrl + '">' + result.instances[i].name + '</option>').val(mineUrl);
}

$("#mineSelector").val($("#mineSelector option:first").val());

// Event handling
$("#mineSelector").change(function() {
window.mineUrl = $(this).val();
var selectedMineName = $("#mineSelector option:selected").text();
document.title = window.currentClassView + " in " + selectedMineName;

// Update the imTable
updateElements(window.imTable.history.currentQuery.constraints, "PieChart");

// Instantiate the im-table with all the data available in Gene from HumanMine
var selector = '#dataTable';
var service = {
root: window.mineUrl.replace(/_/g, ":").replace(/-/g, "/")
};
var query = {
select: ['*'],
from: window.currentClassView
};

imtables.configure({
TableCell: {
PreviewTrigger: 'click'
}
});

imtables.configure('TableResults.CacheFactor', 20);

var imtable = imtables.loadTable(
selector, {
"start": 0,
"size": 25
}, {
service: service,
query: query
}
).then(
function(table) {
console.log('Table loaded', table);
//this .on listener will do something when someone interacts with the table.
table.on("all", function(changeDetail) {
updateElements(table.history.currentQuery.constraints, "PieChart");
});

window.imTable = table;
},
function(error) {
console.error('Could not load table', error);
}
);
});
});
}

$.when(getOntologyTermsInClass()).done(function(result) {

var availableGoTerms = [];
Expand Down Expand Up @@ -555,8 +644,8 @@ function updateElements(constraints, pieChartID) {
});

});
$.when(getDiseasesNamesInClass()).done(function(result) {

$.when(getDiseasesNamesInClass()).done(function(result) {

var availableDiseasesNames = [];

Expand Down Expand Up @@ -601,8 +690,8 @@ function updateElements(constraints, pieChartID) {
});

});
$.when(getAllelesClinicalSignifanceInClass()).done(function(result) {

/*$.when(getAllelesClinicalSignifanceInClass()).done(function(result) {
var availableData = [];
Expand Down Expand Up @@ -632,8 +721,8 @@ function updateElements(constraints, pieChartID) {
});
});
$.when(getAllelesTypesInClass()).done(function(result) {
$.when(getAllelesTypesInClass()).done(function(result) {
var availableData = [];
Expand Down Expand Up @@ -724,7 +813,7 @@ function updateElements(constraints, pieChartID) {
}
});
});
});*/

$.when(getProteinDomainNamesInClass()).done(function(result) {

Expand Down
1 change: 0 additions & 1 deletion test/fetch.js
Expand Up @@ -153,5 +153,4 @@ describe('Fetch', () => {
});
});
});

});
3 changes: 1 addition & 2 deletions views/includes/navbar.pug
Expand Up @@ -7,8 +7,7 @@ nav#mainNav.navbar.navbar-expand-lg.navbar-light.bg-light.fixed-top
button.btn.btn-primary.btn-space(id="genesButton" type="button") Genes
a(href="/proteins" data-toggle="tooltip" title="Change to Proteins view")
button.btn.btn-default.btn-space(id="proteinsButton" type="button") Proteins
select.form-control(style="width: 150px; position: fixed; top: 10px; right: 75px;")
option(value="HumanMine") HumanMine
select#mineSelector.form-control(style="width: 150px; position: fixed; top: 10px; right: 75px;")

#navbarResponsive.navbar-collapse
ul#exampleAccordion.navbar-nav.navbar-sidenav.list-group.panel(style="overflow: auto;")
Expand Down

0 comments on commit 3573393

Please sign in to comment.