Skip to content

Commit

Permalink
Merge pull request #314 from gyorilab/scenario5
Browse files Browse the repository at this point in the history
Scenario5
  • Loading branch information
bgyori authored Mar 26, 2024
2 parents 469f077 + 9e856a1 commit 37d55c4
Show file tree
Hide file tree
Showing 9 changed files with 3,037 additions and 8 deletions.
56 changes: 55 additions & 1 deletion mira/metamodel/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@
"has_subject",
"has_outcome",
"has_controller",
"num_controllers"
"num_controllers",
"get_binding_templates",
"conversion_to_deg_prod",
]

import logging
import sys
from collections import ChainMap
from copy import deepcopy
from itertools import product
from typing import (
Callable,
Expand Down Expand Up @@ -1824,3 +1827,54 @@ def num_controllers(template):
return len(template.controllers)
else:
return 0


def get_binding_templates(a, b, c, kf, kr):
"""Return a list of templates emulating a reversible binding process."""
af = lambda: Concept(name=a)
bf = lambda: Concept(name=b)
cf = lambda: Concept(name=c)
templates = [
GroupedControlledProduction(controllers=[af(), bf()],
outcome=cf()).with_mass_action_rate_law(kf),
ControlledDegradation(controller=af(),
subject=bf()).with_mass_action_rate_law(kf),
ControlledDegradation(controller=bf(),
subject=af()).with_mass_action_rate_law(kf),
NaturalDegradation(subject=cf()).with_mass_action_rate_law(kr),
ControlledProduction(controller=cf(),
outcome=af()).with_mass_action_rate_law(kr),
ControlledProduction(controller=cf(),
outcome=bf()).with_mass_action_rate_law(kr)
]
return templates


def conversion_to_deg_prod(conv_template):
"""Given a conversion template, compile into degradation/production templates."""
if not is_conversion(conv_template):
return [conv_template]
nc = num_controllers(conv_template)
if nc == 0:
tdeg = NaturalDegradation(subject=conv_template.subject,
rate_law=conv_template.rate_law)
tprod = ControlledProduction(outcome=conv_template.outcome,
controller=conv_template.subject,
rate_law=conv_template.rate_law)
elif nc == 1:
tdeg = ControlledDegradation(subject=conv_template.subject,
controller=conv_template.controller,
rate_law=conv_template.rate_law)
tprod = GroupedControlledProduction(outcome=conv_template.outcome,
controllers=[conv_template.controller,
conv_template.subject],
rate_law=conv_template.rate_law)
else:
tdeg = GroupedControlledDegradation(subject=conv_template.subject,
controllers=conv_template.controllers,
rate_law=conv_template.rate_law)
tprod = GroupedControlledProduction(outcome=conv_template.outcome,
controllers=conv_template.controllers +
[conv_template.subject],
rate_law=conv_template.rate_law)
return deepcopy([tdeg, tprod])
6 changes: 4 additions & 2 deletions mira/modeling/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,10 @@ def make_model(self):
ModelParameter(key, display_name=display_name, description=description,
distribution=distribution,
value=value,
concept=self.template_model.parameters[key],
placeholder=False))

for template in self.template_model.templates:
for idx, template in enumerate(self.template_model.templates):
if isinstance(template, StaticConcept):
self.assemble_variable(template.subject,
self.template_model.initials)
Expand Down Expand Up @@ -308,7 +309,7 @@ def make_model(self):
produced, produced_key = tuple(), None

tkey_elements = tuple(
element for element in [consumed_key, produced_key, control_key]
element for element in [consumed_key, produced_key, control_key, str(idx)]
if element is not None
)
tkey = get_transition_key(tkey_elements, template.type)
Expand All @@ -334,6 +335,7 @@ def make_model(self):
ModelParameter(key, display_name=display_name, description=description,
distribution=distribution,
value=value,
concept=self.template_model.parameters[key],
placeholder=False))

def get_create_parameter(self, parameter: ModelParameter) -> ModelParameter:
Expand Down
18 changes: 13 additions & 5 deletions mira/modeling/amr/regnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import json
import logging
from copy import deepcopy
from collections import defaultdict
from typing import Dict, List, Optional, Union

import sympy
Expand Down Expand Up @@ -84,6 +85,9 @@ def __init__(self, model: Model):
self._states_by_id[name] = state_data

idx = 0
# It's possible that something is naturally degraded/replicated
# by multiple transitions so we need to collect and aggregate rates
intrinsic_by_var = defaultdict(list)
for transition in model.transitions.values():
# Regnets cannot represent conversions (only
# production/degradation) so we skip these
Expand Down Expand Up @@ -122,11 +126,7 @@ def __init__(self, model: Model):

if transition.template.rate_law:
rate_law = transition.template.rate_law.args[0]
self.rates.append({
'target': var,
'expression': str(rate_law),
'expression_mathml': expression_to_mathml(rate_law)
})
intrinsic_by_var[var].append(rate_law)
# Beyond these, we can assume that the transition is a
# form of replication or degradation corresponding to
# a regular transition in the regnet framework
Expand Down Expand Up @@ -174,6 +174,14 @@ def __init__(self, model: Model):
self.transitions.append(transition_dict)
idx += 1

for var, rates in intrinsic_by_var.items():
rate_law = sum(rates)
self.rates.append({
'target': var,
'expression': str(rate_law),
'expression_mathml': expression_to_mathml(rate_law)
})

for key, param in model.parameters.items():
if param.placeholder:
continue
Expand Down
Loading

0 comments on commit 37d55c4

Please sign in to comment.