Search in sources :

Example 1 with StochtestCompareStatus

use of org.vcell.stochtest.StochtestCompare.StochtestCompareStatus in project vcell by virtualcell.

the class StochtestCompareService method compareOne.

public void compareOne() throws IllegalArgumentException, SQLException, DataAccessException, XmlParseException, PropertyVetoException, ExpressionException, MappingException, GeometryException, ImageException, IOException {
    StochtestCompare stochtestCompare = StochtestDbUtils.acceptNextWaitingStochtestCompare(conFactory);
    String biomodelXML = null;
    if (stochtestCompare != null) {
        try {
            StochtestRun stochtestRun1 = StochtestDbUtils.getStochtestRun(conFactory, stochtestCompare.stochtestRun1ref);
            StochtestRun stochtestRun2 = StochtestDbUtils.getStochtestRun(conFactory, stochtestCompare.stochtestRun2ref);
            if (stochtestRun1.status != StochtestRunStatus.complete) {
                throw new RuntimeException("incomplete run status found: " + stochtestRun1.status.name());
            }
            if (stochtestRun2.status != StochtestRunStatus.complete) {
                throw new RuntimeException("incomplete run status found: " + stochtestRun2.status.name());
            }
            TimeSeriesMultitrialData data1 = StochtestFileUtils.readData(StochtestFileUtils.getStochtestRunDataFile(baseDir, stochtestRun1));
            TimeSeriesMultitrialData data2 = StochtestFileUtils.readData(StochtestFileUtils.getStochtestRunDataFile(baseDir, stochtestRun2));
            SummaryStatistics results = TimeSeriesMultitrialData.statisticsSummary(data1, data2);
            XmlUtil.writeXMLStringToFile(results.results(), new File(baseDir, "stochtestcompare_" + stochtestCompare.key + "_summary.txt").getPath(), false);
            StochtestFileUtils.writeVarDiffData(new File(baseDir, "stochtestcompare_" + stochtestCompare.key + "_vardiff.csv"), data1, data2);
            StochtestFileUtils.writeKolmogorovSmirnovTest(new File(baseDir, "stochtestcompare_" + stochtestCompare.key + "_kolmogorovSmirnov.csv"), data1, data2);
            StochtestFileUtils.writeChiSquareTest(new File(baseDir, "stochtestcompare_" + stochtestCompare.key + "_chiSquared.csv"), data1, data2);
            StochtestCompareStatus status = (results.pass()) ? StochtestCompareStatus.not_verydifferent : StochtestCompareStatus.verydifferent;
            StochtestDbUtils.finalizeAcceptedStochtestCompare(conFactory, stochtestCompare, status, null, results);
        } catch (Exception e) {
            StochtestDbUtils.finalizeAcceptedStochtestCompare(conFactory, stochtestCompare, StochtestCompare.StochtestCompareStatus.failed, e.getMessage(), null);
            // 
            // write exception trace to .txt file
            // 
            StringWriter stringWriter = new StringWriter();
            PrintWriter printWriter = new PrintWriter(stringWriter);
            e.printStackTrace(printWriter);
            printWriter.flush();
            System.out.println(stringWriter.getBuffer().toString());
            XmlUtil.writeXMLStringToFile(stringWriter.getBuffer().toString(), new File(baseDir, "stochtestrun_" + stochtestCompare.key + "_error.txt").getPath(), false);
        }
    } else {
        System.out.println("no compare jobs waiting");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Also used : StochtestCompareStatus(org.vcell.stochtest.StochtestCompare.StochtestCompareStatus) StringWriter(java.io.StringWriter) SummaryStatistics(org.vcell.stochtest.TimeSeriesMultitrialData.SummaryStatistics) File(java.io.File) ImageException(cbit.image.ImageException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) PropertyVetoException(java.beans.PropertyVetoException) MappingException(cbit.vcell.mapping.MappingException) SQLException(java.sql.SQLException) GeometryException(cbit.vcell.geometry.GeometryException) XmlParseException(cbit.vcell.xml.XmlParseException) PrintWriter(java.io.PrintWriter)

Aggregations

ImageException (cbit.image.ImageException)1 GeometryException (cbit.vcell.geometry.GeometryException)1 MappingException (cbit.vcell.mapping.MappingException)1 ExpressionException (cbit.vcell.parser.ExpressionException)1 XmlParseException (cbit.vcell.xml.XmlParseException)1 PropertyVetoException (java.beans.PropertyVetoException)1 File (java.io.File)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 SQLException (java.sql.SQLException)1 StochtestCompareStatus (org.vcell.stochtest.StochtestCompare.StochtestCompareStatus)1 SummaryStatistics (org.vcell.stochtest.TimeSeriesMultitrialData.SummaryStatistics)1 DataAccessException (org.vcell.util.DataAccessException)1