Commit 88d8e224 authored by Jean-Clement Gallardo's avatar Jean-Clement Gallardo
Browse files

Finish hotfix/MappingInJSON

parents d580f11e 67c4f86e
...@@ -23,7 +23,7 @@ metExploreD3.GraphMapping = { ...@@ -23,7 +23,7 @@ metExploreD3.GraphMapping = {
mapNodeDataFile: function(mapping, objects) { mapNodeDataFile: function(mapping, objects) {
var session = _metExploreViz.getSessionById('viz'); var session = _metExploreViz.getSessionById('viz');
var force = session.getForce(); var force = session.getForce();
force.stop(); force.stop();
var myMask = metExploreD3.createLoadMask("Mapping in progress...", 'graphPanel'); var myMask = metExploreD3.createLoadMask("Mapping in progress...", 'graphPanel');
if(myMask!= undefined){ if(myMask!= undefined){
metExploreD3.showMask(myMask); metExploreD3.showMask(myMask);
...@@ -168,7 +168,7 @@ metExploreD3.GraphMapping = { ...@@ -168,7 +168,7 @@ metExploreD3.GraphMapping = {
try { try {
var session = _metExploreViz.getSessionById('viz'); var session = _metExploreViz.getSessionById('viz');
var force = session.getForce(); var force = session.getForce();
force.stop(); force.stop();
var networkData = session.getD3Data(); var networkData = session.getD3Data();
var conditions = mapping.getConditions().filter(function (c) { var conditions = mapping.getConditions().filter(function (c) {
return c !== "PathwayCoverage" && c !== "PathwayEnrichment" return c !== "PathwayCoverage" && c !== "PathwayEnrichment"
...@@ -284,10 +284,10 @@ metExploreD3.GraphMapping = { ...@@ -284,10 +284,10 @@ metExploreD3.GraphMapping = {
* @throws error in function * @throws error in function
*/ */
reloadMapping : function(mapping) { reloadMapping : function(mapping) {
var session = _metExploreViz.getSessionById('viz'); var session = _metExploreViz.getSessionById('viz');
var force = session.getForce(); var force = session.getForce();
force.stop(); force.stop();
var myMask = metExploreD3.createLoadMask("Mapping in progress...", 'graphPanel'); var myMask = metExploreD3.createLoadMask("Mapping in progress...", 'graphPanel');
if(myMask!= undefined){ if(myMask!= undefined){
...@@ -305,35 +305,35 @@ metExploreD3.GraphMapping = { ...@@ -305,35 +305,35 @@ metExploreD3.GraphMapping = {
switch (mapping.getTargetLabel()) { switch (mapping.getTargetLabel()) {
case "reactionDBIdentifier": case "reactionDBIdentifier":
mapping.getData().forEach(function (map) { mapping.getData().forEach(function (map) {
if (typeof map.getNode() == "object") if (typeof map == "object")
node = networkData.getNodeByDbIdentifier(map.getNode().getDbIdentifier()); node = networkData.getNodeByDbIdentifier(map.node);
else else
node = networkData.getNodeByDbIdentifier(map.getNode()); node = networkData.getNodeByDbIdentifier(map);
if (node != undefined) { if (node != undefined) {
var mapNode = new MappingData(node, mapping.getName(), map.getConditionName(), map.getMapValue()); var mapNode = new MappingData(node, map.mappingName, map.conditionName, map.mapValue);
node.addMappingData(mapNode); node.addMappingData(mapNode);
links = networkData.getLinkByDBIdReaction(node.getDbIdentifier()); links = networkData.getLinkByDBIdReaction(map.node);
links.forEach(function (link) { links.forEach(function (link) {
link.addMappingData(mapNode); link.addMappingData(mapNode);
}) });
} }
}); });
break; break;
case "reactionId": case "reactionId":
mapping.getData().forEach(function (map) { mapping.getData().forEach(function (map) {
if (typeof map.getNode() == "object") if (typeof map == "object")
var node = networkData.getNodeById(map.getNode().getId()); var node = networkData.getNodeById(map.node);
else else
var node = networkData.getNodeById(map.getNode()); var node = networkData.getNodeById(map);
if (node != undefined) { if (node != undefined) {
var mapNode = new MappingData(node, mapping.getName(), map.getConditionName(), map.getMapValue()); var mapNode = new MappingData(node, map.mappingName, map.conditionName, map.mapValue);
node.addMappingData(mapNode); node.addMappingData(mapNode);
links = networkData.getLinkByDBIdReaction(node.getDbIdentifier()); links = networkData.getLinkByDBIdReaction(map.node);
links.forEach(function (link) { links.forEach(function (link) {
link.addMappingData(mapNode); link.addMappingData(mapNode);
}) })
...@@ -343,13 +343,13 @@ metExploreD3.GraphMapping = { ...@@ -343,13 +343,13 @@ metExploreD3.GraphMapping = {
case "metaboliteId": case "metaboliteId":
mapping.getData().forEach(function (map) { mapping.getData().forEach(function (map) {
if (typeof map.getNode() == "object") if (typeof map == "object")
var node = networkData.getNodeById(map.getNode().getId()); var node = networkData.getNodeById(map.node);
else else
var node = networkData.getNodeById(map.getNode()); var node = networkData.getNodeById(map);
if (node != undefined) { if (node != undefined) {
var mapNode = new MappingData(node, mapping.getName(), map.getConditionName(), map.getMapValue()); var mapNode = new MappingData(node, map.mappingName, map.conditionName, map.mapValue);
node.addMappingData(mapNode); node.addMappingData(mapNode);
} }
}); });
...@@ -357,13 +357,13 @@ metExploreD3.GraphMapping = { ...@@ -357,13 +357,13 @@ metExploreD3.GraphMapping = {
case "metaboliteDBIdentifier": case "metaboliteDBIdentifier":
mapping.getData().forEach(function (map) { mapping.getData().forEach(function (map) {
if (typeof map.getNode() == "object") if (typeof map == "object")
var node = networkData.getNodeByDbIdentifier(map.getNode().getDbIdentifier()); var node = networkData.getNodeByDbIdentifier(map.node);
else else
var node = networkData.getNodeByDbIdentifier(map.getNode()); var node = networkData.getNodeByDbIdentifier(map);
if (node != undefined) { if (node != undefined) {
var mapNode = new MappingData(node, mapping.getName(), map.getConditionName(), map.getMapValue()); var mapNode = new MappingData(node, map.mappingName, map.conditionName, map.mapValue);
node.addMappingData(mapNode); node.addMappingData(mapNode);
} }
}); });
...@@ -400,6 +400,124 @@ metExploreD3.GraphMapping = { ...@@ -400,6 +400,124 @@ metExploreD3.GraphMapping = {
}, 1); }, 1);
} }
}, },
// Initial function reloadMapping
// reloadMapping : function(mapping) {
//
// var session = _metExploreViz.getSessionById('viz');
// var force = session.getForce();
// force.stop();
// var myMask = metExploreD3.createLoadMask("Mapping in progress...", 'graphPanel');
// if(myMask!= undefined){
//
// metExploreD3.showMask(myMask);
// setTimeout(
// function() {
// try {
// var session = _metExploreViz.getSessionById('viz');
// var networkData = session.getD3Data();
// var conditions = mapping.getConditions().filter(function (c) {
// return c !== "PathwayCoverage" && c !== "PathwayEnrichment"
// });
// var node = undefined;
// var links = undefined;
// switch (mapping.getTargetLabel()) {
// case "reactionDBIdentifier":
// mapping.getData().forEach(function (map) {
// if (typeof map.getNode() == "object")
// node = networkData.getNodeByDbIdentifier(map.getNode().getDbIdentifier());
// else
// node = networkData.getNodeByDbIdentifier(map.getNode());
//
// if (node != undefined) {
// var mapNode = new MappingData(node, mapping.getName(), map.getConditionName(), map.getMapValue());
// node.addMappingData(mapNode);
//
// links = networkData.getLinkByDBIdReaction(node.getDbIdentifier());
// links.forEach(function (link) {
// link.addMappingData(mapNode);
// })
// }
// });
// break;
//
// case "reactionId":
// mapping.getData().forEach(function (map) {
// if (typeof map.getNode() == "object")
// var node = networkData.getNodeById(map.getNode().getId());
// else
// var node = networkData.getNodeById(map.getNode());
//
// if (node != undefined) {
// var mapNode = new MappingData(node, mapping.getName(), map.getConditionName(), map.getMapValue());
// node.addMappingData(mapNode);
//
// links = networkData.getLinkByDBIdReaction(node.getDbIdentifier());
// links.forEach(function (link) {
// link.addMappingData(mapNode);
// })
// }
// });
// break;
//
// case "metaboliteId":
// mapping.getData().forEach(function (map) {
// if (typeof map.getNode() == "object")
// var node = networkData.getNodeById(map.getNode().getId());
// else
// var node = networkData.getNodeById(map.getNode());
//
// if (node != undefined) {
// var mapNode = new MappingData(node, mapping.getName(), map.getConditionName(), map.getMapValue());
// node.addMappingData(mapNode);
// }
// });
// break;
//
// case "metaboliteDBIdentifier":
// mapping.getData().forEach(function (map) {
// if (typeof map.getNode() == "object")
// var node = networkData.getNodeByDbIdentifier(map.getNode().getDbIdentifier());
// else
// var node = networkData.getNodeByDbIdentifier(map.getNode());
//
// if (node != undefined) {
// var mapNode = new MappingData(node, mapping.getName(), map.getConditionName(), map.getMapValue());
// node.addMappingData(mapNode);
// }
// });
// break;
// case "inchi":
// // Blah
// break;
// default:
// metExploreD3.displayMessage("Warning", 'The type of node "' + mapping.getTargetLabel() + '" isn\'t know.')
// }
//
// metExploreD3.hideMask(myMask);
//
// var anim = session.isAnimated("viz");
// if (anim) {
// var force = session.getForce();
//
// force.alpha(force.alpha()).restart();
// }
// }
// catch (e) {
// e.functionUsed="reloadMapping";
// metExploreD3.hideMask(myMask);
//
// var anim=session.isAnimated("viz");
// if (anim) {
// var session = _metExploreViz.getSessionById('viz');
// var force = session.getForce();
//
// force.alpha(force.alpha()).restart();
// }
// throw e;
// }
// }, 1);
// }
// },
/*********************************************** /***********************************************
* Mapping to discrete data * Mapping to discrete data
* This function will look at metabolites that have data * This function will look at metabolites that have data
...@@ -896,7 +1014,7 @@ metExploreD3.GraphMapping = { ...@@ -896,7 +1014,7 @@ metExploreD3.GraphMapping = {
return "translate("+d.x+", "+d.y+") scale(1)"; return "translate("+d.x+", "+d.y+") scale(1)";
}) })
.style("fill", "white"); .style("fill", "white");
vis.selectAll("g.node") vis.selectAll("g.node")
.filter(function(d){ .filter(function(d){
if(this.getAttribute("mapped")==undefined || this.getAttribute("mapped")==false || this.getAttribute("mapped")=="false") return false; if(this.getAttribute("mapped")==undefined || this.getAttribute("mapped")==false || this.getAttribute("mapped")=="false") return false;
...@@ -904,7 +1022,7 @@ metExploreD3.GraphMapping = { ...@@ -904,7 +1022,7 @@ metExploreD3.GraphMapping = {
}) })
.attr("mapped", "false") .attr("mapped", "false")
.selectAll("rect.stroke") .selectAll("rect.stroke")
.remove(); .remove();
}, },
/*********************************************** /***********************************************
...@@ -954,14 +1072,14 @@ metExploreD3.GraphMapping = { ...@@ -954,14 +1072,14 @@ metExploreD3.GraphMapping = {
* @param {Function} func Callback function * @param {Function} func Callback function
*/ */
launchAfterMappingFunction:function(mappingId, func) { launchAfterMappingFunction:function(mappingId, func) {
var mapping = _metExploreViz.getMappingById(mappingId); var mapping = _metExploreViz.getMappingById(mappingId);
if (mapping !== null) { if (mapping !== null) {
// the variable is defined // the variable is defined
func(mapping); func(mapping);
return; return;
} }
var that = this; var that = this;
setTimeout(function(){that.launchAfterMappingFunction(mappingId, func);}, 100); setTimeout(function(){that.launchAfterMappingFunction(mappingId, func);}, 100);
}, },
/*********************************************** /***********************************************
...@@ -996,7 +1114,7 @@ metExploreD3.GraphMapping = { ...@@ -996,7 +1114,7 @@ metExploreD3.GraphMapping = {
if(mappingJSON){ if(mappingJSON){
var session = _metExploreViz.getSessionById('viz'); var session = _metExploreViz.getSessionById('viz');
var force = session.getForce(); var force = session.getForce();
force.stop(); force.stop();
var myMask = metExploreD3.createLoadMask("Mapping in progress...", 'graphPanel'); var myMask = metExploreD3.createLoadMask("Mapping in progress...", 'graphPanel');
if(myMask!= undefined){ if(myMask!= undefined){
...@@ -1052,7 +1170,7 @@ metExploreD3.GraphMapping = { ...@@ -1052,7 +1170,7 @@ metExploreD3.GraphMapping = {
loadDataTSV : function(url, func) { loadDataTSV : function(url, func) {
var session = _metExploreViz.getSessionById('viz'); var session = _metExploreViz.getSessionById('viz');
var force = session.getForce(); var force = session.getForce();
force.stop(); force.stop();
var myMask = metExploreD3.createLoadMask("Mapping in progress...", 'graphPanel'); var myMask = metExploreD3.createLoadMask("Mapping in progress...", 'graphPanel');
if(myMask!= undefined){ if(myMask!= undefined){
...@@ -1071,8 +1189,8 @@ metExploreD3.GraphMapping = { ...@@ -1071,8 +1189,8 @@ metExploreD3.GraphMapping = {
var array = []; var array = [];
var mapping = new Mapping(title, arrayAttr, targetName, array); var mapping = new Mapping(title, arrayAttr, targetName, array);
_metExploreViz.addMapping(mapping); _metExploreViz.addMapping(mapping);
metExploreD3.GraphMapping.mapNodeDataFile(mapping, data); metExploreD3.GraphMapping.mapNodeDataFile(mapping, data);
metExploreD3.fireEventArg('buttonMap', "jsonmapping", mapping); metExploreD3.fireEventArg('buttonMap', "jsonmapping", mapping);
...@@ -1085,7 +1203,7 @@ metExploreD3.GraphMapping = { ...@@ -1085,7 +1203,7 @@ metExploreD3.GraphMapping = {
var force = session.getForce(); var force = session.getForce();
force.alpha(force.alpha()).restart(); force.alpha(force.alpha()).restart();
} }
}); });
} }
}, },
...@@ -2937,4 +3055,4 @@ metExploreD3.GraphMapping = { ...@@ -2937,4 +3055,4 @@ metExploreD3.GraphMapping = {
} }
}); });
} }
}; };
\ No newline at end of file
...@@ -348,7 +348,8 @@ metExploreD3.GraphPanel = { ...@@ -348,7 +348,8 @@ metExploreD3.GraphPanel = {
if(jsonParsed.mappings) if(jsonParsed.mappings)
{ {
jsonParsed.mappings.forEach(function(mapping){ jsonParsed.mappings.forEach(function(mapping){
var mapping = new Mapping(mapping.name, mapping.conditions, mapping.targetLabel); var mapping = new Mapping(mapping.name, mapping.conditions, mapping.targetLabel, mapping.data);
mapping.data = mapping.id;
_metExploreViz.addMapping(mapping); _metExploreViz.addMapping(mapping);
}); });
} }
......
...@@ -1356,6 +1356,7 @@ metExploreD3.GraphUtils = { ...@@ -1356,6 +1356,7 @@ metExploreD3.GraphUtils = {
networkJSON+=",\n\"metaboliteStyle\":"+JSON.stringify(metExploreD3.getMetaboliteStyle()); networkJSON+=",\n\"metaboliteStyle\":"+JSON.stringify(metExploreD3.getMetaboliteStyle());
networkJSON+=",\n\"comparedPanels\":"+JSON.stringify(_metExploreViz.comparedPanels); networkJSON+=",\n\"comparedPanels\":"+JSON.stringify(_metExploreViz.comparedPanels);
networkJSON+=",\n\"linkedByTypeOfMetabolite\":"+JSON.stringify(_metExploreViz.linkedByTypeOfMetabolite); networkJSON+=",\n\"linkedByTypeOfMetabolite\":"+JSON.stringify(_metExploreViz.linkedByTypeOfMetabolite);
networkJSON+=",\n\"mappings\":"+JSON.stringify(_metExploreViz.mappings);
networkJSON+=",\n\"sessions\":{"; networkJSON+=",\n\"sessions\":{";
......
Supports Markdown
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