Search in sources :

Example 1 with FRAPModel

use of cbit.vcell.microscopy.FRAPModel in project vcell by virtualcell.

the class BestParameterTableModel method getBestModelParameters.

public Parameter[] getBestModelParameters() {
    if (bestModelIndex != null && -1 < bestModelIndex.intValue() && bestModelIndex.intValue() < FRAPModel.NUM_MODEL_TYPES) {
        FRAPModel bestModel = getFrapWorkspace().getWorkingFrapStudy().getModels()[bestModelIndex.intValue()];
        if (bestModel != null) {
            if (bestModelIndex != FRAPModel.IDX_MODEL_REACTION_OFF_RATE) {
                parameters = bestModel.getModelParameters();
            } else {
                parameters = new Parameter[2];
                parameters[0] = bestModel.getModelParameters()[FRAPModel.INDEX_BLEACH_MONITOR_RATE];
                parameters[1] = bestModel.getModelParameters()[FRAPModel.INDEX_OFF_RATE];
            }
            return parameters;
        }
    }
    return null;
}
Also used : FRAPModel(cbit.vcell.microscopy.FRAPModel)

Example 2 with FRAPModel

use of cbit.vcell.microscopy.FRAPModel in project vcell by virtualcell.

the class FRAPStudyPanel method showEstimateParamWizard.

private void showEstimateParamWizard() {
    // check if frapOpt data is null? if yes, run ref simulation.
    // check if parameters of each selected models are there, if not, run analytic solution, get best parameters and store parameters
    AsynchClientTask saveTask = new AsynchClientTask("Preparing for parameter estimation ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
            if (fStudy.hasDiffusionOnlyModel()) {
                // create optdata
                if (fStudy.getFrapOptData() == null) {
                    if (fStudy.getStoredRefData() != null) {
                        getFrapWorkspace().getWorkingFrapStudy().setFrapOptData(new FRAPOptData(fStudy, FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF, getLocalWorkspace(), fStudy.getStoredRefData()));
                    } else {
                        // check external data info
                        if (!FRAPWorkspace.areExternalDataOK(getLocalWorkspace(), fStudy.getFrapDataExternalDataInfo(), fStudy.getRoiExternalDataInfo())) {
                            // if external files are missing/currupt or ROIs are changed, create keys and save them
                            fStudy.setFrapDataExternalDataInfo(FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.IMAGE_EXTDATA_NAME));
                            fStudy.setRoiExternalDataInfo(FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.ROI_EXTDATA_NAME));
                            fStudy.saveROIsAsExternalData(localWorkspace, fStudy.getRoiExternalDataInfo().getExternalDataIdentifier(), fStudy.getStartingIndexForRecovery());
                            fStudy.saveImageDatasetAsExternalData(localWorkspace, fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier(), fStudy.getStartingIndexForRecovery());
                        }
                        // run ref sim
                        fStudy.setFrapOptData(new FRAPOptData(fStudy, FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF, localWorkspace, this.getClientTaskStatusSupport()));
                        fStudy.setSaveNeeded(true);
                    }
                }
            }
            if (fStudy.hasReactionOnlyOffRateModel()) {
                if (fStudy.getFrapOptFunc() == null) {
                    fStudy.setFrapOptFunc(new FRAPOptFunctions(fStudy));
                }
            }
        }
    };
    AsynchClientTask runOptTask = new AsynchClientTask("Running optimization ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
            if (fStudy.getSelectedModels() != null && fStudy.getSelectedModels().size() > 0) {
                ArrayList<Integer> models = fStudy.getSelectedModels();
                for (int i = 0; i < models.size(); i++) {
                    if ((models.get(i)).intValue() == FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT) {
                        if (fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters() == null) {
                            fStudy.getFrapOptData().setNumEstimatedParams(FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF);
                            Parameter[] initialParams = FRAPModel.getInitialParameters(fStudy.getFrapData(), FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT], fStudy.getStartingIndexForRecovery());
                            Parameter[] bestParameters = fStudy.getFrapOptData().getBestParamters(initialParams, fStudy.getSelectedROIsForErrorCalculation());
                            fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].setModelParameters(bestParameters);
                            fStudy.setSaveNeeded(true);
                        }
                    } else if ((models.get(i)).intValue() == FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS) {
                        if (fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters() == null) {
                            fStudy.getFrapOptData().setNumEstimatedParams(FRAPModel.NUM_MODEL_PARAMETERS_TWO_DIFF);
                            Parameter[] initialParams = FRAPModel.getInitialParameters(fStudy.getFrapData(), FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS], fStudy.getStartingIndexForRecovery());
                            Parameter[] bestParameters = fStudy.getFrapOptData().getBestParamters(initialParams, fStudy.getSelectedROIsForErrorCalculation());
                            fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].setModelParameters(bestParameters);
                            fStudy.setSaveNeeded(true);
                        }
                    } else if ((models.get(i)).intValue() == FRAPModel.IDX_MODEL_REACTION_OFF_RATE) {
                        if (fStudy.getModels()[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters() == null) {
                            Parameter[] bestParameters = fStudy.getFrapOptFunc().getBestParamters(fStudy.getFrapData(), null, true);
                            fStudy.getModels()[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].setModelParameters(bestParameters);
                            fStudy.setSaveNeeded(true);
                        }
                    }
                }
            }
        }
    };
    AsynchClientTask evaulateCITask = new AsynchClientTask("Evaluating confidence intervals for model parameters ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
            if (fStudy.getSelectedModels() != null && fStudy.getSelectedModels().size() > 0) {
                ArrayList<Integer> models = fStudy.getSelectedModels();
                for (int i = 0; i < models.size(); i++) {
                    if ((models.get(i)).intValue() == FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT) {
                        if (fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters() != null && fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters().length > 0) {
                            Parameter[] currentParams = fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters();
                            fStudy.getFrapOptData().setNumEstimatedParams(currentParams.length);
                            ProfileData[] profileData = null;
                            if (fStudy.getProfileData_oneDiffComponent() != null) {
                                profileData = fStudy.getProfileData_oneDiffComponent();
                            } else {
                                profileData = fStudy.getFrapOptData().evaluateParameters(currentParams, this.getClientTaskStatusSupport());
                                fStudy.setProfileData_oneDiffComponent(profileData);
                                fStudy.setSaveNeeded(true);
                            }
                        }
                    } else if ((models.get(i)).intValue() == FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS) {
                        if (fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters() != null && fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters().length > 0) {
                            Parameter[] currentParams = fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters();
                            fStudy.getFrapOptData().setNumEstimatedParams(currentParams.length);
                            ProfileData[] profileData = null;
                            if (fStudy.getProfileData_twoDiffComponents() != null) {
                                profileData = fStudy.getProfileData_twoDiffComponents();
                            } else {
                                profileData = fStudy.getFrapOptData().evaluateParameters(currentParams, this.getClientTaskStatusSupport());
                                fStudy.setProfileData_twoDiffComponents(profileData);
                                fStudy.setSaveNeeded(true);
                            }
                        }
                    } else if ((models.get(i)).intValue() == FRAPModel.IDX_MODEL_REACTION_OFF_RATE) {
                        if (fStudy.getModels()[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters() != null && fStudy.getModels()[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters().length > 0) {
                            Parameter[] currentParams = fStudy.getModels()[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters();
                            ProfileData[] profileData = null;
                            if (fStudy.getProfileData_reactionOffRate() != null) {
                                profileData = fStudy.getProfileData_reactionOffRate();
                            } else {
                                profileData = fStudy.getFrapOptFunc().evaluateParameters(currentParams, this.getClientTaskStatusSupport());
                                fStudy.setProfileData_reactionOffRate(profileData);
                                fStudy.setSaveNeeded(true);
                            }
                        }
                    }
                }
            }
            hashTable.put(FRAPSTUDY_KEY, fStudy);
        }
    };
    AsynchClientTask showDialogTask = new AsynchClientTask("Showing estimation results ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            // get frap models  before the wizard
            FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
            FRAPModel[] oldFrapModels = new FRAPModel[FRAPModel.NUM_MODEL_TYPES];
            for (int i = 0; i < fStudy.getModels().length; i++) {
                if (fStudy.getModels()[i] != null) {
                    FRAPModel model = fStudy.getModels()[i];
                    oldFrapModels[i] = new FRAPModel(new String(model.getModelIdentifer()), model.duplicateParameters(), null, model.duplicateTimePoints());
                }
            }
            // get best model index before the wizard
            Integer oldBestModelIndex = null;
            if (fStudy.getBestModelIndex() != null) {
                oldBestModelIndex = new Integer(fStudy.getBestModelIndex().intValue());
                // put old best model index into hashtable
                hashTable.put(BEST_MODEL_KEY, oldBestModelIndex);
            }
            // put old frapmodels in hashtable
            hashTable.put(FRAPMODELS_KEY, oldFrapModels);
            // show wizard
            final Wizard estParamWizard = getEstimateParametersWizard();
            SwingUtilities.invokeLater(new Runnable() {

                public void run() {
                    estParamWizard.showModalDialog(new Dimension(1000, 750));
                }
            });
            // put wizard in hashtable in order to check return code in next task
            hashTable.put(EST_PARAM_WIZARD_KEY, estParamWizard);
        }
    };
    AsynchClientTask updateSaveStatusTask = new AsynchClientTask("...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            Wizard estParamWizard = (Wizard) hashTable.get(EST_PARAM_WIZARD_KEY);
            // get old values from hashtable
            FRAPModel[] oldFrapModels = (FRAPModel[]) hashTable.get(FRAPMODELS_KEY);
            Integer oldBestModelIndex = (Integer) hashTable.get(BEST_MODEL_KEY);
            // get new values
            Integer newBestModelIndex = getFrapWorkspace().getWorkingFrapStudy().getBestModelIndex();
            if (estParamWizard.getReturnCode() == Wizard.FINISH_RETURN_CODE) {
                if (!getFrapWorkspace().getWorkingFrapStudy().areFRAPModelsEqual(oldFrapModels) || (oldBestModelIndex == null && newBestModelIndex != null) || (oldBestModelIndex != null && newBestModelIndex == null) || (oldBestModelIndex != null && newBestModelIndex != null && oldBestModelIndex.intValue() != newBestModelIndex.intValue())) {
                    getFrapWorkspace().getWorkingFrapStudy().setSaveNeeded(true);
                }
            }
        }
    };
    // dispatch
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { saveTask, runOptTask, evaulateCITask, showDialogTask, updateSaveStatusTask }, true, true, true, null, true);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) FRAPOptFunctions(cbit.vcell.microscopy.FRAPOptFunctions) ProfileData(org.vcell.optimization.ProfileData) Dimension(java.awt.Dimension) Point(java.awt.Point) FRAPModel(cbit.vcell.microscopy.FRAPModel) FRAPStudy(cbit.vcell.microscopy.FRAPStudy) FRAPOptData(cbit.vcell.microscopy.FRAPOptData) Parameter(cbit.vcell.opt.Parameter) Wizard(org.vcell.wizard.Wizard)

Example 3 with FRAPModel

use of cbit.vcell.microscopy.FRAPModel in project vcell by virtualcell.

the class ChooseModel_ModelTypesDescriptor method aboutToDisplayPanel.

public void aboutToDisplayPanel() {
    FRAPStudy fStudy = frapWorkspace.getWorkingFrapStudy();
    // if there are models selected and saved, load the model types. otherwise, apply default(diffusion with one component is selected).
    if (fStudy.getModels() != null && fStudy.getModels().length > 0 && fStudy.getSelectedModels().size() > 0) {
        modelTypesPanel.clearAllSelected();
        FRAPModel[] models = fStudy.getModels();
        if (models[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT] != null) {
            modelTypesPanel.setDiffOneSelected(true);
        }
        if (models[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS] != null) {
            modelTypesPanel.setDiffTwoSelected(true);
        }
        if (models[FRAPModel.IDX_MODEL_REACTION_OFF_RATE] != null) {
            modelTypesPanel.setReactionOffRateSelected(true);
        }
    } else // new frap document
    {
        modelTypesPanel.clearAllSelected();
        modelTypesPanel.setDiffOneSelected(true);
    }
}
Also used : FRAPStudy(cbit.vcell.microscopy.FRAPStudy) FRAPModel(cbit.vcell.microscopy.FRAPModel)

Example 4 with FRAPModel

use of cbit.vcell.microscopy.FRAPModel in project vcell by virtualcell.

the class EstParams_CompareResultsDescriptor method aboutToDisplayPanel.

public void aboutToDisplayPanel() {
    FRAPStudy fStudy = frapWorkspace.getWorkingFrapStudy();
    // create Mean square error for different models under different ROIs
    // if(fStudy.getAnalysisMSESummaryData() == null)
    // {
    fStudy.createAnalysisMSESummaryData();
    // }
    // auto find best model for user if best model is not selected.
    double[][] mseSummaryData = fStudy.getAnalysisMSESummaryData();
    // for(int i =0; i<10; i++)
    // System.out.print(mseSummaryData[0][i]+"  ");
    // find best model with significance and has least error
    int bestModel = FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT;
    if (// best model is saved and there is no model selection change
    fStudy.getBestModelIndex() != null) {
        bestModel = fStudy.getBestModelIndex().intValue();
    } else // need to find the best model
    {
        // check model significance if more than one model
        if (fStudy.getSelectedModels().size() > 1) {
            if (getFrapWorkspace().getWorkingFrapStudy().getFrapOptData() != null || getFrapWorkspace().getWorkingFrapStudy().getFrapOptFunc() != null) {
                ProfileSummaryData[][] allProfileSumData = FRAPOptimizationUtils.getAllProfileSummaryData(fStudy);
                FRAPModel[] frapModels = frapWorkspace.getWorkingFrapStudy().getModels();
                int confidenceIdx = ((EstParams_CompareResultsPanel) this.getPanelComponent()).getSelectedConfidenceIndex();
                boolean[] modelSignificance = new boolean[FRAPModel.NUM_MODEL_TYPES];
                Arrays.fill(modelSignificance, true);
                if (frapModels[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT] != null && frapModels[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters() != null && allProfileSumData != null && allProfileSumData[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT] != null) {
                    for (int i = 0; i < FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF; i++) {
                        ConfidenceInterval[] intervals = allProfileSumData[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT][i].getConfidenceIntervals();
                        if (intervals[confidenceIdx].getUpperBound() == frapModels[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters()[i].getUpperBound() && intervals[confidenceIdx].getLowerBound() == frapModels[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters()[i].getLowerBound()) {
                            modelSignificance[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT] = false;
                            break;
                        }
                    }
                }
                if (frapModels[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS] != null && frapModels[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters() != null && allProfileSumData != null && allProfileSumData[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS] != null) {
                    for (int i = 0; i < FRAPModel.NUM_MODEL_PARAMETERS_TWO_DIFF; i++) {
                        ConfidenceInterval[] intervals = allProfileSumData[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS][i].getConfidenceIntervals();
                        if (intervals[confidenceIdx].getUpperBound() == frapModels[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters()[i].getUpperBound() && intervals[confidenceIdx].getLowerBound() == frapModels[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters()[i].getLowerBound()) {
                            modelSignificance[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS] = false;
                            break;
                        }
                    }
                }
                if (frapModels[FRAPModel.IDX_MODEL_REACTION_OFF_RATE] != null && frapModels[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters() != null && allProfileSumData != null && allProfileSumData[FRAPModel.IDX_MODEL_REACTION_OFF_RATE] != null) {
                    for (int i = 0; i < FRAPModel.NUM_MODEL_PARAMETERS_REACTION_OFF_RATE; i++) {
                        if (i == FRAPModel.INDEX_BLEACH_MONITOR_RATE) {
                            ConfidenceInterval[] intervals = allProfileSumData[FRAPModel.IDX_MODEL_REACTION_OFF_RATE][FRAPModel.INDEX_BLEACH_MONITOR_RATE].getConfidenceIntervals();
                            if (intervals[confidenceIdx].getUpperBound() == frapModels[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters()[FRAPModel.INDEX_BLEACH_MONITOR_RATE].getUpperBound() && intervals[confidenceIdx].getLowerBound() == frapModels[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters()[FRAPModel.INDEX_BLEACH_MONITOR_RATE].getLowerBound()) {
                                modelSignificance[FRAPModel.IDX_MODEL_REACTION_OFF_RATE] = false;
                                break;
                            }
                        } else if (i == FRAPModel.INDEX_OFF_RATE) {
                            ConfidenceInterval[] intervals = allProfileSumData[FRAPModel.IDX_MODEL_REACTION_OFF_RATE][FRAPModel.INDEX_OFF_RATE].getConfidenceIntervals();
                            if (intervals[confidenceIdx].getUpperBound() == frapModels[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters()[FRAPModel.INDEX_OFF_RATE].getUpperBound() && intervals[confidenceIdx].getLowerBound() == frapModels[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters()[FRAPModel.INDEX_OFF_RATE].getLowerBound()) {
                                modelSignificance[FRAPModel.IDX_MODEL_REACTION_OFF_RATE] = false;
                                break;
                            }
                        }
                    }
                }
                // check least error model with significance
                double minError = 1E8;
                if (mseSummaryData != null) {
                    // exclude cell and bkground ROIs, include sum of error
                    int secDimLen = FRAPData.VFRAP_ROI_ENUM.values().length - 2 + 1;
                    if (modelSignificance[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT] == modelSignificance[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS] && modelSignificance[FRAPModel.IDX_MODEL_REACTION_OFF_RATE] == modelSignificance[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS]) {
                        // if all models' significance are the same, find the least error
                        for (int i = 0; i < FRAPModel.NUM_MODEL_TYPES; i++) {
                            if ((minError > mseSummaryData[i][secDimLen - 1])) {
                                minError = mseSummaryData[i][secDimLen - 1];
                                bestModel = i;
                            }
                        }
                    } else {
                        // if models' significance are different, find the least error with significance
                        for (int i = 0; i < FRAPModel.NUM_MODEL_TYPES; i++) {
                            if (modelSignificance[i] && (minError > mseSummaryData[i][secDimLen - 1])) {
                                minError = mseSummaryData[i][secDimLen - 1];
                                bestModel = i;
                            }
                        }
                    }
                }
            }
        } else // only one model is selected and the selected model should be the best model
        {
            for (int i = 0; i < fStudy.getModels().length; i++) {
                if (fStudy.getModels()[i] != null) {
                    bestModel = i;
                    break;
                }
            }
        }
    }
    ((EstParams_CompareResultsPanel) this.getPanelComponent()).setBestModelRadioButton(bestModel);
    // set data source to multiSourcePlotPane
    // length should be fStudy.getSelectedModels().size()+1, however, reaction binding may not have data
    ArrayList<DataSource> comparableDataSource = new ArrayList<DataSource>();
    // add exp data
    ReferenceData expReferenceData = FRAPOptimizationUtils.doubleArrayToSimpleRefData(fStudy.getDimensionReducedExpData(), fStudy.getFrapData().getImageDataset().getImageTimeStamps(), fStudy.getStartingIndexForRecovery(), fStudy.getSelectedROIsForErrorCalculation());
    final DataSource expDataSource = new DataSource.DataSourceReferenceData("exp", expReferenceData);
    comparableDataSource.add(expDataSource);
    // add opt/sim data
    // using the same loop, disable the radio button if the model is not included
    // adjust radio buttons
    ((EstParams_CompareResultsPanel) this.getPanelComponent()).disableAllRadioButtons();
    ArrayList<Integer> selectedModelIndexes = fStudy.getSelectedModels();
    for (int i = 0; i < selectedModelIndexes.size(); i++) {
        DataSource newDataSource = null;
        double[] timePoints = fStudy.getFrapData().getImageDataset().getImageTimeStamps();
        int startingIndex = fStudy.getStartingIndexForRecovery();
        double[] truncatedTimes = new double[timePoints.length - startingIndex];
        System.arraycopy(timePoints, startingIndex, truncatedTimes, 0, truncatedTimes.length);
        if (selectedModelIndexes.get(i).equals(FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT)) {
            // adjust radio button
            ((EstParams_CompareResultsPanel) this.getPanelComponent()).enableRadioButton(FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT);
            FRAPModel temModel = fStudy.getFrapModel(FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT);
            ODESolverResultSet temSolverResultSet = FRAPOptimizationUtils.doubleArrayToSolverResultSet(temModel.getData(), truncatedTimes, 0, fStudy.getSelectedROIsForErrorCalculation());
            newDataSource = new DataSource.DataSourceRowColumnResultSet("opt_DF1", temSolverResultSet);
        } else if (selectedModelIndexes.get(i).equals(FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS)) {
            // adjust radio button
            ((EstParams_CompareResultsPanel) this.getPanelComponent()).enableRadioButton(FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS);
            FRAPModel temModel = fStudy.getFrapModel(FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS);
            ODESolverResultSet temSolverResultSet = FRAPOptimizationUtils.doubleArrayToSolverResultSet(temModel.getData(), truncatedTimes, 0, fStudy.getSelectedROIsForErrorCalculation());
            newDataSource = new DataSource.DataSourceRowColumnResultSet("opt_DF2", temSolverResultSet);
        } else if (selectedModelIndexes.get(i).equals(FRAPModel.IDX_MODEL_REACTION_OFF_RATE)) {
            // adjust radio button
            ((EstParams_CompareResultsPanel) this.getPanelComponent()).enableRadioButton(FRAPModel.IDX_MODEL_REACTION_OFF_RATE);
            FRAPModel temModel = fStudy.getFrapModel(FRAPModel.IDX_MODEL_REACTION_OFF_RATE);
            if (temModel.getData() != null) {
                ODESolverResultSet temSolverResultSet = FRAPOptimizationUtils.doubleArrayToSolverResultSet(temModel.getData(), truncatedTimes, 0, // for reaction off model, display curve under bleached region only
                FRAPStudy.createSelectedROIsForReactionOffRateModel());
                newDataSource = new DataSource.DataSourceRowColumnResultSet("sim_Koff", temSolverResultSet);
            }
        }
        if (newDataSource != null) {
            comparableDataSource.add(newDataSource);
        }
    }
    // set data to multiSourcePlotPane
    ((EstParams_CompareResultsPanel) this.getPanelComponent()).setPlotData(comparableDataSource.toArray(new DataSource[comparableDataSource.size()]));
}
Also used : ArrayList(java.util.ArrayList) FRAPModel(cbit.vcell.microscopy.FRAPModel) DataSource(cbit.vcell.modelopt.DataSource) ReferenceData(cbit.vcell.opt.ReferenceData) FRAPStudy(cbit.vcell.microscopy.FRAPStudy) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ConfidenceInterval(org.vcell.optimization.ConfidenceInterval)

Example 5 with FRAPModel

use of cbit.vcell.microscopy.FRAPModel in project vcell by virtualcell.

the class EstParams_ReacBindingDescriptor method aboutToDisplayPanel.

public void aboutToDisplayPanel() {
    FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
    FRAPModel[] frapModels = fStudy.getModels();
    Parameter[] params = null;
    // get parameters to display in reaction binding panel
    if (frapModels[FRAPModel.IDX_MODEL_DIFF_BINDING] != null && frapModels[FRAPModel.IDX_MODEL_DIFF_BINDING].getModelParameters() != null) {
        params = frapModels[FRAPModel.IDX_MODEL_DIFF_BINDING].getModelParameters();
        ((EstParams_ReacBindingPanel) getPanelComponent()).setCurrentSimResults(frapModels[FRAPModel.IDX_MODEL_DIFF_BINDING].getData());
        ((EstParams_ReacBindingPanel) getPanelComponent()).setCurrentRawSimTimePoints(frapModels[FRAPModel.IDX_MODEL_DIFF_BINDING].getTimepoints());
    } else {
        ((EstParams_ReacBindingPanel) getPanelComponent()).setCurrentSimResults(null);
        ((EstParams_ReacBindingPanel) getPanelComponent()).setCurrentRawSimTimePoints(null);
        if (frapModels[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT] != null && frapModels[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters() != null) {
            params = FRAPModel.createReacBindingParametersFromDiffusionParameters(frapModels[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters());
        } else // no parameters are available
        {
            try {
                params = FRAPModel.getInitialParameters(fStudy.getFrapData(), FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_DIFF_BINDING], fStudy.getStartingIndexForRecovery());
            } catch (Exception ex) {
                ex.printStackTrace(System.out);
                DialogUtils.showErrorDialog((getPanelComponent()), "Error getting parameters for diffusion plus binding model." + ex.getMessage());
            }
        }
    }
    ((EstParams_ReacBindingPanel) getPanelComponent()).setReacBindingParams(params);
    try {
        ((EstParams_ReacBindingPanel) getPanelComponent()).setData(fStudy.getFrapData(), params, fStudy.getFrapData().getImageDataset().getImageTimeStamps(), fStudy.getStartingIndexForRecovery(), fStudy.getSelectedROIsForErrorCalculation());
    } catch (Exception ex) {
        ex.printStackTrace(System.out);
        DialogUtils.showErrorDialog((getPanelComponent()), "Error plotting data for diffusion plus binding model." + ex.getMessage());
    }
}
Also used : FRAPStudy(cbit.vcell.microscopy.FRAPStudy) Parameter(cbit.vcell.opt.Parameter) FRAPModel(cbit.vcell.microscopy.FRAPModel)

Aggregations

FRAPModel (cbit.vcell.microscopy.FRAPModel)13 FRAPStudy (cbit.vcell.microscopy.FRAPStudy)7 Parameter (cbit.vcell.opt.Parameter)6 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)4 Hashtable (java.util.Hashtable)4 ArrayList (java.util.ArrayList)3 FRAPOptData (cbit.vcell.microscopy.FRAPOptData)2 FRAPOptFunctions (cbit.vcell.microscopy.FRAPOptFunctions)2 LocalWorkspace (cbit.vcell.microscopy.LocalWorkspace)1 MicroscopyXmlReader (cbit.vcell.microscopy.MicroscopyXmlReader)1 DataSource (cbit.vcell.modelopt.DataSource)1 ReferenceData (cbit.vcell.opt.ReferenceData)1 ODESolverResultSet (cbit.vcell.solver.ode.ODESolverResultSet)1 Dimension (java.awt.Dimension)1 Point (java.awt.Point)1 File (java.io.File)1 ConfidenceInterval (org.vcell.optimization.ConfidenceInterval)1 ProfileData (org.vcell.optimization.ProfileData)1 DescriptiveStatistics (org.vcell.util.DescriptiveStatistics)1 Wizard (org.vcell.wizard.Wizard)1