Search in sources :

Example 36 with Parameter

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

the class FRAPParamTest method runProfileLikelihood.

public void runProfileLikelihood() {
    String errorMsg = checkFrapStudyValidity();
    if (!errorMsg.equals("")) {
        System.out.println("Application terminated due to " + errorMsg);
        System.exit(1);
    } else {
        try {
            ClientTaskStatusSupport ctss = new ClientTaskStatusSupport() {

                public void setProgress(int progress) {
                    System.out.println(progress);
                }

                public void setMessage(String message) {
                    System.out.println(message);
                }

                public boolean isInterrupted() {
                    // TODO Auto-generated method stub
                    return false;
                }

                public int getProgress() {
                    // TODO Auto-generated method stub
                    return 0;
                }

                public void addProgressDialogListener(ProgressDialogListener progressDialogListener) {
                    throw new RuntimeException("not yet implemented");
                }
            };
            // get startign index
            if (frapStudy.getStartingIndexForRecovery() == null) {
                int index = FRAPDataAnalysis.calculateRecoveryIndex(frapStudy.getFrapData());
                frapStudy.setStartingIndexForRecovery(index);
            }
            // get dependent rois
            if (frapStudy.getFrapData().getRois().length < 4) {
                frapStudy.refreshDependentROIs();
            }
            // get selected ROIs
            if (frapStudy.getSelectedROIsForErrorCalculation() == null) {
                boolean[] selectedROIs = new boolean[FRAPData.VFRAP_ROI_ENUM.values().length];
                int counter = 0;
                for (FRAPData.VFRAP_ROI_ENUM roiEnum : FRAPData.VFRAP_ROI_ENUM.values()) {
                    if (roiEnum.name().equals(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()) || roiEnum.name().equals(FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name())) {
                        counter++;
                        continue;
                    }
                    if (frapStudy.getFrapData().getRoi(roiEnum.name()).getNonzeroPixelsCount() > 0) {
                        selectedROIs[counter] = true;
                        counter++;
                    }
                }
                frapStudy.setSelectedROIsForErrorCalculation(selectedROIs);
            }
            // get frap opt data
            if (frapStudy.getFrapOptData() == null) {
                if (!FRAPWorkspace.areExternalDataOK(getLocalWorkspace(), frapStudy.getFrapDataExternalDataInfo(), frapStudy.getRoiExternalDataInfo())) {
                    // if external files are missing/currupt or ROIs are changed, create keys and save them
                    frapStudy.setFrapDataExternalDataInfo(FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.IMAGE_EXTDATA_NAME));
                    frapStudy.setRoiExternalDataInfo(FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.ROI_EXTDATA_NAME));
                    frapStudy.saveROIsAsExternalData(localWorkspace, frapStudy.getRoiExternalDataInfo().getExternalDataIdentifier(), frapStudy.getStartingIndexForRecovery());
                    frapStudy.saveImageDatasetAsExternalData(localWorkspace, frapStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier(), frapStudy.getStartingIndexForRecovery());
                }
                // run ref sim
                frapStudy.setFrapOptData(new FRAPOptData(frapStudy, FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF, localWorkspace, ctss));
            }
            FRAPOptData optData = frapStudy.getFrapOptData();
            // create frapModels
            if (frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT] == null) {
                frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT] = new FRAPModel(FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT], null, null, null);
                if (frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters() == null) {
                    frapStudy.getFrapOptData().setNumEstimatedParams(FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF);
                    Parameter[] initialParams = FRAPModel.getInitialParameters(frapStudy.getFrapData(), FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT], frapStudy.getStartingIndexForRecovery());
                    Parameter[] bestParameters = frapStudy.getFrapOptData().getBestParamters(initialParams, frapStudy.getSelectedROIsForErrorCalculation());
                    frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].setModelParameters(bestParameters);
                }
            }
            if (frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS] == null) {
                frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS] = new FRAPModel(FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS], null, null, null);
                if (frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters() == null) {
                    frapStudy.getFrapOptData().setNumEstimatedParams(FRAPModel.NUM_MODEL_PARAMETERS_TWO_DIFF);
                    Parameter[] initialParams = FRAPModel.getInitialParameters(frapStudy.getFrapData(), FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS], frapStudy.getStartingIndexForRecovery());
                    Parameter[] bestParameters = frapStudy.getFrapOptData().getBestParamters(initialParams, frapStudy.getSelectedROIsForErrorCalculation());
                    frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].setModelParameters(bestParameters);
                }
            }
            // try diffusion with one diffusing component model
            System.out.println("Evaluating parameters in diffusion with one diffusing compoent model...");
            Parameter[] bestParameters = frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters();
            ProfileData[] profileData = optData.evaluateParameters(bestParameters, ctss);
            // output profile likelihood
            File outputDir_oneComponent = new File(getLocalWorkspace().getDefaultWorkspaceDirectory() + SUB_DIRECTORY + "OneComponent_SAVED_AT_" + BeanUtils.generateDateTimeString() + System.getProperty("file.separator"));
            if (!outputDir_oneComponent.exists()) {
                outputDir_oneComponent.mkdirs();
            }
            for (int i = 0; i < profileData.length; i++) {
                ProfileDataElement profileDataElement = profileData[i].getProfileDataElements().get(0);
                outputProfileLikelihood(profileData[i].getProfileDataElements(), profileDataElement.getParamName(), outputDir_oneComponent);
            }
            // try diffusion with two diffusing components model
            System.out.println("Evaluating parameters in diffusion with two diffusing compoents model...");
            bestParameters = frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters();
            profileData = optData.evaluateParameters(bestParameters, ctss);
            // output profile likelihood
            File outputDir_twoComponents = new File(getLocalWorkspace().getDefaultWorkspaceDirectory() + SUB_DIRECTORY + "TwoComponents_SAVED_AT_" + BeanUtils.generateDateTimeString() + System.getProperty("file.separator"));
            if (!outputDir_twoComponents.exists()) {
                outputDir_twoComponents.mkdirs();
            }
            for (int i = 0; i < profileData.length; i++) {
                ProfileDataElement profileDataElement = profileData[i].getProfileDataElements().get(0);
                outputProfileLikelihood(profileData[i].getProfileDataElements(), profileDataElement.getParamName(), outputDir_twoComponents);
            }
        } catch (Exception e) {
            e.printStackTrace(System.out);
            System.exit(1);
        }
    }
}
Also used : ProfileData(org.vcell.optimization.ProfileData) Point(java.awt.Point) IOException(java.io.IOException) ProgressDialogListener(org.vcell.util.ProgressDialogListener) ProfileDataElement(org.vcell.optimization.ProfileDataElement) ClientTaskStatusSupport(org.vcell.util.ClientTaskStatusSupport) Parameter(cbit.vcell.opt.Parameter) File(java.io.File)

Example 37 with Parameter

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

the class FRAPParamTest method outputProfileLikelihood.

private void outputProfileLikelihood(ArrayList<ProfileDataElement> arg_profileData, String fixedParamName, File outputDir) {
    try {
        System.out.println("Writing profile likelihood...");
        // output results
        String outFileName = outputDir.getAbsolutePath() + "\\" + fixedParamName + "_profileLikelihood" + ".txt";
        File outFile = new File(outFileName);
        FileWriter fstream = new FileWriter(outFile);
        BufferedWriter out = new BufferedWriter(fstream);
        // output profile
        for (int i = 0; i < arg_profileData.size(); i++) {
            out.newLine();
            String rowStr = arg_profileData.get(i).getParameterValue() + "\t" + arg_profileData.get(i).getLikelihood();
            Parameter[] params = arg_profileData.get(i).getBestParameters();
            rowStr = rowStr + "\t";
            for (int j = 0; j < params.length; j++) {
                rowStr = rowStr + "\t" + params[j].getInitialGuess();
            }
            out.write(rowStr);
        }
        out.close();
        System.out.println("Output is done. Restults saved to " + outFileName);
    } catch (IOException e) {
        e.printStackTrace(System.out);
    }
}
Also used : FileWriter(java.io.FileWriter) Parameter(cbit.vcell.opt.Parameter) IOException(java.io.IOException) File(java.io.File) Point(java.awt.Point) BufferedWriter(java.io.BufferedWriter)

Example 38 with Parameter

use of cbit.vcell.opt.Parameter 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 39 with Parameter

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

the class EstParams_TwoDiffComponentDescriptor method aboutToDisplayPanel.

public void aboutToDisplayPanel() {
    FRAPStudy fStudy = frapWorkspace.getWorkingFrapStudy();
    Parameter[] params = fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters();
    try {
        if (params == null) {
            params = FRAPModel.getInitialParameters(fStudy.getFrapData(), FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS], fStudy.getStartingIndexForRecovery());
        }
        ((EstParams_TwoDiffComponentPanel) getPanelComponent()).setData(fStudy.getFrapOptData(), fStudy.getFrapData(), params, fStudy.getFrapData().getImageDataset().getImageTimeStamps(), fStudy.getStartingIndexForRecovery(), fStudy.getSelectedROIsForErrorCalculation());
    } catch (Exception ex) {
        ex.printStackTrace(System.out);
        DialogUtils.showErrorDialog((getPanelComponent()), "Error getting parameters for diffusion with one diffusing component model.");
    }
}
Also used : FRAPStudy(cbit.vcell.microscopy.FRAPStudy) Parameter(cbit.vcell.opt.Parameter)

Example 40 with Parameter

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

the class FRAPDiffOneParamPanel method createParameterArray.

private static Parameter[] createParameterArray(double diffusionRate, double mobileFraction, double monitorBleachRate) {
    Parameter[] params = null;
    Parameter diff = new Parameter(FRAPModel.MODEL_PARAMETER_NAMES[FRAPModel.INDEX_PRIMARY_DIFF_RATE], FRAPModel.REF_DIFFUSION_RATE_PARAM.getLowerBound(), FRAPModel.REF_DIFFUSION_RATE_PARAM.getUpperBound(), FRAPModel.REF_DIFFUSION_RATE_PARAM.getScale(), diffusionRate);
    Parameter mobileFrac = new Parameter(FRAPModel.MODEL_PARAMETER_NAMES[FRAPModel.INDEX_PRIMARY_FRACTION], FRAPModel.REF_MOBILE_FRACTION_PARAM.getLowerBound(), FRAPModel.REF_MOBILE_FRACTION_PARAM.getUpperBound(), FRAPModel.REF_MOBILE_FRACTION_PARAM.getScale(), mobileFraction);
    Parameter bleachWhileMonitoringRate = new Parameter(FRAPModel.MODEL_PARAMETER_NAMES[FRAPModel.INDEX_BLEACH_MONITOR_RATE], FRAPModel.REF_BLEACH_WHILE_MONITOR_PARAM.getLowerBound(), FRAPModel.REF_BLEACH_WHILE_MONITOR_PARAM.getUpperBound(), FRAPModel.REF_BLEACH_WHILE_MONITOR_PARAM.getScale(), monitorBleachRate);
    params = new Parameter[FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF];
    params[FRAPModel.INDEX_PRIMARY_DIFF_RATE] = diff;
    params[FRAPModel.INDEX_PRIMARY_FRACTION] = mobileFrac;
    params[FRAPModel.INDEX_BLEACH_MONITOR_RATE] = bleachWhileMonitoringRate;
    return params;
}
Also used : Parameter(cbit.vcell.opt.Parameter)

Aggregations

Parameter (cbit.vcell.opt.Parameter)59 FRAPStudy (cbit.vcell.microscopy.FRAPStudy)11 Hashtable (java.util.Hashtable)10 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)9 ProfileDataElement (org.vcell.optimization.ProfileDataElement)8 Expression (cbit.vcell.parser.Expression)7 File (java.io.File)7 FRAPModel (cbit.vcell.microscopy.FRAPModel)6 ProfileData (org.vcell.optimization.ProfileData)6 OptimizationResultSet (cbit.vcell.opt.OptimizationResultSet)5 Element (org.jdom.Element)5 OptSolverResultSet (cbit.vcell.opt.OptSolverResultSet)4 OptimizationSpec (cbit.vcell.opt.OptimizationSpec)4 SimpleReferenceData (cbit.vcell.opt.SimpleReferenceData)4 ArrayList (java.util.ArrayList)4 ROI (cbit.vcell.VirtualMicroscopy.ROI)3 Dimension (java.awt.Dimension)3 Plot2D (cbit.plot.Plot2D)2 PlotData (cbit.plot.PlotData)2 BioModel (cbit.vcell.biomodel.BioModel)2