use of org.sbml.jsbml.ModifierSpeciesReference 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 org.sbml.jsbml.ModifierSpeciesReference 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, Map<String, String> sbmlToVclNameMap) 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()) {
String sbmlReactantSpId = es.getKey();
String vcSpeciesName = sbmlReactantSpId;
if (sbmlToVclNameMap.get(sbmlReactantSpId) != null) {
vcSpeciesName = sbmlToVclNameMap.get(sbmlReactantSpId);
}
SpeciesContext speciesContext = vcModel.getSpeciesContext(vcSpeciesName);
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()) {
String sbmlProductSpId = es.getKey();
String vcSpeciesName = sbmlProductSpId;
if (sbmlToVclNameMap.get(sbmlProductSpId) != null) {
vcSpeciesName = sbmlToVclNameMap.get(sbmlProductSpId);
}
SpeciesContext speciesContext = vcModel.getSpeciesContext(vcSpeciesName);
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();
String vcSpeciesName = sbmlSpId;
if (sbmlToVclNameMap.get(sbmlSpId) != null) {
vcSpeciesName = sbmlToVclNameMap.get(sbmlSpId);
}
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, vcSpeciesName);
SpeciesContext speciesContext = vcModel.getSpeciesContext(vcSpeciesName);
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
}
Aggregations