Skip to content

Commit

Permalink
Merge branch 'cobra-sbml-parameters' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jonls committed Jul 13, 2015
2 parents d50a9cc + eee3843 commit fff669d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions psamm/datasource/sbml.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
# Level 3 namespaces
SBML_NS_L3_V1_CORE = 'http://www.sbml.org/sbml/level3/version1/core'

MATHML_NS = 'http://www.w3.org/1998/Math/MathML'


def _tag(tag, namespace=None):
"""Prepend namespace to tag name"""
Expand Down Expand Up @@ -391,6 +393,8 @@ def __init__(self):
def write_model(self, file, model, compounds):
"""Write a given model to file"""

ET.register_namespace('mathml', MATHML_NS)

# Load compound information
compound_name = {}
for compound in compounds:
Expand Down Expand Up @@ -465,5 +469,23 @@ def write_model(self, file, model, compounds):
self._sbml_tag('species'), model_species[compound])
spec_ref.set(self._sbml_tag('stoichiometry'), str(abs(value)))

# Create COBRA-compliant parameter list
kl_tag = ET.SubElement(reaction_tag, self._sbml_tag('kineticLaw'))
math_tag = ET.SubElement(kl_tag, self._sbml_tag('math'))
ci_tag = ET.SubElement(math_tag, _tag('ci', MATHML_NS))
ci_tag.text = 'FLUX_VALUE'
param_list = ET.SubElement(
kl_tag, self._sbml_tag('listOfParameters'))
ET.SubElement(param_list, self._sbml_tag('parameter'), {
self._sbml_tag('id'): 'LOWER_BOUND',
self._sbml_tag('name'): 'LOWER_BOUND',
self._sbml_tag('value'): str(model.limits[reaction].lower)
})
ET.SubElement(param_list, self._sbml_tag('parameter'), {
self._sbml_tag('id'): 'UPPER_BOUND',
self._sbml_tag('name'): 'UPPER_BOUND',
self._sbml_tag('value'): str(model.limits[reaction].upper)
})

tree = ET.ElementTree(root)
tree.write(file, default_namespace=self._namespace)

0 comments on commit fff669d

Please sign in to comment.