Gitlab is now using https://gitlab.lcsb.uni.lu as it's primary address. Please update your bookmarks. FAQ.

Commit defcbc9b authored by Marek Ostaszewski's avatar Marek Ostaszewski
Browse files

Merge branch 'display_update' into 'master'

Small display/export updates

See merge request !15
parents 5c152aab 3ace73b8
Pipeline #43144 passed with stages
in 8 minutes and 48 seconds
require('../css/styles.css');
const pluginName = 'GSEA';
const pluginVersion = '0.9.1';
const pluginVersion = '0.9.2';
const containerName = pluginName + '-container';
const globals = {
......@@ -296,8 +296,6 @@ function calculateGSEA() {
const pw = globals.ModelPathway[modelId][pwName];
const mpHgncNames = pw.hgncNames;
// console.log('mpHgncNames', mpHgncNames);
//calculate intersect
const isect = [...ovHgncNames].filter(name => mpHgncNames.has(name));
......@@ -376,7 +374,6 @@ function calculateGSEA() {
`).appendTo(pluginContainer.find('.gsea-results'));
const $table = $mapResultsPanel.find('table');
const exportVals = [];
pVals.sort(function (a, b) {
......@@ -384,8 +381,9 @@ function calculateGSEA() {
}).forEach(p => {
const pValText = p.adjustedPVal < 0.0001 ? "< 0.0001" : `${p.adjustedPVal.toFixed(4)}`;
if (p.pw.bioEntities.length === 0) {
const $title = $mapResultsPanel.find(".panel-title");
$mapResultsPanel.find(".panel-title").text(`${$title.text()} (enriched with adj. p-val ${pValText})`);
// For entire diagrams (empty pathway names) add them to the results table
$table.append(`<tr><td class="first-column">${pValText}</td><td>Entire diagram</td></tr>`);
exportVals.push({enrichedArea: "Entire diagram", adjustedPVal: p.adjustedPVal});
return;
}
const pwName = p.pw.bioEntities[0].getName();
......@@ -409,106 +407,15 @@ function calculateGSEA() {
});
});
dataForExport.data.push({mapName: mapName, areas: exportVals})
});
addExport(pluginContainer.find('.gsea-results'), dataForExport);
minervaProxy.project.map.showBioEntity(highlightPathways);
});
// //Names of all considered aliases
// const allNames = new Set(globals.quickAliases.map(ref => ref.getReferences().filter(tref => (tref.getType() == "HGNC_SYMBOL")).map(ann => ann.getResource())));
//
// deHighlightAll().then(function (){
// return minervaProxy.project.map.getVisibleDataOverlays()
// }).then(function (overlays) {
// let gsea_html = '<table><tr><th style="width:80px;">p val (adj)</th><th>Enriched area</th></tr>';
//
// let ovnames = new Set();
//
// overlays.forEach(e => {
// //const these_ovnames = new Set(e.getAliases().map(ref => ref.getReferences().filter(tref => (tref.getType() == "HGNC_SYMBOL")).map(ann => ann.getResource())));
// // e is a LayoutAlias, needs to be mapped back to map aliases, to retrieve HGNC; defined as set, .has() function looks better in filtering
// const these_ovaliases = new Set([...e.getAliases().map(g => g.getId())]);
// // grab aliases matching the overlay -> get their references -> filter by HGNC_SYMBOL -> get value
// const these_ovnames = new Set(globals.quickAliases.filter(h => these_ovaliases.has(h.getId())).flatMap(ref =>
// ref.getReferences().filter(tref => (tref.getType() == "HGNC_SYMBOL")).map(ann => ann.getResource())));
//
// ovnames = new Set([...ovnames, ...these_ovnames]);
// });
//
// const overlay_pvals = [];
//
// globals.groupedPathways.forEach(g => {
// // split into two steps for better clarity
// // 1. get element aliases for a given key (pathway group), because it's a set, we use [...] notation to cast onto array
// const these_pgaliases = [...g.elementAliases];
// // 2. get element names for the alias array; define as set for unique values
// const these_pgnames = new Set(these_pgaliases.flatMap(ref =>
// ref.getReferences().filter(tref => (tref.getType() === "HGNC_SYMBOL")).map(ann => ann.getResource())));
// //calculate intersect
// const isect = [...ovnames].filter(value => these_pgnames.has(value));
//
// var m = these_pgnames.size;
// var k = isect.length;
// var N = allNames.size;
// var n = ovnames.size;
//
// if (k > 0) {
// //var px = (kcomb(m,k)*kcomb(N-m,n-k))/kcomb(N,n);
// //Approximation using upper boud from Eq (2) in http://page.mi.fu-berlin.de/shagnik/notes/binomials.pdf
// //Simplified, props to Ewa Smula (ewa.smula@uni.lu)
// var this_pval = Math.pow(((m * (n - k)) / (k * (N - m))), k) * Math.pow(((n * (N - m)) / (N * (n - k))), n);
// overlay_pvals.push({ pval: this_pval, pname: g.name })
// }
// });
//
// const highlightPathways = [];
//
// overlay_pvals.sort(function (a, b) {
// return a.pval - b.pval;
// }).forEach(p => {
// const adj_pval = Math.min(p.pval * globals.groupedPathways.length, 1).toFixed(4);
// if (adj_pval < 0.1) {
// if (adj_pval == 0) {
// gsea_html += `<tr><td>< 0.0001</td><td>${p.pname}</td></tr>`;
// } else {
// gsea_html += `<tr><td style="padding-left: 10px;">${adj_pval}</td><td>${p.pname}</td></tr>`;
// }
//
// const hit = globals.groupedPathways.findIndex(fi => fi.name === p.pname);
//
// if (Array.isArray(globals.groupedPathways[hit].aliases)) { //check if this is not a submap
// globals.groupedPathways[hit].aliases.forEach(al => {
// highlightPathways.push({
// element: {
// id: al.getId(),
// modelId: al.getModelId(),
// type: al.constructor.name.toUpperCase()
// },
// type: "SURFACE",
// options: {
// color: '#00FF00',
// opacity: 0.1
// }
// });
// });
// }
// }
// });
// minervaProxy.project.map.showBioEntity(highlightPathways);
//
// gsea_html += '</table>';
// pluginContainer.find('.panel-events .panel-body').html(gsea_html);
// });
}
function addExport($container, data){
$container.append($(`<div class="row">
<div class="col-sm-12">
<button type="button" class="btn-calc btn btn-success btn-default btn-block">Export</button>
......@@ -516,7 +423,6 @@ function addExport($container, data){
</div>`));
$container.find("button").on("click", () => exportData(data, $container));
}
const exportData = function (data, $container) {
......@@ -531,6 +437,7 @@ const exportData = function (data, $container) {
};
const exportToFormat = function (format, data, $container) {
let exportString;
if (format === "json") exportString = exportToJson(data);
if (format === "tsv") exportString = exportToTsv(data);
......@@ -557,6 +464,7 @@ const exportToFormat = function (format, data, $container) {
};
function closeModal() {
pluginContainer.find(".modal-container").modal("hide");
}
......@@ -590,7 +498,7 @@ function exportToTsv(data) {
for (let i = 0; i < data.data.length; ++i) {
res += `${data.data[i].mapName}\n`;
res += '"p-val (adj)"\t"Enriched area"\n';
res += '"Enriched area"\t"p-val (adj)"\n';
const areas = data.data[i].areas;
for (let j = 0; j < areas.length; ++j) {
res += `"${areas[j].enrichedArea}"\t"${areas[j].adjustedPVal}"\n`
......@@ -598,13 +506,9 @@ function exportToTsv(data) {
res += '\n'
}
return res;
}
function exportToJson(data) {
return JSON.stringify(data, null, 2);
}
\ No newline at end of file
}
Markdown is supported
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