Skip to content

Commit

Permalink
Merge pull request #184 from indralab/formulas
Browse files Browse the repository at this point in the history
Clean formulas when processing askenet
  • Loading branch information
bgyori committed Jun 25, 2023
2 parents 7d94ca2 + 00b9d03 commit 79a11a9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
5 changes: 5 additions & 0 deletions mira/sources/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
"""Sources of models."""


def clean_formula(f):
"""Return an expression that can be parsed using sympy."""
return f.replace('lambda', 'XXlambdaXX')
4 changes: 3 additions & 1 deletion mira/sources/askenet/petrinet.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import requests

from mira.metamodel import *
from .. import clean_formula


def model_from_url(url: str) -> TemplateModel:
Expand Down Expand Up @@ -256,7 +257,8 @@ def transition_to_templates(transition_rate, input_concepts, output_concepts,
controller_concepts, symbols):
"""Return a list of templates from a transition"""
rate_law_expression = transition_rate.get('expression')
rate_law = sympy.parse_expr(rate_law_expression, local_dict=symbols) \
rate_law = sympy.parse_expr(clean_formula(rate_law_expression),
local_dict=symbols) \
if rate_law_expression else None
if not controller_concepts:
if not input_concepts:
Expand Down
5 changes: 1 addition & 4 deletions mira/sources/sbml/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from mira.metamodel import *
from mira.resources import get_resource_file
from .. import clean_formula


class TqdmLoggingHandler(logging.Handler):
Expand Down Expand Up @@ -814,7 +815,3 @@ def parse_context_grounding(grounding_str):


grounding_map = _get_grounding_map()


def clean_formula(f):
return f.replace('lambda', 'XXlambdaXX')

0 comments on commit 79a11a9

Please sign in to comment.