Example
Let's look at few concrete examples of using the MetExploreViz API. In this section, you will find the code and it's application below.
Launch drawing from local JSON file
Previously, you learned how to launch a drawing using variables in your script. However, in certain workflows, such as integrating MetExploreViz into a larger system, you might need to launch a drawing from a local JSON file. This can be achieved using the#fetch(path) method.
MetExploreViz.onloadMetExploreViz(function(){
  fetch("path")
    .then(response => response.json())
    .then(json => JSON.stringify(json))
    .then(jsonString => metExploreViz.GraphPanel.refreshPanel(jsonString));
});
Highlight Nodes
Once the network is drawn, you can highlight nodes using data from a file.
Begin by loading the data file using the function #metExploreViz.GraphMapping.loadDataTSV(url). provided by MetExploreViz. This function allows you to load data from a TSV (Tab-Separated Values) file.
After loading the data file, you can map the data onto nodes using the function #metExploreViz.GraphMapping.mapNodes(fileName).
MetExploreViz.onloadMetExploreViz(function(){
  metExploreViz.onloadSession(function(){
      //Load mapping - path start at MetExploreViz folder
    metExploreViz.GraphMapping.loadDataTSV("path");
      //Highlight
    metExploreViz.GraphMapping.mapNodes("map.tsv");
  });
});
Map Nodes
To map data onto nodes or links from a data file, follow these steps:
Load the data file using the same function used to highlight nodes.
Retrieve the style component (link, metabolite, or reaction) using the function # metExploreViz.findCmpt(componentName)
Select a specific style to apply mapping to using the function #styleForm.query("aStyleForm").find(function(aStyleForm){ return aStyleForm.title === "specificStyleName"})
Finally, apply the mapping data onto your selected style using the function #metExploreViz.GraphMapping.graphMappingDiscreteData(fileName / condition, component)
MetExploreViz.onloadMetExploreViz(function(){
  metExploreViz.onloadSession(function(){
      // Load data
    metExploreViz.GraphMapping.loadDataTSV("path");

      // get link style component
    var styleForm = metExploreViz.findCmpt('linkStyleForm');

      // select specific style
    var backgroundForm = styleForm.query("aStyleForm").find(function(aStyleForm){ return aStyleForm.title === "Link color" });

      // apply mapping on selected style
    metExploreViz.GraphMapping.graphMappingDiscreteData("map.tsv / condition", backgroundForm);
  });
});
Duplicate side compounds
MetExploreViz enables you to duplicate side compounds programmatically.
After drawing the network, load the side compounds using the function #metExploreViz.GraphNode.loadSideCompounds(arrayOfMetabolicDataBaseIdentifiers)
Once the side compounds are loaded, use the function #metExploreViz.GraphNetwork.duplicateSideCompounds() to duplicate them.
MetExploreViz.onloadMetExploreViz(function(){
  metExploreViz.onloadSession(function(){
    var sideCompounds = ["NADPH", "H+", "H2O"];
    metExploreViz.GraphNode.loadSideCompounds(sideCompounds);
    metExploreViz.GraphNetwork.duplicateSideCompounds();
  });
});