Commit c6437bb1 authored by David Hoksza's avatar David Hoksza
Browse files

initial commit

parents
Pipeline #7580 passed with stages
in 1 minute and 16 seconds
image: node
before_script:
stages:
- build
- deploy
build:
stage: build
script:
- npm install
- npm run build
deploy:
stage: deploy
only:
- master
script:
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- npm install
- npm run build
- echo "mkdir plugins-www/drug-reactions" | sftp -P 8022 gitlab-ci@10.240.6.160
- echo "put dist/plugin.js plugins-www/drug-reactions/" | sftp -P 8022 gitlab-ci@10.240.6.160
# Drug reactions
`Drug reactions` is a plugin which allows one to explore adverse reactions of drugs which
are interacting with entities present in given disease map.
### General instructions
In order to use the precompiled and publicly available version of the plugin,
open the plugin menu in the MINERVA's upper left corner (see image below) and click plugins.
In the dialog which appears enter the following address in the URL box:
`https://minerva-dev.lcsb.uni.lu/plugins/drug-reactions/plugin.js` .
The plugin shows up in the plugins panel on the right hand side of the screen.
### Plugin functionality
- On plugin load, the plugin connects to a data source with drug-reactions information.
- Next, MINERVA's [drug search API](https://minerva.pages.uni.lu/doc/api/12.1/projects/#drugs)
is used to retrieve the information about species in map interacting with any of the
drugs in the previously loaded data source.
- The data is loaded into a table in the plugin space and the species which interact
with the uploaded drugs are highlighted by icons in the map.
- The table is searchable and automatically synchronized with highlights in the map, so where the content of
the table is updated the highlighted entities in the map update as well.
### Data resources
The original source of dat an the plugin are [drug labels](https://osf.io/9hsxq/)
(prescribing information or package inserts) manually
annotated for adverse drug reactions and mapped to MedDRA for the FDA TAC 2017 evaluation.
However, in order to decrease the required bandwidth, the plugin uses a [modified version]()
of this file where only the relevant columns are kept.
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
{
"name": "adr",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build-css": "node-sass --include-path src/css src/css/styles.scss src/css/styles.css",
"build": "mkdirp dist && npm run build-css && browserify -t [ babelify --presets es2015 ] -t browserify-css src/js/index.js | uglifyjs --compress --mangle > dist/plugin.js ",
"build-debug": "mkdirp dist && npm run build-css && browserify -t [ babelify --presets es2015 ] -t browserify-css src/js/index.js> dist/plugin.js ",
"watch-js": "mkdirp dist && npm run build-css && watchify -v -t [ babelify --presets es2015 ] -t browserify-css src/js/index.js -o dist/plugin.js",
"clean": "rimraf dist"
},
"author": "David Hoksza",
"license": "MIT",
"devDependencies": {
"babel-core": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babelify": "^8.0.0",
"browserify": "^14.5.0",
"browserify-css": "^0.13.1",
"mkdirp": "^0.5.1",
"node-sass": "^4.6.1",
"rimraf": "latest",
"uglify-js": "^3.1.9",
"watchify": "^3.9.0"
},
"dependencies": {
"bootstrap-table": "^1.12.1"
}
}
.select2-container{box-sizing:border-box;display:inline-block;margin:0;position:relative;vertical-align:middle}.select2-container .select2-selection--single{box-sizing:border-box;cursor:pointer;display:block;height:28px;user-select:none;-webkit-user-select:none}.select2-container .select2-selection--single .select2-selection__rendered{display:block;padding-left:8px;padding-right:20px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.select2-container .select2-selection--single .select2-selection__clear{position:relative}.select2-container[dir="rtl"] .select2-selection--single .select2-selection__rendered{padding-right:8px;padding-left:20px}.select2-container .select2-selection--multiple{box-sizing:border-box;cursor:pointer;display:block;min-height:32px;user-select:none;-webkit-user-select:none}.select2-container .select2-selection--multiple .select2-selection__rendered{display:inline-block;overflow:hidden;padding-left:8px;text-overflow:ellipsis;white-space:nowrap}.select2-container .select2-search--inline{float:left}.select2-container .select2-search--inline .select2-search__field{box-sizing:border-box;border:none;font-size:100%;margin-top:5px;padding:0}.select2-container .select2-search--inline .select2-search__field::-webkit-search-cancel-button{-webkit-appearance:none}.select2-dropdown{background-color:white;border:1px solid #aaa;border-radius:4px;box-sizing:border-box;display:block;position:absolute;left:-100000px;width:100%;z-index:1051}.select2-results{display:block}.select2-results__options{list-style:none;margin:0;padding:0}.select2-results__option{padding:6px;user-select:none;-webkit-user-select:none}.select2-results__option[aria-selected]{cursor:pointer}.select2-container--open .select2-dropdown{left:0}.select2-container--open .select2-dropdown--above{border-bottom:none;border-bottom-left-radius:0;border-bottom-right-radius:0}.select2-container--open .select2-dropdown--below{border-top:none;border-top-left-radius:0;border-top-right-radius:0}.select2-search--dropdown{display:block;padding:4px}.select2-search--dropdown .select2-search__field{padding:4px;width:100%;box-sizing:border-box}.select2-search--dropdown .select2-search__field::-webkit-search-cancel-button{-webkit-appearance:none}.select2-search--dropdown.select2-search--hide{display:none}.select2-close-mask{border:0;margin:0;padding:0;display:block;position:fixed;left:0;top:0;min-height:100%;min-width:100%;height:auto;width:auto;opacity:0;z-index:99;background-color:#fff;filter:alpha(opacity=0)}.select2-hidden-accessible{border:0 !important;clip:rect(0 0 0 0) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important}.select2-container--default .select2-selection--single{background-color:#fff;border:1px solid #aaa;border-radius:4px}.select2-container--default .select2-selection--single .select2-selection__rendered{color:#444;line-height:28px}.select2-container--default .select2-selection--single .select2-selection__clear{cursor:pointer;float:right;font-weight:bold}.select2-container--default .select2-selection--single .select2-selection__placeholder{color:#999}.select2-container--default .select2-selection--single .select2-selection__arrow{height:26px;position:absolute;top:1px;right:1px;width:20px}.select2-container--default .select2-selection--single .select2-selection__arrow b{border-color:#888 transparent transparent transparent;border-style:solid;border-width:5px 4px 0 4px;height:0;left:50%;margin-left:-4px;margin-top:-2px;position:absolute;top:50%;width:0}.select2-container--default[dir="rtl"] .select2-selection--single .select2-selection__clear{float:left}.select2-container--default[dir="rtl"] .select2-selection--single .select2-selection__arrow{left:1px;right:auto}.select2-container--default.select2-container--disabled .select2-selection--single{background-color:#eee;cursor:default}.select2-container--default.select2-container--disabled .select2-selection--single .select2-selection__clear{display:none}.select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b{border-color:transparent transparent #888 transparent;border-width:0 4px 5px 4px}.select2-container--default .select2-selection--multiple{background-color:white;border:1px solid #aaa;border-radius:4px;cursor:text}.select2-container--default .select2-selection--multiple .select2-selection__rendered{box-sizing:border-box;list-style:none;margin:0;padding:0 5px;width:100%}.select2-container--default .select2-selection--multiple .select2-selection__placeholder{color:#999;margin-top:5px;float:left}.select2-container--default .select2-selection--multiple .select2-selection__clear{cursor:pointer;float:right;font-weight:bold;margin-top:5px;margin-right:10px}.select2-container--default .select2-selection--multiple .select2-selection__choice{background-color:#e4e4e4;border:1px solid #aaa;border-radius:4px;cursor:default;float:left;margin-right:5px;margin-top:5px;padding:0 5px}.select2-container--default .select2-selection--multiple .select2-selection__choice__remove{color:#999;cursor:pointer;display:inline-block;font-weight:bold;margin-right:2px}.select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover{color:#333}.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice,.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__placeholder,.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-search--inline{float:right}.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice{margin-left:5px;margin-right:auto}.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice__remove{margin-left:2px;margin-right:auto}.select2-container--default.select2-container--focus .select2-selection--multiple{border:solid black 1px;outline:0}.select2-container--default.select2-container--disabled .select2-selection--multiple{background-color:#eee;cursor:default}.select2-container--default.select2-container--disabled .select2-selection__choice__remove{display:none}.select2-container--default.select2-container--open.select2-container--above .select2-selection--single,.select2-container--default.select2-container--open.select2-container--above .select2-selection--multiple{border-top-left-radius:0;border-top-right-radius:0}.select2-container--default.select2-container--open.select2-container--below .select2-selection--single,.select2-container--default.select2-container--open.select2-container--below .select2-selection--multiple{border-bottom-left-radius:0;border-bottom-right-radius:0}.select2-container--default .select2-search--dropdown .select2-search__field{border:1px solid #aaa}.select2-container--default .select2-search--inline .select2-search__field{background:transparent;border:none;outline:0;box-shadow:none;-webkit-appearance:textfield}.select2-container--default .select2-results>.select2-results__options{max-height:200px;overflow-y:auto}.select2-container--default .select2-results__option[role=group]{padding:0}.select2-container--default .select2-results__option[aria-disabled=true]{color:#999}.select2-container--default .select2-results__option[aria-selected=true]{background-color:#ddd}.select2-container--default .select2-results__option .select2-results__option{padding-left:1em}.select2-container--default .select2-results__option .select2-results__option .select2-results__group{padding-left:0}.select2-container--default .select2-results__option .select2-results__option .select2-results__option{margin-left:-1em;padding-left:2em}.select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option{margin-left:-2em;padding-left:3em}.select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option{margin-left:-3em;padding-left:4em}.select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option{margin-left:-4em;padding-left:5em}.select2-container--default .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option .select2-results__option{margin-left:-5em;padding-left:6em}.select2-container--default .select2-results__option--highlighted[aria-selected]{background-color:#5897fb;color:white}.select2-container--default .select2-results__group{cursor:default;display:block;padding:6px}.select2-container--classic .select2-selection--single{background-color:#f7f7f7;border:1px solid #aaa;border-radius:4px;outline:0;background-image:-webkit-linear-gradient(top, #fff 50%, #eee 100%);background-image:-o-linear-gradient(top, #fff 50%, #eee 100%);background-image:linear-gradient(to bottom, #fff 50%, #eee 100%);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFFFFFFF', endColorstr='#FFEEEEEE', GradientType=0)}.select2-container--classic .select2-selection--single:focus{border:1px solid #5897fb}.select2-container--classic .select2-selection--single .select2-selection__rendered{color:#444;line-height:28px}.select2-container--classic .select2-selection--single .select2-selection__clear{cursor:pointer;float:right;font-weight:bold;margin-right:10px}.select2-container--classic .select2-selection--single .select2-selection__placeholder{color:#999}.select2-container--classic .select2-selection--single .select2-selection__arrow{background-color:#ddd;border:none;border-left:1px solid #aaa;border-top-right-radius:4px;border-bottom-right-radius:4px;height:26px;position:absolute;top:1px;right:1px;width:20px;background-image:-webkit-linear-gradient(top, #eee 50%, #ccc 100%);background-image:-o-linear-gradient(top, #eee 50%, #ccc 100%);background-image:linear-gradient(to bottom, #eee 50%, #ccc 100%);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFEEEEEE', endColorstr='#FFCCCCCC', GradientType=0)}.select2-container--classic .select2-selection--single .select2-selection__arrow b{border-color:#888 transparent transparent transparent;border-style:solid;border-width:5px 4px 0 4px;height:0;left:50%;margin-left:-4px;margin-top:-2px;position:absolute;top:50%;width:0}.select2-container--classic[dir="rtl"] .select2-selection--single .select2-selection__clear{float:left}.select2-container--classic[dir="rtl"] .select2-selection--single .select2-selection__arrow{border:none;border-right:1px solid #aaa;border-radius:0;border-top-left-radius:4px;border-bottom-left-radius:4px;left:1px;right:auto}.select2-container--classic.select2-container--open .select2-selection--single{border:1px solid #5897fb}.select2-container--classic.select2-container--open .select2-selection--single .select2-selection__arrow{background:transparent;border:none}.select2-container--classic.select2-container--open .select2-selection--single .select2-selection__arrow b{border-color:transparent transparent #888 transparent;border-width:0 4px 5px 4px}.select2-container--classic.select2-container--open.select2-container--above .select2-selection--single{border-top:none;border-top-left-radius:0;border-top-right-radius:0;background-image:-webkit-linear-gradient(top, #fff 0%, #eee 50%);background-image:-o-linear-gradient(top, #fff 0%, #eee 50%);background-image:linear-gradient(to bottom, #fff 0%, #eee 50%);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFFFFFFF', endColorstr='#FFEEEEEE', GradientType=0)}.select2-container--classic.select2-container--open.select2-container--below .select2-selection--single{border-bottom:none;border-bottom-left-radius:0;border-bottom-right-radius:0;background-image:-webkit-linear-gradient(top, #eee 50%, #fff 100%);background-image:-o-linear-gradient(top, #eee 50%, #fff 100%);background-image:linear-gradient(to bottom, #eee 50%, #fff 100%);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#FFEEEEEE', endColorstr='#FFFFFFFF', GradientType=0)}.select2-container--classic .select2-selection--multiple{background-color:white;border:1px solid #aaa;border-radius:4px;cursor:text;outline:0}.select2-container--classic .select2-selection--multiple:focus{border:1px solid #5897fb}.select2-container--classic .select2-selection--multiple .select2-selection__rendered{list-style:none;margin:0;padding:0 5px}.select2-container--classic .select2-selection--multiple .select2-selection__clear{display:none}.select2-container--classic .select2-selection--multiple .select2-selection__choice{background-color:#e4e4e4;border:1px solid #aaa;border-radius:4px;cursor:default;float:left;margin-right:5px;margin-top:5px;padding:0 5px}.select2-container--classic .select2-selection--multiple .select2-selection__choice__remove{color:#888;cursor:pointer;display:inline-block;font-weight:bold;margin-right:2px}.select2-container--classic .select2-selection--multiple .select2-selection__choice__remove:hover{color:#555}.select2-container--classic[dir="rtl"] .select2-selection--multiple .select2-selection__choice{float:right}.select2-container--classic[dir="rtl"] .select2-selection--multiple .select2-selection__choice{margin-left:5px;margin-right:auto}.select2-container--classic[dir="rtl"] .select2-selection--multiple .select2-selection__choice__remove{margin-left:2px;margin-right:auto}.select2-container--classic.select2-container--open .select2-selection--multiple{border:1px solid #5897fb}.select2-container--classic.select2-container--open.select2-container--above .select2-selection--multiple{border-top:none;border-top-left-radius:0;border-top-right-radius:0}.select2-container--classic.select2-container--open.select2-container--below .select2-selection--multiple{border-bottom:none;border-bottom-left-radius:0;border-bottom-right-radius:0}.select2-container--classic .select2-search--dropdown .select2-search__field{border:1px solid #aaa;outline:0}.select2-container--classic .select2-search--inline .select2-search__field{outline:0;box-shadow:none}.select2-container--classic .select2-dropdown{background-color:#fff;border:1px solid transparent}.select2-container--classic .select2-dropdown--above{border-bottom:none}.select2-container--classic .select2-dropdown--below{border-top:none}.select2-container--classic .select2-results>.select2-results__options{max-height:200px;overflow-y:auto}.select2-container--classic .select2-results__option[role=group]{padding:0}.select2-container--classic .select2-results__option[aria-disabled=true]{color:grey}.select2-container--classic .select2-results__option--highlighted[aria-selected]{background-color:#3875d7;color:#fff}.select2-container--classic .select2-results__group{cursor:default;display:block;padding:6px}.select2-container--classic.select2-container--open .select2-dropdown{border-color:#5897fb}
@import url(../../node_modules/bootstrap-table/dist/bootstrap-table.min.css);
.adr-container {
padding: 15px; }
.adr-container .fixed-table-body {
overflow: auto; }
.adr-container .drugs-loading {
text-align: center; }
.adr-container .drugs-loading .fa-spin {
margin-right: 10px; }
@import "../../node_modules/bootstrap-table/dist/bootstrap-table.min.css";
//@import "../../node_modules/select2-browserify/select2/select2.css";
$pluginName: adr;
.#{$pluginName}-container {
padding: 15px;
}
.#{$pluginName}-container .fixed-table-body {
overflow: auto;
}
.#{$pluginName}-container .drugs-loading {
text-align: center;
}
.#{$pluginName}-container .drugs-loading .fa-spin{
margin-right: 10px;
}
require('../css/styles.css');
require('bootstrap-table');
//var select2 = require('select2-browserify/');
//require('bootstrap-table/dist/extensions/select2-filter/bootstrap-table-select2-filter.min');
const pluginName = 'adr';
const pluginLabel = 'Drug reactions';
const pluginVersion = '1.0.0';
const settings = {
drugColumnName: 'Drug',
typeColumnName: 'Type',
reactionColumnName: 'Reaction',
dataSource: 'http://siret.ms.mff.cuni.cz/hoksza/temp/FinalReferenceStandard200LabelsTrimmed.csv '
};
const globals = {
adrData: {},
adrDataMap: {},
drugs2BioEntities: {},
bioentities2Drugs: {},
idModelId2BioEntity: {}
};
// ******************************************************************************
// ********************* PLUGIN REGISTRATION WITH MINERVA *********************
// ******************************************************************************
let $container;
let $adrTable;
let minervaProxy;
let pluginContainer;
let pluginContainerId;
let selectedInMap = undefined;
const register = function(_minerva) {
// console.log('registering ' + pluginName + ' plugin');
$(".tab-content").css('position', 'relative');
minervaProxy = _minerva;
pluginContainer = $(minervaProxy.element);
pluginContainerId = pluginContainer.attr('id');
// console.log('minerva object ', minervaProxy);
// console.log('project id: ', minervaProxy.project.data.getProjectId());
// console.log('model id: ', minervaProxy.project.data.getModels()[0].modelId);
initPlugin();
};
const unregister = function () {
// console.log('unregistering ' + pluginName + ' plugin');
unregisterListeners();
return deHighlightAll();
};
const getName = function() {
return pluginLabel;
};
const getVersion = function() {
return pluginVersion;
};
/**
* Function provided by Minerva to register the plugin
*/
minervaDefine(function (){
return {
register: register,
unregister: unregister,
getName: getName,
getVersion: getVersion
,minWidth: 300
,defaultWidth: 600
}
});
function initPlugin () {
registerListeners();
const $container = initMainContainer();
initDrugBioEntities().then(function(){
$container.find('.drugs-loading').hide();
initMainPageStructure($container);
initAdrTable($container);
});
}
function registerListeners(){
minervaProxy.project.map.addListener({
dbOverlayName: "search",
type: "onSearch",
callback: searchListener
});
}
function unregisterListeners() {
minervaProxy.project.map.removeAllListeners();
}
// ****************************************************************************
// ********************* MINERVA INTERACTION*********************
// ****************************************************************************
function deHighlightAll(){
return minervaProxy.project.map.getHighlightedBioEntities().then( highlighted => minervaProxy.project.map.hideBioEntity(highlighted) );
}
// ****************************************************************************
// ********************* PLUGIN STRUCTURE AND INTERACTION*********************
// ****************************************************************************
function getContainerClass() {
return pluginName + '-container';
}
function initMainContainer(){
$container = $(`<div class="${getContainerClass()}"></div>`).appendTo(pluginContainer);
$container.append(`
<div class="panel panel-default drugs-loading">
<div class="panel-body">
<i class="fa fa-circle-o-notch fa-spin"></i> Obtaining drug-bioentities mapping. This might take several minutes
if this is the first time the plugin is loaded for this map ...
</div>
</div>`);
return $container;
}
function initMainPageStructure(container){
container.append(`
<table class="adr-table"></table>
<div class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">Error</h4>
</div>
<div class="modal-body">
<p class="text-warning">Issue.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
`);
// container.find('.btn-search').on('click', () => search() );
// container.find('.input-disease').keypress(e => {if (e.which == 13) {search(); return false}} );
}
function initAdrTable($container) {
$adrTable = $container.find('.adr-table');
$adrTable.bootstrapTable({
columns: [{
field: 'State',
sortable: true
},{
field: 'Drug',
title: 'Drug',
sortable: true,
searchable: true
// filter: {
// type: "input"
// }
},{
field: 'Type',
title: 'Type',
sortable: true,
searchable: true
// filter: {
// type: "select",
// data: ["", "ADVERSE REACTIONS"]
// }
},{
field: 'Reaction',
title: 'Reaction',
searchable: true
// filter: {
// type: "select",
// data: []
// }
},{
field: 'Entity',
title: 'Entity',
searchable: true
// filter: {
// type: "select",
// data: []
// }
}, {
field: 'EntityId',
title: 'EntityId',
searchable: false
}],
// filter: true,
// filterTemplate: {
// input: function(bootstrapTable, column, isVisible) {
// return '<input type="text" class="form-control input-sm" data-filter-field="' + column.field + '" style="width: 100%; visibility:' + isVisible + '">';
// }
// },
search:true,
data: globals.adrDataMap.map(d => Object.assign({}, {State:1}, d)),
sortName: 'Drug',
sortOrder: 'asc',
rowStyle: function (row, index){
return row['State'] === 0 ? {classes: 'danger'} : {};
},
onSearch: function (text){
highlightInMap($adrTable);
//highlightSelectedInTable();
},
onPostBody: function (data) {
// $container.find('table td:first-child, table th:first-child').css('display', 'none');
$container.find('table td:last-child, table th:last-child').css('display', 'none');
//highlightSelectedInTable();
}
});
highlightInMap($adrTable);
// setTableHeight(adrTable);
// activateSearchBtton(false);
// registerTableEvents();
}
function highlightInMap($adrTable){
const data = $adrTable.bootstrapTable('getData');
const drugNames = uniquify(data.map(d => d[settings.drugColumnName]));
let bioEntities = drugNames
.map(dn => globals.drugs2BioEntities[dn])
.reduce((acc, val) => acc.concat(val), []);
bioEntities = uniquifyBioentities(bioEntities);
return deHighlightAll().then(function () {
let highlightDefs = bioEntities.map(e => {
return {
element: {
id: e.id,
modelId: e.modelId,
type: e.type
},
type: "ICON"
};
});
return minervaProxy.project.map.showBioEntity(highlightDefs);
});
}
// function recreateBootstrapTable(){
// pluginContainer.find('.bootstrap-table').remove();
// $('<table class="variation-table"></table>').appendTo(pluginContainer.find(`.${getContainerClass()}`));
//
// }
function parseAdrCsv(csv) {
const names = [];
const data = [];
const drugTypeIx = {};
csv.split(/\r?\n/).forEach((line, i) => {
if (line.trim() == '') return;
let row = {};
line.split(";").forEach((col, j) => {
i === 0 ? names.push(col): row[names[j]] = col;
});
if (i > 0) {
let drugType = row[settings.drugColumnName] + row[settings.typeColumnName];
if (drugType in drugTypeIx) {
data[drugTypeIx[drugType]][settings.reactionColumnName] += `, ${row[settings.reactionColumnName]}`;
} else {
drugTypeIx[drugType] = data.length;
data.push(row);
}
}
});
return data;
}
function uniquify(arr) {
return arr.filter((x, i, a) => a.indexOf(x) === i);
}
function uniquifyBioentities(arr) {
const encountered = new Set();
const res = [];
arr.forEach(d => {
let ds = `${d.id}___${d.modelId}___${d.type}`;
if (!encountered.has(ds)) {
encountered.add(ds);
res.push(d);
}
});
return res;
}
function getDrugs(data) {
return uniquify(data.map(d => d[settings.drugColumnName]));
}
function queryMinervaApi(query, parameters, queryType) {
const apiAddress = ServerConnector.getApiBaseUrl();
if (!queryType) queryType = 'GET';
if (!parameters) parameters = '';
return $.ajax({
type: queryType,
url: `${apiAddress}${query}`,
// dataType: 'json',
data: parameters
})
}
function processDSR(drugName, dsr){
let res = [];
if (dsr == undefined) {
console.warn(`Issue with retrieving data for ${drugName}`);
} else {
dsr.forEach(d => {
d.targets.forEach(t => {
res = res.concat(t.targetElements);
});
});
}
return res;
}
function idIdModelId(id, modelId) {
return `${id}____${modelId}`;
}
function getBioEntities(){
let bioEntities = uniquifyBioentities(Object.values(globals.drugs2BioEntities).reduce((acc, val) => acc.concat(val), []));
return minervaProxy.project.data.getBioEntityById(bioEntities).then(function (data) {
data.forEach(e => {
let idModelId = idIdModelId(e.getId(), e.getModelId());
globals.idModelId2BioEntity[idModelId] = e;
})
});
}
function initDrugBioEntities(){
let drugNames;
return $.ajax(settings.dataSource).then(function (csv) {
globals.adrData= parseAdrCsv(csv);
drugNames = getDrugs(globals.adrData);
const promisses = drugNames.map(d =>
queryMinervaApi(`projects/${minervaProxy.project.data.getProjectId()}/drugs:search?query=${d}`)
.catch(error => { return undefined; })
);
return Promise.all(promisses);
}).then(function (drugSearchResults) {
drugNames.forEach((dn, i) => {
const dsrProcessed = processDSR(dn, drugSearchResults[i]);
if (dsrProcessed.length > 0) {
globals.drugs2BioEntities[dn] = dsrProcessed;
dsrProcessed.forEach(bioEntity => {
let combinedId = idIdModelId(bioEntity.id, bioEntity.modelId);
if (!(combinedId in globals.bioentities2Drugs)) globals.bioentities2Drugs[combinedId] = [];
globals.bioentities2Drugs[combinedId].push(dn);
});
}
});
globals.adrDataMap = globals.adrData.filter(d => d[settings.drugColumnName] in globals.drugs2BioEntities);
console.log(' globals', globals);
}).then(function () {
return getBioEntities();
}).then(function () {
globals.adrDataMap.forEach(d => {
d['EntityId'] = globals.drugs2BioEntities[d[settings.drugColumnName]].map(e => idIdModelId(e.id, e.modelId));
d['Entity'] = uniquify(globals.drugs2BioEntities[d[settings.drugColumnName]]
.map(e => globals.idModelId2BioEntity[idIdModelId(e.id, e.modelId)])
.map(be => be.getName()))
.reduce((acc, val) => `${acc}, ${val}` , '').replace(/^,/, '');
});
});
}
function highlightSelectedInTable(){
// $container.find(`td`).parent().removeClass('danger');
$adrTable.find('tbody tr').each(function () {
let rowId = $(this).data('index');
$adrTable.bootstrapTable('updateCell', {index: rowId, field: 'State', value: 1, reinit: false});
});
$adrTable.bootstrapTable('updateCell', {index: 0, field: 'State', value: 1}); //to trigger reinitialization
if (selectedInMap){
let idModelId = idIdModelId(selectedInMap.getId(), selectedInMap.getModelId());
let $tr = $adrTable.find(`td:contains("${idModelId}")`).parent();
// $tr.addClass('danger');
$tr.each(function () {
let rowId = $(this).data('index');
$adrTable.bootstrapTable('updateCell', {index: rowId, field: 'State', value: 0});
});
if ($tr.length > 0){
$adrTable.find('th[data-field="Drug"] .sortable').click();
$adrTable.find('th[data-field="State"] .sortable').click();
}
}
}