Search in sources :

Example 11 with ReferenceData

use of cbit.vcell.opt.ReferenceData in project vcell by virtualcell.

the class FRAPEstimationPanel_NotUsed method displayFit.

private void displayFit(FrapDataAnalysisResults.DiffusionOnlyAnalysisRestults diffAnalysisResults, double[] frapDataTimeStamps, int startIndexForRecovery) {
    if (diffAnalysisResults == null) {
        FRAPParameterEstimateEnum.DIFFUSION_RATE.value = null;
        FRAPParameterEstimateEnum.MOBILE_FRACTION.value = null;
        FRAPParameterEstimateEnum.IMMOBILE_FRATION.value = null;
        FRAPParameterEstimateEnum.START_TIME_RECOVERY.value = null;
        FRAPParameterEstimateEnum.BLEACH_RATE_MONITOR.value = null;
        multisourcePlotPane.setDataSources(null);
    } else {
        FRAPParameterEstimateEnum.DIFFUSION_RATE.value = (diffAnalysisResults.getRecoveryDiffusionRate() == null ? null : diffAnalysisResults.getRecoveryDiffusionRate());
        FRAPParameterEstimateEnum.MOBILE_FRACTION.value = (diffAnalysisResults.getMobilefraction() == null ? null : diffAnalysisResults.getMobilefraction());
        FRAPParameterEstimateEnum.IMMOBILE_FRATION.value = (FRAPParameterEstimateEnum.MOBILE_FRACTION.value == null ? null : 1.0 - FRAPParameterEstimateEnum.MOBILE_FRACTION.value);
        FRAPParameterEstimateEnum.BLEACH_RATE_MONITOR.value = (diffAnalysisResults.getBleachWhileMonitoringTau() == null ? null : diffAnalysisResults.getBleachWhileMonitoringTau());
        // int startIndexForRecovery = FRAPDataAnalysis.getRecoveryIndex(initFRAPData);
        // 
        // Experiment - Cell ROI Average
        // 
        double[] temp_background = initFRAPData.getAvgBackGroundIntensity();
        double[] preBleachAvgXYZ = FrapDataUtils.calculatePreBleachAverageXYZ(initFRAPData, startIndexForRecovery);
        double[] cellRegionData = FRAPDataAnalysis.getAverageROIIntensity(initFRAPData, initFRAPData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()), preBleachAvgXYZ, temp_background);
        ReferenceData expCellAvgData = new SimpleReferenceData(new String[] { "t", "CellROIAvg" }, new double[] { 1.0, 1.0 }, new double[][] { frapDataTimeStamps, cellRegionData });
        DataSource expCellAvgDataSource = new DataSource.DataSourceReferenceData("expCellAvg", expCellAvgData);
        // 
        // Analytic - Cell ROI Average with Bleach while monitor
        // 
        ODESolverResultSet bleachWhileMonitorOdeSolverResultSet = new ODESolverResultSet();
        bleachWhileMonitorOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription("t"));
        try {
            bleachWhileMonitorOdeSolverResultSet.addFunctionColumn(new FunctionColumnDescription(diffAnalysisResults.getFitBleachWhileMonitorExpression(), "CellROI_BleachWhileMonitor", null, "bleachWhileMonitorFit", true));
        } catch (ExpressionException e) {
            e.printStackTrace();
        }
        for (int i = startIndexForRecovery; i < frapDataTimeStamps.length; i++) {
            bleachWhileMonitorOdeSolverResultSet.addRow(new double[] { frapDataTimeStamps[i] });
        }
        // 
        // extend if necessary to plot theoretical curve to 4*tau
        // 
        {
            double T = frapDataTimeStamps[frapDataTimeStamps.length - 1];
            double deltaT = frapDataTimeStamps[frapDataTimeStamps.length - 1] - frapDataTimeStamps[frapDataTimeStamps.length - 2];
            while (T + deltaT < 6 * diffAnalysisResults.getRecoveryTau()) {
                bleachWhileMonitorOdeSolverResultSet.addRow(new double[] { T });
                T += deltaT;
            }
        }
        DataSource bleachWhileMonitorDataSource = new DataSource.DataSourceRowColumnResultSet("bleachwm", bleachWhileMonitorOdeSolverResultSet);
        // Recovery curve
        double[] bleachRegionData = FRAPDataAnalysis.getAverageROIIntensity(initFRAPData, initFRAPData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name()), preBleachAvgXYZ, temp_background);
        ;
        ReferenceData expRefData = new SimpleReferenceData(new String[] { "t", "BleachROIAvg" }, new double[] { 1.0, 1.0 }, new double[][] { frapDataTimeStamps, bleachRegionData });
        DataSource expDataSource = new DataSource.DataSourceReferenceData("experiment", expRefData);
        ODESolverResultSet fitOdeSolverResultSet = new ODESolverResultSet();
        fitOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription("t"));
        try {
            fitOdeSolverResultSet.addFunctionColumn(new FunctionColumnDescription(diffAnalysisResults.getDiffFitExpression(), // "('"+FrapDataAnalysisResults.BLEACH_TYPE_NAMES[bleachEstimationComboBox.getSelectedIndex()]+"')",
            "BleachROI_Recovery", null, "recoveryFit", true));
        } catch (ExpressionException e) {
            e.printStackTrace();
        }
        for (int i = startIndexForRecovery; i < frapDataTimeStamps.length; i++) {
            fitOdeSolverResultSet.addRow(new double[] { frapDataTimeStamps[i] });
        }
        // 
        // extend if necessary to plot theoretical curve to 4*tau
        // 
        double T = frapDataTimeStamps[frapDataTimeStamps.length - 1];
        double deltaT = frapDataTimeStamps[frapDataTimeStamps.length - 1] - frapDataTimeStamps[frapDataTimeStamps.length - 2];
        while (T + deltaT < 6 * diffAnalysisResults.getRecoveryTau()) {
            fitOdeSolverResultSet.addRow(new double[] { T });
            T += deltaT;
        }
        DataSource fitDataSource = new DataSource.DataSourceRowColumnResultSet("fit", fitOdeSolverResultSet);
        multisourcePlotPane.setDataSources(new DataSource[] { expDataSource, fitDataSource, expCellAvgDataSource, bleachWhileMonitorDataSource });
        multisourcePlotPane.selectAll();
    }
    table.repaint();
}
Also used : SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ReferenceData(cbit.vcell.opt.ReferenceData) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) FunctionColumnDescription(cbit.vcell.math.FunctionColumnDescription) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ExpressionException(cbit.vcell.parser.ExpressionException) DataSource(cbit.vcell.modelopt.DataSource)

Example 12 with ReferenceData

use of cbit.vcell.opt.ReferenceData in project vcell by virtualcell.

the class EstParams_ReactionOffRatePanel method displayResults.

private void displayResults(FRAPData frapData, int startIndexRecovery) throws ExpressionException, DivideByZeroException {
    Parameter[] currentParams = offRateParamPanel.getCurrentParameters();
    if (frapData == null || currentParams == null) {
        multisourcePlotPane.setDataSources(null);
    } else {
        double[] frapDataTimeStamps = frapData.getImageDataset().getImageTimeStamps();
        // Experiment - Cell ROI Average
        double[] temp_background = frapData.getAvgBackGroundIntensity();
        double[] preBleachAvgXYZ = FrapDataUtils.calculatePreBleachAverageXYZ(frapData, startIndexRecovery);
        /*double[] cellRegionData = FRAPDataAnalysis.getAverageROIIntensity(frapData, frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()),preBleachAvgXYZ,temp_background);
			ReferenceData expCellAvgData = new SimpleReferenceData(new String[] { ReservedSymbol.TIME.getName(), "CellROIAvg" }, new double[] { 1.0, 1.0 }, new double[][] {frapDataTimeStamps, cellRegionData });
			DataSource expCellAvgDataSource = new DataSource.DataSourceReferenceData("exp", expCellAvgData);
			//Analytic - Cell ROI Average with Bleach while monitor
			ODESolverResultSet bleachWhileMonitorOdeSolverResultSet = new ODESolverResultSet();
			bleachWhileMonitorOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(ReservedSymbol.TIME.getName()));
			Expression cellAvgExp = new Expression(FRAPOptFunctions.FUNC_CELL_INTENSITY);
			// substitute parameter values 
			cellAvgExp.substituteInPlace(new Expression(FRAPOptFunctions.SYMBOL_I_inicell), new Expression(cellRegionData[startIndexRecovery]));
			cellAvgExp.substituteInPlace(new Expression(FRAPOptFunctions.SYMBOL_BWM_RATE), new Expression(currentParams[FRAPModel.INDEX_BLEACH_MONITOR_RATE].getInitialGuess()));
			// time shift
			cellAvgExp.substituteInPlace(new Expression(ReservedSymbol.TIME.getName()), new Expression(ReservedSymbol.TIME.getName()+"-"+frapDataTimeStamps[startIndexRecovery]));
			try {
				bleachWhileMonitorOdeSolverResultSet.addFunctionColumn(
					new FunctionColumnDescription(
						cellAvgExp,
						"CellROIAvg",
						null,"bleachWhileMonitorFit",true));
			} catch (ExpressionException e) {
				e.printStackTrace();
			}
			for (int i = startIndexRecovery; i < frapDataTimeStamps.length; i++) 
			{
				bleachWhileMonitorOdeSolverResultSet.addRow(new double[] { frapDataTimeStamps[i] });
			}
			DataSource bleachWhileMonitorDataSource = new DataSource.DataSourceOdeSolverResultSet("fit", bleachWhileMonitorOdeSolverResultSet);*/
        // experimental bleach region average intensity curve
        double[] bleachRegionData = FRAPDataAnalysis.getAverageROIIntensity(frapData, frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name()), preBleachAvgXYZ, temp_background);
        ;
        ReferenceData expRefData = new SimpleReferenceData(new String[] { ReservedVariable.TIME.getName(), "BleachROIAvg" }, new double[] { 1.0, 1.0 }, new double[][] { frapDataTimeStamps, bleachRegionData });
        DataSource expBleachDataSource = new DataSource.DataSourceReferenceData("exp", expRefData);
        // Analytic - bleach region average intensity with bleach while monitoring rate
        ODESolverResultSet koffFitOdeSolverResultSet = new ODESolverResultSet();
        koffFitOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(ReservedVariable.TIME.getName()));
        Expression bleachedAvgExp = frapWorkspace.getWorkingFrapStudy().getFrapOptFunc().getRecoveryExpressionWithCurrentParameters(currentParams);
        try {
            koffFitOdeSolverResultSet.addFunctionColumn(new FunctionColumnDescription(bleachedAvgExp, "BleachROIAvg", null, "recoveryFit", true));
        } catch (ExpressionException e) {
            e.printStackTrace();
        }
        double[] truncatedTimes = new double[frapDataTimeStamps.length - startIndexRecovery];
        for (int i = startIndexRecovery; i < frapDataTimeStamps.length; i++) {
            koffFitOdeSolverResultSet.addRow(new double[] { frapDataTimeStamps[i] });
            truncatedTimes[i - startIndexRecovery] = frapDataTimeStamps[i];
        }
        setCurrentEstimationResults(frapWorkspace.getWorkingFrapStudy().getFrapOptFunc().createData(bleachedAvgExp.flatten(), truncatedTimes));
        DataSource koffFitDataSource = new DataSource.DataSourceRowColumnResultSet("fit", koffFitOdeSolverResultSet);
        multisourcePlotPane.setDataSources(new DataSource[] { expBleachDataSource, koffFitDataSource /*, expCellAvgDataSource , bleachWhileMonitorDataSource*/
        });
        multisourcePlotPane.selectAll();
    }
}
Also used : SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ExpressionException(cbit.vcell.parser.ExpressionException) DataSource(cbit.vcell.modelopt.DataSource) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ReferenceData(cbit.vcell.opt.ReferenceData) Expression(cbit.vcell.parser.Expression) Parameter(cbit.vcell.opt.Parameter) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) FunctionColumnDescription(cbit.vcell.math.FunctionColumnDescription)

Example 13 with ReferenceData

use of cbit.vcell.opt.ReferenceData in project vcell by virtualcell.

the class ReferenceDataPanel method showEditor.

/**
 * Comment
 */
private void showEditor() {
    ReferenceData referenceData = fieldParameterEstimationTask.getModelOptimizationSpec().getReferenceData();
    if (referenceData != null) {
        geteditorTextArea().setText(((SimpleReferenceData) referenceData).getCSV());
    } else {
        geteditorTextArea().setText("t, data1, data2\n0.0, 0.1, 0.21\n0.1, 0.15, 0.31\n0.2, 0.16, 0.44");
    }
    geteditorTextArea().setCaretPosition(0);
    try {
        int retVal = DialogUtils.showComponentOKCancelDialog(this, geteditorPanel(), "time series data editor");
        if (retVal == javax.swing.JOptionPane.OK_OPTION) {
            RowColumnResultSet rc = (new CSV()).importFrom(new java.io.StringReader(geteditorTextArea().getText()));
            double[] weights = new double[rc.getDataColumnCount()];
            java.util.Arrays.fill(weights, 1.0);
            SimpleReferenceData simpleRefData = new SimpleReferenceData(rc, weights);
            updateReferenceData(simpleRefData);
        }
    } catch (ParseException e) {
        e.printStackTrace();
        showHelp(e);
    } catch (Exception e) {
        e.printStackTrace(System.out);
        DialogUtils.showErrorDialog(this, e.getMessage(), e);
    }
}
Also used : SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ReferenceData(cbit.vcell.opt.ReferenceData) CSV(cbit.vcell.math.CSV) ParseException(java.text.ParseException) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ParseException(java.text.ParseException) UserCancelException(org.vcell.util.UserCancelException) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet)

Example 14 with ReferenceData

use of cbit.vcell.opt.ReferenceData in project vcell by virtualcell.

the class SpatialAnalysisResults method createSummaryReportSourceData.

// This function put exp data and sim data in a hashtable, the key is analysisParameters(right now only 1)
public Hashtable<AnalysisParameters, DataSource[]> createSummaryReportSourceData(final double[] frapDataTimeStamps, int startIndexForRecovery, boolean[] selecredROIs, boolean isSimData) throws Exception {
    Hashtable<AnalysisParameters, DataSource[]> allDataHash = new Hashtable<AnalysisParameters, DataSource[]>();
    Hashtable<CurveInfo, double[]> ROIInfoHash = curveHash;
    Set<CurveInfo> roiInfoSet = ROIInfoHash.keySet();
    Iterator<CurveInfo> roiInfoIter = roiInfoSet.iterator();
    // exp data are stored by ROI type.
    Hashtable<String, double[]> expROIData = new Hashtable<String, double[]>();
    // sim data are stored by AnalysisParameters and then by ROI type.
    Hashtable<AnalysisParameters, Hashtable<String, double[]>> simROIData = new Hashtable<AnalysisParameters, Hashtable<String, double[]>>();
    int roiCount = 0;
    // how many set of parameters are used for sim. 1 for now.
    int analysisParametersCount = 0;
    while (roiInfoIter.hasNext()) {
        CurveInfo roiCurveInfo = roiInfoIter.next();
        if (roiCurveInfo.isExperimentInfo()) {
            expROIData.put(roiCurveInfo.getROIName(), ROIInfoHash.get(roiCurveInfo));
            roiCount++;
        } else {
            Hashtable<String, double[]> simROIDataHash = simROIData.get(roiCurveInfo.getAnalysisParameters());
            if (simROIDataHash == null) {
                simROIDataHash = new Hashtable<String, double[]>();
                simROIData.put(roiCurveInfo.getAnalysisParameters(), simROIDataHash);
                analysisParametersCount++;
            }
            simROIDataHash.put(roiCurveInfo.getROIName(), ROIInfoHash.get(roiCurveInfo));
        }
    }
    // this is for exp data. each row of reference data contains time + intensities under 9 ROIs(bleached + ring1..8). totally 10 cols for each row.
    ReferenceData referenceData = createReferenceData(frapDataTimeStamps, startIndexForRecovery, "", selecredROIs);
    // loop only 1 time, right now the analysisParameters[]'s length is 1.
    for (int analysisParametersRow = 0; analysisParametersRow < analysisParametersCount; analysisParametersRow++) {
        AnalysisParameters currentAnalysisParameters = analysisParameters[analysisParametersRow];
        DataSource[] newDataSourceArr = new DataSource[2];
        // rows for time points and cols for t + roibleached + ring1--8 (10 cols)
        final DataSource expDataSource = new DataSource.DataSourceReferenceData("exp", referenceData);
        newDataSourceArr[ARRAY_INDEX_EXPDATASOURCE] = expDataSource;
        DataSource simDataSource = null;
        if (isSimData) {
            ODESolverResultSet odeSolverResultSet = createODESolverResultSet(currentAnalysisParameters, null, "");
            // rows for time points and cols for t + roibleached + ring1--8 (10 cols)
            simDataSource = new DataSource.DataSourceRowColumnResultSet("sim", odeSolverResultSet);
        }
        newDataSourceArr[ARRAY_INDEX_SIMDATASOURCE] = simDataSource;
        allDataHash.put(currentAnalysisParameters, newDataSourceArr);
    }
    return allDataHash;
}
Also used : Hashtable(java.util.Hashtable) DataSource(cbit.vcell.modelopt.DataSource) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ReferenceData(cbit.vcell.opt.ReferenceData) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet)

Example 15 with ReferenceData

use of cbit.vcell.opt.ReferenceData in project vcell by virtualcell.

the class SpatialAnalysisResults method createSummaryReportTableData.

public Object[][] createSummaryReportTableData(double[] frapDataTimeStamps, int startTimeIndex) {
    String[] summaryReportColumnNames = SpatialAnalysisResults.getSummaryReportColumnNames();
    final Object[][] tableData = new Object[analysisParameters.length][summaryReportColumnNames.length];
    for (int analysisParametersRow = 0; analysisParametersRow < analysisParameters.length; analysisParametersRow++) {
        AnalysisParameters currentAnalysisParameters = analysisParameters[analysisParametersRow];
        for (int roiColumn = 0; roiColumn < SpatialAnalysisResults.ORDERED_ROINAMES.length; roiColumn++) {
            ODESolverResultSet simDataSource = createODESolverResultSet(currentAnalysisParameters, SpatialAnalysisResults.ORDERED_ROINAMES[roiColumn], "");
            ReferenceData expDataSource = // TODO to remove null to put SpatialAnalysisResults.ORDERED_ROINAMES[roiColumn]
            createReferenceData(frapDataTimeStamps, startTimeIndex, "", null);
            int numSamples = expDataSource.getNumDataRows();
            double sumSquaredError = MathTestingUtilities.calcWeightedSquaredError(simDataSource, expDataSource);
            tableData[analysisParametersRow][roiColumn + ANALYSISPARAMETERS_COLUMNS_COUNT] = // unbiased estimator is numsamples-1
            Math.sqrt(sumSquaredError) / (numSamples - 1);
        }
    }
    return tableData;
}
Also used : SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ReferenceData(cbit.vcell.opt.ReferenceData) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet)

Aggregations

ReferenceData (cbit.vcell.opt.ReferenceData)17 SimpleReferenceData (cbit.vcell.opt.SimpleReferenceData)13 ODESolverResultSet (cbit.vcell.solver.ode.ODESolverResultSet)8 DataSource (cbit.vcell.modelopt.DataSource)6 ExpressionException (cbit.vcell.parser.ExpressionException)5 ODESolverResultSetColumnDescription (cbit.vcell.math.ODESolverResultSetColumnDescription)4 RowColumnResultSet (cbit.vcell.math.RowColumnResultSet)4 Variable (cbit.vcell.math.Variable)3 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)3 ParseException (java.text.ParseException)3 Vector (java.util.Vector)3 Element (org.jdom.Element)3 UserCancelException (org.vcell.util.UserCancelException)3 MappingException (cbit.vcell.mapping.MappingException)2 CSV (cbit.vcell.math.CSV)2 Constant (cbit.vcell.math.Constant)2 FunctionColumnDescription (cbit.vcell.math.FunctionColumnDescription)2 MathException (cbit.vcell.math.MathException)2 ParameterVariable (cbit.vcell.math.ParameterVariable)2 MatrixException (cbit.vcell.matrix.MatrixException)2