Search in sources :

Example 1 with MultisourcePlotPane

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

use of cbit.vcell.modelopt.gui.MultisourcePlotPane in project vcell by virtualcell.

the class ReferenceDataPanel method getmultisourcePlotPane.

/**
 * Return the multisourcePlotPane property value.
 * @return cbit.vcell.modelopt.gui.MultisourcePlotPane
 */
private MultisourcePlotPane getmultisourcePlotPane() {
    if (ivjmultisourcePlotPane == null) {
        try {
            ivjmultisourcePlotPane = new MultisourcePlotPane();
            ivjmultisourcePlotPane.setName("multisourcePlotPane");
            ivjmultisourcePlotPane.setListVisible(false);
        } catch (java.lang.Throwable ivjExc) {
            handleException(ivjExc);
        }
    }
    return ivjmultisourcePlotPane;
}
Also used : MultisourcePlotPane(cbit.vcell.modelopt.gui.MultisourcePlotPane)

Aggregations

MultisourcePlotPane (cbit.vcell.modelopt.gui.MultisourcePlotPane)2 Variable (cbit.vcell.math.Variable)1 ReservedSymbol (cbit.vcell.model.Model.ReservedSymbol)1 DataSource (cbit.vcell.modelopt.DataSource)1 ModelOptimizationSpec (cbit.vcell.modelopt.ModelOptimizationSpec)1 ReferenceDataMappingSpec (cbit.vcell.modelopt.ReferenceDataMappingSpec)1 SortDataReferenceHelper (cbit.vcell.modelopt.gui.MultisourcePlotListModel.SortDataReferenceHelper)1 OptimizationException (cbit.vcell.opt.OptimizationException)1 ReferenceData (cbit.vcell.opt.ReferenceData)1 ExpressionException (cbit.vcell.parser.ExpressionException)1 ODESolverResultSet (cbit.vcell.solver.ode.ODESolverResultSet)1 ParameterEstimationTaskSimulatorIDA (org.vcell.optimization.ParameterEstimationTaskSimulatorIDA)1 UtilCancelException (org.vcell.util.UtilCancelException)1