Skip to content

Commit

Permalink
Merge pull request #13 from Midnighter/add-error-msg
Browse files Browse the repository at this point in the history
refactor: modify messages, add reaction ID
  • Loading branch information
AnneGoelzer authored Oct 1, 2021
2 parents c13ff96 + 08bbe2d commit a81263c
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions rba/prerba/sbml_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ def _extract_reactions_and_enzymes(self, model, cytosol_id, interface_id):
for reaction in model.getListOfReactions():
try:
enzymes = parser.enzyme_composition(reaction)
except UserWarning:
self._print_invalid_enzyme_notes()
raise UserWarning('Invalid SBML.')
except UserWarning as warn:
raise UserWarning(
'ERROR: In reaction \'{}\':\n'
'{}'.format(reaction.id, warn.args[0])
)
# we create one reaction per associated enzyme
for suffix, enzyme in enumerate(enzymes):
id_ = reaction.getId()
Expand All @@ -114,19 +116,20 @@ def _extract_reactions_and_enzymes(self, model, cytosol_id, interface_id):
self.enzymes.append(self._create_enzyme(
new_reaction, enzyme, cytosol_id, interface_id
))
if not self.enzymes:
raise UserWarning(
'Your SBML document does not contain any fbc gene products nor uses '
'COBRA notes to define enzyme compositions for '
'reactions. Please comply with SBML'
' requirements defined in the README and rerun the script.'
)

def _create_annotation_parser(self, model):
if model.getPlugin('fbc'):
return FbcAnnotationParser(model.getPlugin('fbc'))
else:
return CobraNoteParser()

def _print_invalid_enzyme_notes(self):
print('Your SBML file does not contain fbc gene products nor uses '
' COBRA notes to define enzyme composition for every '
'reaction. Please comply with SBML'
' requirements defined in the README and rerun script.')

def _create_reaction(self, id_, reaction):
result = rba.xml.Reaction(id_, reaction.getReversible())
for r in reaction.getListOfReactants():
Expand Down Expand Up @@ -245,8 +248,13 @@ def _read_fbc_association_components(self, association):
result += self._read_fbc_association_components(assoc)
return result
else:
print('Invalid association (we only support ors of ands)')
raise UserWarning('Invalid SBML.')
raise UserWarning(
'Invalid or RBApy-incompatible SBML document.\n'
'RBApy forbids that gene reaction rules contain OR statements inside '
'AND statements. For example a rule "A and (B or C)" is not allowed '
'and would have to be converted into "(A and B) or (A and C)". Please '
'modify your input model and reformulate the Boolean rules in this way.'
)


class CobraNoteParser(object):
Expand Down

0 comments on commit a81263c

Please sign in to comment.