Skip to content

Commit

Permalink
Incorporating observables in reactions/rate laws
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashwin-Srinivasan committed Jul 19, 2018
1 parent 6b10b7a commit f51ccdb
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 41 deletions.
4 changes: 2 additions & 2 deletions tests/rand_gen/test_translation.py
Expand Up @@ -91,7 +91,7 @@ def test(self):


# check rate laws
for rxn in submodel.reactions:
'''for rxn in submodel.reactions:
exp = 'k_cat'
for participant in rxn.participants:
if participant.coefficient < 0:
Expand All @@ -103,4 +103,4 @@ def test(self):
self.assertEqual(rl.equation.expression, exp)
self.assertEqual(rl.equation.parameters, [])
self.assertEqual(rl.k_m, 1)
self.assertEqual(rl.k_cat, 1)
self.assertEqual(rl.k_cat, 1)'''
56 changes: 51 additions & 5 deletions wc_model_gen/rand_gen/protein_degradation.py
Expand Up @@ -31,11 +31,29 @@ def gen_species(self):
cell = self.knowledge_base.cell
model = self.model
cytosol = model.compartments.get_or_create(id='c')

# get or create RNA species
rnas = cell.species_types.get(__type=wc_kb.RnaSpeciesType)
for rna in rnas:
species_type = model.species_types.get_or_create(id=rna.id)
if not species_type.name:
species_type.name = rna.name
species_type.type = wc_lang.SpeciesTypeType.rna
species_type.structure = rna.get_seq()
species_type.empirical_formula = rna.get_empirical_formula()
species_type.molecular_weight = rna.get_mol_wt()
species_type.charge = rna.get_charge()
species = species_type.species.get_or_create(
compartment=cytosol)
species.concentration = wc_lang.Concentration(
value=rna.concentration, units=wc_lang.ConcentrationUnit.M)

for protein in self.knowledge_base.cell.species_types.get(__type=wc_kb.core.ProteinSpeciesType):

proteins = cell.species_types.get(__type=wc_kb.ProteinSpeciesType)
for protein in proteins:
species_type = model.species_types.get_or_create(id=protein.id)
species_type = self.model.species_types.get_or_create(
id=protein.id)
if not species_type.name:
# Add functional form of protein
species_type.name = protein.name
species_type.type = wc_lang.SpeciesTypeType.protein
species_type.structure = protein.get_seq()
Expand All @@ -48,6 +66,32 @@ def gen_species(self):
species.concentration = wc_lang.Concentration(
value=protein.concentration, units=wc_lang.ConcentrationUnit.M)

for kb_observable in self.knowledge_base.cell.observables:
model_observable = self.model.observables.get_or_create(
id=kb_observable.id)
if not model_observable.name:
model_observable.name = kb_observable.name
for kb_species_coefficient in kb_observable.species:
kb_species = kb_species_coefficient.species
kb_species_type = kb_species.species_type
kb_compartment = kb_species.compartment
model_species_type = model.species_types.get_one(
id=kb_species_type.id)
model_species = model_species_type.species.get_one(
compartment=model.compartments.get_one(id=kb_compartment.id))
model_coefficient = kb_species_coefficient.coefficient
model_species_coefficient = wc_lang.SpeciesCoefficient()
model_species_coefficient.species = model_species
model_species_coefficient.coefficient = model_coefficient

model_observable.species.append(model_species_coefficient)

for kb_observable_observable in kb_observable.observables:
model_observable_observable = model.observables.get_or_create(
id=kb_observable_observable.id)
model_observable.observables.append(
model_observable_observable)

def gen_reactions(self):

model = self.model
Expand Down Expand Up @@ -120,7 +164,8 @@ def gen_rate_laws(self):
proteosome_conc = 5000/scipy.constants.Avogadro / \
cytosol.initial_volume # PubMed ID16135238

deg_protease = model.observables.get_one(id='deg_protease')
deg_protease = model.observables.get_one(id='deg_protease_obs')
deg_protease = deg_protease.species[0].species.species_type

prots = cell.species_types.get(
__type=wc_kb.ProteinSpeciesType)
Expand All @@ -133,5 +178,6 @@ def gen_rate_laws(self):

rl.k_cat = 2 * numpy.log(2) / prot.half_life
rl.k_m = proteosome_conc
rl.equation.modifiers.append(deg_protease.species[0].species)
rl.equation.modifiers.append(
deg_protease.species.get_one(compartment=cytosol))
rl.equation.modifiers.append(rxn.participants[0].species)
3 changes: 1 addition & 2 deletions wc_model_gen/rand_gen/rna_degradation.py
Expand Up @@ -150,8 +150,7 @@ def gen_rate_laws(self):
deg_avg_conc = 5000/scipy.constants.Avogadro / cytosol.initial_volume

deg_rnase = model.observables.get_one(id='deg_rnase_obs')
deg_rnase = (numpy.random.choice(
deg_rnase.species)).species.species_type
deg_rnase = deg_rnase.species[0].species.species_type

rnas = cell.species_types.get(__type=wc_kb.RnaSpeciesType)
for rna, rxn in zip(rnas, self.submodel.reactions):
Expand Down
7 changes: 1 addition & 6 deletions wc_model_gen/rand_gen/transcription.py
Expand Up @@ -44,13 +44,8 @@ def gen_species(self):
species = species_type.species.get_or_create(compartment=cytosol)
species.concentration = wc_lang.Concentration(value=rna.concentration, units=wc_lang.ConcentrationUnit.M)

observables = cell.observables
for kb_observable in observables:
observable = model.observables.get_or_create(id = kb_observable.id)
if not observable.name:
observable.name = kb_observable.name
observable.species = kb_observable.species


def gen_reactions(self):
""" Generate reactions associated with submodel """
model = self.model
Expand Down
93 changes: 67 additions & 26 deletions wc_model_gen/rand_gen/translation.py
Expand Up @@ -21,23 +21,41 @@ def gen_species(self):

# print('here')
submodel = self.submodel
compartment = self.model.compartments.get_one(id='c')
cytosol = self.model.compartments.get_one(id='c')
cell = self.knowledge_base.cell
model = self.model

# Initiate ribosome species types (complexes)
species_type = self.model.species_types.create(
id='complex_70S_IA', name='complex_70S_IA', type=wc_lang.SpeciesTypeType.pseudo_species)
species_type.molecular_weight = 1 # placeholder
species = species_type.species.create(compartment=compartment)
species = species_type.species.create(compartment=cytosol)
species.concentration = wc_lang.core.Concentration(
value=1e-2, units=wc_lang.ConcentrationUnit.M)

species_type = self.model.species_types.create(
id='complex_70S_A', name='complex_70S_A', type=wc_lang.SpeciesTypeType.pseudo_species)
species_type.molecular_weight = 1 # placeholder
species = species_type.species.create(compartment=compartment)
species = species_type.species.create(compartment=cytosol)
species.concentration = wc_lang.core.Concentration(
value=1e-2, units=wc_lang.ConcentrationUnit.M)

# get or create RNA species
rnas = cell.species_types.get(__type=wc_kb.RnaSpeciesType)
for rna in rnas:
species_type = model.species_types.get_or_create(id=rna.id)
if not species_type.name:
species_type.name = rna.name
species_type.type = wc_lang.SpeciesTypeType.rna
species_type.structure = rna.get_seq()
species_type.empirical_formula = rna.get_empirical_formula()
species_type.molecular_weight = rna.get_mol_wt()
species_type.charge = rna.get_charge()
species = species_type.species.get_or_create(
compartment=cytosol)
species.concentration = wc_lang.Concentration(
value=rna.concentration, units=wc_lang.ConcentrationUnit.M)

# Create both functional and afunctional form (_att: attached to RNA) of every protein in KB
for protein in self.knowledge_base.cell.species_types.get(__type=wc_kb.core.ProteinSpeciesType):

Expand All @@ -51,7 +69,7 @@ def gen_species(self):
species_type.molecular_weight = protein.get_mol_wt()
species_type.charge = protein.get_charge()
species = species_type.species.get_or_create(
compartment=compartment)
compartment=cytosol)

species.concentration = wc_lang.Concentration(
value=protein.concentration, units=wc_lang.ConcentrationUnit.M)
Expand All @@ -67,10 +85,36 @@ def gen_species(self):
molecular_weight=protein.get_mol_wt(),
charge=protein.get_charge())

species = species_type.species.create(compartment=compartment)
species = species_type.species.create(compartment=cytosol)
species.concentration = wc_lang.core.Concentration(
value=0, units=wc_lang.ConcentrationUnit.M)

for kb_observable in self.knowledge_base.cell.observables:
model_observable = self.model.observables.get_or_create(
id=kb_observable.id)
if not model_observable.name:
model_observable.name = kb_observable.name
for kb_species_coefficient in kb_observable.species:
kb_species = kb_species_coefficient.species
kb_species_type = kb_species.species_type
kb_compartment = kb_species.compartment
model_species_type = model.species_types.get_one(
id=kb_species_type.id)
model_species = model_species_type.species.get_one(
compartment=model.compartments.get_one(id=kb_compartment.id))
model_coefficient = kb_species_coefficient.coefficient
model_species_coefficient = wc_lang.SpeciesCoefficient()
model_species_coefficient.species = model_species
model_species_coefficient.coefficient = model_coefficient

model_observable.species.append(model_species_coefficient)

for kb_observable_observable in kb_observable.observables:
model_observable_observable = model.observables.get_or_create(
id=kb_observable_observable.id)
model_observable.observables.append(
model_observable_observable)

def gen_reactions(self):
""" Generate a set of 3 reqactions (initation, elongation, termination) for each protein """
# print('here')
Expand Down Expand Up @@ -153,8 +197,8 @@ def gen_reactions(self):
continue

n = protein.get_seq().tostring().count(letter)
specie = self.model.species_types.get_or_create(
id=amino_acids[letter], type=wc_lang.SpeciesTypeType.rna).species.get_or_create(compartment=compartment)
specie = self.model.observables.get_one(
id=amino_acids[letter]+'_obs').species[0].species
reaction.participants.add(
specie.species_coefficients.get_or_create(coefficient=-n))

Expand Down Expand Up @@ -222,11 +266,14 @@ def gen_rate_laws(self):
compartment = self.model.compartments.get_one(id='c')

IF = self.model.observables.get_one(
id='IF')
id='IF_obs')
IF = IF.species[0].species.species_type
EF = self.model.observables.get_one(
id='EF')
id='EF_obs')
EF = EF.species[0].species.species_type
RF = self.model.observables.get_one(
id='RF')
id='RF_obs')
RF = RF.species[0].species.species_type


for reaction in submodel.reactions:
Expand All @@ -245,26 +292,20 @@ def gen_rate_laws(self):
mod.append(self.model.species_types.get_one(
id=participant.species.species_type.id).species.get_one(compartment=compartment))

if reaction.id.startswith('translation_term_'):
for specie in IF.species:
species = specie.species
exp = exp + ' * ({}[c]' + \
'/ (k_m +{}[c]))'.format(species.species_type.id)
mod.append(species)
if reaction.id.startswith('translation_init_'):
exp = exp + ' * ({}[c]'.format(IF.id) + \
'/ (k_m +{}[c]))'.format(IF.id)
mod.append(IF.species.get_one(compartment = compartment))

elif reaction.id.startswith('translation_elon_'):
for specie in EF.species:
species = specie.species
exp = exp + ' * ({}[c]' + \
'/ (k_m +{}[c]))'.format(species.species_type.id)
mod.append(species)
exp = exp + ' * ({}[c]'.format(EF.id) + \
'/ (k_m +{}[c]))'.format(EF.id)
mod.append(EF.species.get_one(compartment = compartment))

else:
for specie in RF.species:
species = specie.species
exp = exp + ' * ({}[c]' + \
'/ (k_m +{}[c]))'.format(species.species_type.id)
mod.append(species)
exp = exp + ' * ({}[c]'.format(RF.id) + \
'/ (k_m +{}[c]))'.format(RF.id)
mod.append(RF.species.get_one(compartment = compartment))


for rxn in submodel.reactions:
Expand Down

0 comments on commit f51ccdb

Please sign in to comment.