Skip to content

Commit

Permalink
Allow input option of list of modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
YinHoon committed Jun 13, 2019
1 parent c3838b0 commit 77497f9
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 74 deletions.
42 changes: 32 additions & 10 deletions tests/eukaryote/test_rna_degradation.py
Expand Up @@ -39,7 +39,8 @@ def setUp(self):
chr1 = wc_kb.core.DnaSpeciesType(cell=cell, id='chr1', sequence_path=self.sequence_path)
gene1 = wc_kb.eukaryote_schema.GeneLocus(cell=cell, id='gene1', polymer=chr1, start=1, end=18)
exon1 = wc_kb.eukaryote_schema.GenericLocus(start=4, end=18)
transcript1 = wc_kb.eukaryote_schema.TranscriptSpeciesType(cell=cell, id='trans1', name='transcript1', gene=gene1, exons=[exon1])
transcript1 = wc_kb.eukaryote_schema.TranscriptSpeciesType(cell=cell, id='trans1',
name='transcript1', gene=gene1, exons=[exon1])
transcript1_half_life = wc_kb.core.SpeciesTypeProperty(property='half_life', species_type=transcript1,
value='36000.0', value_type=wc_ontology['WC:float'])
transcript1_spec = wc_kb.core.Species(species_type=transcript1, compartment=nucleus)
Expand All @@ -48,11 +49,19 @@ def setUp(self):
chrM = wc_kb.core.DnaSpeciesType(cell=cell, id='chrM', sequence_path=self.sequence_path)
gene2 = wc_kb.eukaryote_schema.GeneLocus(cell=cell, id='gene2', polymer=chrM, start=1, end=18)
exon2 = wc_kb.eukaryote_schema.GenericLocus(start=1, end=10)
transcript2 = wc_kb.eukaryote_schema.TranscriptSpeciesType(cell=cell, id='trans2', name='transcript2', gene=gene2, exons=[exon2])
transcript2 = wc_kb.eukaryote_schema.TranscriptSpeciesType(cell=cell, id='trans2',
name='transcript2', gene=gene2, exons=[exon2])
transcript2_half_life = wc_kb.core.SpeciesTypeProperty(property='half_life', species_type=transcript2,
value='15000.0', value_type=wc_ontology['WC:float'])
transcript2_spec = wc_kb.core.Species(species_type=transcript2, compartment=mito)
transcript2_conc = wc_kb.core.Concentration(cell=cell, species=transcript2_spec, value=10.)
transcript2_conc = wc_kb.core.Concentration(cell=cell, species=transcript2_spec, value=10.)

transcript3 = wc_kb.eukaryote_schema.TranscriptSpeciesType(cell=cell, id='trans3',
name='transcript3', gene=gene2, exons=[exon2])
transcript3_half_life = wc_kb.core.SpeciesTypeProperty(property='half_life', species_type=transcript3,
value='36000.0', value_type=wc_ontology['WC:float'])
transcript3_spec = wc_kb.core.Species(species_type=transcript3, compartment=mito)
transcript3_conc = wc_kb.core.Concentration(cell=cell, species=transcript3_spec, value=10.)

# Create initial model content
self.model = model = wc_lang.Model()
Expand All @@ -65,7 +74,8 @@ def setUp(self):
init_volume = wc_lang.core.InitVolume(distribution=wc_ontology['WC:normal_distribution'],
mean=v[1], std=0)
c = model.compartments.create(id=k, name=v[0], init_volume=init_volume)
c.init_density = model.parameters.create(id='density_' + k, value=1000, units=unit_registry.parse_units('g l^-1'))
c.init_density = model.parameters.create(id='density_' + k, value=1000,
units=unit_registry.parse_units('g l^-1'))
volume = model.functions.create(id='volume_' + k, units=unit_registry.parse_units('l'))
volume.expression, error = wc_lang.FunctionExpression.deserialize(f'{c.id} / {c.init_density.id}', {
wc_lang.Compartment: {c.id: c},
Expand All @@ -82,7 +92,8 @@ def setUp(self):
mean=10., units=unit_registry.parse_units('molecule'))
conc_model.id = conc_model.gen_id()

complexes = {'complex1': ('Exosome','n'), 'complex2': ('Exosome', 'n'), 'complex3': ('Mitochondrial Exosome', 'm')}
complexes = {'complex1': ('Exosome','n'), 'complex2': ('Exosome', 'n'), 'complex3': ('Mitochondrial Exosome', 'm'),
'complex4': ('Mitochondrial Exosome variant', 'm')}
for k, v in complexes.items():
model_species_type = model.species_types.create(id=k, name=v[0])
model_compartment = model.compartments.get_one(id=v[1])
Expand All @@ -109,28 +120,35 @@ def tearDown(self):
def test_methods(self):

gen = rna_degradation.RnaDegradationSubmodelGenerator(self.kb, self.model, options={
'rna_exo_pair': {'trans1': 'Exosome', 'trans2': 'Mitochondrial Exosome'}
'rna_exo_pair': {'trans1': ['Exosome'], 'trans2': ['Mitochondrial Exosome'],
'trans3': ['Mitochondrial Exosome', 'Mitochondrial Exosome variant']}
})
gen.run()

# Test gen_reactions
self.assertEqual([i.id for i in self.model.submodels], ['rna_degradation'])
self.assertEqual(sorted([i.id for i in self.model.reactions]), sorted(['degradation_trans1', 'degradation_trans2']))
self.assertEqual(sorted([i.name for i in self.model.reactions]), sorted(['degradation of transcript1', 'degradation of transcript2']))
self.assertEqual(sorted([i.id for i in self.model.reactions]),
sorted(['degradation_trans1', 'degradation_trans2', 'degradation_trans3']))
self.assertEqual(sorted([i.name for i in self.model.reactions]),
sorted(['degradation of transcript1', 'degradation of transcript2', 'degradation of transcript3']))
self.assertEqual(set([i.submodel.id for i in self.model.reactions]), set(['rna_degradation']))
self.assertEqual({i.species.id: i.coefficient for i in self.model.reactions.get_one(id='degradation_trans1').participants},
{'amp[n]': 4, 'cmp[n]': 2, 'gmp[n]': 2, 'ump[n]': 7, 'h[n]': 14, 'h2o[n]': -14, 'trans1[n]': -1})
self.assertEqual({i.species.id: i.coefficient for i in self.model.reactions.get_one(id='degradation_trans2').participants},
{'amp[m]': 2, 'cmp[m]': 2, 'gmp[m]': 1, 'ump[m]': 5, 'h[m]': 9, 'h2o[m]': -9, 'trans2[m]': -1})
self.assertEqual(len(self.model.observables), 2)
self.assertEqual(len(self.model.observables), 4)
self.assertEqual(self.model.observables.get_one(name='Exosome observable in nucleus').id, 'obs_1')
self.assertEqual(self.model.observables.get_one(name='Exosome observable in nucleus').expression.expression,
'complex1[n] + complex2[n]')
self.assertEqual(self.model.observables.get_one(name='Mitochondrial Exosome observable in mitochondria').expression.expression,
'complex3[m]')
self.assertEqual(self.model.observables.get_one(name='Mitochondrial Exosome variant observable in mitochondria').expression.expression,
'complex4[m]')
self.assertEqual(self.model.observables.get_one(name='Combined exosome observable in mitochondria').expression.expression,
'obs_2 + obs_3')

# Test gen_rate_laws
self.assertEqual(len(self.model.rate_laws), 2)
self.assertEqual(len(self.model.rate_laws), 3)
self.assertEqual(self.model.rate_laws.get_one(id='degradation_trans1-forward').expression.expression,
'k_cat_degradation_trans1 * obs_1 * '
'(trans1[n] / (trans1[n] + K_m_degradation_trans1_trans1 * Avogadro * volume_n)) * '
Expand All @@ -139,6 +157,10 @@ def test_methods(self):
'k_cat_degradation_trans2 * obs_2 * '
'(trans2[m] / (trans2[m] + K_m_degradation_trans2_trans2 * Avogadro * volume_m)) * '
'(h2o[m] / (h2o[m] + K_m_degradation_trans2_h2o * Avogadro * volume_m))')
self.assertEqual(self.model.rate_laws.get_one(id='degradation_trans3-forward').expression.expression,
'k_cat_degradation_trans3 * obs_4 * '
'(trans3[m] / (trans3[m] + K_m_degradation_trans3_trans3 * Avogadro * volume_m)) * '
'(h2o[m] / (h2o[m] + K_m_degradation_trans3_h2o * Avogadro * volume_m))')

# Test calibrate_submodel
self.assertEqual(self.model.parameters.get_one(id='K_m_degradation_trans1_h2o').value, 1500/scipy.constants.Avogadro/5E-14)
Expand Down
46 changes: 35 additions & 11 deletions tests/eukaryote/test_transcription.py
Expand Up @@ -39,7 +39,8 @@ def setUp(self):
chr1 = wc_kb.core.DnaSpeciesType(cell=cell, id='chr1', sequence_path=self.sequence_path)
gene1 = wc_kb.eukaryote_schema.GeneLocus(cell=cell, id='gene1', polymer=chr1, start=1, end=18)
exon1 = wc_kb.eukaryote_schema.GenericLocus(start=4, end=18)
transcript1 = wc_kb.eukaryote_schema.TranscriptSpeciesType(cell=cell, id='trans1', name='transcript1', gene=gene1, exons=[exon1])
transcript1 = wc_kb.eukaryote_schema.TranscriptSpeciesType(cell=cell, id='trans1',
name='transcript1', gene=gene1, exons=[exon1])
transcript1_half_life = wc_kb.core.SpeciesTypeProperty(property='half_life', species_type=transcript1,
value='36000.0', value_type=wc_ontology['WC:float'])
transcript1_spec = wc_kb.core.Species(species_type=transcript1, compartment=nucleus)
Expand All @@ -48,11 +49,19 @@ def setUp(self):
chrM = wc_kb.core.DnaSpeciesType(cell=cell, id='chrM', sequence_path=self.sequence_path)
gene2 = wc_kb.eukaryote_schema.GeneLocus(cell=cell, id='gene2', polymer=chrM, start=1, end=18)
exon2 = wc_kb.eukaryote_schema.GenericLocus(start=1, end=10)
transcript2 = wc_kb.eukaryote_schema.TranscriptSpeciesType(cell=cell, id='trans2', name='transcript2', gene=gene2, exons=[exon2])
transcript2 = wc_kb.eukaryote_schema.TranscriptSpeciesType(cell=cell, id='trans2',
name='transcript2', gene=gene2, exons=[exon2])
transcript2_half_life = wc_kb.core.SpeciesTypeProperty(property='half_life', species_type=transcript2,
value='15000.0', value_type=wc_ontology['WC:float'])
transcript2_spec = wc_kb.core.Species(species_type=transcript2, compartment=mito)
transcript2_conc = wc_kb.core.Concentration(cell=cell, species=transcript2_spec, value=10.)
transcript2_conc = wc_kb.core.Concentration(cell=cell, species=transcript2_spec, value=10.)

transcript3 = wc_kb.eukaryote_schema.TranscriptSpeciesType(cell=cell, id='trans3',
name='transcript3', gene=gene2, exons=[exon2])
transcript3_half_life = wc_kb.core.SpeciesTypeProperty(property='half_life', species_type=transcript3,
value='36000.0', value_type=wc_ontology['WC:float'])
transcript3_spec = wc_kb.core.Species(species_type=transcript3, compartment=mito)
transcript3_conc = wc_kb.core.Concentration(cell=cell, species=transcript3_spec, value=10.)

# Create initial model content
self.model = model = wc_lang.Model()
Expand All @@ -66,7 +75,8 @@ def setUp(self):
init_volume = wc_lang.core.InitVolume(distribution=wc_ontology['WC:normal_distribution'],
mean=v[1], std=0)
c = model.compartments.create(id=k, name=v[0], init_volume=init_volume)
c.init_density = model.parameters.create(id='density_' + k, value=1000, units=unit_registry.parse_units('g l^-1'))
c.init_density = model.parameters.create(id='density_' + k, value=1000,
units=unit_registry.parse_units('g l^-1'))
volume = model.functions.create(id='volume_' + k, units=unit_registry.parse_units('l'))
volume.expression, error = wc_lang.FunctionExpression.deserialize(f'{c.id} / {c.init_density.id}', {
wc_lang.Compartment: {c.id: c},
Expand All @@ -83,7 +93,8 @@ def setUp(self):
mean=10., units=unit_registry.parse_units('molecule'))
conc_model.id = conc_model.gen_id()

complexes = {'complex1': ('RNA Polymerase I','n'), 'complex2': ('RNA Polymerase I', 'n'), 'complex3': ('RNA Polymerase II', 'm')}
complexes = {'complex1': ('RNA Polymerase I','n'), 'complex2': ('RNA Polymerase I', 'n'),
'complex3': ('RNA Polymerase II', 'm'), 'complex4': ('RNA Polymerase III', 'm')}
for k, v in complexes.items():
model_species_type = model.species_types.create(id=k, name=v[0])
model_compartment = model.compartments.get_one(id=v[1])
Expand All @@ -110,28 +121,35 @@ def tearDown(self):
def test_methods(self):

gen = transcription.TranscriptionSubmodelGenerator(self.kb, self.model, options={
'rna_pol_pair': {'trans1': 'RNA Polymerase I', 'trans2': 'RNA Polymerase II'}
'rna_pol_pair': {'trans1': ['RNA Polymerase I'], 'trans2': ['RNA Polymerase II'],
'trans3': ['RNA Polymerase II', 'RNA Polymerase III']}
})
gen.run()

# Test gen_reactions
self.assertEqual([i.id for i in self.model.submodels], ['transcription'])
self.assertEqual(sorted([i.id for i in self.model.reactions]), sorted(['transcription_trans1', 'transcription_trans2']))
self.assertEqual(sorted([i.name for i in self.model.reactions]), sorted(['transcription of transcript1', 'transcription of transcript2']))
self.assertEqual(sorted([i.id for i in self.model.reactions]),
sorted(['transcription_trans1', 'transcription_trans2', 'transcription_trans3']))
self.assertEqual(sorted([i.name for i in self.model.reactions]),
sorted(['transcription of transcript1', 'transcription of transcript2', 'transcription of transcript3']))
self.assertEqual(set([i.submodel.id for i in self.model.reactions]), set(['transcription']))
self.assertEqual({i.species.id: i.coefficient for i in self.model.reactions.get_one(id='transcription_trans1').participants},
{'atp[n]': -4, 'ctp[n]': -2, 'gtp[n]': -2, 'utp[n]': -7, 'ppi[n]': 14, 'trans1[n]': 1})
self.assertEqual({i.species.id: i.coefficient for i in self.model.reactions.get_one(id='transcription_trans2').participants},
{'atp[m]': -2, 'ctp[m]': -2, 'gtp[m]': -1, 'utp[m]': -5, 'ppi[m]': 9, 'trans2[m]': 1})
self.assertEqual(len(self.model.observables), 2)
self.assertEqual(len(self.model.observables), 4)
self.assertEqual(self.model.observables.get_one(name='RNA Polymerase I observable in nucleus').id, 'obs_1')
self.assertEqual(self.model.observables.get_one(name='RNA Polymerase I observable in nucleus').expression.expression,
'complex1[n] + complex2[n]')
self.assertEqual(self.model.observables.get_one(name='RNA Polymerase II observable in mitochondria').expression.expression,
'complex3[m]')
self.assertEqual(self.model.observables.get_one(name='RNA Polymerase III observable in mitochondria').expression.expression,
'complex4[m]')
self.assertEqual(self.model.observables.get_one(name='Combined RNA polymerase observable in mitochondria').expression.expression,
'obs_2 + obs_3')

# Test gen_rate_laws
self.assertEqual(len(self.model.rate_laws), 2)
self.assertEqual(len(self.model.rate_laws), 3)
self.assertEqual(self.model.rate_laws.get_one(id='transcription_trans1-forward').expression.expression,
'k_cat_transcription_trans1 * obs_1 * '
'(atp[n] / (atp[n] + K_m_transcription_trans1_atp * Avogadro * volume_n)) * '
Expand All @@ -144,7 +162,13 @@ def test_methods(self):
'(ctp[m] / (ctp[m] + K_m_transcription_trans2_ctp * Avogadro * volume_m)) * '
'(gtp[m] / (gtp[m] + K_m_transcription_trans2_gtp * Avogadro * volume_m)) * '
'(utp[m] / (utp[m] + K_m_transcription_trans2_utp * Avogadro * volume_m))')

self.assertEqual(self.model.rate_laws.get_one(id='transcription_trans3-forward').expression.expression,
'k_cat_transcription_trans3 * obs_4 * '
'(atp[m] / (atp[m] + K_m_transcription_trans3_atp * Avogadro * volume_m)) * '
'(ctp[m] / (ctp[m] + K_m_transcription_trans3_ctp * Avogadro * volume_m)) * '
'(gtp[m] / (gtp[m] + K_m_transcription_trans3_gtp * Avogadro * volume_m)) * '
'(utp[m] / (utp[m] + K_m_transcription_trans3_utp * Avogadro * volume_m))')

# Test calibrate_submodel
self.assertEqual(self.model.parameters.get_one(id='K_m_transcription_trans1_utp').value, 1500/scipy.constants.Avogadro/5E-14)
self.assertEqual(self.model.parameters.get_one(id='K_m_transcription_trans2_utp').value, 1500/scipy.constants.Avogadro/2.5E-14)
Expand Down

0 comments on commit 77497f9

Please sign in to comment.