use of org.vcell.pathway.sbo.SBOTerm in project vcell by virtualcell.
the class PathwayModel method ProcessKineticLaws.
/*
* For each kinetic law verify whether the SBOTerm which defines the type of kinetic law exists
* If it doesn't exist try to guesstimate it based on the type of parameters
* For example, if Km is present we assume it's Michaelis-Menten rate law, otherwise it's mass action
*/
private void ProcessKineticLaws() {
Set<Control> controls = BioPAXUtil.getAllControls(this);
Iterator<Control> iterator = controls.iterator();
while (iterator.hasNext()) {
Control control = iterator.next();
ArrayList<SBEntity> sbEntities = control.getSBSubEntity();
for (SBEntity sbE : sbEntities) {
// the only SBSubEntities allowed in a control are kinetic laws
if (sbE.getID().contains("kineticLaw")) {
// build list of the parameters of this kinetic law in sboParams
// params of this kinetic law
ArrayList<SBOParam> sboParams = new ArrayList<SBOParam>();
ArrayList<SBEntity> subEntities = sbE.getSBSubEntity();
for (SBEntity subEntity : subEntities) {
if (subEntity instanceof SBMeasurable) {
SBMeasurable m = (SBMeasurable) subEntity;
if (!m.hasTerm()) {
// we don't know what to do with a measurable with no SBTerm
break;
}
String termName = m.extractSBOTermAsString();
SBOTerm sboT = SBOListEx.sboMap.get(termName);
System.out.println(" " + sboT.getIndex() + " " + sboT.getName());
SBOParam sboParam = SBPAXKineticsExtractor.matchSBOParam(sboT);
if (m.hasNumber()) {
double number = m.getNumber().get(0);
sboParam.setNumber(number);
}
if (m.hasUnit()) {
String unit = m.extractSBOUnitAsString();
sboParam.setUnit(unit);
}
sboParams.add(sboParam);
}
}
ArrayList<SBVocabulary> sbTerms = sbE.getSBTerm();
if (sbTerms.isEmpty()) {
// we try to guesstimate kinetic law type based on params found above
SBVocabularyEx sbTerm = new SBVocabularyEx();
ArrayList<String> termNames = new ArrayList<String>();
String id;
SBOParam kMichaelis = SBPAXKineticsExtractor.extractMichaelisForwardParam(sboParams);
if (kMichaelis == null) {
// mass action rate law
id = new String("SBO:0000012");
System.out.println(" --- matched kinetic law to Mass Action");
} else {
// irreversible Henri-Michaelis-Menten rate law
id = new String("SBO:0000029");
System.out.println(" --- matched kinetic law to Henri-Michaelis-Menten");
}
sbTerm.setInferred(true);
sbTerm.setID(id);
sbTerms.add(sbTerm);
}
}
}
}
}
use of org.vcell.pathway.sbo.SBOTerm in project vcell by virtualcell.
the class KineticContext method getParameter.
public ModelParameter getParameter(SBOSet sboSet) {
ModelParameter param = sboSetToParam.get(sboSet);
if (param == null) {
for (Map.Entry<SBOTerm, ModelParameter> entry : termToParam.entrySet()) {
SBOTerm sboTerm = entry.getKey();
if (sboSet.includes(sboTerm)) {
param = entry.getValue();
sboSetToParam.put(sboSet, param);
break;
}
}
}
return param;
}
use of org.vcell.pathway.sbo.SBOTerm in project vcell by virtualcell.
the class SBPAXKineticsExtractor method extractKineticsExactMatch.
public static boolean extractKineticsExactMatch(ReactionStep reaction, Process process) throws ExpressionException, PropertyVetoException {
// we try a perfect match first based on the existence of a SBOTerm in the kinetic law
if (process.getControl() == null) {
// no control means no kinetic law - nothing more to do
return true;
}
Control control = process.getControl();
ArrayList<SBEntity> sbEntities = control.getSBSubEntity();
for (SBEntity sbE : sbEntities) {
// the only SBSubEntities allowed in a control are kinetic laws
if (sbE.getID().contains("kineticLaw")) {
// build list of the parameters of this kinetic law in sboParams
// params of this kinetic law
ArrayList<SBOParam> sboParams = new ArrayList<SBOParam>();
ArrayList<SBEntity> subEntities = sbE.getSBSubEntity();
for (SBEntity subEntity : subEntities) {
if (subEntity instanceof SBMeasurable) {
SBMeasurable m = (SBMeasurable) subEntity;
if (!m.hasTerm()) {
// we don't know what to do with a measurable with no SBTerm
break;
}
String termName = m.extractSBOTermAsString();
SBOTerm sboT = SBOListEx.sboMap.get(termName);
System.out.println(" " + sboT.getIndex() + " " + sboT.getName());
SBOParam sboParam = matchSBOParam(sboT);
if (m.hasNumber()) {
double number = m.getNumber().get(0);
sboParam.setNumber(number);
}
if (m.hasUnit()) {
String unit = m.extractSBOUnitAsString();
sboParam.setUnit(unit);
}
sboParams.add(sboParam);
}
}
// find if a kinetic law type exists and if not guesstimate one based on parameters
// simple rule: if we have a Km param it's MM, otherwise it's mass action
ArrayList<SBVocabulary> sbTerms = sbE.getSBTerm();
if (sbTerms.isEmpty()) {
// return false;
SBVocabulary sbTerm = new SBVocabulary();
ArrayList<String> termNames = new ArrayList<String>();
String id;
SBOParam kMichaelis = extractMichaelisForwardParam(sboParams);
if (kMichaelis == null) {
// mass action rate law
id = new String("SBO:0000012");
} else {
// irreversible Henri-Michaelis-Menten rate law
id = new String("SBO:0000029");
}
// termNames.add(id);
// sbTerm.setTerm(termNames);
sbTerm.setID(id);
sbTerms.add(sbTerm);
}
System.out.println(" kinetic law ID: " + sbTerms.get(0).getID());
// identify the kinetic law type (mass action, michaelis menten, etc) and bring it in vCell
for (SBVocabulary sbv : sbTerms) {
// use for loop even though we only expect 1 SBTerm
// SBVocabulary id, used to retrieve the kinetic law type
String vocabularyID = sbv.getID();
SBOTerm sboT = SBOUtil.getSBOTermFromVocabularyId(vocabularyID);
System.out.println(vocabularyID + " " + sboT.getName());
SBOParam kForward;
SBOParam kCat;
SBOParam vM;
SBOParam kReverse;
SBOParam kMichaelis;
Kinetics kinetics;
MappedKinetics current = matchSBOKineticLaw(sboT);
switch(current) {
case SBO_0000069:
case SBO_0000432:
// some kinetic laws unknown to vCell will fall through to this category
// honestly i don't know what to do with them
System.out.println("GeneralKinetics");
// TODO: what to do here?
return true;
case SBO_0000012:
case SBO_0000078:
System.out.println("MassActionKinetics - reversible");
kForward = extractKForwardParam(sboParams);
kReverse = extractKReverseParam(sboParams);
kinetics = new MassActionKinetics(reaction);
reaction.setKinetics(kinetics);
setKForwardParam(reaction, kForward, kinetics);
setKReverseParam(reaction, kReverse, kinetics);
return true;
case SBO_0000043:
System.out.println("MassActionKinetics - zeroth order irreversible, Kr <- 0 ");
kForward = extractKForwardParam(sboParams);
kinetics = new MassActionKinetics(reaction);
// TODO: what to do here?
return true;
case SBO_0000044:
System.out.println("MassActionKinetics - first order irreversible, Kr <- 0 ");
kForward = extractKForwardParam(sboParams);
kinetics = new MassActionKinetics(reaction);
reaction.setKinetics(kinetics);
setKForwardParam(reaction, kForward, kinetics);
return true;
case SBO_0000028:
case SBO_0000029:
System.out.println("HMM_IRRKinetics");
// TODO: make kCat global variable, set its number and unit in annotation
// TODO: make vM global variable, set its number and unit in annotation
// get the numbers, if present (may be null)
kMichaelis = extractMichaelisForwardParam(sboParams);
vM = extractVMForwardParam(sboParams, process);
kCat = extractKCatForwardParam(sboParams);
kinetics = new HMM_IRRKinetics((SimpleReaction) reaction);
try {
// TODO: create expression only if kCat != null, otherwise use vM directly (if != null) otherwise ???
kinetics.reading(true);
setVMForwardParamAsExpression(reaction, kCat, kinetics);
} finally {
kinetics.reading(false);
}
reaction.setKinetics(kinetics);
setMichaelisForwardParam(reaction, kMichaelis, kinetics);
return true;
case SBO_0000438:
System.out.println("HMMREVKinetics");
kinetics = new HMM_REVKinetics((SimpleReaction) reaction);
return true;
default:
// TODO: guessing happens above - if we have nothing by now we need to raise runtime exception
// change the code below !!!
System.out.println("Unable to match the SBOTerm with any compatible kinetic law.");
// found unmapped kinetic law, we'll try to guess a match
return false;
}
}
}
}
// no SBTerm found so we cannot know for sure the kinetic law, we'll have to guess it
return false;
}
use of org.vcell.pathway.sbo.SBOTerm in project vcell by virtualcell.
the class SBPAXParameterExtractor method extractParameter.
public static Map<SBOTerm, ModelParameter> extractParameter(ReactionStep reaction, SBMeasurable measurable) throws PropertyVetoException {
Map<SBOTerm, ModelParameter> sboToParameters = new HashMap<SBOTerm, ModelParameter>();
Set<SBOTerm> sboTerms = SBPAXSBOExtractor.extractSBOTerms(measurable);
String symbol = null;
VCUnitDefinition targetUnit = null;
Model model = reaction.getModel();
ModelUnitSystem modelUnitSystem = model.getUnitSystem();
Set<SBOTerm> termsWithUnituM = SetUtil.newSet(SBOList.sbo0000027MichaelisConstant, SBOList.sbo0000322MichaelisConstantForSubstrate);
for (SBOTerm sboTerm : sboTerms) {
if (termsWithUnituM.contains(sboTerm)) {
targetUnit = modelUnitSystem.getVolumeConcentrationUnit();
// targetUnit = VCUnitDefinition.UNIT_uM;
}
if (StringUtil.notEmpty(sboTerm.getSymbol())) {
symbol = sboTerm.getSymbol();
}
for (int i = 0; i < symbol.length(); ++i) {
char charAt = symbol.charAt(i);
if (!Character.isJavaIdentifierPart(charAt)) {
symbol = symbol.replace(charAt, '_');
}
}
}
VCUnitDefinition unit = UOMEUnitExtractor.extractVCUnitDefinition(measurable, modelUnitSystem);
double conversionFactor = 1.0;
if (targetUnit != null && unit != null && unit != modelUnitSystem.getInstance_TBD() && !targetUnit.equals(unit)) {
// if(unit.equals(VCUnitDefinition.UNIT_M) && targetUnit.equals(VCUnitDefinition.UNIT_uM)) {
if (unit.isCompatible(targetUnit)) {
conversionFactor = unit.convertTo(conversionFactor, targetUnit);
unit = targetUnit;
}
}
ArrayList<Double> numbers = measurable.getNumber();
if (StringUtil.isEmpty(symbol)) {
symbol = "p" + (++nParameter);
}
for (Double number : numbers) {
String parameterName = symbol + "_" + reaction.getName();
if (model.getModelParameter(parameterName) != null) {
int count = 0;
while (model.getModelParameter(parameterName + "_" + count) != null) {
++count;
}
parameterName = parameterName + "_" + count;
}
ModelParameter parameter = model.new ModelParameter(parameterName, new Expression(conversionFactor * number.doubleValue()), Model.ROLE_UserDefined, unit);
model.addModelParameter(parameter);
for (SBOTerm sboTerm : sboTerms) {
sboToParameters.put(sboTerm, parameter);
}
}
return sboToParameters;
}
use of org.vcell.pathway.sbo.SBOTerm in project vcell by virtualcell.
the class BioPaxObjectPropertiesPanel method refreshInterface.
protected void refreshInterface() {
if (bioPaxObject == null) {
// sanity check
return;
}
ArrayList<BioPaxObjectProperty> propertyList = new ArrayList<BioPaxObjectProperty>();
if (!(bioPaxObject instanceof SBEntity)) {
tableModel.setData(propertyList);
return;
}
SBEntity sbEntity = (SBEntity) bioPaxObject;
if (!(sbEntity instanceof Entity)) {
tableModel.setData(propertyList);
return;
}
Entity entity = (Entity) sbEntity;
// entity::type
propertyList.add(new BioPaxObjectProperty("Type", bioPaxObject.getTypeLabel()));
if (lookupContains(entity)) {
propertyList.add(new BioPaxObjectProperty("Name", entity.getName().get(0) + " (looking...)"));
} else if (entity.getFormalNames() != null && entity.getFormalNames().size() != 0) {
propertyList.add(new BioPaxObjectProperty("Name", entity.getName().get(0) + " (" + entity.getFormalNames().get(0) + ")"));
} else if (entity.getName() != null && entity.getName().size() > 0) {
String displayName = entity.getName().get(0);
if (entity.getxRef() != null && entity.getxRef().size() > 0) {
displayName = displayName + " (double-click lookup)";
}
// entity::name
propertyList.add(new BioPaxObjectProperty("Name", displayName));
}
// entity::Link
for (RelationshipObject rObject : bioModel.getRelationshipModel().getRelationshipObjects(bioPaxObject)) {
BioModelEntityObject beObject = rObject.getBioModelEntityObject();
propertyList.add(new BioPaxObjectProperty("Linked physiology object", beObject.getName(), beObject));
}
if (entity instanceof PhysicalEntity) {
// ------------------------ PHYSICAL ENTITY -----------------------
PhysicalEntity physicalEntity = (PhysicalEntity) entity;
// physicalEntity::feature (***ignored***)
// physicalEntity::memberPhysicalEntity (***ignored***)
// physicalEntity::notFeature (***ignored***)
// TODO: extract the kinetic law, then the SBEntities, then the measurables, units, aso
boolean isReactionParticipant = BioPAXUtil.isReactionParticipant(physicalEntity, bioModel.getPathwayModel());
String role = "";
if (BioPAXUtil.isController(physicalEntity, bioModel.getPathwayModel())) {
role += "Controller";
if (isReactionParticipant) {
role += ", Participant";
}
} else if (isReactionParticipant) {
role += "Participant";
}
if (!role.isEmpty()) {
propertyList.add(new BioPaxObjectProperty("Role(s)", role));
}
if (!(physicalEntity instanceof SmallMolecule)) {
// physicalEntity::cellular location
CellularLocationVocabulary cellularLocation = physicalEntity.getCellularLocation();
if (cellularLocation != null && cellularLocation.getTerm() != null && cellularLocation.getTerm().size() > 0) {
propertyList.add(new BioPaxObjectProperty("Cellular Location", cellularLocation.getTerm().get(0), cellularLocation));
} else if (entity.getName() != null && entity.getName().size() > 1) {
String location = entity.getName().get(1);
if (location.contains("[") && location.contains("]")) {
location = location.substring(location.indexOf("[") + 1, location.indexOf("]"));
propertyList.add(new BioPaxObjectProperty("Cellular Location", location));
}
}
}
if (physicalEntity instanceof Complex) {
Complex complex = (Complex) physicalEntity;
// complex::components
for (PhysicalEntity pe : complex.getComponents()) {
propertyList.add(new BioPaxObjectProperty("Component", getEntityName(pe), pe));
}
} else if (physicalEntity instanceof Protein) {
// Protein protein = (Protein)entity;
// protein::entity reference (***ignored***)
} else if (physicalEntity instanceof SmallMolecule) {
SmallMolecule sm = (SmallMolecule) physicalEntity;
EntityReference er = sm.getEntityReference();
if (er != null && !er.getName().isEmpty() && er.getName().get(0) != null && !er.getName().get(0).isEmpty()) {
propertyList.add(new BioPaxObjectProperty("Entity Reference", er.getName().get(0)));
ArrayList<Xref> xrefList = er.getxRef();
for (Xref xref : xrefList) {
propertyList.add(new BioPaxObjectProperty(" Xref", xref.getDb() + ":" + xref.getId(), xref));
}
}
} else if (physicalEntity instanceof Dna) {
// dna::entityReference (***ignored***)
} else if (physicalEntity instanceof DnaRegion) {
// dnaRegion::entityReference (***ignored***)
} else if (physicalEntity instanceof Rna) {
// rna::entityReference (***ignored***)
} else if (physicalEntity instanceof RnaRegion) {
// rnaRegion::entityReference (***ignored***)
}
} else if (entity instanceof Interaction) {
// --------------------------- INTERACTION -------------------
Interaction interaction = (Interaction) entity;
// interaction::interactionType
for (InteractionVocabulary interactionVocabulary : interaction.getInteractionTypes()) {
if (interactionVocabulary.getTerm().size() > 0) {
propertyList.add(new BioPaxObjectProperty("Interaction Type", interactionVocabulary.getTerm().get(0), interactionVocabulary));
}
}
// interaction::participants
for (InteractionParticipant interactionParticipant : interaction.getParticipants()) {
PhysicalEntity physicalEntity = interactionParticipant.getPhysicalEntity();
String physicalEntityName = physicalEntity.getName().size() > 0 ? physicalEntity.getName().get(0) : physicalEntity.getIDShort();
String cellularLocation = "";
if (physicalEntity.getCellularLocation() != null) {
cellularLocation = physicalEntity.getCellularLocation().getTerm().size() > 0 ? " [" + physicalEntity.getCellularLocation().getTerm().get(0) + "]" : "";
}
propertyList.add(new BioPaxObjectProperty(interactionParticipant.getLevel3PropertyName(), physicalEntityName + cellularLocation, physicalEntity));
}
// get the controllers for interactions
// we always need this because there's no guarantee we'll have kinetic laws
// for instance pathway commons doesn't have quantitative information
Set<String> controllersNames = getControllersNames(interaction);
if (controllersNames.size() > 0) {
for (String str : controllersNames) {
// String tooltip = "<html>how many of these 12 M <br>average size 1.12345*E12 nm <br>temperature 37 degrees Celsius</html>";
String tooltip = "";
propertyList.add(new BioPaxObjectProperty("Controlled by", str, interaction, tooltip));
}
}
// get the kinetic laws (if any)
Set<Control> controls = BioPAXUtil.getControlsOfInteraction(interaction, bioModel.getPathwayModel());
for (Control control : controls) {
ArrayList<SBEntity> sbEntities = control.getSBSubEntity();
for (SBEntity sbE : sbEntities) {
// the only SBSubEntities allowed in a control are kinetic laws
if (sbE.getID().contains("kineticLaw")) {
String str = new String();
if (control.getPhysicalControllers() != null) {
str += " for Controller(s): ";
for (PhysicalEntity ep : control.getPhysicalControllers()) {
if (ep.getName().size() > 0) {
str += ep.getName().get(0);
} else {
str += ep.getIDShort();
}
str += " ";
}
}
String sDetails = "";
ArrayList<SBVocabulary> sbTerms = sbE.getSBTerm();
for (SBVocabulary sbv : sbTerms) {
// type of kinetic law
String str1 = sbv.getID();
str1 = str1.substring(str1.lastIndexOf('#') + 1);
System.out.println(str1);
SBOTerm sboT = SBOListEx.sboMap.get(str1);
sDetails += "<font color=\"#660000\"><b>" + sboT.getName() + "</b></font>" + " " + "<font color=\"#006600\">" + sboT.getDescription() + "</font>";
sDetails += "<br>";
}
ArrayList<SBEntity> klProperties = sbE.getSBSubEntity();
for (SBEntity klProperty : klProperties) {
if (klProperty instanceof SBMeasurable) {
SBMeasurable m = (SBMeasurable) klProperty;
String str1 = "";
String str2 = "";
String str3 = "";
if (m.hasTerm()) {
str1 += m.extractSBOTermAsString();
}
if (m.hasNumber()) {
str2 += m.getNumber().get(0);
}
if (m.hasUnit()) {
str3 += m.extractSBOUnitAsString();
}
// str1 is an SBO id, for example "SBO:0000064"
SBOTerm sboT = SBOListEx.sboMap.get(str1);
sDetails += sboT.getSymbol() + " (" + sboT.getName() + ")" + "<font color=\"#660000\"><b>" + str2 + str3 + "</b></font>" + " " + "<font color=\"#006600\">" + sboT.getDescription() + "</font>";
} else {
sDetails = klProperty.getIDShort() + " " + klProperty.getTypeLabel();
}
sDetails += "<br>";
}
// String tooltip = "<html>how many of these 12 M <br>average size 1.12345*E12 nm <br>temperature 37 degrees Celsius</html>";
String tooltip = "";
BioPaxObjectProperty bpop = new BioPaxObjectProperty("Kinetic Law" + str, sbE.getID(), sbE, tooltip);
bpop.setDetails(sDetails);
propertyList.add(bpop);
}
}
}
if (interaction instanceof Control) {
// TODO: is this ever being called?
Control c = (Control) interaction;
// catalysis::controlled
Interaction controlledInteraction = c.getControlledInteraction();
if (controlledInteraction != null) {
String controlledName = controlledInteraction.getIDShort();
if (controlledInteraction.getName().size() > 0) {
controlledName = controlledInteraction.getName().get(0);
}
propertyList.add(new BioPaxObjectProperty("Controlled Interaction", controlledName, controlledInteraction));
}
}
} else if (entity instanceof GroupObject) {
// ---------------------- GROUP OBJECT ------------------
GroupObject groupObject = (GroupObject) entity;
for (BioPaxObject bpo : groupObject.getGroupedObjects()) {
propertyList.add(new BioPaxObjectProperty("Element::" + bpo.getTypeLabel(), getEntityName((Entity) bpo), bpo));
}
}
// entity::comments
for (String comment : entity.getComments()) {
propertyList.add(new BioPaxObjectProperty("Comment", comment));
}
// entity::xRef
ArrayList<Xref> xrefList = ((Entity) bioPaxObject).getxRef();
for (Xref xref : xrefList) {
if (xref instanceof UnificationXref) {
propertyList.add(new BioPaxObjectProperty("Xref", xref.getDb() + ":" + xref.getId(), xref));
}
}
for (Xref xref : xrefList) {
if (xref instanceof RelationshipXref) {
propertyList.add(new BioPaxObjectProperty("Xref (related)", xref.getDb() + ":" + xref.getId(), xref));
}
}
for (Xref xref : xrefList) {
if (xref instanceof PublicationXref) {
propertyList.add(new BioPaxObjectProperty("Publication", xref.getDb() + ":" + xref.getId(), xref));
}
}
// for(SBVocabulary sbVocab : sbEntity.getSBTerm()) {
// propertyList.add(new BioPaxObjectProperty("SBO Term", SBPAXLabelUtil.makeLabel(sbVocab)));
// }
// if(sbEntity instanceof Interaction) {
// // TODO: this goes away
// Interaction interaction = (Interaction) sbEntity;
// Set<SBEntity> subEntities = new HashSet<SBEntity>();
// subEntities.add(interaction);
// Set<Control> controls = BioPAXUtil.findAllControls(interaction, bioModel.getPathwayModel());
// subEntities.addAll(controls);
// subEntities = SBPAX3Util.extractAllEntities(subEntities);
// for(SBEntity subEntity : subEntities) {
// if(subEntity instanceof SBMeasurable) {
// propertyList.add(new BioPaxObjectProperty("Measured quantity", SBPAXLabelUtil.makeLabel(subEntity)));
// }
// }
// }
tableModel.setData(propertyList);
}
Aggregations