Search in sources :

Example 11 with FRAPStudy

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

the class FRAPStudyPanel method saveAsMatLabFile.

public void saveAsMatLabFile(String matFileName) throws IOException, Exception {
    FRAPStudy frapStudy = getFrapWorkspace().getWorkingFrapStudy();
    FRAPData frapData = frapStudy.getFrapData();
    FrapDataUtils.saveImageDatasetAsExternalMatlabData(frapData, getLocalWorkspace(), matFileName, frapStudy.getStartingIndexForRecovery(), frapStudy.getCartesianMesh());
}
Also used : FRAPData(cbit.vcell.microscopy.FRAPData) FRAPStudy(cbit.vcell.microscopy.FRAPStudy)

Example 12 with FRAPStudy

use of cbit.vcell.microscopy.FRAPStudy 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 13 with FRAPStudy

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

the class FRAPStudyPanel method saveProcedure.

private void saveProcedure(File xmlFrapFile, boolean bSaveAs, ClientTaskStatusSupport progressListener) throws Exception {
    if (bSaveAs) {
        // remove simulation key from simulation, save as doesn't copy simulation files over
        FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
        if (fStudy.getBioModel() != null && fStudy.getBioModel().getSimulations() != null && fStudy.getBioModel().getSimulations().length > 0 && fStudy.getBioModel().getSimulations()[0] != null) {
            Simulation oldSim = fStudy.getBioModel().getSimulations()[0];
            fStudy.getBioModel().removeSimulation(oldSim);
        }
    }
    // save
    MicroscopyXmlproducer.writeXMLFile(getFrapWorkspace().getWorkingFrapStudy(), xmlFrapFile, true, progressListener, VirtualFrapMainFrame.SAVE_COMPRESSED);
    getFrapWorkspace().getWorkingFrapStudy().setXmlFilename(xmlFrapFile.getAbsolutePath());
    getFrapWorkspace().getWorkingFrapStudy().setSaveNeeded(false);
}
Also used : Simulation(cbit.vcell.solver.Simulation) FRAPStudy(cbit.vcell.microscopy.FRAPStudy)

Example 14 with FRAPStudy

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

the class FRAPStudyPanel method runSimulationForSelectedModel.

private void runSimulationForSelectedModel() {
    AsynchClientTask prepareRunBindingReactionTask = new AsynchClientTask("Preparing to run simulation ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
            boolean bExtDataOK = FRAPWorkspace.areExternalDataOK(getLocalWorkspace(), fStudy.getFrapDataExternalDataInfo(), fStudy.getRoiExternalDataInfo());
            if (!bExtDataOK) {
                // refresh rois
                refreshROIs();
                // if external files are missing/currupt or ROIs are changed, create keys and save them
                fStudy.setFrapDataExternalDataInfo(FRAPStudy.createNewExternalDataInfo(getLocalWorkspace(), FRAPStudy.IMAGE_EXTDATA_NAME));
                fStudy.setRoiExternalDataInfo(FRAPStudy.createNewExternalDataInfo(getLocalWorkspace(), FRAPStudy.ROI_EXTDATA_NAME));
                try {
                    fStudy.saveROIsAsExternalData(getLocalWorkspace(), fStudy.getRoiExternalDataInfo().getExternalDataIdentifier(), fStudy.getStartingIndexForRecovery());
                    fStudy.saveImageDatasetAsExternalData(getLocalWorkspace(), fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier(), fStudy.getStartingIndexForRecovery());
                } catch (Exception e) {
                    e.printStackTrace(System.out);
                    (getAnalysisResultsPanel()).setResultsButtonEnabled(false);
                    throw e;
                }
            }
        }
    };
    // -------------------------------------------------------------------------
    AsynchClientTask runReactionBindingTask = new AsynchClientTask("Running simulation ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
            Parameter[] bestParams = fStudy.getModels()[fStudy.getBestModelIndex().intValue()].getModelParameters();
            if (bestParams.length < 3) {
                return;
            } else {
                if (fStudy != null && fStudy.getBioModel() != null && fStudy.getBioModel().getSimulations() != null && fStudy.getBioModel().getSimulations().length > 0 && fStudy.getBioModel().getSimulations()[0].getVersion() != null && fStudy.getBioModel().getSimulations()[0].getVersion().getVersionKey() != null) {
                    fStudy.getBioModel().getSimulations()[0].getVersion().getVersionKey();
                }
                BioModel bioModel = null;
                try {
                    bioModel = FRAPStudy.createNewSimBioModel(fStudy, bestParams, null, LocalWorkspace.createNewKeyValue(), LocalWorkspace.getDefaultOwner(), fStudy.getStartingIndexForRecovery());
                    // run simulation
                    FRAPStudy.runFVSolverStandalone(new File(getLocalWorkspace().getDefaultSimDataDirectory()), bioModel.getSimulation(0), fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier(), fStudy.getRoiExternalDataInfo().getExternalDataIdentifier(), this.getClientTaskStatusSupport(), false);
                    fStudy.setBioModel(bioModel);
                } catch (Exception e) {
                    if (bioModel != null && bioModel.getSimulations() != null) {
                        FRAPStudy.removeExternalDataAndSimulationFiles(bioModel.getSimulations()[0].getVersion().getVersionKey(), null, null, getLocalWorkspace());
                        (getAnalysisResultsPanel()).setResultsButtonEnabled(false);
                    }
                    throw e;
                }
            }
        }
    };
    AsynchClientTask updateUITask = new AsynchClientTask("Simulation Done.", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            VirtualFrapMainFrame.updateStatus("Simulation Done. Click on \'View Spatial Results\' to see simulation results.");
            (getAnalysisResultsPanel()).setResultsButtonEnabled(true);
        }
    };
    // dispatch
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { prepareRunBindingReactionTask, runReactionBindingTask, updateUITask }, true, true, true, null, true);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) BioModel(cbit.vcell.biomodel.BioModel) FRAPStudy(cbit.vcell.microscopy.FRAPStudy) Parameter(cbit.vcell.opt.Parameter) File(java.io.File) IOException(java.io.IOException) CannotUndoException(javax.swing.undo.CannotUndoException) ImageException(cbit.image.ImageException) FileNotFoundException(java.io.FileNotFoundException) UserCancelException(org.vcell.util.UserCancelException)

Example 15 with FRAPStudy

use of cbit.vcell.microscopy.FRAPStudy 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)

Aggregations

FRAPStudy (cbit.vcell.microscopy.FRAPStudy)51 Hashtable (java.util.Hashtable)19 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)18 File (java.io.File)17 ArrayList (java.util.ArrayList)13 Parameter (cbit.vcell.opt.Parameter)11 Point (java.awt.Point)8 FRAPModel (cbit.vcell.microscopy.FRAPModel)7 UserCancelException (org.vcell.util.UserCancelException)7 ImageException (cbit.image.ImageException)6 MicroscopyXmlReader (cbit.vcell.microscopy.MicroscopyXmlReader)5 FRAPData (cbit.vcell.microscopy.FRAPData)4 FRAPOptData (cbit.vcell.microscopy.FRAPOptData)4 FRAPOptFunctions (cbit.vcell.microscopy.FRAPOptFunctions)4 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 CannotUndoException (javax.swing.undo.CannotUndoException)4 PDEDataManager (cbit.vcell.simdata.PDEDataManager)3 Simulation (cbit.vcell.solver.Simulation)3 Wizard (org.vcell.wizard.Wizard)3