Search in sources :

Example 1 with DataSource

use of cbit.vcell.modelopt.DataSource in project vcell by virtualcell.

the class ParameterEstimationRunTaskPanel method plot.

private void plot() {
    try {
        java.util.Vector<DataSource> dataSourceList = new java.util.Vector<DataSource>();
        java.util.Vector<String> nameVector = new java.util.Vector<String>();
        ModelOptimizationSpec modelOptimizationSpec = parameterEstimationTask.getModelOptimizationSpec();
        final ReferenceDataMappingSpec[] mappingSpecs = modelOptimizationSpec.getReferenceDataMappingSpecs();
        int timeIndex = modelOptimizationSpec.getReferenceDataTimeColumnIndex();
        ReferenceData referenceData = modelOptimizationSpec.getReferenceData();
        if (referenceData != null) {
            dataSourceList.add(new DataSource.DataSourceReferenceData("EXPT", timeIndex, referenceData));
            String[] refColumnNames = referenceData.getColumnNames();
            for (int i = 0; i < refColumnNames.length; i++) {
                if (i == timeIndex) {
                    continue;
                }
                nameVector.add(refColumnNames[i]);
                break;
            }
        }
        ParameterEstimationTaskSimulatorIDA parestSimulator = new ParameterEstimationTaskSimulatorIDA();
        ODESolverResultSet odeSolverResultSet = parestSimulator.getOdeSolverResultSet(parameterEstimationTask);
        if (odeSolverResultSet != null) {
            dataSourceList.add(new DataSource.DataSourceRowColumnResultSet("EST", odeSolverResultSet));
            if (mappingSpecs != null) {
                for (int i = 0; i < mappingSpecs.length; i++) {
                    if (i == timeIndex) {
                        continue;
                    }
                    Variable var = parameterEstimationTask.getMathSymbolMapping().getVariable(mappingSpecs[i].getModelObject());
                    nameVector.add(var.getName());
                    break;
                }
            }
        }
        DataSource[] dataSources = (DataSource[]) BeanUtils.getArray(dataSourceList, DataSource.class);
        MultisourcePlotPane multisourcePlotPane = new MultisourcePlotPane();
        multisourcePlotPane.setGroupingListSorter(new Comparator<SortDataReferenceHelper>() {

            @Override
            public int compare(SortDataReferenceHelper o1, SortDataReferenceHelper o2) {
                DataSource ds01 = o1.dataReference.getDataSource();
                DataSource ds02 = o2.dataReference.getDataSource();
                // System.out.println(ds01.getClass().getSimpleName()+" "+o1.dataReference.getIdentifier()+" "+ds02.getClass().getSimpleName()+" "+o2.dataReference.getIdentifier());
                if (ds01 instanceof DataSource.DataSourceReferenceData) {
                    if (ds02 instanceof DataSource.DataSourceReferenceData) {
                        // both reference data, sort names
                        ReferenceDataMappingSpec mspec01 = null;
                        ReferenceDataMappingSpec mspec02 = null;
                        for (ReferenceDataMappingSpec rdMappingSpec : mappingSpecs) {
                            // Variable var = parameterEstimationTask.getMathSymbolMapping().getVariable(rdMappingSpec.getModelObject());
                            if (rdMappingSpec.getModelObject() instanceof ReservedSymbol) {
                                continue;
                            }
                            if (o1.dataReference.getIdentifier().equals(rdMappingSpec.getReferenceDataColumnName())) {
                                mspec01 = rdMappingSpec;
                                o1.setReferenceDataMappingSpec(rdMappingSpec);
                            } else if (o2.dataReference.getIdentifier().equals(rdMappingSpec.getReferenceDataColumnName())) {
                                mspec02 = rdMappingSpec;
                                o2.setReferenceDataMappingSpec(rdMappingSpec);
                            }
                        }
                        if (mspec01 == null && mspec02 == null) {
                            return o1.dataReference.getIdentifier().compareToIgnoreCase(o2.dataReference.getIdentifier());
                        } else if (mspec01 != null && mspec02 != null) {
                            return mspec01.getReferenceDataColumnName().compareToIgnoreCase(mspec02.getReferenceDataColumnName());
                        } else if (mspec01 != null && mspec02 == null) {
                            return -1;
                        } else {
                            return 1;
                        }
                    } else {
                        // compare ref to ode
                        ReferenceDataMappingSpec mspec01 = null;
                        ReferenceDataMappingSpec mspec02 = null;
                        for (ReferenceDataMappingSpec rdMappingSpec : mappingSpecs) {
                            Variable var = parameterEstimationTask.getMathSymbolMapping().getVariable(rdMappingSpec.getModelObject());
                            if (rdMappingSpec.getModelObject() instanceof ReservedSymbol) {
                                continue;
                            }
                            if (o1.dataReference.getIdentifier().equals(rdMappingSpec.getReferenceDataColumnName())) {
                                mspec01 = rdMappingSpec;
                                o1.setReferenceDataMappingSpec(rdMappingSpec);
                            } else if (o2.dataReference.getIdentifier().equals(var.getName())) {
                                mspec02 = rdMappingSpec;
                                o2.setReferenceDataMappingSpec(rdMappingSpec);
                            }
                        }
                        if (mspec01 == null && mspec02 == null) {
                            return -1;
                        } else if (mspec01 != null && mspec02 == null) {
                            return -1;
                        } else if (mspec02 != null && mspec01 == null) {
                            return 1;
                        } else {
                            // BeanUtils.forceStringSize(mspec02.getReferenceDataColumnName(), 25, " ", true));
                            return mspec01.getReferenceDataColumnName().compareToIgnoreCase(mspec02.getReferenceDataColumnName());
                        }
                    }
                } else {
                    if (ds02 instanceof DataSource.DataSourceRowColumnResultSet) {
                        // both OdeSolverResultSet data, sort names
                        ReferenceDataMappingSpec mspec01 = null;
                        ReferenceDataMappingSpec mspec02 = null;
                        for (ReferenceDataMappingSpec rdMappingSpec : mappingSpecs) {
                            Variable var = parameterEstimationTask.getMathSymbolMapping().getVariable(rdMappingSpec.getModelObject());
                            if (rdMappingSpec.getModelObject() instanceof ReservedSymbol) {
                                continue;
                            }
                            if (o1.dataReference.getIdentifier().equals(var.getName())) {
                                mspec01 = rdMappingSpec;
                                o1.setReferenceDataMappingSpec(rdMappingSpec);
                            } else if (o2.dataReference.getIdentifier().equals(var.getName())) {
                                mspec02 = rdMappingSpec;
                                o2.setReferenceDataMappingSpec(rdMappingSpec);
                            }
                        }
                        if (mspec01 == null && mspec02 == null) {
                            return o1.dataReference.getIdentifier().compareToIgnoreCase(o2.dataReference.getIdentifier());
                        } else if (mspec01 != null && mspec02 != null) {
                            return mspec01.getReferenceDataColumnName().compareToIgnoreCase(mspec02.getReferenceDataColumnName());
                        } else if (mspec01 != null && mspec02 == null) {
                            return -1;
                        } else {
                            return 1;
                        }
                    } else {
                        // compare ode to ref
                        ReferenceDataMappingSpec mspec01 = null;
                        ReferenceDataMappingSpec mspec02 = null;
                        for (ReferenceDataMappingSpec rdMappingSpec : mappingSpecs) {
                            Variable var = parameterEstimationTask.getMathSymbolMapping().getVariable(rdMappingSpec.getModelObject());
                            if (rdMappingSpec.getModelObject() instanceof ReservedSymbol) {
                                continue;
                            }
                            if (o2.dataReference.getIdentifier().equals(rdMappingSpec.getReferenceDataColumnName())) {
                                mspec02 = rdMappingSpec;
                                o2.setReferenceDataMappingSpec(rdMappingSpec);
                            } else if (o1.dataReference.getIdentifier().equals(var.getName())) {
                                mspec01 = rdMappingSpec;
                                o1.setReferenceDataMappingSpec(rdMappingSpec);
                            }
                        }
                        if (mspec01 == null && mspec02 == null) {
                            return 1;
                        } else if (mspec01 != null && mspec02 == null) {
                            return -1;
                        } else if (mspec02 != null && mspec01 == null) {
                            return 1;
                        } else {
                            // BeanUtils.forceStringSize(mspec02.getReferenceDataColumnName(), 25, " ", true));
                            return mspec01.getReferenceDataColumnName().compareToIgnoreCase(mspec02.getReferenceDataColumnName());
                        }
                    }
                }
            }
        });
        multisourcePlotPane.setDataSources(dataSources);
        String[] nameArray = new String[nameVector.size()];
        nameArray = (String[]) BeanUtils.getArray(nameVector, String.class);
        multisourcePlotPane.select(nameArray);
        DialogUtils.showComponentCloseDialog(JOptionPane.getFrameForComponent(this), multisourcePlotPane, "Data Plot");
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
}
Also used : Variable(cbit.vcell.math.Variable) MultisourcePlotPane(cbit.vcell.modelopt.gui.MultisourcePlotPane) ReferenceDataMappingSpec(cbit.vcell.modelopt.ReferenceDataMappingSpec) ReservedSymbol(cbit.vcell.model.Model.ReservedSymbol) ModelOptimizationSpec(cbit.vcell.modelopt.ModelOptimizationSpec) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ParameterEstimationTaskSimulatorIDA(org.vcell.optimization.ParameterEstimationTaskSimulatorIDA) OptimizationException(cbit.vcell.opt.OptimizationException) UtilCancelException(org.vcell.util.UtilCancelException) ExpressionException(cbit.vcell.parser.ExpressionException) DataSource(cbit.vcell.modelopt.DataSource) SortDataReferenceHelper(cbit.vcell.modelopt.gui.MultisourcePlotListModel.SortDataReferenceHelper) ReferenceData(cbit.vcell.opt.ReferenceData)

Example 2 with DataSource

use of cbit.vcell.modelopt.DataSource in project vcell by virtualcell.

the class NonGUIFRAPTest method dumpSpatialResults.

public static void dumpSpatialResults(SpatialAnalysisResults spatialAnalysisResults, double[] frapDataTimeStamps, File outputFile) throws Exception {
    FileWriter fw = new FileWriter(outputFile);
    // FileOutputStream fos = new FileOutputStream(outputFile);
    // BufferedOutputStream bos = new BufferedOutputStream(fos);
    ReferenceData[] referenceDataArr = spatialAnalysisResults.createReferenceDataForAllDiffusionRates(frapDataTimeStamps);
    ODESolverResultSet[] odeSolverResultSetArr = spatialAnalysisResults.createODESolverResultSetForAllDiffusionRates();
    for (int i = 0; i < spatialAnalysisResults.analysisParameters.length; i++) {
        DataSource expDataSource = new DataSource.DataSourceReferenceData("experiment", referenceDataArr[i]);
        DataSource fitDataSource = new DataSource.DataSourceRowColumnResultSet("fit", odeSolverResultSetArr[i]);
    // MultisourcePlotListModel multisourcePlotListModel =
    // new MultisourcePlotListModel();
    // multisourcePlotListModel.setDataSources(new DataSource[] {expDataSource,fitDataSource});
    // System.out.println("AnalysisParameters = "+spatialAnalysisResults.analysisParameters[i]);
    // for (int j = 0; j < multisourcePlotListModel.getSize(); j++) {
    // DataReference dataReference = (DataReference)multisourcePlotListModel.getElementAt(j);
    // DataSource dataSource = dataReference.getDataSource();
    // for (int k = 0; k < dataSource.getNumRows(); k++) {
    // for (int k2 = 0; k2 < dataSource.getNumColumns(); k2++) {
    // System.out.print(dataSource.getRowData(k)[k2]+" ");
    // fw.write(dataSource.getRowData(k)[k2]+" ");
    // }
    // System.out.println();
    // fw.write("\n");
    // }
    // if(dataReference.getDataSource().getSource() instanceof ReferenceData){
    // ReferenceData refData = (ReferenceData)dataReference.getDataSource().getSource();
    // for (int k = 0; k < refData.getNumRows(); k++) {
    // for (int k2 = 0; k2 < refData.getNumColumns(); k2++) {
    // System.out.print(refData.getRowData(k)[k2]+" ");
    // fw.write(refData.getRowData(k)[k2]+" ");
    // }
    // System.out.println();
    // fw.write("\n");
    // }
    // }else{
    // ODESolverResultSet odeRS = (ODESolverResultSet)dataReference.getDataSource().getSource();
    // for (int k = 0; k < odeRS.getRowCount(); k++) {
    // for (int k2 = 0; k2 < odeRS.getDataColumnCount(); k2++) {
    // System.out.print(odeRS.getRow(k)[k2]+" ");
    // fw.write(odeRS.getRow(k)[k2]+" ");
    // }
    // System.out.println();
    // fw.write("\n");
    // }
    // }
    // }
    }
    fw.close();
}
Also used : ReferenceData(cbit.vcell.opt.ReferenceData) FileWriter(java.io.FileWriter) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) DataSource(cbit.vcell.modelopt.DataSource)

Example 3 with DataSource

use of cbit.vcell.modelopt.DataSource in project vcell by virtualcell.

the class MultisourcePlotListModel method refreshAll.

/**
 * Insert the method's description here.
 * Creation date: (8/31/2005 4:18:09 PM)
 */
private void refreshAll() {
    // 
    // get list of objects (data names)
    // 
    sortDataReferenceHelpers = new ArrayList<SortDataReferenceHelper>();
    for (int i = 0; getDataSources() != null && i < getDataSources().length; i++) {
        DataSource dataSource = getDataSources(i);
        String[] columnNames = dataSource.getColumnNames();
        int timeIndex = dataSource.getTimeColumnIndex();
        for (int j = 0; j < columnNames.length; j++) {
            if (j == timeIndex) {
                continue;
            }
            sortDataReferenceHelpers.add(new SortDataReferenceHelper(sortDataReferenceHelpers.size(), new DataReference(dataSource, columnNames[j])));
        // System.out.println("unsort="+(sortDataReferenceHelpers.size()-1)+" i="+i+" j="+j+" columnames[j]="+columnNames[j]);
        }
    }
    if (sortDataReferenceHelpers.size() > 0) {
        if (comparatorDataSource != null) {
            Collections.sort(sortDataReferenceHelpers, comparatorDataSource);
        } else {
            // default sort
            Collections.sort(sortDataReferenceHelpers, new Comparator<SortDataReferenceHelper>() {

                @Override
                public int compare(SortDataReferenceHelper o1, SortDataReferenceHelper o2) {
                    int idCompare = o1.dataReference.getIdentifier().compareToIgnoreCase(o2.dataReference.getIdentifier());
                    if (idCompare == 0) {
                        return o1.dataReference.getDataSource().getName().compareToIgnoreCase(o2.dataReference.getDataSource().getName());
                    }
                    return idCompare;
                }
            });
        }
    }
    if (sortDataReferenceHelpers.size() > 0) {
        DataReference[] dataReferences = new DataReference[sortDataReferenceHelpers.size()];
        for (int i = 0; i < dataReferences.length; i++) {
            dataReferences[i] = sortDataReferenceHelpers.get(i).dataReference;
        }
        setContents(dataReferences);
    } else {
        setContents(null);
    }
}
Also used : DataReference(cbit.vcell.modelopt.DataReference) DataSource(cbit.vcell.modelopt.DataSource)

Example 4 with DataSource

use of cbit.vcell.modelopt.DataSource in project vcell by virtualcell.

the class MultisourcePlotPane method getJList1.

/**
 * Return the JList1 property value.
 * @return javax.swing.JList
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JList<DataReference> getJList1() {
    if (ivjJList1 == null) {
        try {
            ivjJList1 = new javax.swing.JList<DataReference>();
            ivjJList1.setName("JList1");
            ivjJList1.setBounds(0, 0, 255, 480);
            ivjJList1.setCellRenderer(new ListCellRenderer<DataReference>() {

                DefaultListCellRenderer defaultListCellRenderer = new DefaultListCellRenderer();

                private Boolean isEvenMatchedSet(int index0) {
                    if (ivjJList1.getModel().getSize() == 0) {
                        return null;
                    }
                    if (getmultisourcePlotListModel().getSortedDataReferences().get(index0).matchCount == null) {
                        // create matched set group counts (this happens 1 time)
                        int masterMatchCount = 0;
                        for (int i = 0; i < ivjJList1.getModel().getSize(); i++) {
                            DataSource dataSource = getmultisourcePlotListModel().getSortedDataReferences().get(i).dataReference.getDataSource();
                            if (dataSource instanceof DataSource.DataSourceReferenceData) {
                                if (i != ivjJList1.getModel().getSize() - 1) {
                                    SortDataReferenceHelper mySortDataReferenceHelper = getmultisourcePlotListModel().getSortedDataReferences().get(i);
                                    SortDataReferenceHelper potentialMatchSortDataReferenceHelper = getmultisourcePlotListModel().getSortedDataReferences().get(i + 1);
                                    if (potentialMatchSortDataReferenceHelper.getReferenceDataMappingSpec() != null && mySortDataReferenceHelper != null && potentialMatchSortDataReferenceHelper.getReferenceDataMappingSpec().getReferenceDataColumnName().equals(mySortDataReferenceHelper.dataReference.getIdentifier())) {
                                        mySortDataReferenceHelper.matchCount = masterMatchCount;
                                        potentialMatchSortDataReferenceHelper.matchCount = masterMatchCount;
                                        masterMatchCount++;
                                    } else {
                                        mySortDataReferenceHelper.matchCount = -1;
                                    }
                                } else {
                                    getmultisourcePlotListModel().getSortedDataReferences().get(i).matchCount = -1;
                                }
                            } else if (getmultisourcePlotListModel().getSortedDataReferences().get(i).matchCount == null) {
                                getmultisourcePlotListModel().getSortedDataReferences().get(i).matchCount = -1;
                            }
                        }
                    }
                    if (getmultisourcePlotListModel().getSortedDataReferences().get(index0).matchCount == -1) {
                        // not part of matched set
                        return null;
                    }
                    return getmultisourcePlotListModel().getSortedDataReferences().get(index0).matchCount % 2 == 0;
                }

                @Override
                public Component getListCellRendererComponent(JList<? extends DataReference> list, DataReference value, int index, boolean isSelected, boolean cellHasFocus) {
                    Component comp = defaultListCellRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                    try {
                        if (bGroupingListSorter && comp instanceof JLabel) {
                            if (isSelected) {
                                comp.setBackground(getJList1().getSelectionBackground());
                                comp.setForeground(getJList1().getSelectionForeground());
                            } else {
                                Boolean evenMatch = isEvenMatchedSet(index);
                                comp.setBackground(evenMatch == null || evenMatch ? getJList1().getBackground() : DefaultScrollTableCellRenderer.everyOtherRowColor);
                                comp.setForeground(getJList1().getForeground());
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return comp;
                }
            });
        // user code begin {1}
        // user code end
        } catch (java.lang.Throwable ivjExc) {
            // user code begin {2}
            // user code end
            handleException(ivjExc);
        }
    }
    return ivjJList1;
}
Also used : JLabel(javax.swing.JLabel) DataSource(cbit.vcell.modelopt.DataSource) SortDataReferenceHelper(cbit.vcell.modelopt.gui.MultisourcePlotListModel.SortDataReferenceHelper) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) Component(java.awt.Component) DataReference(cbit.vcell.modelopt.DataReference)

Example 5 with DataSource

use of cbit.vcell.modelopt.DataSource 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

DataSource (cbit.vcell.modelopt.DataSource)13 ODESolverResultSet (cbit.vcell.solver.ode.ODESolverResultSet)9 ReferenceData (cbit.vcell.opt.ReferenceData)6 ODESolverResultSetColumnDescription (cbit.vcell.math.ODESolverResultSetColumnDescription)5 Color (java.awt.Color)5 DataReference (cbit.vcell.modelopt.DataReference)3 SimpleReferenceData (cbit.vcell.opt.SimpleReferenceData)3 ExpressionException (cbit.vcell.parser.ExpressionException)3 FunctionColumnDescription (cbit.vcell.math.FunctionColumnDescription)2 FRAPStudy (cbit.vcell.microscopy.FRAPStudy)2 SortDataReferenceHelper (cbit.vcell.modelopt.gui.MultisourcePlotListModel.SortDataReferenceHelper)2 Plot2D (cbit.plot.Plot2D)1 PlotData (cbit.plot.PlotData)1 RowColumnResultSet (cbit.vcell.math.RowColumnResultSet)1 Variable (cbit.vcell.math.Variable)1 FRAPModel (cbit.vcell.microscopy.FRAPModel)1 ReservedSymbol (cbit.vcell.model.Model.ReservedSymbol)1 ModelOptimizationSpec (cbit.vcell.modelopt.ModelOptimizationSpec)1 ReferenceDataMappingSpec (cbit.vcell.modelopt.ReferenceDataMappingSpec)1 MultisourcePlotPane (cbit.vcell.modelopt.gui.MultisourcePlotPane)1