Search in sources :

Example 96 with AsynchClientTask

use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.

the class OptModelParamPanel method computeProfileLikelihood.

public void computeProfileLikelihood() {
    final Repository repository = new MemoryRepository();
    Workflow workflow = new Workflow("profileLikelihoodWorkflow");
    final TaskContext context = new TaskContext(workflow, repository, localWorkspace);
    System.err.println("OptModelParamPanel.showParameterEvaluation(): how do we pass in the initial guess to ProfileLikelihood code??? should be an independent input to ProfileLikelihood so that it is explicit ... and OptContext is immutable.????");
    final RunProfileLikelihoodGeneral runProfileLikelihoodGeneral = new RunProfileLikelihoodGeneral("internal");
    WorkflowParameter<OptContext> optContextParam = workflow.addParameter(OptContext.class, "optContext", repository, optContext);
    workflow.connectParameter(optContextParam, runProfileLikelihoodGeneral.optContext);
    workflow.addTask(runProfileLikelihoodGeneral);
    final DisplayProfileLikelihoodPlots displayProfileLikelihoodPlots = new DisplayProfileLikelihoodPlots("displayProfileLikihood");
    workflow.connect2(runProfileLikelihoodGeneral.profileData, displayProfileLikelihoodPlots.profileData);
    WorkflowParameter<String> titleParam = workflow.addParameter(String.class, "title", repository, "profile likelihood");
    workflow.connectParameter(titleParam, displayProfileLikelihoodPlots.title);
    workflow.addTask(displayProfileLikelihoodPlots);
    AsynchClientTask evaluateTask = new AsynchClientTask("Prepare to evaluate parameters ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            runProfileLikelihoodGeneral.compute(context, getClientTaskStatusSupport());
        }
    };
    AsynchClientTask showResultTask = new AsynchClientTask("Showing profile likelihood and confidence intervals ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            displayProfileLikelihoodPlots.compute(context, getClientTaskStatusSupport());
        }
    };
    // dispatch
    ClientTaskDispatcher.dispatch(OptModelParamPanel.this, new Hashtable<String, Object>(), new AsynchClientTask[] { evaluateTask, showResultTask }, false, true, null, true);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) TaskContext(org.vcell.workflow.TaskContext) Hashtable(java.util.Hashtable) Workflow(org.vcell.workflow.Workflow) DisplayProfileLikelihoodPlots(org.vcell.vmicro.workflow.task.DisplayProfileLikelihoodPlots) OptContext(org.vcell.vmicro.workflow.data.OptContext) RunProfileLikelihoodGeneral(org.vcell.vmicro.workflow.task.RunProfileLikelihoodGeneral) MemoryRepository(org.vcell.workflow.MemoryRepository) Repository(org.vcell.workflow.Repository) MemoryRepository(org.vcell.workflow.MemoryRepository)

Example 97 with AsynchClientTask

use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.

the class BioModelEditor method createNewBiomodelFromApp.

private void createNewBiomodelFromApp() {
    SimulationContext simulationContext = getSelectedSimulationContext();
    if (simulationContext == null) {
        PopupGenerator.showErrorDialog(this, "Please select an application.");
        return;
    }
    // bioModel.getVCMetaData().cleanupMetadata();
    try {
        String newBMXML = XmlHelper.bioModelToXML(bioModel);
        BioModel newBioModel = XmlHelper.XMLToBioModel(new XMLSource(newBMXML));
        newBioModel.clearVersion();
        SimulationContext[] newBMSimcontexts = newBioModel.getSimulationContexts();
        for (int i = 0; i < newBMSimcontexts.length; i++) {
            if (!newBMSimcontexts[i].getName().equals(simulationContext.getName())) {
                // Remove sims before removing simcontext
                Simulation[] newBMSims = newBMSimcontexts[i].getSimulations();
                for (int j = 0; j < newBMSims.length; j++) {
                    newBMSimcontexts[i].removeSimulation(newBMSims[j]);
                }
                newBioModel.removeSimulationContext(newBMSimcontexts[i]);
            }
        }
        VCDocument.DocumentCreationInfo newBMDocCreateInfo = new VCDocument.DocumentCreationInfo(VCDocumentType.BIOMODEL_DOC, VCDocument.BIO_OPTION_DEFAULT);
        newBMDocCreateInfo.setPreCreatedDocument(newBioModel);
        AsynchClientTask[] newBMTasks = getBioModelWindowManager().newDocument(newBMDocCreateInfo);
        ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), newBMTasks);
    } catch (Exception e) {
        e.printStackTrace();
        PopupGenerator.showErrorDialog(this, "Error creating new BioModel from Application '" + simulationContext.getName() + "'\n" + e.getMessage());
    }
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) VCDocument(org.vcell.util.document.VCDocument) SimulationContext(cbit.vcell.mapping.SimulationContext) PropertyVetoException(java.beans.PropertyVetoException) UnsupportedOperationException(javax.help.UnsupportedOperationException) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel) BioPaxObject(org.vcell.pathway.BioPaxObject) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) CSGObject(cbit.vcell.geometry.CSGObject) XMLSource(cbit.vcell.xml.XMLSource)

Example 98 with AsynchClientTask

use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.

the class BioModelEditor method popupMenuActionPerformed.

@Override
protected void popupMenuActionPerformed(DocumentEditorPopupMenuAction action, String actionCommand) {
    Model model = bioModel.getModel();
    final SimulationContext selectedSimulationContext = getSelectedSimulationContext();
    switch(action) {
        case add_new:
            try {
                Object obj = documentEditorTree.getLastSelectedPathComponent();
                if (obj == null || !(obj instanceof BioModelNode)) {
                    return;
                }
                BioModelNode selectedNode = (BioModelNode) obj;
                Object userObject = selectedNode.getUserObject();
                if (userObject instanceof DocumentEditorTreeFolderNode) {
                    DocumentEditorTreeFolderClass folderClass = ((DocumentEditorTreeFolderNode) userObject).getFolderClass();
                    Object newObject = null;
                    switch(folderClass) {
                        case REACTIONS_NODE:
                            // TODO: should add a Add New Rule menu item
                            newObject = model.createSimpleReaction(model.getStructure(0));
                            break;
                        case STRUCTURES_NODE:
                            newObject = model.createFeature();
                            break;
                        case SPECIES_NODE:
                            newObject = model.createSpeciesContext(model.getStructure(0));
                            break;
                        case MOLECULAR_TYPES_NODE:
                            MolecularType mt = model.getRbmModelContainer().createMolecularType();
                            model.getRbmModelContainer().addMolecularType(mt, true);
                            newObject = mt;
                            break;
                        case OBSERVABLES_NODE:
                            if (bioModel.getModel().getRbmModelContainer().getMolecularTypeList().isEmpty()) {
                                PopupGenerator.showInfoDialog(this, VCellErrorMessages.MustBeRuleBased);
                                return;
                            }
                            RbmObservable o = model.getRbmModelContainer().createObservable(RbmObservable.ObservableType.Molecules);
                            model.getRbmModelContainer().addObservable(o);
                            SpeciesPattern sp = new SpeciesPattern();
                            o.addSpeciesPattern(sp);
                            newObject = o;
                            break;
                        case SIMULATIONS_NODE:
                            if (selectedSimulationContext != null) {
                                AsynchClientTask task1 = new AsynchClientTask("new simulation", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

                                    @Override
                                    public void run(Hashtable<String, Object> hashTable) throws Exception {
                                        MathMappingCallback callback = new MathMappingCallbackTaskAdapter(getClientTaskStatusSupport());
                                        selectedSimulationContext.refreshMathDescription(callback, NetworkGenerationRequirements.AllowTruncatedStandardTimeout);
                                    }
                                };
                                AsynchClientTask task2 = new AsynchClientTask("new simulation", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

                                    @Override
                                    public void run(Hashtable<String, Object> hashTable) throws Exception {
                                        MathMappingCallback callback = new MathMappingCallbackTaskAdapter(getClientTaskStatusSupport());
                                        Object newsim = selectedSimulationContext.addNewSimulation(SimulationOwner.DEFAULT_SIM_NAME_PREFIX, callback, NetworkGenerationRequirements.AllowTruncatedStandardTimeout);
                                        selectionManager.setSelectedObjects(new Object[] { newsim });
                                    }
                                };
                                ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 });
                            }
                            break;
                        default:
                            break;
                    }
                    if (newObject != null) {
                        selectionManager.setSelectedObjects(new Object[] { newObject });
                    }
                }
            } catch (Exception ex) {
                DialogUtils.showErrorDialog(this, ex.getMessage());
            }
            break;
        case add_new_app_deterministic:
            newApplication(Application.NETWORK_DETERMINISTIC);
            break;
        case add_new_app_stochastic:
            newApplication(Application.NETWORK_STOCHASTIC);
            break;
        case add_new_app_rulebased:
            {
                // if(model.getStructures().length > 1) {
                // DialogUtils.showErrorDialog(this, VCellErrorMessages.NFSimAppNotAllowedForMultipleStructures);
                // return;
                // }
                newApplication(Application.RULE_BASED_STOCHASTIC);
                break;
            }
        case copy_app:
            ApplicationActionCommand acc = ApplicationActionCommand.lookup(actionCommand);
            switch(acc.actionType()) {
                case COPY_AS_IS:
                    copyApplication();
                    break;
                case COPY_CHANGE:
                    boolean bothSpatial = acc.isSourceSpatial() && acc.isDestSpatial();
                    // if(acc.getAppType().equals(SimulationContext.Application.RULE_BASED_STOCHASTIC) && model.getStructures().length > 1) {
                    // DialogUtils.showErrorDialog(this, VCellErrorMessages.NFSimAppNotAllowedForMultipleStructures);
                    // return;
                    // }
                    copyApplication(bothSpatial, acc.getAppType());
                    break;
                case CREATE:
                    // not used in this menu
                    throw new UnsupportedOperationException();
            }
            break;
        case app_new_biomodel:
            if (actionCommand.equals(GuiConstants.MENU_TEXT_APP_NEWBIOMODEL)) {
                createNewBiomodelFromApp();
            }
            break;
        case delete:
            try {
                if (selectedSimulationContext != null) {
                    String confirm = PopupGenerator.showOKCancelWarningDialog(this, "Deleting application", "You are going to delete the Application '" + selectedSimulationContext.getName() + "'. Continue?");
                    if (confirm.equals(UserMessage.OPTION_CANCEL)) {
                        return;
                    }
                    deleteSimulationcontexts(new SimulationContext[] { selectedSimulationContext });
                }
            } catch (Exception ex) {
                DialogUtils.showErrorDialog(this, ex.getMessage());
            }
            break;
        case deleteChoose:
            try {
                SimulationContext[] allSimContexts = Arrays.copyOf(getBioModelWindowManager().getVCDocument().getSimulationContexts(), getBioModelWindowManager().getVCDocument().getSimulationContexts().length);
                Arrays.sort(allSimContexts, new Comparator<SimulationContext>() {

                    @Override
                    public int compare(SimulationContext o1, SimulationContext o2) {
                        return o1.getName().compareToIgnoreCase(o2.getName());
                    }
                });
                String[][] rowDataOrig = new String[allSimContexts.length][2];
                for (int i = 0; i < allSimContexts.length; i++) {
                    rowDataOrig[i][0] = allSimContexts[i].getName();
                    rowDataOrig[i][1] = allSimContexts[i].getSimulations().length + "";
                }
                final String DELETE = "Delete";
                final String CANCEL = "Cancel";
                TableListResult result = DialogUtils.showComponentOptionsTableList(this, "Select Applications (and associated Simulations) to delete.", new String[] { "Application", "# of Sims" }, rowDataOrig, ListSelectionModel.MULTIPLE_INTERVAL_SELECTION, null, new String[] { DELETE, CANCEL }, CANCEL, null);
                if (result != null && result.selectedOption != null && result.selectedOption.equals(DELETE) && result.selectedTableRows != null && result.selectedTableRows.length > 0) {
                    ArrayList<SimulationContext> deleteTheseSimcontexts = new ArrayList<SimulationContext>();
                    for (int i = 0; i < result.selectedTableRows.length; i++) {
                        deleteTheseSimcontexts.add(allSimContexts[result.selectedTableRows[i]]);
                    }
                    deleteSimulationcontexts(deleteTheseSimcontexts.toArray(new SimulationContext[0]));
                }
            } catch (Exception ex) {
                DialogUtils.showErrorDialog(this, ex.getMessage());
            }
            break;
        default:
            break;
    }
}
Also used : TableListResult(org.vcell.util.gui.DialogUtils.TableListResult) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) ApplicationActionCommand(cbit.vcell.client.constants.ApplicationActionCommand) ArrayList(java.util.ArrayList) BioModelNode(cbit.vcell.desktop.BioModelNode) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) UnsupportedOperationException(javax.help.UnsupportedOperationException) MathMappingCallbackTaskAdapter(cbit.vcell.mapping.MathMappingCallbackTaskAdapter) MathMappingCallback(cbit.vcell.mapping.SimulationContext.MathMappingCallback) Hashtable(java.util.Hashtable) RbmObservable(cbit.vcell.model.RbmObservable) DocumentEditorTreeFolderNode(cbit.vcell.client.desktop.biomodel.DocumentEditorTreeModel.DocumentEditorTreeFolderNode) SimulationContext(cbit.vcell.mapping.SimulationContext) DocumentEditorTreeFolderClass(cbit.vcell.client.desktop.biomodel.DocumentEditorTreeModel.DocumentEditorTreeFolderClass) PropertyVetoException(java.beans.PropertyVetoException) UnsupportedOperationException(javax.help.UnsupportedOperationException) MolecularType(org.vcell.model.rbm.MolecularType) Model(cbit.vcell.model.Model) ListSelectionModel(javax.swing.ListSelectionModel) BioModel(cbit.vcell.biomodel.BioModel) BioPaxObject(org.vcell.pathway.BioPaxObject) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) CSGObject(cbit.vcell.geometry.CSGObject)

Example 99 with AsynchClientTask

use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.

the class BioModelEditorApplicationPanel method setSimulationContext.

public void setSimulationContext(SimulationContext newValue) {
    if (simulationContext == newValue) {
        return;
    }
    final boolean respondingToSelectionManager = selectionManager.isBusy();
    final Object[] selectedObj = selectionManager.getSelectedObjects();
    SimulationContext oldValue = simulationContext;
    if (oldValue != null) {
        oldValue.removePropertyChangeListener(eventHandler);
    }
    if (newValue != null) {
        newValue.addPropertyChangeListener(eventHandler);
    }
    simulationContext = newValue;
    AsynchClientTask task1 = new AsynchClientTask("loading application", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            simulationContext.getGeometry().precomputeAll(new GeometryThumbnailImageFactoryAWT());
        }
    };
    AsynchClientTask task2 = new AsynchClientTask("showing application", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            applicationGeometryPanel.setSimulationContext(simulationContext);
            applicationSpecificationsPanel.setSimulationContext(simulationContext);
            applicationProtocolsPanel.setSimulationContext(simulationContext);
            applicationSimulationsPanel.setSimulationContext(simulationContext);
            parameterEstimationPanel.setSelectionManager(null);
            showOrHideFittingPanel();
            parameterEstimationPanel.setSelectionManager(selectionManager);
            // showOrHideProtocolsPanel();
            if (respondingToSelectionManager) {
                selectionManager.setSelectedObjects(new Object[0]);
                selectionManager.setSelectedObjects(selectedObj);
            }
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 });
}
Also used : GeometryThumbnailImageFactoryAWT(cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) SimulationContext(cbit.vcell.mapping.SimulationContext)

Example 100 with AsynchClientTask

use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.

the class SimulationListPanel method newSimulation.

/**
 * Comment
 */
private void newSimulation(final NetworkGenerationRequirements networkGenerationRequirements) {
    AsynchClientTask task1 = new AsynchClientTask("new simulation", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            MathMappingCallback mathMappingCallback = new MathMappingCallbackTaskAdapter(getClientTaskStatusSupport());
            if (getSimulationWorkspace().getSimulationOwner() instanceof SimulationContext) {
                SimulationContext simulationContext = (SimulationContext) getSimulationWorkspace().getSimulationOwner();
                simulationContext.refreshMathDescription(mathMappingCallback, networkGenerationRequirements);
            }
        }
    };
    AsynchClientTask task2 = new AsynchClientTask("new simulation", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            MathMappingCallback mathMappingCallback = new MathMappingCallbackTaskAdapter(getClientTaskStatusSupport());
            int newSimIndex = getSimulationWorkspace().newSimulation(SimulationListPanel.this, mathMappingCallback, networkGenerationRequirements);
            getScrollPaneTable().getSelectionModel().setSelectionInterval(newSimIndex, newSimIndex);
            getScrollPaneTable().scrollRectToVisible(getScrollPaneTable().getCellRect(newSimIndex, 0, true));
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 });
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) MathMappingCallbackTaskAdapter(cbit.vcell.mapping.MathMappingCallbackTaskAdapter) MathMappingCallback(cbit.vcell.mapping.SimulationContext.MathMappingCallback) Hashtable(java.util.Hashtable) SimulationContext(cbit.vcell.mapping.SimulationContext)

Aggregations

AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)229 Hashtable (java.util.Hashtable)219 ArrayList (java.util.ArrayList)68 UserCancelException (org.vcell.util.UserCancelException)52 File (java.io.File)35 CSGObject (cbit.vcell.geometry.CSGObject)30 Point (java.awt.Point)23 DataAccessException (org.vcell.util.DataAccessException)22 SimulationContext (cbit.vcell.mapping.SimulationContext)21 FRAPStudy (cbit.vcell.microscopy.FRAPStudy)18 PropertyVetoException (java.beans.PropertyVetoException)18 ImageException (cbit.image.ImageException)17 IOException (java.io.IOException)17 GeometryThumbnailImageFactoryAWT (cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT)14 Vector (java.util.Vector)14 DataFormatException (java.util.zip.DataFormatException)14 UtilCancelException (org.vcell.util.UtilCancelException)14 Geometry (cbit.vcell.geometry.Geometry)12 ActionEvent (java.awt.event.ActionEvent)12 BioModel (cbit.vcell.biomodel.BioModel)11