Search in sources :

Example 6 with ModelProcess

use of cbit.vcell.model.ModelProcess in project vcell by virtualcell.

the class BioModelEditorReactionTableModel method checkInputValue.

public String checkInputValue(String inputValue, int row, int column) {
    ModelProcess modelProcess = getValueAt(row);
    String errMsg = null;
    switch(column) {
        case COLUMN_NAME:
            if (modelProcess == null || !modelProcess.getName().equals(inputValue)) {
                if (getModel().getReactionStep(inputValue) != null) {
                    errMsg = "Reaction '" + inputValue + "' already exist!";
                    errMsg += VCellErrorMessages.PressEscToUndo;
                    errMsg = "<html>" + errMsg + "</html>";
                    return errMsg;
                }
                if (getModel().getRbmModelContainer().getReactionRule(inputValue) != null) {
                    errMsg = "ReactionRule '" + inputValue + "' already exist!";
                    errMsg += VCellErrorMessages.PressEscToUndo;
                    errMsg = "<html>" + errMsg + "</html>";
                    return errMsg;
                }
            }
            break;
        case COLUMN_EQUATION:
            try {
                if (modelProcess instanceof ReactionStep) {
                    ReactionStep reactionStep = (ReactionStep) modelProcess;
                    ModelProcessEquation.parseReaction(reactionStep, getModel(), inputValue);
                } else if (modelProcess instanceof ReactionRule) {
                    // ReactionRuleEmbedded reactionRule = (ReactionRuleEmbedded)modelProcess;
                    ReactionRule newlyParsedReactionRule_NotUsedForValidation = RbmUtils.parseReactionRule(inputValue, getModel().getStructures()[0], bioModel);
                } else {
                    // new row ... it's a rule if contains parentheses, plain reaction if it does not
                    if (inputValue.contains("(") && inputValue.contains(")")) {
                        ReactionRule newlyParsedReactionRule_NotUsedForValidation = RbmUtils.parseReactionRule(inputValue, getModel().getStructures()[0], bioModel);
                        if (newlyParsedReactionRule_NotUsedForValidation == null) {
                            throw new RuntimeException("Unable to generate a reaction rule for this input.");
                        }
                    } else {
                        ReactionStep reactionStep = (ReactionStep) modelProcess;
                        ModelProcessEquation.parseReaction(reactionStep, getModel(), inputValue);
                    }
                }
            } catch (org.vcell.model.bngl.ParseException ex) {
                errMsg = ex.getMessage();
                errMsg += VCellErrorMessages.PressEscToUndo;
                errMsg = "<html>" + errMsg + "</html>";
                return errMsg;
            } catch (Exception ex) {
                errMsg = ex.getMessage();
                errMsg += VCellErrorMessages.PressEscToUndo;
                errMsg = "<html>" + errMsg + "</html>";
                return errMsg;
            }
            break;
        case COLUMN_STRUCTURE:
            if (getModel().getStructure(inputValue) == null) {
                errMsg = "Structure '" + inputValue + "' does not exist!";
                errMsg += VCellErrorMessages.PressEscToUndo;
                errMsg = "<html>" + errMsg + "</html>";
                return errMsg;
            }
            break;
    }
    return null;
}
Also used : ReactionRule(cbit.vcell.model.ReactionRule) ReactionStep(cbit.vcell.model.ReactionStep) ModelProcess(cbit.vcell.model.ModelProcess)

Example 7 with ModelProcess

use of cbit.vcell.model.ModelProcess in project vcell by virtualcell.

the class BioModelEditorReactionTableModel method computeData.

protected ArrayList<ModelProcess> computeData() {
    ArrayList<ModelProcess> processList = new ArrayList<ModelProcess>();
    if (getModel() != null) {
        ModelProcess[] modelProcesses = getModel().getModelProcesses();
        if (searchText == null || searchText.length() == 0) {
            processList.addAll(Arrays.asList(modelProcesses));
        } else {
            String lowerCaseSearchText = searchText.toLowerCase();
            for (ModelProcess process : modelProcesses) {
                boolean bMatchRelationshipObj = false;
                if (process instanceof ReactionStep) {
                    ReactionStep reactionStep = (ReactionStep) process;
                    HashSet<RelationshipObject> relObjsHash = bioModel.getRelationshipModel().getRelationshipObjects(reactionStep);
                    for (RelationshipObject relObj : relObjsHash) {
                        if (relObj.getBioPaxObject() instanceof Entity) {
                            if (((Entity) relObj.getBioPaxObject()).getName().get(0).toLowerCase().contains(lowerCaseSearchText)) {
                                bMatchRelationshipObj = true;
                                break;
                            }
                        }
                    }
                }
                if (bMatchRelationshipObj || process.containsSearchText(lowerCaseSearchText)) {
                    if (!processList.contains(process)) {
                        processList.add(process);
                    }
                }
                if (process instanceof ReactionStep) {
                    // we also search in reaction step expression, for strings like "s1 + s2" or s1 -> s2
                    ModelProcessEquation mpe = new ModelProcessEquation(process, bioModel.getModel());
                    if (mpe.toString().toLowerCase().contains(lowerCaseSearchText)) {
                        if (!processList.contains(process)) {
                            processList.add(process);
                        }
                    }
                }
            }
        }
    }
    return processList;
}
Also used : Entity(org.vcell.pathway.Entity) ReactionStep(cbit.vcell.model.ReactionStep) ArrayList(java.util.ArrayList) ModelProcessEquation(cbit.gui.ModelProcessEquation) ModelProcess(cbit.vcell.model.ModelProcess) RelationshipObject(org.vcell.relationship.RelationshipObject)

Example 8 with ModelProcess

use of cbit.vcell.model.ModelProcess in project vcell by virtualcell.

the class BioModelEditorModelPanel method duplicateButtonPressed.

private void duplicateButtonPressed() {
    computeCurrentSelectedTable();
    int row = currentSelectedTable.getSelectedRow();
    System.out.println("Duplicate Button Pressed for row " + row);
    if (currentSelectedTable == reactionsTable) {
        ModelProcess mp = reactionTableModel.getValueAt(row);
        if (!(mp instanceof ReactionRule)) {
            return;
        }
        ReactionRule oldRule = (ReactionRule) mp;
        if (bioModel.getModel().getNumStructures() == 1) {
            duplicateReactionRule(oldRule, oldRule.getStructure());
        } else if (bioModel.getModel().getNumStructures() > 1) {
            final JPopupMenu menu = new JPopupMenu("Choose compartment");
            for (int i = 0; i < bioModel.getModel().getNumStructures(); i++) {
                String ourType = oldRule.getStructure().getTypeName();
                Structure s = bioModel.getModel().getStructure(i);
                String theirType = s.getTypeName();
                if (!ourType.equals(theirType)) {
                    // offer to duplicate only within structures of the same type as the original,
                    continue;
                // otherwise units will be meaningless (surface vs volume)
                }
                String sName = s.getName();
                JMenuItem menuItem = new JMenuItem("In " + s.getTypeName() + " " + sName);
                menuItem.setIcon(new StructureToolShapeIcon(17));
                menu.add(menuItem);
                menuItem.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        newObject = duplicateReactionRule(oldRule, s);
                    // moves selection on the newly created object
                    // if (newObject != null) {
                    // for (int i = 0; i < currentSelectedTableModel.getRowCount(); i ++) {
                    // if (currentSelectedTableModel.getValueAt(i) == newObject) {
                    // currentSelectedTable.setRowSelectionInterval(i, i);
                    // break;
                    // }
                    // }
                    // }
                    }
                });
            }
            menu.show(duplicateButton, 0, duplicateButton.getHeight());
        }
    } else if (currentSelectedTable == speciesTable) {
        SpeciesContext sc = speciesTableModel.getValueAt(row);
        if (!sc.hasSpeciesPattern()) {
            return;
        }
        if (bioModel.getModel().getNumStructures() == 1) {
            duplicateSpecies(sc, sc.getStructure(), bioModel.getModel());
        } else if (bioModel.getModel().getNumStructures() > 1) {
            final JPopupMenu menu = new JPopupMenu("Choose compartment");
            for (int i = 0; i < bioModel.getModel().getNumStructures(); i++) {
                String ourType = sc.getStructure().getTypeName();
                Structure s = bioModel.getModel().getStructure(i);
                String theirType = s.getTypeName();
                if (!ourType.equals(theirType)) {
                    continue;
                }
                String sName = s.getName();
                JMenuItem menuItem = new JMenuItem("In " + s.getTypeName() + " " + sName);
                menuItem.setIcon(new StructureToolShapeIcon(17));
                menu.add(menuItem);
                menuItem.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        newObject = duplicateSpecies(sc, s, bioModel.getModel());
                    }
                });
            }
            menu.show(duplicateButton, 0, duplicateButton.getHeight());
        }
    } else if (currentSelectedTable == observablesTable) {
        RbmObservable o = observableTableModel.getValueAt(row);
        if (o.getSpeciesPatternList().isEmpty()) {
            return;
        }
        if (bioModel.getModel().getNumStructures() == 1) {
            duplicateObservable(o, o.getStructure(), bioModel.getModel());
        } else if (bioModel.getModel().getNumStructures() > 1) {
            final JPopupMenu menu = new JPopupMenu("Choose compartment");
            for (int i = 0; i < bioModel.getModel().getNumStructures(); i++) {
                Structure s = bioModel.getModel().getStructure(i);
                String sName = s.getName();
                JMenuItem menuItem = new JMenuItem("In " + s.getTypeName() + " " + sName);
                menuItem.setIcon(new StructureToolShapeIcon(17));
                menu.add(menuItem);
                menuItem.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        newObject = duplicateObservable(o, s, bioModel.getModel());
                    }
                });
            }
            menu.show(duplicateButton, 0, duplicateButton.getHeight());
        }
    }
}
Also used : ReactionRule(cbit.vcell.model.ReactionRule) ActionEvent(java.awt.event.ActionEvent) RbmObservable(cbit.vcell.model.RbmObservable) ModelProcess(cbit.vcell.model.ModelProcess) SpeciesContext(cbit.vcell.model.SpeciesContext) JPopupMenu(javax.swing.JPopupMenu) StructureToolShapeIcon(cbit.vcell.graph.gui.StructureToolShapeIcon) ActionListener(java.awt.event.ActionListener) Structure(cbit.vcell.model.Structure) JMenuItem(javax.swing.JMenuItem)

Example 9 with ModelProcess

use of cbit.vcell.model.ModelProcess in project vcell by virtualcell.

the class PhysiologyRelationshipTableModel method refreshData.

private void refreshData() {
    ArrayList<PhysiologyRelationshipTableRow> pathwayObjectList = new ArrayList<PhysiologyRelationshipTableRow>();
    if (bioModel != null) {
        HashSet<RelationshipObject> relationshipObjects = null;
        if (bioModelEntityObject != null) {
            relationshipObjects = bioModel.getRelationshipModel().getRelationshipObjects(bioModelEntityObject);
        }
        List<PhysiologyRelationshipTableRow> allPathwayObjectList = new ArrayList<PhysiologyRelationshipTableRow>();
        for (BioPaxObject bpObject1 : bioModel.getPathwayModel().getBiopaxObjects()) {
            if ((bpObject1 instanceof PhysicalEntity && (bioModelEntityObject == null || bioModelEntityObject instanceof SpeciesContext)) || (bpObject1 instanceof Conversion && (bioModelEntityObject == null || bioModelEntityObject instanceof ModelProcess)) || (bpObject1 instanceof PhysicalEntity && (bioModelEntityObject == null || bioModelEntityObject instanceof MolecularType))) {
                PhysiologyRelationshipTableRow entityRow = new PhysiologyRelationshipTableRow(bpObject1);
                if (relationshipObjects != null) {
                    for (RelationshipObject ro : relationshipObjects) {
                        if (ro.getBioPaxObject() == entityRow.getBioPaxObject()) {
                            entityRow.setSelected(true);
                            break;
                        }
                    }
                }
                if (!bShowLinkOnly || entityRow.selected) {
                    allPathwayObjectList.add(entityRow);
                }
            }
        }
        if (searchText == null || searchText.length() == 0) {
            pathwayObjectList.addAll(allPathwayObjectList);
        } else {
            for (PhysiologyRelationshipTableRow rs : allPathwayObjectList) {
                BioPaxObject bpObject = rs.getBioPaxObject();
                String lowerCaseSearchText = searchText.toLowerCase();
                if (getLabel(bpObject).toLowerCase().contains(lowerCaseSearchText) || getType(bpObject).toLowerCase().contains(lowerCaseSearchText)) {
                    pathwayObjectList.add(rs);
                }
            }
        }
    }
    setData(pathwayObjectList);
    GuiUtils.flexResizeTableColumns(ownerTable);
}
Also used : BioPaxObject(org.vcell.pathway.BioPaxObject) ArrayList(java.util.ArrayList) ModelProcess(cbit.vcell.model.ModelProcess) SpeciesContext(cbit.vcell.model.SpeciesContext) RelationshipObject(org.vcell.relationship.RelationshipObject) Conversion(org.vcell.pathway.Conversion) MolecularType(org.vcell.model.rbm.MolecularType) PhysicalEntity(org.vcell.pathway.PhysicalEntity)

Aggregations

ModelProcess (cbit.vcell.model.ModelProcess)9 ReactionRule (cbit.vcell.model.ReactionRule)6 ReactionStep (cbit.vcell.model.ReactionStep)6 SpeciesContext (cbit.vcell.model.SpeciesContext)4 ArrayList (java.util.ArrayList)4 Structure (cbit.vcell.model.Structure)3 RelationshipObject (org.vcell.relationship.RelationshipObject)3 ModelProcessEquation (cbit.gui.ModelProcessEquation)2 RbmObservable (cbit.vcell.model.RbmObservable)2 MolecularType (org.vcell.model.rbm.MolecularType)2 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)2 BioPaxObject (org.vcell.pathway.BioPaxObject)2 BioModel (cbit.vcell.biomodel.BioModel)1 VCellSortTableModel (cbit.vcell.client.desktop.biomodel.VCellSortTableModel)1 SpeciesPatternSmallShape (cbit.vcell.graph.SpeciesPatternSmallShape)1 StructureToolShapeIcon (cbit.vcell.graph.gui.StructureToolShapeIcon)1 ModelProcessSpec (cbit.vcell.mapping.ModelProcessSpec)1 BioModelEntityObject (cbit.vcell.model.BioModelEntityObject)1 Feature (cbit.vcell.model.Feature)1 Membrane (cbit.vcell.model.Membrane)1