Search in sources :

Example 1 with ReactionNameScope

use of cbit.vcell.model.ReactionStep.ReactionNameScope in project vcell by virtualcell.

the class ReactionCartoonTool method detailsDeleteSpecies.

private static DeleteSpeciesInfo detailsDeleteSpecies(Component requester, SpeciesContext[] speciesContextArr, ReactionStep[] toBeDeletedReactStepArr, ReactionCartoon rxCartoon) throws Exception, UserCancelException {
    if (speciesContextArr == null || speciesContextArr.length == 0) {
        return null;
    }
    // Warn user that there may be some BioModel components that reference speciesContext to be removed
    // Get ReactionParticipant list
    Collection<Shape> rxPartColl = rxCartoon.getShapes();
    HashMap<SpeciesContext, HashSet<ReactionParticipant>> rxPartHashMap = new HashMap<SpeciesContext, HashSet<ReactionParticipant>>();
    for (Shape objShape : rxPartColl) {
        if (objShape instanceof ReactionParticipantShape) {
            ReactionParticipant objReactionParticipant = ((ReactionParticipantShape) objShape).getReactionParticipant();
            if (Arrays.asList(speciesContextArr).contains(objReactionParticipant.getSpeciesContext())) {
                if (!rxPartHashMap.containsKey(objReactionParticipant.getSpeciesContext())) {
                    rxPartHashMap.put(objReactionParticipant.getSpeciesContext(), new HashSet<ReactionParticipant>());
                }
                if (!rxPartHashMap.get(objReactionParticipant.getSpeciesContext()).contains(objReactionParticipant)) {
                    rxPartHashMap.get(objReactionParticipant.getSpeciesContext()).add(objReactionParticipant);
                }
            }
        }
    }
    int reactionParticipantCount = 0;
    for (HashSet<ReactionParticipant> objReactPart : rxPartHashMap.values()) {
        reactionParticipantCount += objReactPart.size();
    }
    // find bioModel and get SymbolTable references to SpeciesContext
    BioModelEditor bioModelEditor = (BioModelEditor) BeanUtils.findTypeParentOfComponent(requester, BioModelEditor.class);
    if (bioModelEditor == null) {
        throw new Exception("Error deleting Speciescontext, Can't find BiomodelEditor");
    }
    BioModel bioModel = bioModelEditor.getBioModelWindowManager().getVCDocument();
    HashMap<SpeciesContext, HashSet<SymbolTableEntry>> referencingSymbolsHashMap = new HashMap<SpeciesContext, HashSet<SymbolTableEntry>>();
    for (int i = 0; i < speciesContextArr.length; i++) {
        List<SymbolTableEntry> referencingSymbolsList = bioModel.findReferences(speciesContextArr[i]);
        if (referencingSymbolsList != null && referencingSymbolsList.size() > 0) {
            if (!referencingSymbolsHashMap.containsKey(speciesContextArr[i])) {
                referencingSymbolsHashMap.put(speciesContextArr[i], new HashSet<SymbolTableEntry>());
            }
            referencingSymbolsHashMap.get(speciesContextArr[i]).addAll(referencingSymbolsList);
        }
    }
    int referencingSymbolsCount = 0;
    for (HashSet<SymbolTableEntry> objSimTableEntry : referencingSymbolsHashMap.values()) {
        referencingSymbolsCount += objSimTableEntry.size();
    }
    // Warn user about delete
    HashMap<SpeciesContext, Boolean> bUnresolvableHashMap = new HashMap<SpeciesContext, Boolean>();
    for (int i = 0; i < speciesContextArr.length; i++) {
        bUnresolvableHashMap.put(speciesContextArr[i], Boolean.FALSE);
    }
    String[][] rowData = null;
    if (rxPartHashMap.size() == 0 && referencingSymbolsHashMap.size() == 0) {
        rowData = new String[speciesContextArr.length][4];
        for (int i = 0; i < speciesContextArr.length; i++) {
            rowData[i][0] = speciesContextArr[i].getName();
            rowData[i][1] = "";
            rowData[i][2] = "";
            rowData[i][3] = "";
        }
        Arrays.sort(rowData, new Comparator<String[]>() {

            @Override
            public int compare(String[] o1, String[] o2) {
                return o1[0].compareToIgnoreCase(o2[0]);
            }
        });
    } else {
        // find SpeciesContext that had no reference warnings
        Vector<SpeciesContext> speciesContextNoReferences = new Vector<SpeciesContext>();
        for (int i = 0; i < speciesContextArr.length; i++) {
            if (!rxPartHashMap.containsKey(speciesContextArr[i]) && !referencingSymbolsHashMap.containsKey(speciesContextArr[i])) {
                speciesContextNoReferences.add(speciesContextArr[i]);
            }
        }
        rowData = new String[reactionParticipantCount + referencingSymbolsCount + speciesContextNoReferences.size()][4];
        int count = 0;
        for (SpeciesContext objSpeciesContext : speciesContextNoReferences) {
            rowData[count][0] = objSpeciesContext.getName();
            rowData[count][1] = "";
            rowData[count][2] = "";
            rowData[count][3] = "";
            count++;
        }
        for (SpeciesContext objSpeciesContext : rxPartHashMap.keySet()) {
            Iterator<ReactionParticipant> iterRxPart = rxPartHashMap.get(objSpeciesContext).iterator();
            while (iterRxPart.hasNext()) {
                rowData[count][0] = objSpeciesContext.getName();
                rowData[count][1] = "";
                rowData[count][2] = "Reaction Diagram stoichiometry '" + iterRxPart.next().getReactionStep().getName() + "'";
                rowData[count][3] = "";
                count++;
            }
        }
        for (SpeciesContext objSpeciesContext : referencingSymbolsHashMap.keySet()) {
            Iterator<SymbolTableEntry> iterSymbolTableEntry = referencingSymbolsHashMap.get(objSpeciesContext).iterator();
            while (iterSymbolTableEntry.hasNext()) {
                rowData[count][0] = objSpeciesContext.getName();
                rowData[count][1] = "";
                SymbolTableEntry objSymbolTableEntry = iterSymbolTableEntry.next();
                boolean bKineticsParameter = objSymbolTableEntry instanceof KineticsParameter;
                if (bKineticsParameter) {
                    KineticsParameter kp = (KineticsParameter) objSymbolTableEntry;
                    boolean isOK = kp.isRegenerated();
                    for (int i = 0; toBeDeletedReactStepArr != null && i < toBeDeletedReactStepArr.length; i++) {
                        if (toBeDeletedReactStepArr[i] == kp.getKinetics().getReactionStep()) {
                            // OK to delete this Speciescontext if were deleting the reaction that contained the reference
                            isOK = true;
                        }
                    }
                    rowData[count][1] = (isOK ? "" : RXSPECIES_ERROR);
                    bUnresolvableHashMap.put(objSpeciesContext, bUnresolvableHashMap.get(objSpeciesContext) || !isOK);
                }
                boolean bReaction = objSymbolTableEntry.getNameScope() instanceof ReactionNameScope;
                rowData[count][2] = (bReaction ? "Reaction" : objSymbolTableEntry.getNameScope().getClass().getName()) + "( " + objSymbolTableEntry.getNameScope().getName() + " )";
                rowData[count][3] = (bKineticsParameter ? "Parameter" : objSymbolTableEntry.getClass().getName()) + "( " + objSymbolTableEntry.getName() + " )";
                count++;
            }
        }
        // for (SymbolTableEntry referencingSTE : referencingSymbols) {
        // System.out.println("REFERENCE   "+referencingSTE.getClass().getName()+"("+referencingSTE.getName()+") nameScope "+referencingSTE.getNameScope().getClass().getName()+"("+referencingSTE.getNameScope().getName()+")");
        // }
        Arrays.sort(rowData, new Comparator<String[]>() {

            @Override
            public int compare(String[] o1, String[] o2) {
                return o1[0].compareToIgnoreCase(o2[0]);
            }
        });
    }
    if (rowData == null || rowData.length == 0) {
        return null;
    }
    return new DeleteSpeciesInfo(rxPartHashMap, bUnresolvableHashMap, rowData);
}
Also used : SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) RubberBandRectShape(cbit.gui.graph.RubberBandRectShape) ProductShape(cbit.vcell.graph.ProductShape) ContainerShape(cbit.gui.graph.ContainerShape) CatalystShape(cbit.vcell.graph.CatalystShape) FluxReactionShape(cbit.vcell.graph.FluxReactionShape) ContainerContainerShape(cbit.vcell.graph.ContainerContainerShape) ReactantShape(cbit.vcell.graph.ReactantShape) ElipseShape(cbit.gui.graph.ElipseShape) SimpleReactionShape(cbit.vcell.graph.SimpleReactionShape) ReactionStepShape(cbit.vcell.graph.ReactionStepShape) ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) Shape(cbit.gui.graph.Shape) RuleParticipantSignatureDiagramShape(cbit.vcell.graph.RuleParticipantSignatureDiagramShape) ReactionRuleDiagramShape(cbit.vcell.graph.ReactionRuleDiagramShape) RubberBandEdgeShape(cbit.gui.graph.RubberBandEdgeShape) ReactionParticipantShape(cbit.vcell.graph.ReactionParticipantShape) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) SpeciesContext(cbit.vcell.model.SpeciesContext) ReactionParticipantShape(cbit.vcell.graph.ReactionParticipantShape) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) BioModelEditor(cbit.vcell.client.desktop.biomodel.BioModelEditor) Vector(java.util.Vector) ReactionNameScope(cbit.vcell.model.ReactionStep.ReactionNameScope) HashSet(java.util.HashSet) Point(java.awt.Point) PropertyVetoException(java.beans.PropertyVetoException) UtilCancelException(org.vcell.util.UtilCancelException) ExpressionException(cbit.vcell.parser.ExpressionException) UserCancelException(org.vcell.util.UserCancelException) BioModel(cbit.vcell.biomodel.BioModel) ReactionParticipant(cbit.vcell.model.ReactionParticipant)

Aggregations

ContainerShape (cbit.gui.graph.ContainerShape)1 ElipseShape (cbit.gui.graph.ElipseShape)1 RubberBandEdgeShape (cbit.gui.graph.RubberBandEdgeShape)1 RubberBandRectShape (cbit.gui.graph.RubberBandRectShape)1 Shape (cbit.gui.graph.Shape)1 BioModel (cbit.vcell.biomodel.BioModel)1 BioModelEditor (cbit.vcell.client.desktop.biomodel.BioModelEditor)1 CatalystShape (cbit.vcell.graph.CatalystShape)1 ContainerContainerShape (cbit.vcell.graph.ContainerContainerShape)1 FluxReactionShape (cbit.vcell.graph.FluxReactionShape)1 ProductShape (cbit.vcell.graph.ProductShape)1 ReactantShape (cbit.vcell.graph.ReactantShape)1 ReactionContainerShape (cbit.vcell.graph.ReactionContainerShape)1 ReactionParticipantShape (cbit.vcell.graph.ReactionParticipantShape)1 ReactionRuleDiagramShape (cbit.vcell.graph.ReactionRuleDiagramShape)1 ReactionStepShape (cbit.vcell.graph.ReactionStepShape)1 RuleParticipantSignatureDiagramShape (cbit.vcell.graph.RuleParticipantSignatureDiagramShape)1 SimpleReactionShape (cbit.vcell.graph.SimpleReactionShape)1 SpeciesContextShape (cbit.vcell.graph.SpeciesContextShape)1 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)1