Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions psamm/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,17 @@ def __call__(self, parser, namespace, values, option_string=None):
arguments.append(values)


class ReactionReference(object):
def __init__(self, reaction_ref):
self._reaction_id = reaction_ref

def resolve(self, model):
if not model.has_reaction(self._reaction_id):
raise ValueError('Invalid reaction reference')

return self._reaction_id


class _ErrorMarker(object):
"""Signals error in the child process."""

Expand Down
9 changes: 6 additions & 3 deletions psamm/commands/formulacheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import logging

from ..command import Command, FilePrefixAppendAction
from ..command import Command, FilePrefixAppendAction, ReactionReference
from ..formula import Formula
from ..balancecheck import formula_balance

Expand All @@ -38,14 +38,17 @@ class FormulaBalanceCommand(Command):
def init_parser(cls, parser):
parser.add_argument(
'--exclude', metavar='reaction', action=FilePrefixAppendAction,
type=str, default=[], help='Exclude reaction from balance check')
type=ReactionReference, default=[],
help='Exclude reaction from balance check')
super(FormulaBalanceCommand, cls).init_parser(parser)

def run(self):
"""Run formula balance command"""

mm = self._model.create_metabolic_model()

# Create a set of excluded reactions
exclude = set(self._args.exclude)
exclude = set(r.resolve(mm) for r in self._args.exclude)
count = 0
unbalanced = 0
unchecked = 0
Expand Down