Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create utils and tests; minor typo correction
- Loading branch information
Showing
3 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
""" Tests for utility methods | ||
:Author: Yin Hoon Chew <yinhoon.chew@mssm.edu> | ||
:Date: 2019-02-13 | ||
:Copyright: 2019, Karr Lab | ||
:License: MIT | ||
""" | ||
|
||
from wc_utils.util.ontology import wcm_ontology | ||
from wc_utils.util.units import unit_registry | ||
import wc_model_gen.utils as utils | ||
import math | ||
import unittest | ||
import wc_lang | ||
|
||
|
||
class TestCase(unittest.TestCase): | ||
|
||
def test_calculate_average_synthesis_rate(self): | ||
|
||
test_rate = utils.calculate_average_synthesis_rate(0.5, 300., 36000.) | ||
self.assertAlmostEqual(test_rate, 0.001164872, places=9) | ||
|
||
def test_MM_like_rate_law(self): | ||
|
||
Avogadro = wc_lang.Parameter(id='Avogadro') | ||
|
||
c = wc_lang.Compartment(id='c') | ||
c.init_density = wc_lang.Parameter(id='density_' + c.id) | ||
volume = wc_lang.Function(id='volume_' + c.id) | ||
volume.expression, error = wc_lang.FunctionExpression.deserialize(f'{c.id} / {c.init_density.id}', { | ||
wc_lang.Compartment: {c.id: c}, | ||
wc_lang.Parameter: {c.init_density.id: c.init_density}, | ||
}) | ||
|
||
species_types = {} | ||
species = {} | ||
for i in range(1,6): | ||
Id = 's' + str(i) | ||
species_types[Id] = wc_lang.SpeciesType(id=Id) | ||
species[Id + '_c'] = wc_lang.Species(species_type=species_types[Id], compartment=c) | ||
wc_lang.DistributionInitConcentration(species=species[Id + '_c'], mean=0.5) | ||
|
||
ob = wc_lang.ObservableExpression(expression='s4[c] + s5[c]', species=[species['s4_c'], species['s5_c']]) | ||
modifier = wc_lang.Observable(id='e1', expression=ob) | ||
|
||
participant1 = wc_lang.SpeciesCoefficient(species=species['s1_c'], coefficient=-1) | ||
participant2 = wc_lang.SpeciesCoefficient(species=species['s2_c'], coefficient=-1) | ||
participant3 = wc_lang.SpeciesCoefficient(species=species['s3_c'], coefficient=1) | ||
reaction = wc_lang.Reaction(id='r1', participants=[participant1, participant2, participant3]) | ||
|
||
rate_law, parameters = utils.MM_like_rate_law(Avogadro, reaction, modifier, 1.) | ||
|
||
self.assertEqual(rate_law.expression, 'k_cat_r1 * e1 * (s1[c] / (s1[c] + K_m_r1_s1 * Avogadro * volume_c)) * (s2[c] / (s2[c] + K_m_r1_s2 * Avogadro * volume_c))') | ||
self.assertEqual(set([i.gen_id() for i in rate_law.species]), set(['s1[c]', 's2[c]'])) | ||
self.assertEqual(rate_law.observables, [modifier]) | ||
self.assertEqual(set(rate_law.parameters), set(parameters)) | ||
self.assertEqual(rate_law.parameters.get_one(id='k_cat_r1').type, wcm_ontology['WCM:k_cat']) | ||
self.assertEqual(rate_law.parameters.get_one(id='k_cat_r1').units, unit_registry.parse_units('s^-1')) | ||
self.assertEqual(rate_law.parameters.get_one(id='K_m_r1_s2').type, wcm_ontology['WCM:K_m']) | ||
self.assertEqual(rate_law.parameters.get_one(id='K_m_r1_s2').value, 0.5) | ||
self.assertEqual(rate_law.parameters.get_one(id='K_m_r1_s2').units, unit_registry.parse_units('M')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
""" Utility methods for generating submodels | ||
:Author: Yin Hoon Chew <yinhoon.chew@mssm.edu> | ||
:Date: 2019-01-23 | ||
:Copyright: 2019, Karr Lab | ||
:License: MIT | ||
""" | ||
|
||
from wc_utils.util.ontology import wcm_ontology | ||
from wc_utils.util.units import unit_registry | ||
import math | ||
import wc_lang | ||
|
||
|
||
def calculate_average_synthesis_rate(mean_concentration, half_life, mean_doubling_time): | ||
""" Calculate the average synthesis rate of a species over a cell cycle | ||
Args: | ||
mean_concentration (:obj:`float`): species mean concentration | ||
half_life (:obj:`float`): species half life | ||
mean_doubling_time (:obj:`float`): mean doubling time of cells | ||
Returns: | ||
:obj:`float`: the average synthesis rate of the species | ||
""" | ||
ave_synthesis_rate = math.log(2) * (1. / mean_doubling_time + 1. / half_life) * mean_concentration | ||
|
||
return ave_synthesis_rate | ||
|
||
def MM_like_rate_law(Avogadro, reaction, modifier, beta): | ||
""" Generate a Michaelis-Menten-like rate law. For a multi-substrate reaction, | ||
the substrate term is formulated as the multiplication of a Hill equation | ||
with a coefficient of 1 for each substrate. | ||
Example: | ||
Rate = k_cat * [E] * [S1]/(Km_S1 + [S1]) * [S2]/(Km_S2 + [S2]) | ||
where | ||
k_cat: catalytic constant | ||
[E]: concentration of enzyme (modifier) | ||
[Sn]: concentration of nth substrate | ||
Km_Sn: Michaelis-Menten constant for nth substrate | ||
Args: | ||
Avogadro (:obj:`wc_lang.Parameter`): model parameter for Avogadro number | ||
reaction (:obj:`wc_lang.Reaction`): reaction | ||
modifier (:obj:`wc_lang.Observable`): an observable that evaluates to the | ||
total concentration of all enzymes that catalyze the reaction | ||
beta (:obj:`float`): ratio of Michaelis-Menten constant to substrate | ||
concentration (Km/[S]) | ||
Returns: | ||
:obj:`wc_lang.RateLawExpression`: rate law | ||
:obj:`list` of :obj:`wc_lang.Parameter`: list of parameters in the rate law | ||
""" | ||
parameters = [] | ||
|
||
model_k_cat = wc_lang.Parameter(id='k_cat_{}'.format(reaction.id), | ||
type=wcm_ontology['WCM:k_cat'], | ||
units=unit_registry.parse_units('s^-1')) | ||
parameters.append(model_k_cat) | ||
|
||
expression_terms = [] | ||
all_species = [] | ||
for species in reaction.get_reactants(): | ||
all_species.append(species) | ||
model_k_m = wc_lang.Parameter(id='K_m_{}_{}'.format(reaction.id, species.species_type.id), | ||
type=wcm_ontology['WCM:K_m'], | ||
value=beta * species.distribution_init_concentration.mean, | ||
units=unit_registry.parse_units('M')) | ||
parameters.append(model_k_m) | ||
volume = species.compartment.init_density.function_expressions[0].function | ||
expression_terms.append('({} / ({} + {} * {} * {}))'.format(species.gen_id(), | ||
species.gen_id(), | ||
model_k_m.id, Avogadro.id, | ||
volume.id)) | ||
|
||
expression = '{} * {} * {}'.format(model_k_cat.id, modifier.id, ' * '.join(expression_terms)) | ||
|
||
rate_law = wc_lang.RateLawExpression(expression=expression, | ||
parameters=parameters, | ||
species=all_species, | ||
observables=[modifier]) | ||
|
||
return rate_law, parameters |