Search in sources :

Example 1 with VCellModelSearchResults

use of org.vcell.imagej.helper.VCellHelper.VCellModelSearchResults in project vcell by virtualcell.

the class NikitaTest method run.

@Override
public void run() {
    try {
        // Find the port that a separately running VCell client is listening on
        System.out.println("vcell service port=" + vcellHelper.findVCellApiServerPort());
    } catch (Exception e) {
        uiService.showDialog("Activate VCell client ImageJ service\nTools->'Start Fiji (ImageJ) service'\n" + e.getMessage(), "Couldn't contact VCell client", MessageType.ERROR_MESSAGE);
        return;
    }
    String theCacheKey = null;
    VCellHelper.VCellModelSearch vcms = new VCellHelper.VCellModelSearch(VCellHelper.ModelType.valueOf(modelType), vCellUser, vCellModel, application, simulation, null, null);
    try {
        ArrayList<VCellModelSearchResults> vcmsr = vcellHelper.getSearchedModelSimCacheKey(false, vcms, null);
        if (vcmsr.size() == 0) {
            throw new Exception("No Results for search found");
        }
        theCacheKey = vcmsr.get(0).getCacheKey();
        System.out.println("theCacheKey=" + theCacheKey);
    } catch (Exception e) {
        uiService.showDialog(modelType + ", " + vCellUser + ", " + vCellModel + ", " + application + ", " + simulation + ", null, null\n" + e.getMessage(), "Search failed", MessageType.ERROR_MESSAGE);
        return;
    }
    IJDataList timePointData = null;
    // there is 1 timePoint
    int[] timePointIndexes = new int[1];
    int theTimePointIndex = 0;
    timePointIndexes[theTimePointIndex] = timePoint;
    try {
        timePointData = vcellHelper.getTimePointData(theCacheKey, variable, VARTYPE_POSTPROC.NotPostProcess, timePointIndexes, 0);
    } catch (Exception e) {
        uiService.showDialog(modelType + ", " + vCellUser + ", " + vCellModel + ", " + application + ", " + simulation + ", " + variable + ", " + timePoint + "\n" + e.getMessage(), "Get Data failed", MessageType.ERROR_MESSAGE);
        return;
    }
    double[] theTimePointData = timePointData.ijData[theTimePointIndex].getDoubleData();
    Range xAxisRange = null;
    int[] dataIndexes = new int[endIndex - startIndex + 1];
    // This is just for JFreeChart
    double[] dataIndexesDouble = new double[dataIndexes.length];
    for (int i = startIndex; i <= endIndex; i++) {
        dataIndexes[i - startIndex] = i;
        dataIndexesDouble[i - startIndex] = i;
        xAxisRange = Range.expandToInclude(xAxisRange, dataIndexesDouble[i - startIndex]);
    }
    Range yAxisRange = null;
    double[] chartTheseDataPoints = new double[dataIndexes.length];
    for (int i = 0; i < dataIndexes.length; i++) {
        chartTheseDataPoints[i] = theTimePointData[dataIndexes[i]];
        yAxisRange = Range.expandToInclude(yAxisRange, chartTheseDataPoints[i]);
    // ijTimeSeriesJobResults.data[0/*index of "r"*/][i+1/*data, skip 0 because it holds copy of times*/][0/*0 always because we had only 1 timePoint=22.0*/]
    }
    try {
        // LINE plot of data at 1 timePoint along defined indexes
        // Create JFreechart x,y axis arrays for plotting x=data indexes, y=dataPoint values
        double[][] data = new double[][] { dataIndexesDouble, chartTheseDataPoints };
        String title = "LINE Plot at time=" + timePoint;
        String xAxisLabel = "distance";
        String yAxisLabel = "val";
        DefaultXYDataset xyDataset = new DefaultXYDataset();
        xyDataset.addSeries("data1", data);
        JFreeChart chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, xyDataset, PlotOrientation.VERTICAL, false, false, false);
        // Y
        chart.getXYPlot().getDomainAxis().setRange(xAxisRange);
        // X
        chart.getXYPlot().getRangeAxis().setRange(yAxisRange);
        ChartPanel chartPanel = new ChartPanel(chart);
        JFrame frame = new JFrame("Chart");
        // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(chartPanel);
        // Display the window.
        frame.pack();
        frame.setVisible(true);
    } catch (Exception e) {
        uiService.showDialog("LINE PlotGet Data failed\n" + e.getMessage(), MessageType.ERROR_MESSAGE);
        return;
    }
    IJTimeSeriesJobResults timeSeries = null;
    try {
        IJVarInfos simulationInfo = vcellHelper.getSimulationInfo(theCacheKey);
        double[] times = simulationInfo.getTimes();
        timeSeries = vcellHelper.getTimeSeries(new String[] { variable }, new int[] { dataIndexes[0] }, times[0], 1, times[times.length - 1], false, false, 0, Integer.parseInt(theCacheKey));
    } catch (Exception e) {
        uiService.showDialog("TIME Plot Get Data failed\n" + e.getMessage(), MessageType.ERROR_MESSAGE);
        return;
    }
    try {
        // TIME plot of data at 1 timePoint along defined indexes
        // Create JFreechart x,y axis arrays for plotting x=data indexes, y=dataPoint values
        double[][] data = new double[][] { timeSeries.data[0][0], timeSeries.data[0][1] };
        String title = "TIME Plot at dataIndex=" + dataIndexes[0];
        String xAxisLabel = "time";
        String yAxisLabel = "val";
        DefaultXYDataset xyDataset = new DefaultXYDataset();
        xyDataset.addSeries("data1", data);
        JFreeChart chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, xyDataset, PlotOrientation.VERTICAL, false, false, false);
        // chart.getXYPlot().getDomainAxis().setRange(yAxisRange);//Y
        // chart.getXYPlot().getRangeAxis().setRange(xAxisRange);//X
        ChartPanel chartPanel = new ChartPanel(chart);
        JFrame frame = new JFrame("Chart");
        // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(chartPanel);
        // Display the window.
        frame.pack();
        frame.setVisible(true);
    } catch (Exception e) {
        uiService.showDialog("TIME Plot show chart failed\n" + e.getMessage(), MessageType.ERROR_MESSAGE);
        return;
    }
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) IJVarInfos(org.vcell.imagej.helper.VCellHelper.IJVarInfos) DefaultXYDataset(org.jfree.data.xy.DefaultXYDataset) VCellModelSearchResults(org.vcell.imagej.helper.VCellHelper.VCellModelSearchResults) Range(org.jfree.data.Range) VCellHelper(org.vcell.imagej.helper.VCellHelper) JFreeChart(org.jfree.chart.JFreeChart) JFrame(javax.swing.JFrame) IJDataList(org.vcell.imagej.helper.VCellHelper.IJDataList) IJTimeSeriesJobResults(org.vcell.imagej.helper.VCellHelper.IJTimeSeriesJobResults)

Example 2 with VCellModelSearchResults

use of org.vcell.imagej.helper.VCellHelper.VCellModelSearchResults in project vcell by virtualcell.

the class SmallCR method getSimulationCacheKey.

// public static void main(String[] args) {
// try {
// VCellHelper vh = new VCellHelper();
// ImageJ ij = new ImageJ();
// ij.ui().showUI();
// 
// ExampleDatasets exampleDatasets = openExample(ij, new File("C:\\Users\\frm\\VCellTrunkGitWorkspace2\\vcell\\vcell-imagej-helper")/*new File(System.getProperty("user.dir", "."))*/);
// int ANALYZE_BEGIN_TIMEINDEX = 3;
// int ANALYZE_END_TIMEINDEX = 8;
// int ANALYZE_COUNT = ANALYZE_END_TIMEINDEX - ANALYZE_BEGIN_TIMEINDEX +1;
// int xIndex = exampleDatasets.experimentalData.dimensionIndex(Axes.X);
// int xsize = (int)exampleDatasets.experimentalData.dimension(xIndex);
// int yIndex = exampleDatasets.experimentalData.dimensionIndex(Axes.Y);
// int ysize = (int)exampleDatasets.experimentalData.dimension(yIndex);
// FinalInterval analyzeOrigInterval = FinalInterval.createMinSize(new long[] {0,0,ANALYZE_BEGIN_TIMEINDEX, xsize,ysize,ANALYZE_COUNT});//xyzt:origin and xyzt:size
// int assumedZIndex = -1;
// for (int i = 0; i < exampleDatasets.segmentedGeom.numDimensions(); i++) {
// if(exampleDatasets.segmentedGeom.dimensionIndex(Axes.X)!=i && exampleDatasets.segmentedGeom.dimensionIndex(Axes.Y)!=i) {
// assumedZIndex = i;
// break;
// }
// }
// int zsize = (assumedZIndex == -1?1:(int)exampleDatasets.segmentedGeom.dimension(assumedZIndex));
// HashMap<Integer, String> segmentedGeomValuesMapSubvolumeName = new HashMap();
// segmentedGeomValuesMapSubvolumeName.put(0, "cyt");
// segmentedGeomValuesMapSubvolumeName.put(255, "Nuc");
// VCellHelper.IJGeom overrideGeom = createGeometry(exampleDatasets.segmentedGeom, xIndex, yIndex, assumedZIndex, xsize, ysize, zsize, segmentedGeomValuesMapSubvolumeName);
// double[] diffRates = new double[] {
// 1.25,
// 1.3,
// 1.4,
// 1.45,
// 1.5,
// 1.55,
// 1.6
// };
// double[] mse = new double[diffRates.length];
// for (int i = 0; i < diffRates.length; i++) {
// String simulationCacheKey = getSimulationCacheKey(vh);
// IJSolverStatus ijSolverStatus = runFrapSolver(vh, diffRates[i],simulationCacheKey,overrideGeom);
// String simulationDataCacheKey = waitForSolverGetCacheForData(vh, ijSolverStatus);
// SCIFIOImgPlus<DoubleType> annotatedZProjectedSimPostBleachData = zProjectNormalizeSimData(vh, "Sim Data "+diffRates[i], simulationDataCacheKey, "rf", 0, ijSolverStatus.getJobIndex(), ANALYZE_BEGIN_TIMEINDEX, ANALYZE_END_TIMEINDEX);
// showAndZoom(ij, "Sim Data "+diffRates[i], annotatedZProjectedSimPostBleachData, 4);
// mse[i] = calcMSE(ij, annotatedZProjectedSimPostBleachData,exampleDatasets,analyzeOrigInterval);
// }
// for(int i=0;i<mse.length;i++){
// System.out.println("diffRate="+diffRates[i]+" MSE="+(mse[i]));
// }
// 
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
public static String getSimulationCacheKey(VCellHelper vh) throws Exception {
    // User can search (with simple wildcard *=any) for VCell Model by:
    // model type {biomodel,mathmodel,quickrun}
    // user name
    // model name
    // application name (if searching for BioModels, not applicable for MathModels)
    // simulation name
    // version time range (all VCell Models saved on the VCell server have a last date 'saved')
    SimpleDateFormat easyDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    VCellHelper.VCellModelVersionTimeRange vcellModelVersionTimeRange = new VCellHelper.VCellModelVersionTimeRange(easyDate.parse("2018-06-01 00:00:00"), easyDate.parse("2018-08-01 00:00:00"));
    VCellHelper.VCellModelSearch search = new VCellHelper.VCellModelSearch(VCellHelper.ModelType.bm, "frm", "Tutorial_FRAPbinding", "Spatial", "FRAP binding", null, null);
    ArrayList<VCellModelSearchResults> vcellModelSearchResults = vh.getSearchedModelSimCacheKey(true, search, vcellModelVersionTimeRange);
    if (vcellModelSearchResults.size() != 1) {
        throw new Exception("Expecting only 1 model from search results");
    }
    String cacheKey = vcellModelSearchResults.get(0).getCacheKey();
    return cacheKey;
}
Also used : VCellModelSearchResults(org.vcell.imagej.helper.VCellHelper.VCellModelSearchResults) SimpleDateFormat(java.text.SimpleDateFormat) VCellHelper(org.vcell.imagej.helper.VCellHelper)

Example 3 with VCellModelSearchResults

use of org.vcell.imagej.helper.VCellHelper.VCellModelSearchResults in project vcell by virtualcell.

the class LinePlot method run.

@Override
public void run() {
    try {
        // Find the port that a separately running VCell client is listening on
        System.out.println("vcell service port=" + vcellHelper.findVCellApiServerPort());
    } catch (Exception e) {
        uiService.showDialog("Activate VCell client ImageJ service\nTools->'Start Fiji (ImageJ) service'\n" + e.getMessage(), "Couldn't contact VCell client", MessageType.ERROR_MESSAGE);
        return;
    }
    String theCacheKey = null;
    VCellHelper.VCellModelSearch vcms = new VCellHelper.VCellModelSearch(VCellHelper.ModelType.valueOf(modelType), vCellUser, vCellModel, application, simulation, null, null);
    try {
        ArrayList<VCellModelSearchResults> vcmsr = vcellHelper.getSearchedModelSimCacheKey(false, vcms, null);
        if (vcmsr.size() == 0) {
            throw new Exception("No Results for search found");
        }
        theCacheKey = vcmsr.get(0).getCacheKey();
        System.out.println("theCacheKey=" + theCacheKey);
    } catch (Exception e) {
        uiService.showDialog(modelType + ", " + vCellUser + ", " + vCellModel + ", " + application + ", " + simulation + ", null, null\n" + e.getMessage(), "Search failed", MessageType.ERROR_MESSAGE);
        return;
    }
    IJDataList timePointData = null;
    // there is 1 timePoint
    int[] timePointIndexes = new int[1];
    int theTimePointIndex = 0;
    timePointIndexes[theTimePointIndex] = timePoint;
    try {
        timePointData = vcellHelper.getTimePointData(theCacheKey, variable, VARTYPE_POSTPROC.NotPostProcess, timePointIndexes, 0);
    } catch (Exception e) {
        uiService.showDialog(modelType + ", " + vCellUser + ", " + vCellModel + ", " + application + ", " + simulation + ", " + variable + ", " + timePoint + "\n" + e.getMessage(), "Get Data failed", MessageType.ERROR_MESSAGE);
        return;
    }
    double[] theTimePointData = timePointData.ijData[theTimePointIndex].getDoubleData();
    Range xAxisRange = null;
    int[] dataIndexes = new int[endIndex - startIndex + 1];
    // This is just for JFreeChart
    double[] dataIndexesDouble = new double[dataIndexes.length];
    for (int i = startIndex; i <= endIndex; i++) {
        dataIndexes[i - startIndex] = i;
        dataIndexesDouble[i - startIndex] = i;
        xAxisRange = Range.expandToInclude(xAxisRange, dataIndexesDouble[i - startIndex]);
    }
    Range yAxisRange = null;
    double[] chartTheseDataPoints = new double[dataIndexes.length];
    for (int i = 0; i < dataIndexes.length; i++) {
        chartTheseDataPoints[i] = theTimePointData[dataIndexes[i]];
        yAxisRange = Range.expandToInclude(yAxisRange, chartTheseDataPoints[i]);
    // ijTimeSeriesJobResults.data[0/*index of "r"*/][i+1/*data, skip 0 because it holds copy of times*/][0/*0 always because we had only 1 timePoint=22.0*/]
    }
    try {
        // LINE plot of data at 1 timePoint along defined indexes
        // Create JFreechart x,y axis arrays for plotting x=data indexes, y=dataPoint values
        double[][] data = new double[][] { dataIndexesDouble, chartTheseDataPoints };
        String title = "LINE Plot at time=" + timePoint;
        String xAxisLabel = "distance";
        String yAxisLabel = "val";
        DefaultXYDataset xyDataset = new DefaultXYDataset();
        xyDataset.addSeries("data1", data);
        JFreeChart chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, xyDataset, PlotOrientation.VERTICAL, false, false, false);
        // Y
        chart.getXYPlot().getDomainAxis().setRange(xAxisRange);
        // X
        chart.getXYPlot().getRangeAxis().setRange(yAxisRange);
        ChartPanel chartPanel = new ChartPanel(chart);
        JFrame frame = new JFrame("Chart");
        // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(chartPanel);
        // Display the window.
        frame.pack();
        frame.setVisible(true);
    } catch (Exception e) {
        uiService.showDialog("LINE PlotGet Data failed\n" + e.getMessage(), MessageType.ERROR_MESSAGE);
        return;
    }
    IJTimeSeriesJobResults timeSeries = null;
    try {
        IJVarInfos simulationInfo = vcellHelper.getSimulationInfo(theCacheKey);
        double[] times = simulationInfo.getTimes();
        timeSeries = vcellHelper.getTimeSeries(new String[] { variable }, new int[] { dataIndexes[0] }, times[0], 1, times[times.length - 1], false, false, 0, Integer.parseInt(theCacheKey));
    } catch (Exception e) {
        uiService.showDialog("TIME Plot Get Data failed\n" + e.getMessage(), MessageType.ERROR_MESSAGE);
        return;
    }
    try {
        // TIME plot of data at 1 timePoint along defined indexes
        // Create JFreechart x,y axis arrays for plotting x=data indexes, y=dataPoint values
        double[][] data = new double[][] { timeSeries.data[0][0], timeSeries.data[0][1] };
        String title = "TIME Plot at dataIndex=" + dataIndexes[0];
        String xAxisLabel = "time";
        String yAxisLabel = "val";
        DefaultXYDataset xyDataset = new DefaultXYDataset();
        xyDataset.addSeries("data1", data);
        JFreeChart chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, xyDataset, PlotOrientation.VERTICAL, false, false, false);
        // chart.getXYPlot().getDomainAxis().setRange(yAxisRange);//Y
        // chart.getXYPlot().getRangeAxis().setRange(xAxisRange);//X
        ChartPanel chartPanel = new ChartPanel(chart);
        JFrame frame = new JFrame("Chart");
        // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(chartPanel);
        // Display the window.
        frame.pack();
        frame.setVisible(true);
    } catch (Exception e) {
        uiService.showDialog("TIME Plot show chart failed\n" + e.getMessage(), MessageType.ERROR_MESSAGE);
        return;
    }
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) IJVarInfos(org.vcell.imagej.helper.VCellHelper.IJVarInfos) DefaultXYDataset(org.jfree.data.xy.DefaultXYDataset) VCellModelSearchResults(org.vcell.imagej.helper.VCellHelper.VCellModelSearchResults) Range(org.jfree.data.Range) VCellHelper(org.vcell.imagej.helper.VCellHelper) JFreeChart(org.jfree.chart.JFreeChart) JFrame(javax.swing.JFrame) IJDataList(org.vcell.imagej.helper.VCellHelper.IJDataList) IJTimeSeriesJobResults(org.vcell.imagej.helper.VCellHelper.IJTimeSeriesJobResults)

Example 4 with VCellModelSearchResults

use of org.vcell.imagej.helper.VCellHelper.VCellModelSearchResults in project vcell by virtualcell.

the class ModelLoad method run.

@Override
public void run() {
    displayProgressBar(true, "Checking listening ports...", "Checking for VCell Client");
    startJProgressThread0(null, "Check");
    try {
        // Find the port that a separately running VCell client is listening on
        // 
        System.out.println("vcell service port=" + vcellHelper.findVCellApiServerPort());
        // uiService.getDisplayViewer(textDisplay).dispose();
        displayProgressBar(false, null, null);
    } catch (Exception e) {
        // e.printStackTrace();
        displayProgressBar(false, null, null);
        // uiService.getDisplayViewer(textDisplay).dispose();
        uiService.showDialog("Activate VCell client ImageJ service\nTools->'Start Fiji (ImageJ) service'\n" + e.getMessage(), "Couldn't contact VCell client", MessageType.ERROR_MESSAGE);
        return;
    }
    displayProgressBar(true, "Searching...", "Searching VCell Models");
    startJProgressThread0("Check", "Search");
    String theCacheKey = null;
    VCellHelper.VCellModelSearch vcms = new VCellHelper.VCellModelSearch(VCellHelper.ModelType.bm, vCellUser, vCellModel, application, simulation, null, null);
    try {
        ArrayList<VCellModelSearchResults> vcmsr = vcellHelper.getSearchedModelSimCacheKey(false, vcms, null);
        if (vcmsr.size() == 0) {
            throw new Exception("No Results for search found");
        }
        theCacheKey = vcmsr.get(0).getCacheKey();
        System.out.println("theCacheKey=" + theCacheKey);
        displayProgressBar(false, null, null);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        // e.printStackTrace();
        uiService.showDialog("VCellHelper.ModelType.bm,vCellUser,vCellModel,application,simulation,null,null\n" + e.getMessage(), "Search failed", MessageType.ERROR_MESSAGE);
        displayProgressBar(false, null, null);
    }
    displayProgressBar(true, "Loading Data...", "Loading Data");
    startJProgressThread0("Search", "getTimePointData");
    try {
        String var = variable;
        int[] time = new int[] { timePoint };
        IJDataList tpd = vcellHelper.getTimePointData(theCacheKey, var, VCellHelper.VARTYPE_POSTPROC.NotPostProcess, time, 0);
        double[] data = tpd.ijData[0].getDoubleData();
        BasicStackDimensions bsd = tpd.ijData[0].stackInfo;
        System.out.println(bsd.xsize + " " + bsd.ysize);
        ArrayImg<DoubleType, DoubleArray> testimg = ArrayImgs.doubles(data, bsd.xsize, bsd.ysize);
        uiService.show(testimg);
        displayProgressBar(false, null, null);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        // e.printStackTrace();
        uiService.showDialog("theCacheKey,var,VCellHelper.VARTYPE_POSTPROC.NotPostProcess,time,0\n" + e.getMessage(), "getTimePoint(...) failed", MessageType.ERROR_MESSAGE);
        displayProgressBar(false, null, null);
    }
    startJProgressThread0("getTimePointData", null);
}
Also used : VCellModelSearchResults(org.vcell.imagej.helper.VCellHelper.VCellModelSearchResults) VCellHelper(org.vcell.imagej.helper.VCellHelper) DoubleType(net.imglib2.type.numeric.real.DoubleType) IJDataList(org.vcell.imagej.helper.VCellHelper.IJDataList) BasicStackDimensions(org.vcell.imagej.helper.VCellHelper.BasicStackDimensions) DoubleArray(net.imglib2.img.basictypeaccess.array.DoubleArray)

Aggregations

VCellHelper (org.vcell.imagej.helper.VCellHelper)4 VCellModelSearchResults (org.vcell.imagej.helper.VCellHelper.VCellModelSearchResults)4 IJDataList (org.vcell.imagej.helper.VCellHelper.IJDataList)3 JFrame (javax.swing.JFrame)2 ChartPanel (org.jfree.chart.ChartPanel)2 JFreeChart (org.jfree.chart.JFreeChart)2 Range (org.jfree.data.Range)2 DefaultXYDataset (org.jfree.data.xy.DefaultXYDataset)2 IJTimeSeriesJobResults (org.vcell.imagej.helper.VCellHelper.IJTimeSeriesJobResults)2 IJVarInfos (org.vcell.imagej.helper.VCellHelper.IJVarInfos)2 SimpleDateFormat (java.text.SimpleDateFormat)1 DoubleArray (net.imglib2.img.basictypeaccess.array.DoubleArray)1 DoubleType (net.imglib2.type.numeric.real.DoubleType)1 BasicStackDimensions (org.vcell.imagej.helper.VCellHelper.BasicStackDimensions)1