Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge added plotting features with master #61

Merged
merged 13 commits into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions licenses/AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
[email protected]
Hannes Planatscher, NMI Reutlingen, Germany,
[email protected]
Shalin Shah, Duke University USA,
[email protected]

-- Thanks to --

Expand Down
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<!--<scope>test</scope> -->
</dependency>
<dependency>
<groupId>org.sbml.jsbml</groupId>
Expand Down Expand Up @@ -304,25 +303,21 @@
<groupId>scpsolver</groupId>
<artifactId>SCPSolver</artifactId>
<version>1.0v2</version>
<!-- <scope>system</scope> <systemPath>${project.basedir}/src/lib/maven/scpsolver/SCPSolver/1.0/SCPSolver-1.0.jar</systemPath> -->
</dependency>
<dependency>
<groupId>scpsolver</groupId>
<artifactId>GLPKSolverPack</artifactId>
<version>4.35v2</version>
<!-- <scope>system</scope> <systemPath>${project.basedir}/src/lib/maven/scpsolver/GLPKSolverPack/4.35/GLPKSolverPack-4.35.jar</systemPath> -->
</dependency>
<dependency>
<groupId>scpsolver</groupId>
<artifactId>LPSOLVESolverPack</artifactId>
<version>5.5.2.5</version>
<!-- <scope>system</scope> <systemPath>${project.basedir}/src/lib/maven/scpsolver/LPSOLVESolverPack/5.5.2.5/LPSOLVESolverPack-5.5.2.5.jar</systemPath> -->
</dependency>
<dependency>
<groupId>kisao</groupId>
<artifactId>libkisao</artifactId>
<version>1.0.3.1-rc</version>
<!-- <scope>system</scope> <systemPath>${project.basedir}/src/lib/kisao/LibKiSAO/1.0.3.1/libkisao-1.0.3.1-rc.jar</systemPath> -->
</dependency>
<!-- OMEX archive -->
<dependency>
Expand Down
Binary file removed src/lib/UmlGraph.jar
Binary file not shown.
Binary file removed src/lib/commons-math-2.2-src.zip
Binary file not shown.
Binary file removed src/lib/commons-math-2.2.jar
Binary file not shown.
Binary file not shown.
Binary file removed src/lib/ext-lib/commons-io-1.4.jar
Binary file not shown.
Binary file removed src/lib/ext-lib/jaxen-1.1.1.jar
Binary file not shown.
Binary file removed src/lib/ext-lib/jdom-contrib.jar
Binary file not shown.
Binary file removed src/lib/ext-lib/jdom.jar
Binary file not shown.
Binary file removed src/lib/ext-lib/jmathml.jar
Binary file not shown.
Binary file removed src/lib/ext-lib/xom-1.2.1.jar
Binary file not shown.
Binary file removed src/lib/jfree/jfreechart/1.0.19/jcommon-1.0.23.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed src/lib/lp-lib/GLPKSolverPack.jar
Binary file not shown.
Binary file removed src/lib/lp-lib/LPSOLVESolverPack.jar
Binary file not shown.
Binary file removed src/lib/nmi/scpsolver/1.0/GLPKSolverPack-4.35v2.jar
Binary file not shown.
Binary file not shown.
Binary file removed src/lib/nmi/scpsolver/1.0/SCPSolver-1.0v2.jar
Binary file not shown.
Binary file not shown.
Binary file removed src/lib/org/sbml/JSBML/1.3.1/jsbml-1.3.1.jar
Binary file not shown.
42 changes: 30 additions & 12 deletions src/main/java/org/simulator/examples/SEDMLExample.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
package org.simulator.examples;

import de.binfalse.bflog.LOGGER;
import static org.junit.Assert.fail;

import java.io.File;
import java.util.List;
import java.util.Map;

import org.jfree.ui.RefineryUtilities;
import org.jlibsedml.*;
import org.jlibsedml.AbstractTask;
import org.jlibsedml.Curve;
import org.jlibsedml.Libsedml;
import org.jlibsedml.Output;
import org.jlibsedml.Plot2D;
import org.jlibsedml.SedML;
import org.jlibsedml.XMLException;
import org.jlibsedml.execution.IProcessedSedMLSimulationResults;
import org.jlibsedml.execution.IRawSedmlSimulationResults;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.simulator.math.odes.MultiTable;
import org.simulator.plot.PlotMultiTable;
import org.simulator.plot.PlotProcessedSedmlResults;
import org.simulator.sedml.SedMLSBMLSimulatorExecutor;

import java.io.File;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.fail;
import de.binfalse.bflog.LOGGER;

/**
* This test class shows how a SED-ML file can be interpreted and executed using
Expand Down Expand Up @@ -43,7 +49,7 @@ public static void main(String[] args) throws XMLException, OWLOntologyCreationE

// in this SED-ML file there's just one output. If there were several,
// we could either iterate or get user to decide what they want to run.
Output wanted = sedml.getOutputs().get(0);
Output wanted = sedml.getOutputs().get(2);
SedMLSBMLSimulatorExecutor exe = new SedMLSBMLSimulatorExecutor(sedml, wanted, sedmlDir);
// This gets the raw simulation results - one for each Task that was run.
LOGGER.warn("Collecting tasks...");
Expand All @@ -52,10 +58,22 @@ public static void main(String[] args) throws XMLException, OWLOntologyCreationE
fail ("Simulatation failed: " + exe.getFailureMessages().get(0));
return;
}

// now process.In this case, there's no processing performed - we're displaying the
// raw results.
LOGGER.warn("Outputs wanted: " + wanted.getAllDataGeneratorReferences());
IProcessedSedMLSimulationResults mt = exe.processSimulationResults(wanted, res);
LOGGER.warn("Outputs wanted: " + wanted.getId());
IProcessedSedMLSimulationResults prRes = exe.processSimulationResults(wanted, res);

if(wanted.isPlot2d()) {
Plot2D plots = (Plot2D) wanted;
List<Curve> curves = plots.getListOfCurves();

// plot all processed results as per curve descriptions
PlotProcessedSedmlResults p = new PlotProcessedSedmlResults(prRes, curves, plots.getElementName());
p.pack();
RefineryUtilities.centerFrameOnScreen(p);
p.setVisible( true );
}
}

}
153 changes: 153 additions & 0 deletions src/main/java/org/simulator/plot/PlotProcessedSedmlResults.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* ---------------------------------------------------------------------
* This file is part of Simulation Core Library, a Java-based library
* for efficient numerical simulation of biological models.
*
* Copyright (C) 2007-2016 jointly by the following organizations:
* 1. University of Tuebingen, Germany
* 2. Keio University, Japan
* 3. Harvard University, USA
* 4. The University of Edinburgh, UK
* 5. EMBL European Bioinformatics Institute (EBML-EBI), Hinxton, UK
* 6. The University of California, San Diego, La Jolla, CA, USA
* 7. The Babraham Institute, Cambridge, UK
* 8. Duke University, USA
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation. A copy of the license
* agreement is provided in the file named "LICENSE.txt" included with
* this software distribution and also available online as
* <http://www.gnu.org/licenses/lgpl-3.0-standalone.html>.
* ---------------------------------------------------------------------
*/
package org.simulator.plot;

import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartUtilities;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.ui.ApplicationFrame;
import org.jlibsedml.Curve;
import org.jlibsedml.execution.IProcessedSedMLSimulationResults;

import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

/**
* This class adds output data-plot support to SBSCL
*
* @author Shalin Shah
* @since 1.5
*/
@SuppressWarnings("serial")
public class PlotProcessedSedmlResults extends ApplicationFrame {
private IProcessedSedMLSimulationResults species;
private XYSeriesCollection graphData;
private String title;
private List<Curve> curves;
private JFreeChart lineChart;
private static final int CHART_WIDTH = 1366;
private static final int CHART_HEIGHT = 768;

/**
* Initializes the JFreeChart and dataSet for the chart using IProcessedSedMLSimulationResults
*
* @param IProcessedSedMLSimulationResults
* The input data type to the plot API is 2D data wrapped with jsedmllib data structure
* which gets converted internally to XY line plot
*/
public PlotProcessedSedmlResults(IProcessedSedMLSimulationResults data, String title) {
super(title);

this.title = title;
this.species = data;
this.lineChart = ChartFactory.createXYLineChart(this.title,
".", ".", createDataset(),
PlotOrientation.VERTICAL, true, true, false);

ChartPanel chartPanel = new ChartPanel( this.lineChart );
chartPanel.setPreferredSize( new java.awt.Dimension(CHART_WIDTH, CHART_HEIGHT));
setContentPane(chartPanel);

}

public PlotProcessedSedmlResults(IProcessedSedMLSimulationResults data, List<Curve> curves, String title) {
super(title);

this.title = title;
this.species = data;
this.curves = curves;

this.lineChart = ChartFactory.createXYLineChart(this.title,
".", ".", createDataset(),
PlotOrientation.VERTICAL, true, true, false);


ChartPanel chartPanel = new ChartPanel( this.lineChart );
chartPanel.setPreferredSize( new java.awt.Dimension(CHART_WIDTH, CHART_HEIGHT));
setContentPane(chartPanel);
}

/**
* Helper function that converts IProcessedSedMLSimulationResults to DataSet for LineChart
*/
private XYSeriesCollection createDataset() {
graphData = new XYSeriesCollection();

// For each curve in the current output element of sedml file
// simple extract data generators and plot them
for(Curve cur: this.curves) {
Double[] xData = species.getDataByColumnId(cur.getXDataReference());
Double[] yData = species.getDataByColumnId(cur.getYDataReference());
XYSeries series = new XYSeries(cur.getId(), false);

for(int row = 0; row < Math.min(xData.length, yData.length); row++) {
series.add(xData[row], yData[row]);
}
graphData.addSeries(series);
}

return graphData;
}

/**
* Helper function that can save the generated plot (simulationPath sedml file) as a PNG image
* with fileName in the results folder
*/
public void savePlot(String simulationPath, String fileName) throws IOException {
// Get full folder for sedml xml file
String outputPath = getFolderPathForTestResource(simulationPath);
// Store the plots in the results folder in the same directory
outputPath = outputPath + "/results/simulation_core/" + fileName + ".png";
OutputStream out = FileUtils.openOutputStream(new File(outputPath));
// Use default width and height for chart size and save as png
ChartUtilities.writeChartAsPNG(out, this.lineChart, CHART_WIDTH, CHART_HEIGHT);
}

/**
* Get absolute parent path for given test resource.
* Due to the relative paths of SBML and SED-ML files the resource loading is not working
* in maven.
*
* Example:
* resourcePath="/fba/e_coli_core.xml"
*/
private static String getFolderPathForTestResource(String resourcePath) {

String path = null;
File currentDir = new File(System.getProperty("user.dir"));
path = currentDir.getAbsolutePath() + "/src/test/resources" + resourcePath;
File pwd = new File(path);

return pwd.getParentFile().getAbsolutePath();
}
}
6 changes: 4 additions & 2 deletions src/main/java/org/simulator/sedml/ProcessSedMLResults.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ private IRawSedmlSimulationResults flattenResultsList(List<IRawSedmlSimulationRe
mergeTimeCols(a, b),
mergeDataCols(a.getData(), b.getData()),
results.get(0).getColumnHeaders()))).get();
return flat;
return flat;
}

/**
Expand Down Expand Up @@ -396,7 +396,9 @@ private double[][] extractNonTimeData(double[][] data) {
private double[] mergeTimeCols(IRawSedmlSimulationResults a, IRawSedmlSimulationResults b) {
// Get end time point for taskA
double[] timeA = ((MultTableSEDMLWrapper)a).getMultiTable().getTimePoints();
double timeBegin = timeA[timeA.length - 1];
// Following tellurim we concat all the iterations of repeated tasks
// so start time from 0
double timeBegin = 0d;

// Add end time point to taskB
double[] timeB = Arrays.stream(((MultTableSEDMLWrapper)b).getMultiTable().getTimePoints()).map(row -> row + timeBegin).toArray();
Expand Down
Loading