Search in sources :

Example 31 with FluxReaction

use of cbit.vcell.model.FluxReaction 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 32 with FluxReaction

use of cbit.vcell.model.FluxReaction 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 33 with FluxReaction

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

the class SBMLExporter method getAnnotationElement.

/**
 * 	getAnnotationElement :
 *	For a flux reaction, we need to add an annotation specifying the structure, flux carrier, carrier valence and fluxOption.
 *  For a simple reaction, we need to add a annotation specifying the structure (useful for import)
 *  Using XML JDOM elements, so that it is convenient for libSBML setAnnotation (requires the annotation to be provided as an xml string).
 */
private Element getAnnotationElement(ReactionStep reactionStep) throws cbit.vcell.xml.XmlParseException {
    Element sbmlImportRelatedElement = new Element(XMLTags.VCellRelatedInfoTag, sbml_vcml_ns);
    Element rxnElement = null;
    if (reactionStep instanceof FluxReaction) {
        FluxReaction fluxRxn = (FluxReaction) reactionStep;
        // Element for flux reaction. Write out the structure and flux carrier name.
        rxnElement = new Element(XMLTags.FluxStepTag, sbml_vcml_ns);
        rxnElement.setAttribute(XMLTags.StructureAttrTag, fluxRxn.getStructure().getName());
        // Get the physics option value.
        if (fluxRxn.getPhysicsOptions() == ReactionStep.PHYSICS_ELECTRICAL_ONLY) {
            rxnElement.setAttribute(XMLTags.FluxOptionAttrTag, XMLTags.FluxOptionElectricalOnly);
        } else if (fluxRxn.getPhysicsOptions() == ReactionStep.PHYSICS_MOLECULAR_AND_ELECTRICAL) {
            rxnElement.setAttribute(XMLTags.FluxOptionAttrTag, XMLTags.FluxOptionMolecularAndElectrical);
        } else if (fluxRxn.getPhysicsOptions() == ReactionStep.PHYSICS_MOLECULAR_ONLY) {
            rxnElement.setAttribute(XMLTags.FluxOptionAttrTag, XMLTags.FluxOptionMolecularOnly);
        }
    } else if (reactionStep instanceof cbit.vcell.model.SimpleReaction) {
        // Element for a simple reaction - just store structure name - will be useful while importing.
        cbit.vcell.model.SimpleReaction simpleRxn = (cbit.vcell.model.SimpleReaction) reactionStep;
        rxnElement = new org.jdom.Element(cbit.vcell.xml.XMLTags.SimpleReactionTag, sbml_vcml_ns);
        rxnElement.setAttribute(cbit.vcell.xml.XMLTags.StructureAttrTag, simpleRxn.getStructure().getName());
    }
    // Add rate name as an element of annotation - this is especially useful when roundtripping VCell models, when the reaction
    // rate parameters have been renamed by user.
    Element rateElement = new Element(XMLTags.ReactionRateTag, sbml_vcml_ns);
    if (reactionStep.getKinetics() instanceof DistributedKinetics) {
        rateElement.setAttribute(XMLTags.NameAttrTag, ((DistributedKinetics) reactionStep.getKinetics()).getReactionRateParameter().getName());
    } else if (reactionStep.getKinetics() instanceof LumpedKinetics) {
        rateElement.setAttribute(XMLTags.NameAttrTag, ((LumpedKinetics) reactionStep.getKinetics()).getLumpedReactionRateParameter().getName());
    } else {
        throw new RuntimeException("unexpected kinetic type " + reactionStep.getKinetics().getClass().getName());
    }
    sbmlImportRelatedElement.addContent(rxnElement);
    sbmlImportRelatedElement.addContent(rateElement);
    return sbmlImportRelatedElement;
}
Also used : DistributedKinetics(cbit.vcell.model.DistributedKinetics) LumpedKinetics(cbit.vcell.model.LumpedKinetics) Element(org.jdom.Element) FluxReaction(cbit.vcell.model.FluxReaction)

Example 34 with FluxReaction

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

the class VCReactionProxy method factory.

/**
 * get proxy for Reaction type
 * @param reaction not null
 * @return proxy
 * @throws ProgrammingException unknown type
 */
public static VCReactionProxy factory(ReactionStep reaction) {
    VCAssert.assertValid(reaction);
    SimpleReaction sr = BeanUtils.downcast(SimpleReaction.class, reaction);
    if (sr != null) {
        return new Simple(sr);
    }
    FluxReaction fr = BeanUtils.downcast(FluxReaction.class, reaction);
    if (fr != null) {
        return new Flux(fr);
    }
    throw new ProgrammingException("Unknown reaction type " + ExecutionTrace.justClassName(reaction));
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) FluxReaction(cbit.vcell.model.FluxReaction) ProgrammingException(org.vcell.util.ProgrammingException)

Example 35 with FluxReaction

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

the class ReactStepTable method getReactionStep.

/**
 * This method was created in VisualAge.
 * @return cbit.vcell.model.ReactionParticipant
 * @param rset java.sql.ResultSet
 */
public ReactionStep getReactionStep(Structure structure, Model model, KeyValue rsKey, java.sql.ResultSet rset, DatabaseSyntax dbSyntax) throws java.sql.SQLException, DataAccessException {
    KeyValue key = rsKey;
    if (rset.wasNull()) {
        key = null;
    }
    String reactType = rset.getString(ReactStepTable.table.reactType.toString());
    String reactionStepName = null;
    String nameString = rset.getString(ReactStepTable.table.name.toString());
    if (rset.wasNull()) {
        nameString = null;
    }
    if (nameString != null) {
        reactionStepName = TokenMangler.getSQLRestoredString(nameString);
    }
    ReactionStep rs = null;
    try {
        if (reactType.equals(ReactStepTable.REACTTYPE_FLUX_REVERSIBLE)) {
            rs = new FluxReaction(model, (Membrane) structure, key, reactionStepName, true);
        } else if (reactType.equals(ReactStepTable.REACTTYPE_FLUX_IRREVERSIBLE)) {
            rs = new FluxReaction(model, (Membrane) structure, key, reactionStepName, false);
        } else if (reactType.equals(ReactStepTable.REACTTYPE_SIMPLE_REVERSIBLE)) {
            rs = new SimpleReaction(model, structure, key, reactionStepName, true);
        } else if (reactType.equals(ReactStepTable.REACTTYPE_SIMPLE_IRREVERSIBLE)) {
            rs = new SimpleReaction(model, structure, key, reactionStepName, false);
        }
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace(System.out);
        throw new DataAccessException(e.getMessage());
    }
    // 
    // if valence is stored as a 'null', it was an error (previous models were updated administratively).
    // 
    int valenceValue = rset.getInt(ReactStepTable.table.chargeValence.toString());
    if (rset.wasNull()) {
        throw new DataAccessException("unexpected null for chargeValence");
    }
    // 
    // New procedure for getting kinetics
    // 
    String kinetics_vcml = DbDriver.varchar2_CLOB_get(rset, ReactStepTable.table.kineticsSmall, ReactStepTable.table.kineticsLarge, dbSyntax);
    if (kinetics_vcml == null || kinetics_vcml.length() == 0) {
        throw new DataAccessException("no data stored for kinetics");
    }
    // This isn't needed?
    // if (kinetics_vcml.endsWith(";}\n")){
    // StringBuffer buffer = new StringBuffer(kinetics_vcml.substring(0,kinetics_vcml.length()-2));
    // buffer.append("\n}\n");
    // kinetics_vcml = buffer.toString();
    // }
    org.vcell.util.CommentStringTokenizer tokens = new org.vcell.util.CommentStringTokenizer(kinetics_vcml);
    Kinetics kinetics = null;
    try {
        String token = tokens.nextToken();
        if (!token.equalsIgnoreCase(VCMODL.Kinetics)) {
            throw new DataAccessException("expected " + VCMODL.Kinetics);
        }
        token = tokens.nextToken();
        KineticsDescription kineticsDescription = KineticsDescription.fromVCMLKineticsName(token);
        if (kineticsDescription != null) {
            kinetics = kineticsDescription.createKinetics(rs);
        } else {
            throw new DataAccessException("expected valid kinetics type, read '" + token + "'");
        }
        kinetics.fromTokens(kinetics_vcml);
        // 
        // for debug purposes only, remove when unresolvedParameters are ok ... when globals exist
        // 
        // if (kinetics.getUnresolvedParameters().length!=0){
        // System.out.println("<<<WARNING>>> ReactStepTable.getReactionStep(key="+rsKey+") has "+kinetics.getUnresolvedParameters().length+" UnresolvedParameters");
        // for (int i = 0; i < kinetics.getUnresolvedParameters().length; i++){
        // System.out.println(">>>>>>>>>>>>> UnresolvedParameter["+i+"] = "+kinetics.getUnresolvedParameters()[i].toString());
        // }
        // }
        KineticsParameter chargeValenceParameter = kinetics.getChargeValenceParameter();
        if (chargeValenceParameter != null) {
            chargeValenceParameter.setExpression(new cbit.vcell.parser.Expression(valenceValue));
        }
    } catch (Exception e) {
        lg.error(e.getMessage(), e);
        throw new DataAccessException(e.getMessage());
    }
    rs.setKinetics(kinetics);
    // 
    // if physicsOptions is stored as a 'null', it was an error (previous models were updated administratively).
    // 
    int physicsOptionsValue = rset.getInt(ReactStepTable.table.physicsOptions.toString());
    if (rset.wasNull()) {
        throw new DataAccessException("unexpected null for physicsOptions");
    }
    try {
        rs.setPhysicsOptions(physicsOptionsValue);
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace(System.out);
    }
    String annot = rset.getString(ReactStepTable.table.annotation.getUnqualifiedColName());
    if (!rset.wasNull()) {
    // annot = TokenMangler.getSQLRestoredString(annot);
    // rs.setAnnotation(annot);
    }
    return rs;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) SimpleReaction(cbit.vcell.model.SimpleReaction) KineticsDescription(cbit.vcell.model.KineticsDescription) FluxReaction(cbit.vcell.model.FluxReaction) DataAccessException(org.vcell.util.DataAccessException) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) ReactionStep(cbit.vcell.model.ReactionStep) Membrane(cbit.vcell.model.Membrane) Kinetics(cbit.vcell.model.Kinetics) DataAccessException(org.vcell.util.DataAccessException)

Aggregations

FluxReaction (cbit.vcell.model.FluxReaction)35 SimpleReaction (cbit.vcell.model.SimpleReaction)26 SpeciesContext (cbit.vcell.model.SpeciesContext)17 Structure (cbit.vcell.model.Structure)17 Membrane (cbit.vcell.model.Membrane)16 ReactionParticipant (cbit.vcell.model.ReactionParticipant)16 ArrayList (java.util.ArrayList)14 ReactionStep (cbit.vcell.model.ReactionStep)13 Shape (cbit.gui.graph.Shape)12 Feature (cbit.vcell.model.Feature)12 Reactant (cbit.vcell.model.Reactant)12 Expression (cbit.vcell.parser.Expression)11 Product (cbit.vcell.model.Product)10 Point (java.awt.Point)10 PropertyVetoException (java.beans.PropertyVetoException)9 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)8 RuleParticipantSignature (cbit.vcell.model.RuleParticipantSignature)8 Catalyst (cbit.vcell.model.Catalyst)7 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)7 LumpedKinetics (cbit.vcell.model.LumpedKinetics)6