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
}
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())));
}
}
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;
}
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;
}
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;
}
Aggregations