Search in sources :

Example 51 with ReactionParticipant

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

the class SBMLImporter method addReactionParticipants.

/**
 * addReactionParticipant : Adds reactants and products and modifiers to a
 * reaction. Input args are the sbml reaction, vc reaction This method was
 * created mainly to handle reactions where there are reactants and/or
 * products that appear multiple times in a reaction. Virtual Cell now
 * allows the import of such reactions.
 */
private void addReactionParticipants(org.sbml.jsbml.Reaction sbmlRxn, ReactionStep vcRxn) throws Exception {
    Model vcModel = vcBioModel.getSimulationContext(0).getModel();
    // if (!(vcRxn instanceof FluxReaction)) {
    if (true) {
        // reactants in sbmlRxn
        HashMap<String, Integer> sbmlReactantsHash = new HashMap<String, Integer>();
        for (int j = 0; j < (int) sbmlRxn.getNumReactants(); j++) {
            SpeciesReference spRef = sbmlRxn.getReactant(j);
            String sbmlReactantSpId = spRef.getSpecies();
            if (sbmlModel.getSpecies(sbmlReactantSpId) != null) {
                // check
                // if
                // spRef
                // is in
                // sbml
                // model
                // If stoichiometry of speciesRef is not an integer, it is
                // not handled in the VCell at this time; no point going
                // further
                double stoichiometry = 0.0;
                if (level < 3) {
                    // for SBML models < L3, default
                    // stoichiometry is 1, if field is not
                    // set.
                    // default value of stoichiometry,
                    stoichiometry = 1.0;
                    // if not set.
                    if (spRef.isSetStoichiometry()) {
                        stoichiometry = spRef.getStoichiometry();
                        if (((int) stoichiometry != stoichiometry) || spRef.isSetStoichiometryMath()) {
                            throw new SBMLImportException("Non-integer stoichiometry ('" + stoichiometry + "' for reactant '" + sbmlReactantSpId + "' in reaction '" + sbmlRxn.getId() + "') or stoichiometryMath not handled in VCell at this time.", Category.NON_INTEGER_STOICH);
                        // logger.sendMessage(VCLogger.Priority.HighPriority,
                        // VCLogger.ErrorType.ReactionError,
                        // "Non-integer stoichiometry or stoichiometryMath not handled in VCell at this time.");
                        }
                    }
                } else {
                    if (spRef.isSetStoichiometry()) {
                        stoichiometry = spRef.getStoichiometry();
                        if (((int) stoichiometry != stoichiometry) || spRef.isSetStoichiometryMath()) {
                            throw new SBMLImportException("Non-integer stoichiometry ('" + stoichiometry + "' for reactant '" + sbmlReactantSpId + "' in reaction '" + sbmlRxn.getId() + "') or stoichiometryMath not handled in VCell at this time.", Category.NON_INTEGER_STOICH);
                        // logger.sendMessage(VCLogger.Priority.HighPriority,
                        // VCLogger.ErrorType.ReactionError,
                        // "Non-integer stoichiometry or stoichiometryMath not handled in VCell at this time.");
                        // logger.sendMessage(VCLogger.Priority.HighPriority,
                        // VCLogger.ErrorType.ReactionError,
                        // "Non-integer stoichiometry or stoichiometryMath not handled in VCell at this time.");
                        }
                    } else {
                        throw new SBMLImportException("This is a SBML level 3 model, stoichiometry is not set for the reactant '" + sbmlReactantSpId + "' and no default value can be assumed.");
                    // logger.sendMessage(VCLogger.Priority.HighPriority,
                    // VCLogger.ErrorType.ReactionError,
                    // "This is a SBML level 3 model, stoichiometry is not set for the reactant '"
                    // + spRef.getSpecies() +
                    // "' and no default value can be assumed.");
                    }
                }
                if (sbmlReactantsHash.get(sbmlReactantSpId) == null) {
                    // if sbmlReactantSpId is NOT in sbmlReactantsHash, add
                    // it with its stoichiometry
                    sbmlReactantsHash.put(sbmlReactantSpId, Integer.valueOf((int) stoichiometry));
                } else {
                    // if sbmlReactantSpId IS in sbmlReactantsHash, update
                    // its stoichiometry value to (existing-from-hash +
                    // stoichiometry) and put it back in hash
                    int intStoich = sbmlReactantsHash.get(sbmlReactantSpId).intValue();
                    intStoich += (int) stoichiometry;
                    sbmlReactantsHash.put(sbmlReactantSpId, Integer.valueOf(intStoich));
                }
            } else {
                // spRef is not in model, throw exception
                throw new SBMLImportException("Reactant '" + sbmlReactantSpId + "' in reaction '" + sbmlRxn.getId() + "' not found as species in SBML model.");
            }
        // end - if (spRef is species in model)
        }
        // sbmlReactionParticipantsHash as reactants to vcRxn
        for (Entry<String, Integer> es : sbmlReactantsHash.entrySet()) {
            SpeciesContext speciesContext = vcModel.getSpeciesContext(es.getKey());
            int stoich = es.getValue();
            vcRxn.addReactant(speciesContext, stoich);
        }
        /*
			Iterator<String> sbmlReactantsIter = sbmlReactantsHash.keySet()
					.iterator();
			while (sbmlReactantsIter.hasNext()) {
				String sbmlReactantStr = sbmlReactantsIter.next();
				SpeciesContext speciesContext = vcModel
						.getSpeciesContext(sbmlReactantStr);
				int stoich = sbmlReactantsHash.get(sbmlReactantStr).intValue();
				((SimpleReaction) vcRxn).addReactant(speciesContext, stoich);
			}
			*/
        // products in sbmlRxn
        HashMap<String, Integer> sbmlProductsHash = new HashMap<String, Integer>();
        for (int j = 0; j < (int) sbmlRxn.getNumProducts(); j++) {
            SpeciesReference spRef = sbmlRxn.getProduct(j);
            String sbmlProductSpId = spRef.getSpecies();
            if (sbmlModel.getSpecies(sbmlProductSpId) != null) {
                /* check if spRef is in sbml model
					If stoichiometry of speciesRef is not an integer, it is
					not handled in the VCell at this time; no point going
					further */
                double stoichiometry = 0.0;
                if (level < 3) {
                    // for sBML models < L3, default
                    // stoichiometry is 1, if field is not
                    // set.
                    // default value of stoichiometry,
                    stoichiometry = 1.0;
                    // if not set.
                    if (spRef.isSetStoichiometry()) {
                        stoichiometry = spRef.getStoichiometry();
                        if (((int) stoichiometry != stoichiometry) || spRef.isSetStoichiometryMath()) {
                            throw new SBMLImportException("Non-integer stoichiometry ('" + stoichiometry + "' for product '" + sbmlProductSpId + "' in reaction '" + sbmlRxn.getId() + "') or stoichiometryMath not handled in VCell at this time.", Category.NON_INTEGER_STOICH);
                        // logger.sendMessage(VCLogger.Priority.HighPriority,
                        // VCLogger.ErrorType.ReactionError,
                        // "Non-integer stoichiometry or stoichiometryMath not handled in VCell at this time.");
                        }
                    }
                } else {
                    if (spRef.isSetStoichiometry()) {
                        stoichiometry = spRef.getStoichiometry();
                        if (((int) stoichiometry != stoichiometry) || spRef.isSetStoichiometryMath()) {
                            throw new SBMLImportException("Non-integer stoichiometry ('" + stoichiometry + "' for product '" + sbmlProductSpId + "' in reaction '" + sbmlRxn.getId() + "') or stoichiometryMath not handled in VCell at this time.", Category.NON_INTEGER_STOICH);
                        // logger.sendMessage(VCLogger.Priority.HighPriority,
                        // VCLogger.ErrorType.ReactionError,
                        // "Non-integer stoichiometry or stoichiometryMath not handled in VCell at this time.");
                        }
                    } else {
                        throw new SBMLImportException("This is a SBML level 3 model, stoichiometry is not set for the product '" + sbmlProductSpId + "' and no default value can be assumed.");
                    // logger.sendMessage(VCLogger.Priority.HighPriority,
                    // VCLogger.ErrorType.ReactionError,
                    // "This is a SBML level 3 model, stoichiometry is not set for the product '"
                    // + spRef.getSpecies() +
                    // "' and no default value can be assumed.");
                    }
                }
                if (sbmlProductsHash.get(sbmlProductSpId) == null) {
                    // if sbmlProductSpId is NOT in sbmlProductsHash, add it
                    // with its stoichiometry
                    sbmlProductsHash.put(sbmlProductSpId, Integer.valueOf((int) stoichiometry));
                } else {
                    // if sbmlProductSpId IS in sbmlProductsHash, update its
                    // stoichiometry value to (existing-value-from-hash +
                    // stoichiometry) and put it back in hash
                    int intStoich = sbmlProductsHash.get(sbmlProductSpId).intValue();
                    intStoich += (int) stoichiometry;
                    sbmlProductsHash.put(sbmlProductSpId, Integer.valueOf(intStoich));
                }
            } else {
                // spRef is not in model, throw exception
                throw new SBMLImportException("Product '" + sbmlProductSpId + "' in reaction '" + sbmlRxn.getId() + "' not found as species in SBML model.");
            }
        // end - if (spRef is species in model)
        }
        // as products to vcRxn
        for (Entry<String, Integer> es : sbmlProductsHash.entrySet()) {
            SpeciesContext speciesContext = vcModel.getSpeciesContext(es.getKey());
            int stoich = es.getValue();
            vcRxn.addProduct(speciesContext, stoich);
        }
    /*
			Iterator<String> sbmlProductsIter = sbmlProductsHash.keySet()
					.iterator();
			while (sbmlProductsIter.hasNext()) {
				String sbmlProductStr = sbmlProductsIter.next();
				SpeciesContext speciesContext = vcModel
						.getSpeciesContext(sbmlProductStr);
				int stoich = sbmlProductsHash.get(sbmlProductStr).intValue();
				((SimpleReaction) vcRxn).addProduct(speciesContext, stoich);
			}
			*/
    // proxy.addProducts(sbmlProductsHash);
    }
    // modifiers
    for (int j = 0; j < (int) sbmlRxn.getNumModifiers(); j++) {
        ModifierSpeciesReference spRef = sbmlRxn.getModifier(j);
        String sbmlSpId = spRef.getSpecies();
        if (sbmlModel.getSpecies(sbmlSpId) != null) {
            // check if this modifier species is preesent in vcRxn (could
            // have been added as reactamt/product/catalyst).
            // If alreay a catalyst in vcRxn, do nothing
            ArrayList<ReactionParticipant> vcRxnParticipants = getVCReactionParticipantsFromSymbol(vcRxn, sbmlSpId);
            SpeciesContext speciesContext = vcModel.getSpeciesContext(sbmlSpId);
            if (vcRxnParticipants == null || vcRxnParticipants.size() == 0) {
                // If not in reactionParticipantList of vcRxn, add as
                // catalyst.
                vcRxn.addCatalyst(speciesContext);
            } else {
                for (ReactionParticipant rp : vcRxnParticipants) {
                    if (rp instanceof Reactant || rp instanceof Product) {
                        // If already a reactant or product in vcRxn, add
                        // warning to localIssuesList, don't do anything
                        localIssueList.add(new Issue(speciesContext, issueContext, IssueCategory.SBMLImport_Reaction, "Species " + speciesContext.getName() + " was already added as a reactant and/or product to " + vcRxn.getName() + "; Cannot add it as a catalyst also.", Issue.SEVERITY_INFO));
                        break;
                    }
                }
            }
        } else {
            // spRef is not in model, throw exception
            throw new SBMLImportException("Modifier '" + sbmlSpId + "' in reaction '" + sbmlRxn.getId() + "' not found as species in SBML model.");
        }
    // end - if (spRef is species in model)
    }
// end - for modifiers
}
Also used : Issue(org.vcell.util.Issue) HashMap(java.util.HashMap) Product(cbit.vcell.model.Product) SpeciesContext(cbit.vcell.model.SpeciesContext) Reactant(cbit.vcell.model.Reactant) InteriorPoint(org.sbml.jsbml.ext.spatial.InteriorPoint) SpeciesReference(org.sbml.jsbml.SpeciesReference) ModifierSpeciesReference(org.sbml.jsbml.ModifierSpeciesReference) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel) ModifierSpeciesReference(org.sbml.jsbml.ModifierSpeciesReference) ReactionParticipant(cbit.vcell.model.ReactionParticipant)

Example 52 with ReactionParticipant

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

the class SBPAXKineticsExtractor method setVMForwardParamAsExpression.

private static void setVMForwardParamAsExpression(ReactionStep reaction, SBOParam kCat, Kinetics kinetics) throws ExpressionException, PropertyVetoException {
    if (kCat != null) {
        KineticsParameter Vmax = ((HMM_IRRKinetics) kinetics).getVmaxParameter();
        String unitF = SBOParam.formatUnit(kCat.getUnit());
        VCUnitDefinition kCatUnit = reaction.getModel().getUnitSystem().getInstance(unitF);
        Double numberKCat = 0.0;
        if (kCat.hasNumber()) {
            numberKCat = kCat.getNumber();
        }
        Expression KCatExpression = new Expression(numberKCat);
        KineticsParameter Kcat = kinetics.addUserDefinedKineticsParameter("Kcat", KCatExpression, kCatUnit);
        String enzymeName = "";
        ReactionParticipant[] participants = reaction.getReactionParticipants();
        for (int i = 0; i < participants.length; i++) {
            ReactionParticipant rp = participants[i];
            if (rp instanceof Catalyst) {
                enzymeName = rp.getName();
            }
        }
        SpeciesContext enzyme = reaction.getModel().getSpeciesContext(enzymeName);
        Vmax.setExpression(Expression.mult(new Expression(Kcat, reaction.getNameScope()), new Expression(enzyme, reaction.getNameScope())));
    }
}
Also used : VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) Expression(cbit.vcell.parser.Expression) HMM_IRRKinetics(cbit.vcell.model.HMM_IRRKinetics) SpeciesContext(cbit.vcell.model.SpeciesContext) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Catalyst(cbit.vcell.model.Catalyst)

Example 53 with ReactionParticipant

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

the class ReactPartTable method getReactionParticipant.

/**
 * This method was created in VisualAge.
 * @return cbit.vcell.model.ReactionParticipant
 * @param rset java.sql.ResultSet
 */
public ReactionParticipant getReactionParticipant(KeyValue rpKey, java.sql.ResultSet rset) throws java.sql.SQLException, DataAccessException {
    ReactionParticipant rp = null;
    KeyValue key = rpKey;
    String role = rset.getString(ReactPartTable.table.role.toString());
    int stoichiometry = rset.getInt(ReactPartTable.table.stoich.toString());
    if (role.equals(ROLE_CATALYST)) {
        rp = new Catalyst(key, null, null);
    } else if (role.equals(ROLE_PRODUCT)) {
        rp = new Product(key, null, null, stoichiometry);
    } else if (role.equals(ROLE_REACTANT)) {
        rp = new Reactant(key, null, null, stoichiometry);
    } else if (role.equals(ROLE_FLUX)) {
        rp = new FluxReaction.Flux(key, null, null);
    } else {
        throw new DataAccessException("unexpected value of " + ReactPartTable.table.role.toString() + "'" + role + "'");
    }
    rp.setStoichiometry(stoichiometry);
    return rp;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) Product(cbit.vcell.model.Product) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Reactant(cbit.vcell.model.Reactant) Catalyst(cbit.vcell.model.Catalyst) DataAccessException(org.vcell.util.DataAccessException)

Example 54 with ReactionParticipant

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

the class ReactStepDbDriver method getReactionStep.

/**
 * This method was created in VisualAge.
 * @return cbit.vcell.model.ReactionStep
 * @param rset java.sql.ResultSet
 * @exception java.sql.SQLException The exception description.
 */
private ReactionStep getReactionStep(QueryHashtable dbc, Connection con, ResultSet rset, Model model) throws SQLException, DataAccessException, PropertyVetoException {
    // 
    // try to get ReactionStep from the object cache
    // 
    KeyValue rsKey = new KeyValue(rset.getBigDecimal(ReactStepTable.table.id.toString()));
    ReactionStep rs = (ReactionStep) dbc.get(rsKey);
    if (rs != null) {
        return rs;
    }
    // 
    // construct reactionStep (from ReactStepTable results)
    // 
    KeyValue structKey = new KeyValue(rset.getBigDecimal(ReactStepTable.table.structRef.toString()));
    Structure structure = getStructure(dbc, con, structKey);
    rs = reactStepTable.getReactionStep(structure, model, rsKey, rset, dbSyntax);
    // 
    // add reaction participants for this reactionStep
    // 
    ReactionParticipant[] rp_Array = getReactionParticipants(dbc, con, rsKey, rs);
    rs.setReactionParticipantsFromDatabase(model, rp_Array);
    try {
        rs.getKinetics().bind(rs);
    } catch (cbit.vcell.parser.ExpressionException e) {
        e.printStackTrace(System.out);
        throw new DataAccessException("ExpressionException: " + e.getMessage());
    }
    dbc.put(rsKey, rs);
    // MIRIAMTable.table.setMIRIAMAnnotation(con, rs, rs.getKey());
    return rs;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) ReactionStep(cbit.vcell.model.ReactionStep) Structure(cbit.vcell.model.Structure) ReactionParticipant(cbit.vcell.model.ReactionParticipant) DataAccessException(org.vcell.util.DataAccessException)

Example 55 with ReactionParticipant

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

the class ReactStepDbDriver method insertReactionStep.

/**
 * addModel method comment.
 */
KeyValue insertReactionStep(InsertHashtable hash, Connection con, User user, ReactionStep reactionStep, KeyValue modelKey) throws SQLException, DataAccessException {
    // log.print("ReactStepDbDriver.insertReactionStep(user="+user+", reacitonStep="+reactionStep+")");
    // 
    // make sure all species and structures are in the database
    // 
    ReactionParticipant[] rp_Array = reactionStep.getReactionParticipants();
    for (int i = 0; i < rp_Array.length; i++) {
        // 
        // insert/update species for this reactionParticipant
        // 
        Species species = rp_Array[i].getSpecies();
        KeyValue speciesKey = hash.getDatabaseKey(species);
        if (speciesKey == null) {
            speciesKey = insertSpecies(hash, con, species, user);
        // throw new DataAccessException("Database error: species "+species.getName()+" has null key");
        }
        // }
        if (hash.getDatabaseKey(species) == null) {
            hash.put(species, speciesKey);
        }
        // 
        // may insert structure for this reactionParicipant
        // 
        Structure structure = rp_Array[i].getStructure();
        if (structure != null && hash.getDatabaseKey(structure) == null) {
            throw new DataAccessException("ReactionParticipant '" + rp_Array[i].getName() + "' for reaction '" + reactionStep.getName() + "' refers to structure '" + structure.getName() + "' which is not found in database");
        }
    }
    // 
    // make sure structure holding reactionStep is also in database
    // 
    Structure structure = reactionStep.getStructure();
    if (hash.getDatabaseKey(structure) == null) {
        throw new DataAccessException("Structure '" + structure.getName() + "' for reaction '" + reactionStep.getName() + "' not found in database");
    }
    // 
    // insert reactionStep
    // 
    KeyValue rsKey = keyFactory.getNewKey(con);
    insertReactionStepSQL(con, modelKey, hash.getDatabaseKey(structure), reactionStep, rsKey);
    // 
    // insert reactionParticipants
    // 
    ReactionParticipant[] react_participants = reactionStep.getReactionParticipants();
    for (int i = 0; i < react_participants.length; i++) {
        KeyValue rpKey = keyFactory.getNewKey(con);
        insertReactionParticipantSQL(hash, con, rpKey, react_participants[i], rsKey);
    }
    return rsKey;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) Structure(cbit.vcell.model.Structure) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Species(cbit.vcell.model.Species) DBSpecies(cbit.vcell.model.DBSpecies) DataAccessException(org.vcell.util.DataAccessException)

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