fbc: GeneProductAssociations not written to SBML
matthiaskoenig opened this issue · comments
Not sure what is going on, but it seems that GeneProductAssociations are not written to SBML.
import libsbml
sbmlns: libsbml.SBMLNamespaces = libsbml.SBMLNamespaces(3, 1)
sbmlns.addPkgNamespace("fbc", 3)
doc: libsbml.SBMLDocument = libsbml.SBMLDocument(sbmlns)
doc_fbc: libsbml.FbcSBMLDocumentPlugin = doc.getPlugin("fbc")
doc_fbc.setRequired(False)
model: libsbml.Model = doc.createModel()
model_fbc: libsbml.FbcModelPlugin = model.getPlugin("fbc")
model_fbc.setStrict(True)
c: libsbml.Compartment = model.createCompartment()
c.setId("c1")
c.setSize(1.0)
c.setConstant(True)
s1: libsbml.Species = model.createSpecies()
s1.setId("s1")
s1.setCompartment("c1")
s1.setInitialConcentration(1.0)
s1.setConstant(False)
s1.setHasOnlySubstanceUnits(False)
s1.setBoundaryCondition(False)
p1: libsbml.Parameter = model.createParameter()
p1.setId("lb")
p1.setValue(-100)
p1.setConstant(True)
p2: libsbml.Parameter = model.createParameter()
p2.setId("ub")
p2.setValue(100)
p2.setConstant(True)
# Support exists for user constraints
r: libsbml.Reaction = model.createReaction()
r.setId("r1")
r.setReversible(True)
r.setFast(False)
r_fbc: libsbml.FbcReactionPlugin = r.getPlugin("fbc")
r_fbc.setUpperFluxBound("ub")
r_fbc.setLowerFluxBound("lb")
reactant: libsbml.SpeciesReference = r.createReactant()
reactant.setSpecies("s1")
reactant.setConstant(True)
reactant.setStoichiometry(1.0)
gp1 = model_fbc.createGeneProduct()
gp1.setId("g1")
gp1.setLabel("g1")
gp2 = model_fbc.createGeneProduct()
gp2.setId("g2")
gp2.setLabel("g2")
gpa: libsbml.GeneProductAssociation = r_fbc.createGeneProductAssociation()
gpa.setId("r_gpa")
gpa.setName("r_gpa")
gpa.setAssociation("g1 and g2", True, False)
print("required attributes:", gpa.hasRequiredAttributes())
print(gpa.toSBML())
sbml_str: str = libsbml.writeSBMLToString(doc)
print("-" * 80)
print(sbml_str)
print("-" * 80)
Results in
required attributes: True
<fbc:geneProductAssociation fbc:id="r_gpa" fbc:name="r_gpa">
<fbc:and>
<fbc:geneProductRef fbc:geneProduct="g1"/>
<fbc:geneProductRef fbc:geneProduct="g2"/>
</fbc:and>
</fbc:geneProductAssociation>
--------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<sbml xmlns="http://www.sbml.org/sbml/level3/version1/core" xmlns:fbc="http://www.sbml.org/sbml/level3/version1/fbc/version3" level="3" version="1" fbc:required="false">
<model fbc:strict="true">
<listOfCompartments>
<compartment id="c1" size="1" constant="true"/>
</listOfCompartments>
<listOfSpecies>
<species id="s1" compartment="c1" initialConcentration="1" hasOnlySubstanceUnits="false" boundaryCondition="false" constant="false"/>
</listOfSpecies>
<listOfParameters>
<parameter id="lb" value="-100" constant="true"/>
<parameter id="ub" value="100" constant="true"/>
</listOfParameters>
<listOfReactions>
<reaction id="r1" reversible="true" fast="false" fbc:lowerFluxBound="lb" fbc:upperFluxBound="ub">
<listOfReactants>
<speciesReference species="s1" stoichiometry="1" constant="true"/>
</listOfReactants>
</reaction>
</listOfReactions>
<fbc:listOfGeneProducts>
<fbc:geneProduct fbc:id="g1" fbc:label="g1"/>
<fbc:geneProduct fbc:id="g2" fbc:label="g2"/>
</fbc:listOfGeneProducts>
</model>
</sbml>
The GeneProductAssociation just does not appear in the SBML despite added ?!
This probably also solves #253, because the association is set successfully but just not written to SBML.