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

p val calc working

parent a5eca9c1
Pipeline #7215 failed with stages
in 3 minutes and 24 seconds
......@@ -9,6 +9,7 @@ const globals = {
selected: [],
allBioEntities: [],
pathways: [],
quickAliases: [],
pickedRandomly: undefined
};
......@@ -36,6 +37,8 @@ const register = function(_minerva) {
globals.modelIds = minervaProxy.project.data.getModels();
calculatePathways();
initPlugin();
};
......@@ -160,7 +163,7 @@ function initMainPageStructure(){
</div>
`);
container.find('.btn-calc').on('click', () => calculatePathways() );
container.find('.btn-calc').on('click', () => calculateGSEA() );
container.find('.btn-reset').on('click', () => deHighlightAll() );
container.find('.btn-highlight-random').on('click', () => highlightSelected(true) );
container.find('.btn-focus-random').on('click', () => focusOnSelected(true) );
......@@ -234,18 +237,15 @@ function highlightSelected(pickedRandomly = false) {
minervaProxy.project.map.showBioEntity(highlightDefs);
}
//temp1.project.map.getVisibleDataOverlays().then(function(data) { console.log(data)})
function calculatePathways() {
function populatePathways(){
const pathwayAliases = [];
const pathwayObjs = [];
const pathwayObjs = [];
function populatePathways(){
const pgrObjects = [];
// For the time being, handle only the main map
// minervaProxy.project.data.getModels() registered earlier
globals.allBioEntities.forEach( e => {
if(e.getModelId() == globals.modelIds[0].modelId) {
var this_type = e.getType();
......@@ -256,35 +256,29 @@ function calculatePathways() {
pgrObjects.push(e)
}
}
});
globals.quickAliases = pgrObjects;
pathwayObjs.forEach( function(e, i) {
const these_dims = new Array(e.getX(), e.getX()+e.getWidth(), e.getY(), e.getY()+e.getHeight());
const these_hits = [];
pgrObjects.forEach( g => {
// Comparison needs improvement
if(g.getX() >= these_dims[0] && g.getX() <= these_dims[1]
&& g.getY() >= these_dims[2] && g.getY() <= these_dims[3]) {
these_hits.push(g);
}
});
e.pathwayAliases = these_hits;
});
}
let html = "";
console.log(pathwayObjs);
console.log(pgrObjects);
pathwayObjs.forEach(
e => { html += `${e.getElementId()} - ${e.getName()}; `; }
);
pluginContainer.find('.panel-events .panel-body').html(html);
const highlightDefs = [];
pathwayObjs.forEach( e => {
highlightDefs.push({
element: {
id: e.getId(),
modelId: e.getModelId(),
type: e.constructor.name.toUpperCase()
},
type: "SURFACE",
options: {
color: '#00FF00',
opacity: 0.5
}
});
});
minervaProxy.project.map.showBioEntity(highlightDefs);
globals.pathways = pathwayObjs;
}
if (globals.allBioEntities.length > 0) {
populatePathways();
......@@ -298,40 +292,133 @@ function calculatePathways() {
}
function calculateGSEA() {
function focus(entity) {
if (entity.constructor.name === 'Alias') {
minervaProxy.project.map.fitBounds({
modelId: entity.getModelId(),
x1: entity.getX(),
y1: entity.getY(),
x2: entity.getX() + entity.getWidth(),
y2: entity.getY() + entity.getHeight()
});
} else {
minervaProxy.project.map.fitBounds({
modelId: entity.getModelId(),
x1: entity.getCenter().x,
y1: entity.getCenter().y,
x2: entity.getCenter().x,
y2: entity.getCenter().y
// Define factorial function, to calculate the hypergeometric test
var f = [];
function factorial (n) {
if (n == 0 || n == 1)
return 1;
if (f[n] > 0)
return f[n];
return f[n] = factorial(n-1) * n;
};
function kcomb (n,k) {
//return factorial(n)/(factorial(k)*(factorial(n - k)));
//Approximation using upper boud from Eq (2) in http://page.mi.fu-berlin.de/shagnik/notes/binomials.pdf
var ret = Math.pow(n*Math.E/k,k);
console.log(ret);
return ret;
};
// Get active overlays
minervaProxy.project.map.getVisibleDataOverlays().then(function(overlays) {
let gsea_html = '';
overlays.forEach( e => {
const these_ovaliases = e.getAliases().map( g => g.getId());
globals.pathways.forEach( g => {
const these_paliases = g.pathwayAliases.map(h => h.getId());
const isect = these_ovaliases.filter(value => -1 !== these_paliases.indexOf(value));
console.log(isect);
var m = these_paliases.length;
var k = isect.length;
var N = globals.quickAliases.length;
var n = these_ovaliases.length;
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
var px = Math.pow(((m*(n-k))/(k*(N-m))),k) * Math.pow(((n*(N-m))/(N*(n-k))),n);
console.log(px);
gsea_html += `${px} - ${g.getName()};<br/>`;
console.log(gsea_html);
};
});
}
}
if (globals.allBioEntities.length > 0) {
pick();
}
else {
minervaProxy.project.data.getAllBioEntities().then(function(bioEntities) {
globals.allBioEntities = bioEntities;
pick();
});
}
pluginContainer.find('.panel-events .panel-body').html(gsea_html);
});
if (!pickedRandomly && globals.selected.length > 0) focus(globals.selected[0]);
if (pickedRandomly && globals.pickedRandomly) focus(globals.pickedRandomly);
// const highlightDefs = [];
// pathwayObjs.forEach( e => {
// highlightDefs.push({
// element: {
// id: e.getId(),
// modelId: e.getModelId(),
// type: e.constructor.name.toUpperCase()
// },
// type: "SURFACE",
// options: {
// color: '#00FF00',
// opacity: 0.5
// }
// });
// });
// globals.pathways[0].pathwayAliases.forEach( e => {
// highlightDefs.push({
// element: {
// id: e.getId(),
// modelId: e.getModelId(),
// type: e.constructor.name.toUpperCase()
// },
// type: "SURFACE",
// options: {
// color: '#00FF00',
// opacity: 0.5
// }
// });
// });
// highlightDefs.push({
// element: {
// id: globals.pathways[0].getId(),
// modelId: globals.pathways[0].getModelId(),
// type: globals.pathways[0].constructor.name.toUpperCase()
// },
// type: "SURFACE",
// options: {
// color: '#00FF00',
// opacity: 0.5
// }
// });
// minervaProxy.project.map.showBioEntity(highlightDefs);
// function focus(entity) {
// if (entity.constructor.name === 'Alias') {
// minervaProxy.project.map.fitBounds({
// modelId: entity.getModelId(),
// x1: entity.getX(),
// y1: entity.getY(),
// x2: entity.getX() + entity.getWidth(),
// y2: entity.getY() + entity.getHeight()
// });
// } else {
// minervaProxy.project.map.fitBounds({
// modelId: entity.getModelId(),
// x1: entity.getCenter().x,
// y1: entity.getCenter().y,
// x2: entity.getCenter().x,
// y2: entity.getCenter().y
// });
// }
// }
// if (globals.allBioEntities.length > 0) {
// pick();
// }
// else {
// minervaProxy.project.data.getAllBioEntities().then(function(bioEntities) {
// globals.allBioEntities = bioEntities;
// pick();
// });
// }
// if (!pickedRandomly && globals.selected.length > 0) focus(globals.selected[0]);
// if (pickedRandomly && globals.pickedRandomly) focus(globals.pickedRandomly);
}
function retrieveUniprot() {
......
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