Search in sources :

Example 16 with FRAPStudy

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

Example 17 with FRAPStudy

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

the class EstParams_ReacBindingPanel method activateReacDiffEstPanel.

public void activateReacDiffEstPanel() {
    FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
    // check if we can do auto estimation on reaction binding papameters
    Parameter[] params = null;
    if (fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT] != null && fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters() != null) {
        params = fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters();
    } else {
        DialogUtils.showErrorDialog(EstParams_ReacBindingPanel.this, "Parameters from 'Diffusion with One Diffusing Component' model " + "is needed for automated estimation of reaction binding parameters.\n" + "Please include the above-mentioned model using 'Choose Model Types' wizard.");
        return;
    }
    if (estGuidePanel == null) {
        estGuidePanel = new FRAPReacDiffEstimationGuidePanel();
    }
    // set initial parameters from diffusion with one diffusing component
    estGuidePanel.setPrimaryParameters(params);
    int choice2 = DialogUtils.showComponentOKCancelDialog(EstParams_ReacBindingPanel.this, estGuidePanel, "FRAP Parameter Estimation Guide");
    if (choice2 == JOptionPane.OK_OPTION) {
        if (estGuidePanel.getParamTable() != null) {
            int rowLen = estGuidePanel.getParamTable().getRowCount();
            for (int i = 0; i < rowLen; i++) {
                String name = ((String) estGuidePanel.getParamTable().getValueAt(i, EstimatedParameterTableModel.COLUMN_NAME));
                double val = ((Double) estGuidePanel.getParamTable().getValueAt(i, EstimatedParameterTableModel.COLUMN_VALUE)).doubleValue();
                if (name.equals(FRAPReacDiffEstimationGuidePanel.paramNames[FRAPReacDiffEstimationGuidePanel.IDX_FreePartDiffRate])) {
                    reactionDiffusionPanel.setFreeDiffRate(val + "");
                } else if (name.equals(FRAPReacDiffEstimationGuidePanel.paramNames[FRAPReacDiffEstimationGuidePanel.IDX_FreePartConc])) {
                    reactionDiffusionPanel.setFreeFraction(val + "");
                } else if (name.equals(FRAPReacDiffEstimationGuidePanel.paramNames[FRAPReacDiffEstimationGuidePanel.IDX_BWMRate])) {
                    reactionDiffusionPanel.setBleachMonitorRate(val + "");
                } else if (name.equals(FRAPReacDiffEstimationGuidePanel.paramNames[FRAPReacDiffEstimationGuidePanel.IDX_ComplexConc])) {
                    reactionDiffusionPanel.setComplexFraction(val + "");
                } else if (name.equals(FRAPReacDiffEstimationGuidePanel.paramNames[FRAPReacDiffEstimationGuidePanel.IDX_ReacPseudoOnRate])) {
                    reactionDiffusionPanel.setOnRate(val + "");
                } else if (name.equals(FRAPReacDiffEstimationGuidePanel.paramNames[FRAPReacDiffEstimationGuidePanel.IDX_ReacOffRate])) {
                    reactionDiffusionPanel.setOffRate(val + "");
                } else if (name.equals(FRAPReacDiffEstimationGuidePanel.paramNames[FRAPReacDiffEstimationGuidePanel.IDX_Immobile])) {
                    reactionDiffusionPanel.setImmobileFraction(val + "");
                }
            }
        // multisourcePlotPane.setDataSources(null);
        }
    }
}
Also used : FRAPStudy(cbit.vcell.microscopy.FRAPStudy) Parameter(cbit.vcell.opt.Parameter)

Example 18 with FRAPStudy

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

the class EstParams_ReacBindingPanel method plotDerivedSimulationResults.

private void plotDerivedSimulationResults(AnalysisParameters[] anaParams) {
    try {
        if (getCurrentSimResults() == null || getCurrentRawSimTimePoints() == null || allDataHash == null || allDataHash.get(anaParams[0]) == null || (allDataHash.get(anaParams[0])[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE]) == null) {
            multisourcePlotPane.setDataSources(null);
            return;
        }
        String description = null;
        int totalROIlen = FRAPData.VFRAP_ROI_ENUM.values().length;
        boolean[] wantsROITypes = new boolean[totalROIlen];
        System.arraycopy(frapWorkspace.getWorkingFrapStudy().getSelectedROIsForErrorCalculation(), 0, wantsROITypes, 0, totalROIlen);
        ODESolverResultSet simSolverResultSet = new ODESolverResultSet();
        simSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription("t"));
        for (int j = 0; j < totalROIlen; j++) {
            if (!wantsROITypes[j]) {
                continue;
            }
            String currentROIName = FRAPData.VFRAP_ROI_ENUM.values()[j].name();
            String name = (description == null ? /*"sim D="+diffusionRates[diffusionRateIndex]+"::"*/
            "" : description) + currentROIName;
            simSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(name));
        }
        int totalWantedROIlen = 0;
        for (int i = 0; i < wantsROITypes.length; i++) {
            if (wantsROITypes[i]) {
                totalWantedROIlen++;
            }
        }
        FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
        // 
        // populate time
        // 
        double[] shiftedSimTimes = getCurrentRawSimTimePoints();
        int startIndexRecovery = fStudy.getStartingIndexForRecovery();
        for (int j = 0; j < shiftedSimTimes.length; j++) {
            double[] row = new double[totalWantedROIlen + 1];
            row[0] = shiftedSimTimes[j] + fStudy.getFrapData().getImageDataset().getImageTimeStamps()[startIndexRecovery];
            simSolverResultSet.addRow(row);
        }
        // 
        // populate values
        // 
        double[][] currentSimData = getCurrentSimResults();
        // populate sim data
        int columncounter = 0;
        for (int j = 0; j < totalROIlen; j++) {
            if (!wantsROITypes[j]) {
                continue;
            }
            double[] values = currentSimData[j];
            for (int k = 0; k < values.length; k++) {
                simSolverResultSet.setValue(k, columncounter + 1, values[k]);
            }
            columncounter++;
        }
        // get exp data and generate datasource to display
        // anaParams[0] is the key in allDataHash to get the dataSource[]:exp & sim
        DataSource[] selectedRowDataSourceArr = allDataHash.get(anaParams[0]);
        if (selectedRowDataSourceArr != null) {
            // referenceData is the exp data
            // ReferenceData referenceData = (ReferenceData)selectedRowDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE].getSource();
            final DataSource expDataSource = /*new DataSource(referenceData,"exp")*/
            selectedRowDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE];
            // from simulation
            final DataSource simDataSource = new DataSource.DataSourceRowColumnResultSet("sim", simSolverResultSet);
            DataSource[] newDataSourceArr = new DataSource[2];
            newDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE] = expDataSource;
            newDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_SIMDATASOURCE] = simDataSource;
            // the following paragraph of code is just to get selected color for selected ROIs
            // and make them the same as we show on ChooseModel_RoiForErrorPanel/RoiForErrorPanel
            // double valid ROI colors (not include cell and background)
            int validROISize = FRAPData.VFRAP_ROI_ENUM.values().length - 2;
            Color[] fullColors = ColorUtil.generateAutoColor(validROISize * 2, getBackground(), new Integer(0));
            boolean[] selectedROIs = frapWorkspace.getWorkingFrapStudy().getSelectedROIsForErrorCalculation();
            int selectedROICounter = 0;
            for (int i = 0; i < selectedROIs.length; i++) {
                if (selectedROIs[i]) {
                    selectedROICounter++;
                }
            }
            // double the size, each ROI is a comparison of exp and sim
            Color[] selectedColors = new Color[selectedROICounter * 2];
            int selectedColorIdx = 0;
            for (int i = 0; i < selectedROIs.length; i++) {
                if (selectedROIs[i] && i == 0) {
                    selectedColors[selectedColorIdx] = fullColors[i];
                    selectedColors[selectedColorIdx + selectedROICounter] = fullColors[i + validROISize];
                    selectedColorIdx++;
                }
                if (// skip cell and background ROIs
                selectedROIs[i] && i > 2) {
                    selectedColors[selectedColorIdx] = fullColors[i - 2];
                    selectedColors[selectedColorIdx + selectedROICounter] = fullColors[i - 2 + validROISize];
                    selectedColorIdx++;
                }
            }
            multisourcePlotPane.setDataSources(newDataSourceArr, selectedColors);
            multisourcePlotPane.selectAll();
        }
    } catch (Exception e2) {
        e2.printStackTrace();
        DialogUtils.showErrorDialog(this, "Error graphing Optimizer data " + e2.getMessage());
    }
}
Also used : Color(java.awt.Color) DataSource(cbit.vcell.modelopt.DataSource) FRAPStudy(cbit.vcell.microscopy.FRAPStudy) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription)

Example 19 with FRAPStudy

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

the class EstParams_ReactionOffRateDescriptor method aboutToDisplayPanel.

public void aboutToDisplayPanel() {
    FRAPStudy fStudy = frapWorkspace.getWorkingFrapStudy();
    Parameter[] params = fStudy.getModels()[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters();
    try {
        if (params == null) {
            params = fStudy.getFrapOptFunc().getBestParamters(fStudy.getFrapData(), null, true);
        }
        ((EstParams_ReactionOffRatePanel) getPanelComponent()).setData(params, fStudy.getFrapData(), /*fStudy.getFrapOptFunc().getOffRateResults(),*/
        fStudy.getStartingIndexForRecovery());
    } catch (Exception ex) {
        ex.printStackTrace(System.out);
        DialogUtils.showErrorDialog((getPanelComponent()), "Error getting parameters for reaction dominant off rate model.");
    }
}
Also used : FRAPStudy(cbit.vcell.microscopy.FRAPStudy) Parameter(cbit.vcell.opt.Parameter)

Example 20 with FRAPStudy

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

the class LoadFRAPData_MultiFileDescriptor method preNextProcess.

// load the data before the panel disappears
public ArrayList<AsynchClientTask> preNextProcess() {
    // create AsynchClientTask arraylist
    ArrayList<AsynchClientTask> taskArrayList = new ArrayList<AsynchClientTask>();
    final File[] files = multiFilePanel.getSelectedFiles();
    if (files.length > 0) {
        final String filePath = files[0].getParent();
        final String LOADING_MESSAGE = "Loading files from directory " + filePath + "...";
        AsynchClientTask updateUIBeforeLoadTask = new AsynchClientTask("", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                try {
                    VirtualFrapMainFrame.updateStatus(LOADING_MESSAGE);
                } catch (Exception e) {
                    e.printStackTrace(System.out);
                }
            }
        };
        AsynchClientTask loadTask = new AsynchClientTask(LOADING_MESSAGE, AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                FRAPStudy newFRAPStudy = null;
                newFRAPStudy = FRAPWorkspace.loadFRAPDataFromMultipleFiles(files, this.getClientTaskStatusSupport(), multiFilePanel.isTimeSeries(), multiFilePanel.getTimeInterval());
                isFileLoaded = true;
                // for all loaded files
                hashTable.put(FRAPStudyPanel.NEW_FRAPSTUDY_KEY, newFRAPStudy);
            }
        };
        AsynchClientTask afterLoadingSwingTask = new AsynchClientTask(LOADING_MESSAGE, AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                FRAPStudy newFRAPStudy = (FRAPStudy) hashTable.get(FRAPStudyPanel.NEW_FRAPSTUDY_KEY);
                // setFrapStudy fires property change, so we have to put it in Swing thread.
                getFrapWorkspace().setFrapStudy(newFRAPStudy, true);
                VirtualFrapLoader.mf.setMainFrameTitle("");
                VirtualFrapMainFrame.updateProgress(0);
                if (isFileLoaded) {
                    VirtualFrapMainFrame.updateStatus("Loaded files from " + filePath);
                } else {
                    VirtualFrapMainFrame.updateStatus("Failed loading files from " + filePath + ".");
                }
            }
        };
        taskArrayList.add(updateUIBeforeLoadTask);
        taskArrayList.add(loadTask);
        taskArrayList.add(afterLoadingSwingTask);
    } else {
        DialogUtils.showErrorDialog(multiFilePanel, "No file is selected. Please input one or more file names to continue.");
        throw new RuntimeException("No file is selected. Please input one or more file names to continue.");
    }
    return taskArrayList;
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) FRAPStudy(cbit.vcell.microscopy.FRAPStudy) File(java.io.File)

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