Search in sources :

Example 46 with ReactionParticipant

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

the class Xmlproducer method getXML.

/**
 * This method returns a XML representation of a Flux Reaction object.
 * Creation date: (2/26/2001 12:30:13 PM)
 * @return Element
 * @param param cbit.vcell.model.FluxReaction
 */
private Element getXML(FluxReaction param) throws XmlParseException {
    Element fluxreaction = new Element(XMLTags.FluxStepTag);
    // get Attributes
    String versionName = (param.getName() != null) ? mangle(param.getName()) : "unnamed_fluxReaction";
    fluxreaction.setAttribute(XMLTags.NameAttrTag, versionName);
    fluxreaction.setAttribute(XMLTags.StructureAttrTag, mangle(param.getStructure().getName()));
    fluxreaction.setAttribute(XMLTags.ReversibleAttrTag, mangle(Boolean.valueOf(param.isReversible()).toString()));
    if (param.getPhysicsOptions() == FluxReaction.PHYSICS_ELECTRICAL_ONLY) {
        fluxreaction.setAttribute(XMLTags.FluxOptionAttrTag, XMLTags.FluxOptionElectricalOnly);
    } else if (param.getPhysicsOptions() == FluxReaction.PHYSICS_MOLECULAR_AND_ELECTRICAL) {
        fluxreaction.setAttribute(XMLTags.FluxOptionAttrTag, XMLTags.FluxOptionMolecularAndElectrical);
    } else if (param.getPhysicsOptions() == FluxReaction.PHYSICS_MOLECULAR_ONLY) {
        fluxreaction.setAttribute(XMLTags.FluxOptionAttrTag, XMLTags.FluxOptionMolecularOnly);
    }
    // If keyFlag is on print the Keyvalue
    if (param.getKey() != null && this.printKeysFlag) {
        fluxreaction.setAttribute(XMLTags.KeyValueAttrTag, param.getKey().toString());
    }
    // Add subelements: Reactants/Products/Catalysts
    // separate the order of the reactants, products, and modifiers.
    ReactionParticipant[] rpArray = param.getReactionParticipants();
    ArrayList<Element> products = new ArrayList<Element>();
    ArrayList<Element> modifiers = new ArrayList<Element>();
    for (int i = 0; i < rpArray.length; i++) {
        Element rp = getXML(rpArray[i]);
        if (rp != null) {
            if (rpArray[i] instanceof Reactant)
                fluxreaction.addContent(rp);
            else if (rpArray[i] instanceof Product)
                products.add(rp);
            else if (rpArray[i] instanceof Catalyst)
                modifiers.add(rp);
        }
    }
    for (int i = 0; i < products.size(); i++) fluxreaction.addContent((Element) products.get(i));
    for (int i = 0; i < modifiers.size(); i++) fluxreaction.addContent((Element) modifiers.get(i));
    // Add Kinetics
    fluxreaction.addContent(getXML(param.getKinetics()));
    return fluxreaction;
}
Also used : Element(org.jdom.Element) ArrayList(java.util.ArrayList) Product(cbit.vcell.model.Product) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Reactant(cbit.vcell.model.Reactant) Catalyst(cbit.vcell.model.Catalyst)

Example 47 with ReactionParticipant

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

the class ModelProcessEquation method computeEquationString.

private void computeEquationString() {
    if (modelProcess instanceof ReactionStep) {
        ReactionStep reactionStep = (ReactionStep) modelProcess;
        ReactionParticipant[] reactantParticipants = reactionStep.getReactionParticipants();
        ArrayList<ReactionParticipant> reactantList = new ArrayList<ReactionParticipant>();
        ArrayList<ReactionParticipant> productList = new ArrayList<ReactionParticipant>();
        // if (reactionStep instanceof SimpleReaction) {
        for (ReactionParticipant rp : reactantParticipants) {
            if (rp instanceof Reactant) {
                reactantList.add(rp);
            } else if (rp instanceof Product) {
                productList.add(rp);
            }
        }
        // } else {
        // Membrane membrane = (Membrane) ((FluxReaction)reactionStep).getStructure();
        // StructureTopology structTopology = reactionStep.getModel().getStructureTopology();
        // for (ReactionParticipant rp : reactantParticipants) {
        // if (rp instanceof Flux) {
        // Flux flux = (Flux)rp;
        // Feature scf = (Feature) flux.getSpeciesContext().getStructure();
        // if (structTopology.getInsideFeature(membrane) == scf) {
        // productList.add(rp);
        // } else {
        // reactantList.add(rp);
        // }
        // }
        // }
        // }
        StringBuffer sb = new StringBuffer();
        for (ReactionParticipant r : reactantList) {
            if (sb.length() > 0) {
                sb.append(" + ");
            }
            int stoichiometry = r.getStoichiometry();
            sb.append((stoichiometry > 1 ? stoichiometry : "") + r.getName());
        }
        equationleftHand = sb.toString();
        sb = new StringBuffer();
        for (ReactionParticipant p : productList) {
            if (sb.length() > 0) {
                sb.append(" + ");
            }
            int stoichiometry = p.getStoichiometry();
            sb.append((stoichiometry > 1 ? stoichiometry : "") + p.getName());
        }
        equationRightHand = sb.toString();
        equationString = equationleftHand + " " + REACTION_GOESTO + " " + equationRightHand;
    } else if (modelProcess instanceof ReactionRule) {
        ReactionRule reactionRuleEmbedded = (ReactionRule) modelProcess;
        equationString = RbmUtils.toBnglStringShort(reactionRuleEmbedded, CompartmentMode.hide);
    }
}
Also used : ReactionRule(cbit.vcell.model.ReactionRule) ReactionStep(cbit.vcell.model.ReactionStep) ArrayList(java.util.ArrayList) Product(cbit.vcell.model.Product) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Reactant(cbit.vcell.model.Reactant)

Example 48 with ReactionParticipant

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

the class PathwayMapping method parseReaction.

private ReactionParticipant[] parseReaction(ReactionStep reactionStep, BioModel bioModel, RelationshipObject relationshipObject) throws ExpressionException, PropertyVetoException {
    if (reactionStep == null || bioModel == null || bioModel.getRelationshipModel() == null) {
        return null;
    }
    // create the reaction equation string
    String leftHand = getParticipantsString(((Conversion) relationshipObject.getBioPaxObject()).getLeft());
    String rightHand = getParticipantsString(((Conversion) relationshipObject.getBioPaxObject()).getRight());
    StringTokenizer st = new StringTokenizer(leftHand, "+");
    HashMap<String, SpeciesContext> speciesContextMap = new HashMap<String, SpeciesContext>();
    ArrayList<ReactionParticipant> rplist = new ArrayList<ReactionParticipant>();
    // create and add reaction participants to list for left-hand side of equation
    Model model = bioModel.getModel();
    Structure structure = reactionStep.getStructure();
    while (st.hasMoreElements()) {
        String nextToken = st.nextToken().trim();
        if (nextToken.length() == 0) {
            continue;
        }
        int stoichiIndex = 0;
        while (true) {
            if (Character.isDigit(nextToken.charAt(stoichiIndex))) {
                stoichiIndex++;
            } else {
                break;
            }
        }
        int stoichi = 1;
        String tmp = nextToken.substring(0, stoichiIndex);
        if (tmp.length() > 0) {
            stoichi = Integer.parseInt(tmp);
        }
        String var = nextToken.substring(stoichiIndex).trim();
        // get speciesContext object based on its name
        // if the speciesContext is not existed, create a new one
        SpeciesContext sc = model.getSpeciesContext(var);
        if (sc == null) {
            sc = speciesContextMap.get(var);
            if (sc == null) {
                // get species object based on its name
                // if the species is not existed, create a new one
                Species species = model.getSpecies(var);
                if (species == null) {
                    species = new Species(var, null);
                }
                sc = new SpeciesContext(species, structure);
                sc.setName(var);
                speciesContextMap.put(var, sc);
            }
        }
        // add the existed speciesContext objects or new speciesContext objects to reaction participant list
        if (reactionStep instanceof SimpleReaction || reactionStep instanceof FluxReaction) {
            rplist.add(new Reactant(null, (SimpleReaction) reactionStep, sc, stoichi));
        }
    }
    // create and add reaction participants to list for right-hand side of equation
    st = new StringTokenizer(rightHand, "+");
    while (st.hasMoreElements()) {
        String nextToken = st.nextToken().trim();
        if (nextToken.length() == 0) {
            continue;
        }
        int stoichiIndex = 0;
        while (true) {
            if (Character.isDigit(nextToken.charAt(stoichiIndex))) {
                stoichiIndex++;
            } else {
                break;
            }
        }
        int stoichi = 1;
        String tmp = nextToken.substring(0, stoichiIndex);
        if (tmp.length() > 0) {
            stoichi = Integer.parseInt(tmp);
        }
        String var = nextToken.substring(stoichiIndex);
        SpeciesContext sc = model.getSpeciesContext(var);
        if (sc == null) {
            sc = speciesContextMap.get(var);
            if (sc == null) {
                Species species = model.getSpecies(var);
                if (species == null) {
                    species = new Species(var, null);
                }
                sc = new SpeciesContext(species, structure);
                sc.setName(var);
                speciesContextMap.put(var, sc);
            }
        }
        if (reactionStep instanceof SimpleReaction || reactionStep instanceof FluxReaction) {
            rplist.add(new Product(null, (SimpleReaction) reactionStep, sc, stoichi));
        }
    }
    return rplist.toArray(new ReactionParticipant[0]);
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Product(cbit.vcell.model.Product) FluxReaction(cbit.vcell.model.FluxReaction) SpeciesContext(cbit.vcell.model.SpeciesContext) Reactant(cbit.vcell.model.Reactant) StringTokenizer(java.util.StringTokenizer) BioModel(cbit.vcell.biomodel.BioModel) Model(cbit.vcell.model.Model) Structure(cbit.vcell.model.Structure) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Species(cbit.vcell.model.Species)

Example 49 with ReactionParticipant

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

the class PathwayMapping method createReactionStep.

/*
	 * for reaction:
	 * 1. annotate the selected vcell object using linked pathway conversion
	 * 2. add non-existing speciesContexts from linked pathway conversion
	 * 3. add links between relative vcell objects and pathway objects
	 * Questions:
	 * - how to deal with the case that the reaction is existing in the model?
	 * 		+ add it in no matter what? 
	 * 				(this is the version we have now: 
	 * 					add the duplicated reactions in without name changing, 
	 * 				 	all duplicated reactions share the same participant objects)
	 *      + just modify the existing one?
	 */
private void createReactionStep(BioModel bioModel, Process process, ReactionStep reactionStep, RelationshipObject relationshipObject, ArrayList<ConversionTableRow> participants, boolean addSubunits) throws Exception {
    if (reactionStep == null || bioModel == null || bioModel.getRelationshipModel() == null || participants.size() < 1) {
        return;
    }
    ArrayList<ReactionParticipant> rplist = new ArrayList<ReactionParticipant>();
    // create and add reaction participants to list
    for (ConversionTableRow ctr : participants) {
        if (ctr.getBioPaxObject() instanceof Conversion)
            continue;
        int stoich = ctr.stoich().intValue();
        String safeId = getSafetyName(ctr.id());
        // get speciesContext object based on its name
        // if the speciesContext is not existed, create a new one
        createSpeciesContextFromTableRow(bioModel, (PhysicalEntity) ctr.getBioPaxObject(), ctr.stoich(), ctr.id(), ctr.location(), addSubunits);
        // add the existed speciesContext objects or new speciesContext objects to reaction participant list
        if (ctr.participantType().equals("Reactant")) {
            if (reactionStep instanceof SimpleReaction || reactionStep instanceof FluxReaction) {
                rplist.add(new Reactant(null, reactionStep, bioModel.getModel().getSpeciesContext(safeId), stoich));
            }
        } else if (ctr.participantType().equals("Product")) {
            if (reactionStep instanceof SimpleReaction || reactionStep instanceof FluxReaction) {
                rplist.add(new Product(null, reactionStep, bioModel.getModel().getSpeciesContext(safeId), stoich));
            }
        }
    // we do not add catalysts
    }
    ReactionParticipant[] rpArray = rplist.toArray(new ReactionParticipant[0]);
    reactionStep.setReactionParticipants(rpArray);
    // add Controls to the reaction
    Set<PhysicalEntity> controllers = process.getControllers();
    for (ConversionTableRow ctr : participants) {
        if (controllers.contains(ctr.getBioPaxObject())) {
            if (ctr.participantType().equals("Catalyst")) {
                String safeId = getSafetyName(ctr.id());
                /* 
					 * using addCatalyst() to create catalyst in reaction: 
					 * this function cannot allow an object to be catalyst and (reactant/product) in the same reaction
					 */
                // reactionStep.addCatalyst(bioModel.getModel().getSpeciesContext(safeId));
                /* However, in pathway interaction object, an physicalEntity can be catalyst and (reactant/product) in the same reaction
					 * So we just call create catalyst for the reaction no matter what rolls the object is playing in the reaction
					 * Switch back to the addCatalyst() function when it is necessary, but exceptions make be reported for some reactions
					 */
                reactionStep.addReactionParticipant(new Catalyst(null, reactionStep, bioModel.getModel().getSpeciesContext(safeId)));
            } else if (ctr.participantType().equals("Control")) {
                String safeId = getSafetyName(ctr.id());
                // reactionStep.addCatalyst(bioModel.getModel().getSpeciesContext(safeId));
                reactionStep.addReactionParticipant(new Catalyst(null, reactionStep, bioModel.getModel().getSpeciesContext(safeId)));
            }
        }
    }
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) ArrayList(java.util.ArrayList) Product(cbit.vcell.model.Product) FluxReaction(cbit.vcell.model.FluxReaction) Conversion(org.vcell.pathway.Conversion) Reactant(cbit.vcell.model.Reactant) PhysicalEntity(org.vcell.pathway.PhysicalEntity) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Catalyst(cbit.vcell.model.Catalyst)

Example 50 with ReactionParticipant

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

the class SBMLImporter method getVCReactionParticipantsFromSymbol.

private ArrayList<ReactionParticipant> getVCReactionParticipantsFromSymbol(ReactionStep reactionStep, String reactParticipantName) {
    ReactionParticipant[] rp_Array = reactionStep.getReactionParticipants();
    ArrayList<ReactionParticipant> matchingRxnParticipants = new ArrayList<ReactionParticipant>();
    for (int i = 0; i < rp_Array.length; i++) {
        if (AbstractNameScope.getStrippedIdentifier(reactParticipantName).equals(rp_Array[i].getSpeciesContext().getName())) {
            matchingRxnParticipants.add(rp_Array[i]);
        }
    }
    return matchingRxnParticipants;
}
Also used : ArrayList(java.util.ArrayList) ReactionParticipant(cbit.vcell.model.ReactionParticipant) InteriorPoint(org.sbml.jsbml.ext.spatial.InteriorPoint)

Aggregations

ReactionParticipant (cbit.vcell.model.ReactionParticipant)55 Reactant (cbit.vcell.model.Reactant)30 SpeciesContext (cbit.vcell.model.SpeciesContext)30 ReactionStep (cbit.vcell.model.ReactionStep)29 Product (cbit.vcell.model.Product)26 SimpleReaction (cbit.vcell.model.SimpleReaction)20 Structure (cbit.vcell.model.Structure)19 Expression (cbit.vcell.parser.Expression)18 FluxReaction (cbit.vcell.model.FluxReaction)16 Catalyst (cbit.vcell.model.Catalyst)14 ArrayList (java.util.ArrayList)14 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)13 Model (cbit.vcell.model.Model)13 ExpressionException (cbit.vcell.parser.ExpressionException)13 Membrane (cbit.vcell.model.Membrane)12 PropertyVetoException (java.beans.PropertyVetoException)12 Kinetics (cbit.vcell.model.Kinetics)11 Point (java.awt.Point)10 HashMap (java.util.HashMap)10 Shape (cbit.gui.graph.Shape)9