Skip to content

Commit

Permalink
Merge pull request #219 from jonls/sbml-ignore-boundary-comp
Browse files Browse the repository at this point in the history
sbml: Ignore boundary compartments
  • Loading branch information
jonls committed Mar 6, 2017
2 parents 36aa737 + b5c00cb commit 38722c5
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 77 deletions.
19 changes: 18 additions & 1 deletion psamm/datasource/sbml.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ class SBMLReader(object):
If ``ignore_boundary`` is ``True``, the species that are marked as
boundary conditions will simply be dropped from the species list and from
the reaction equations.
the reaction equations, and any boundary compartment will be dropped too.
"""

def __init__(self, file, strict=False, ignore_boundary=False,
Expand Down Expand Up @@ -632,6 +632,23 @@ def __init__(self, file, strict=False, ignore_boundary=False,
entry = ReactionEntry(self, reaction, filemark=filemark)
self._model_reactions[entry.id] = entry

if self._ignore_boundary:
# Remove compartments that only contain boundary compounds
empty_compartments = set(self._model_compartments)
valid_compartments = set()
for species in itervalues(self._model_species):
empty_compartments.discard(species.compartment)
if not species.boundary:
valid_compartments.add(species.compartment)

boundary_compartments = (
set(self._model_compartments) - empty_compartments -
valid_compartments)
for compartment in boundary_compartments:
logger.info('Ignoring boundary compartment: {}'.format(
compartment))
del self._model_compartments[compartment]

# Objectives
self._model_objectives = {}
self._active_objective = None
Expand Down

0 comments on commit 38722c5

Please sign in to comment.