|
From: <tra...@us...> - 2016-06-16 07:04:40
|
Revision: 647
http://sourceforge.net/p/sbfc/code/647
Author: tramy-nguyen
Date: 2016-06-16 07:04:37 +0000 (Thu, 16 Jun 2016)
Log Message:
-----------
- wrote methods to check for valid sbml id, valid sbml name, and valid sbml meta id;
- Started adding reactants and stoichiometry when parsing conversion interaction. Need to finish up getting product for this interaction. Then I can make use of the getReactant(), getStoichiometry(), and getProduct() to create interactions for the rest of conversion Interaction.
Modified Paths:
--------------
trunk/src/org/sbfc/converter/biopax2sbml/BioPAX2SBML.java
Modified: trunk/src/org/sbfc/converter/biopax2sbml/BioPAX2SBML.java
===================================================================
--- trunk/src/org/sbfc/converter/biopax2sbml/BioPAX2SBML.java 2016-06-15 17:12:37 UTC (rev 646)
+++ trunk/src/org/sbfc/converter/biopax2sbml/BioPAX2SBML.java 2016-06-16 07:04:37 UTC (rev 647)
@@ -24,6 +24,10 @@
*/
package org.sbfc.converter.biopax2sbml;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
import javax.xml.stream.XMLStreamException;
import org.biopax.paxtools.model.Model;
@@ -34,6 +38,8 @@
import org.biopax.paxtools.model.level3.ComplexAssembly;
import org.biopax.paxtools.model.level3.Control;
import org.biopax.paxtools.model.level3.Conversion;
+import org.biopax.paxtools.model.level3.ConversionDirectionType;
+import org.biopax.paxtools.model.level3.Degradation;
import org.biopax.paxtools.model.level3.Dna;
import org.biopax.paxtools.model.level3.DnaRegion;
import org.biopax.paxtools.model.level3.Entity;
@@ -46,8 +52,11 @@
import org.biopax.paxtools.model.level3.Rna;
import org.biopax.paxtools.model.level3.RnaRegion;
import org.biopax.paxtools.model.level3.SmallMolecule;
+import org.biopax.paxtools.model.level3.Stoichiometry;
import org.biopax.paxtools.model.level3.TemplateReactionRegulation;
import org.biopax.paxtools.model.level3.Transport;
+import org.biopax.paxtools.model.level3.TransportWithBiochemicalReaction;
+import org.biopax.paxtools.model.level3.Xref;
import org.identifiers.registry.RegistryLocalProvider;
import org.sbfc.converter.exceptions.ConversionException;
import org.sbfc.converter.exceptions.ReadModelException;
@@ -64,14 +73,19 @@
import org.sbml.jsbml.SBMLException;
import org.sbml.jsbml.SBO;
import org.sbml.jsbml.Species;
+import org.sbml.jsbml.SpeciesReference;
import org.sbml.jsbml.UnitDefinition;
+import org.sbml.jsbml.ext.qual.QualModelPlugin;
+
public class BioPAX2SBML extends GeneralConverter {
protected final static String notesStartString = "<notes><body xmlns=\"http://www.w3.org/1999/xhtml\">";
protected final static String notesEndString = "</body></notes>";
public static boolean isLetter(char c) { return ((c >= 97) && (c <= 122)) || ((c >= 65) && (c <= 90)); }
+ public static boolean isDigit(char c) { return ((c >= 48) && (c <= 57)); }
+ public static boolean isDelimiter(char c) { return ((c != 65534) && (c != 65535)); }
// creation of the link to the web services
public static RegistryLocalProvider link;
@@ -106,17 +120,13 @@
org.biopax.paxtools.model.level3.Pathway pathway = bioModel.getObjects(Pathway.class).iterator().next();
sbmlModel.setId(pathway.toString());
+ //TODO: Should I set metaId to rdfId and should I check for valid MetaId?
sbmlModel.setMetaId("meta_" + pathway.toString());
sbmlModel.setTimeUnits(UnitDefinition.TIME);
sbmlModel.setVolumeUnits(UnitDefinition.VOLUME);
sbmlModel.setSubstanceUnits(UnitDefinition.SUBSTANCE);
- sbmlModel.setName(pathway.toString());
+ sbmlModel.setName(pathway.getDisplayName());
-// org.sbml.jsbml.Compartment defaultCompartment = sbmlModel.createCompartment("default");
-// defaultCompartment.setName("default");
-// defaultCompartment.setSBOTerm(SBO.getCompartment());
-// defaultCompartment.setConstant(true);
-
History hist = new History();
Creator creator = new Creator();
creator.setOrganisation("GSoC 2016, National Resource for Network Biology");
@@ -156,46 +166,52 @@
}
}
- private void parsePhysicalEntity(PhysicalEntity entity, org.sbml.jsbml.Model sbmlModel)
+ private String parsePhysicalEntity(PhysicalEntity entity, org.sbml.jsbml.Model sbmlModel)
{
- // TODO: Assume biopax file always provide RDFId and displayName
- // TODO: Check if RDFId is valid
- String speciesId = entity.getRDFId();
- String speciesName = getValidSBMLId(entity);
- Species sbmlSpecies = setSpecies(sbmlModel, speciesId, speciesName, entity.getCellularLocation());
- setPhysicalEntitySBO(entity, sbmlSpecies);
+ String speciesId = getValidSBMLId(entity);
+ if(!sbmlModel.containsSpecies(speciesId))
+ {
+ Species sbmlSpecies = setSpecies(sbmlModel, speciesId, entity);
+ setPhysicalEntitySBO(entity, sbmlSpecies);
+ }
- return;
+ return speciesId;
}
- private String getValidSBMLId(PhysicalEntity entity)
+ private String getValidSBMLName(PhysicalEntity entity)
{
- if(entity.getDisplayName() != null && entity.getDisplayName().length() > 0
- && isValidSBMLId(entity.getDisplayName()))
+ // Assume that the biopax displayName and RDFId given is valid strings. Expect biopax input file to be valid.
+ if(entity.getDisplayName() != null && entity.getDisplayName().length() > 0 && isValidSBMLname(entity.getDisplayName()))
return entity.getDisplayName();
- else if(entity.getName() != null && !entity.getName().isEmpty()
- && isValidSBMLId(entity.getName().toString()))
- return entity.getName().toString();
- else if(entity.getRDFId() != null && entity.getRDFId().length() > 0
+ else if(entity.getRDFId() != null && entity.getRDFId().length() > 0 && isValidSBMLname(entity.getRDFId()))
+ return entity.getRDFId();
+
+ //Since name is optional in SBML, don't set sbml name if getValidSBMLName returns null
+ return null;
+ }
+
+ private String getValidSBMLId(Entity entity)
+ {
+ if(entity.getRDFId() != null && entity.getRDFId().length() > 0
&& isValidSBMLId(entity.getRDFId()))
return entity.getRDFId();
//TODO: Need to come up with better secure conventional id...
- String conventionId = "sbml_" + removeInvalidSBMLcharId(entity.getRDFId()) + "_" + removeInvalidSBMLcharId(entity.getDisplayName());
+ String conventionId = "";
return conventionId;
}
- private String removeInvalidSBMLcharId(String id)
- {
- String result = id.replaceAll("[^a-zA-Z0-9]", "");
- return result;
- }
- private Species setSpecies(org.sbml.jsbml.Model sbmlModel, String speciesId, String speciesName, CellularLocationVocabulary cellularLocation)
+ private Species setSpecies(org.sbml.jsbml.Model sbmlModel, String speciesId, PhysicalEntity entity)
{
- Species sbmlSpecies = sbmlModel.createSpecies(speciesId, speciesName, setCompartment(sbmlModel, cellularLocation));
+ Species sbmlSpecies = sbmlModel.createSpecies(speciesId, setCompartment(sbmlModel, entity));
- //TODO: verify if the following are set correctly
+ //Since name is optional in SBML, don't set sbml name if getValidSBMLName returns null
+ String speciesName = getValidSBMLName(entity);
+ if(speciesName != null)
+ sbmlSpecies.setName(speciesName);
+
+ //TODO: verify if the following are set correctly since sbml requires these members to be set
sbmlSpecies.setHasOnlySubstanceUnits(true);
sbmlSpecies.setBoundaryCondition(false);
sbmlSpecies.setConstant(false);
@@ -204,27 +220,55 @@
private boolean isValidSBMLId(String id)
{
- for (int i = 0; i < id.length(); i++)
+ if(id.charAt(0) != '_' && !isLetter(id.charAt(0)))
+ return false;
+
+ for (int i = 1; i < id.length(); i++)
{
- if(!isLetter(id.charAt(i)))
+ if(!isLetter(id.charAt(i)) && !isDigit(id.charAt(i)) && id.charAt(i) != '_')
return false;
}
return true;
}
- private Compartment setCompartment(org.sbml.jsbml.Model sbmlModel, CellularLocationVocabulary cellularLocation)
+ private boolean isValidSBMLmetaId(String metaId)
{
+ if(!isLetter(metaId.charAt(0)) && metaId.charAt(0) != '_' && metaId.charAt(0) != ':' )
+ return false;
+ for (int i = 1; i < metaId.length(); i++)
+ {
+ //TODO: finish up this check for combining char and extender
+ if(!isLetter(metaId.charAt(i)) && !isDigit(metaId.charAt(i)) &&
+ metaId.charAt(i) != '.' && metaId.charAt(i) != '-' && metaId.charAt(i) != '_' && metaId.charAt(i) != ':')
+ return false;
+ }
+ return true;
+ }
+
+ private boolean isValidSBMLname(String name)
+ {
+ for(int i = 0; i < name.length(); i++)
+ {
+ if(isDelimiter(name.charAt(i)))
+ return false;
+ }
+ return true;
+ }
+
+ private Compartment setCompartment(org.sbml.jsbml.Model sbmlModel, PhysicalEntity entity)
+ {
//Check if the compartment already exist in the sbml model
- //TODO: does all CellularLocation return alphanumeric id?
- if(cellularLocation != null)
+ if(entity.getCellularLocation() != null)
{
- if(sbmlModel.containsCompartment(cellularLocation.toString()))
+ if( isValidSBMLId(entity.getCellularLocation().toString()) && sbmlModel.containsCompartment(entity.getCellularLocation().toString()))
{
- return sbmlModel.getCompartment(cellularLocation.toString());
+ return sbmlModel.getCompartment(entity.getCellularLocation().toString());
}
else
{
- org.sbml.jsbml.Compartment compartment = sbmlModel.createCompartment(cellularLocation.toString());
+ //TODO: how to deal with a cellularlocation that exist but the name of the cellularLocation is not valid sbml name to set id of sbml compartment?
+ // I can't call getValidSBMLId for this class because cellularLocation does not contain an RDFId.
+ org.sbml.jsbml.Compartment compartment = sbmlModel.createCompartment((entity.getCellularLocation().toString()));
compartment.setSBOTerm(SBO.getCompartment()); //TODO: can there be more than one type of compartment?
compartment.setConstant(true); //TODO: verify if constant should be set to true
return compartment;
@@ -238,7 +282,6 @@
}
org.sbml.jsbml.Compartment defaultCompartment = sbmlModel.createCompartment("default");
- defaultCompartment.setName("default");
defaultCompartment.setSBOTerm(SBO.getCompartment());
defaultCompartment.setConstant(true);
return defaultCompartment;
@@ -250,21 +293,19 @@
if (Gene.class.isAssignableFrom(entity.getClass()))
sbmlSpecies.setSBOTerm(SBO.getGene());
else if (Complex.class.isAssignableFrom(entity.getClass()))
- sbmlSpecies.setSBOTerm(SBO.getComplex());
+ sbmlSpecies.setSBOTerm(SBO.getComplex()); //SBO:0000253
else if (Protein.class.isAssignableFrom(entity.getClass()))
- sbmlSpecies.setSBOTerm(SBO.getProtein());
+ sbmlSpecies.setSBOTerm("SBO:0000297"); //TODO: verify
else if (Dna.class.isAssignableFrom(entity.getClass()))
sbmlSpecies.setSBOTerm("SBO:0000251");
else if (DnaRegion.class.isAssignableFrom(entity.getClass()))
- sbmlSpecies.setSBOTerm("SBO:0000251"); //TODO: DNARegion equivalent to DNA?
+ sbmlSpecies.setSBOTerm("SBO:0000251"); //TODO: DNARegion ?
else if (Rna.class.isAssignableFrom(entity.getClass()))
sbmlSpecies.setSBOTerm(SBO.getRNA());
else if (RnaRegion.class.isAssignableFrom(entity.getClass()))
- sbmlSpecies.setSBOTerm("SBO:0000250");
+ sbmlSpecies.setSBOTerm("SBO:0000250"); //TODO: RNARegion ?
else if (SmallMolecule.class.isAssignableFrom(entity.getClass()))
- sbmlSpecies.setSBOTerm(SBO.getSimpleMolecule()); //TODO: simpleMolecule is equiv. to smallMolecule?
- else
- sbmlSpecies.setSBOTerm(SBO.getUnknownMolecule()); //TODO: Unknown SBO
+ sbmlSpecies.setSBOTerm("SBO:0000247"); //TODO: smallMolecule? verify
return;
}
@@ -273,21 +314,135 @@
{
Reaction r = setReaction(entity, sbmlModel);
+ if (Conversion.class.isAssignableFrom(entity.getClass()))
+ {
+ parseConversionInteraction(entity, sbmlModel);
+ setConversionSBO((Conversion) entity, r);
+ }
if (Control.class.isAssignableFrom(entity.getClass()))
{
+ //TODO: Check if control has Controller and Controlled object to create a reaction out of
setControlSBO((Control) entity, r);
}
- if (Conversion.class.isAssignableFrom(entity.getClass()))
+ }
+
+ private void parseConversionInteraction(Interaction entity, org.sbml.jsbml.Model sbmlModel)
+ {
+ if (ComplexAssembly.class.isAssignableFrom(entity.getClass()))
{
- setConversionSBO((Conversion) entity, r);
+ parseComplexAssembly((ComplexAssembly) entity, sbmlModel);
+
}
+ else if (BiochemicalReaction.class.isAssignableFrom(entity.getClass()))
+ {
+ BiochemicalReaction br = (BiochemicalReaction) entity;
+ }
+ else if (TransportWithBiochemicalReaction.class.isAssignableFrom(entity.getClass()))
+ {
+ TransportWithBiochemicalReaction tbr = (TransportWithBiochemicalReaction) entity;
+ }
+ else if (Transport.class.isAssignableFrom(entity.getClass()))
+ {
+ Transport t = (Transport) entity;
+ }
+ else if (Degradation.class.isAssignableFrom(entity.getClass()))
+ {
+ Degradation d = (Degradation) entity;
+ }
+ else
+ //TODO: a default conversion class
+
+ return;
}
+ private void parseComplexAssembly(ComplexAssembly ca, org.sbml.jsbml.Model sbmlModel)
+ {
+ ConversionDirectionType conDirType = ca.getConversionDirection();
+ Set<PhysicalEntity> leftParticipants = ca.getLeft();
+ Set<PhysicalEntity> rightParticipants = ca.getRight();
+ Set<Stoichiometry> stoichiometrySet = ca.getParticipantStoichiometry();
+ Set<Xref> xref = ca.getXref();
+
+// List<> reactantList;
+ Reaction reaction = setReaction(ca, sbmlModel);
+
+ //Parse for reactant/substrate
+ getReactants(leftParticipants, stoichiometrySet, sbmlModel);
+
+ //TODO: Parse for product
+ }
+
+ private List<org.sbml.jsbml.SpeciesReference> getReactants(Set<PhysicalEntity> participants,
+ Set<Stoichiometry> stoichiometrySet, org.sbml.jsbml.Model sbmlModel)
+ {
+ List<SpeciesReference> reactantList = new ArrayList<SpeciesReference>();
+
+ for(PhysicalEntity p : participants)
+ {
+ //TODO: set reactant id and name?
+ SpeciesReference reactant = new SpeciesReference();
+
+ //Check if participant species already exist in sbml model. If not, add to sbml model
+ String speciesId = parsePhysicalEntity(p, sbmlModel);
+ reactant.setSpecies(speciesId);
+ reactant.setConstant(true); //TODO: verify
+
+ double speciesStoic = getSpeciesStochiometry(stoichiometrySet, p);
+ if( speciesStoic != 0)
+ {
+ reactant.setStoichiometry(speciesStoic);
+ }
+
+ reactantList.add(reactant);
+ }
+ return reactantList;
+ }
+
+ private double getSpeciesStochiometry(Set<Stoichiometry> stoichiometrySet, PhysicalEntity entity)
+ {
+ for (Stoichiometry stoichiometry : stoichiometrySet)
+ {
+ if(stoichiometry.getPhysicalEntity().equals(entity))
+ {
+ if(isValidStoichiometry(stoichiometry.getStoichiometricCoefficient()))
+ return stoichiometry.getStoichiometricCoefficient();
+ }
+ }
+
+ return 0;
+ }
+
+ private boolean isValidStoichiometry(double stoichiometry)
+ {
+ return (stoichiometry > 0 && stoichiometry < Double.MAX_VALUE);
+ }
+
+
+ private void parseControlInteraction(Interaction entity, org.sbml.jsbml.Model sbmlModel)
+ {
+ if (Catalysis.class.isAssignableFrom(entity.getClass()))
+ {
+
+ }
+ else if (Modulation.class.isAssignableFrom(entity.getClass()))
+ {
+
+ }
+ else if (TemplateReactionRegulation.class.isAssignableFrom(entity.getClass()))
+ {
+
+ }
+ else
+ //TODO: a default control class
+ return;
+ }
+
private Reaction setReaction(Interaction entity, org.sbml.jsbml.Model sbmlModel)
{
//TODO: assume RDFId and displayName is always given
- Reaction reaction = sbmlModel.createReaction(entity.getRDFId());
+ Reaction reaction = sbmlModel.createReaction(getValidSBMLId(entity));
reaction.setName(entity.getDisplayName());
+ //TODO: Should I check for valid MetaId?
reaction.setMetaId("meta_" + entity.getRDFId());
reaction.setFast(false); //TODO: check if this are set to false
reaction.setReversible(false); //TODO: check if this are set to false
@@ -310,11 +465,17 @@
private void setConversionSBO(Conversion entity, Reaction reaction)
{
if (ComplexAssembly.class.isAssignableFrom(entity.getClass()))
- reaction.setSBOTerm(SBO.getComplex()); //TODO: IS Complex SBO equiv. to ComplexAssembly?
+ reaction.setSBOTerm("SBO:0000526"); //TODO: IS Complex SBO equiv. to ComplexAssembly?
else if (BiochemicalReaction.class.isAssignableFrom(entity.getClass()))
- reaction.setSBOTerm(SBO.getInteraction()); //TODO: what SBO is set for this?
+ reaction.setSBOTerm("SBO:0000176");
+ else if (TransportWithBiochemicalReaction.class.isAssignableFrom(entity.getClass()))
+ reaction.setSBOTerm("SBO:0000167"); //TODO: verify
else if (Transport.class.isAssignableFrom(entity.getClass()))
reaction.setSBOTerm(SBO.getTransport());
+ else if (Degradation.class.isAssignableFrom(entity.getClass()))
+ reaction.setSBOTerm("SBO:0000179");
+ else if (Conversion.class.isAssignableFrom(entity.getClass()))
+ reaction.setSBOTerm("SBO:0000182");
return;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|