Skip to content

Commit

Permalink
Merge branch 'master' of ssh://github.com/KarrLab/wc_model_gen
Browse files Browse the repository at this point in the history
  • Loading branch information
jonrkarr committed Sep 25, 2019
2 parents c431cb0 + 03da3ae commit fac7e95
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 44 deletions.
81 changes: 51 additions & 30 deletions tests/eukaryote/test_complexation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def setUp(self):

nucleus = cell.compartments.create(id='n')
mito = cell.compartments.create(id='m')
lysosome = cell.compartments.create(id='l')

chr1 = wc_kb.core.DnaSpeciesType(cell=cell, id='chr1', sequence_path=self.sequence_path)
gene1 = wc_kb.eukaryote.GeneLocus(cell=cell, id='gene1', polymer=chr1, start=1, end=12)
Expand Down Expand Up @@ -63,15 +64,19 @@ def setUp(self):
wc_kb.core.SpeciesTypeCoefficient(species_type=prot1, coefficient=1),
wc_kb.core.SpeciesTypeCoefficient(species_type=prot2, coefficient=2),
wc_kb.core.SpeciesTypeCoefficient(species_type=prot3, coefficient=0),
])
])

complex2 = wc_kb.core.ComplexSpeciesType(cell=cell, id='complex2', subunits=[
wc_kb.core.SpeciesTypeCoefficient(species_type=prot3, coefficient=2),
])

# Create initial model content
self.model = model = wc_lang.Model()

model.parameters.create(id='Avogadro', value = scipy.constants.Avogadro,
units = unit_registry.parse_units('molecule mol^-1'))

compartments = {'n': ('nucleus', 5E-14), 'm': ('mitochondria', 2.5E-14)}
compartments = {'n': ('nucleus', 5E-14), 'm': ('mitochondria', 2.5E-14), 'l': ('lysosome', 2.5E-14)}
for k, v in compartments.items():
init_volume = wc_lang.core.InitVolume(distribution=wc_ontology['WC:normal_distribution'],
mean=v[1], std=0)
Expand Down Expand Up @@ -102,26 +107,32 @@ def setUp(self):
mean=20, units=unit_registry.parse_units('molecule'))
conc_model.id = conc_model.gen_id()

model_species_type = model.species_types.create(id=complex1.id)
subunit_compartments = [[s.compartment.id for s in sub.species_type.species]
for sub in complex1.subunits]
shared_compartments = set([])
for i in range(len(subunit_compartments)):
shared_compartments = (set(subunit_compartments[i])
if i==0 else shared_compartments).intersection(
set(subunit_compartments[i+1]) if i<(len(subunit_compartments)-1) else shared_compartments)
compartment_ids = set(list(shared_compartments))
for compartment_id in compartment_ids:
model_compartment = model.compartments.get_one(id=compartment_id)
model_species = model.species.get_or_create(species_type=model_species_type, compartment=model_compartment)
model_species.id = model_species.gen_id()
for compl in [complex1, complex2]:
model_species_type = model.species_types.create(id=compl.id)
subunit_compartments = [[s.compartment.id for s in sub.species_type.species]
for sub in compl.subunits]
if len(subunit_compartments) == 1:
shared_compartments = set(subunit_compartments[0])
else:
shared_compartments = set([])
for i in range(len(subunit_compartments)):
shared_compartments = (set(subunit_compartments[i])
if i==0 else shared_compartments).intersection(
set(subunit_compartments[i+1]) if i<(len(subunit_compartments)-1) else shared_compartments)
compartment_ids = set(list(shared_compartments))
for compartment_id in compartment_ids:
model_compartment = model.compartments.get_one(id=compartment_id)
model_species = model.species.get_or_create(species_type=model_species_type, compartment=model_compartment)
model_species.id = model_species.gen_id()

metabolic_participants = ['Ala', 'Cys', 'Asp', 'Glu', 'h2o']
metabolic_compartments = ['l', 'm']
for i in metabolic_participants:
model_species_type = model.species_types.create(id=i)
model_compartment = model.compartments.get_one(id='n')
model_species = model.species.create(species_type=model_species_type, compartment=model_compartment)
model_species.id = model_species.gen_id()
for c in metabolic_compartments:
model_species_type = model.species_types.get_or_create(id=i)
model_compartment = model.compartments.get_one(id=c)
model_species = model.species.get_or_create(species_type=model_species_type, compartment=model_compartment)
model_species.id = model_species.gen_id()

def tearDown(self):
shutil.rmtree(self.tmp_dirname)
Expand All @@ -141,40 +152,50 @@ def test_methods(self):
})
gen.run()

self.assertEqual(len(model.reactions), 4)
self.assertEqual(len(model.reactions), 8)
self.assertEqual([i.id for i in model.submodels], ['complexation'])

# Test gen_reaction
complex_assembly = model.reactions.get_one(id='complex_association_complex1_n')
self.assertEqual(complex_assembly.name, 'Complexation of complex1 in nucleus')
self.assertEqual(complex_assembly.reversible, False)
self.assertEqual(complex_assembly.comments, '')
self.assertEqual([(i.species.id, i.coefficient) for i in complex_assembly.participants],
complex1_assembly = model.reactions.get_one(id='complex_association_complex1_n')
self.assertEqual(complex1_assembly.name, 'Complexation of complex1 in nucleus')
self.assertEqual(complex1_assembly.reversible, False)
self.assertEqual(complex1_assembly.comments, '')
self.assertEqual([(i.species.id, i.coefficient) for i in complex1_assembly.participants],
[('prot1[n]', -1), ('prot2[n]', -2), ('prot3[n]', -1), ('complex1[n]', 1)])

dissociate_prot1 = model.reactions.get_one(id='complex1_n_dissociation_prot1_degradation')
self.assertEqual(dissociate_prot1.name, 'Dissociation of complex1 and degradation of prot1 in nucleus')
self.assertEqual(dissociate_prot1.reversible, False)
self.assertEqual(dissociate_prot1.comments, '')
self.assertEqual(sorted([(i.species.id, i.coefficient) for i in dissociate_prot1.participants]),
sorted([('complex1[n]', -1), ('h2o[n]', -1), ('Ala[n]', 1), ('Cys[n]', 1), ('prot2[n]', 2), ('prot3[n]', 1)]))
sorted([('complex1[n]', -1), ('h2o[l]', -1), ('Ala[l]', 1), ('Cys[l]', 1), ('prot2[n]', 2), ('prot3[n]', 1)]))

dissociate_prot2 = model.reactions.get_one(id='complex1_n_dissociation_prot2_degradation')
self.assertEqual(sorted([(i.species.id, i.coefficient) for i in dissociate_prot2.participants]),
sorted([('complex1[n]', -1), ('h2o[n]', -1), ('Cys[n]', 1), ('Asp[n]', 1), ('prot1[n]', 1), ('prot2[n]', 1), ('prot3[n]', 1)]))
sorted([('complex1[n]', -1), ('h2o[l]', -1), ('Cys[l]', 1), ('Asp[l]', 1), ('prot1[n]', 1), ('prot2[n]', 1), ('prot3[n]', 1)]))

dissociate_prot3 = model.reactions.get_one(id='complex1_n_dissociation_prot3_degradation')
self.assertEqual(sorted([(i.species.id, i.coefficient) for i in dissociate_prot3.participants]),
sorted([('complex1[n]', -1), ('h2o[n]', -1), ('Asp[n]', 2), ('prot1[n]', 1), ('prot2[n]', 2)]))
sorted([('complex1[n]', -1), ('h2o[l]', -1), ('Asp[l]', 2), ('prot1[n]', 1), ('prot2[n]', 2)]))

complex2_assembly = model.reactions.get_one(id='complex_association_complex2_m')
self.assertEqual(complex2_assembly.name, 'Complexation of complex2 in mitochondria')
self.assertEqual(complex2_assembly.reversible, False)
self.assertEqual(complex2_assembly.comments, '')
self.assertEqual([(i.species.id, i.coefficient) for i in complex2_assembly.participants],
[('prot3[m]', -2), ('complex2[m]', 1)])

c2_dissociate_prot3 = model.reactions.get_one(id='complex2_m_dissociation_prot3_degradation')
self.assertEqual(sorted([(i.species.id, i.coefficient) for i in c2_dissociate_prot3.participants]),
sorted([('complex2[m]', -1), ('h2o[m]', -1), ('Asp[m]', 2), ('prot3[m]', 1)]))

# Test gen_rate_laws
self.assertEqual(complex_assembly.rate_laws[0].expression.expression,
self.assertEqual(complex1_assembly.rate_laws[0].expression.expression,
'k_cat_complex_association_complex1_n * '
'(prot1[n] / (prot1[n] + K_m_complex_association_complex1_n_prot1 * Avogadro * volume_n)) * '
'(prot2[n] / (prot2[n] + K_m_complex_association_complex1_n_prot2 * Avogadro * volume_n)) * '
'(prot3[n] / (prot3[n] + K_m_complex_association_complex1_n_prot3 * Avogadro * volume_n))')
self.assertEqual(complex_assembly.rate_laws[0].direction, wc_lang.RateLawDirection.forward)
self.assertEqual(complex1_assembly.rate_laws[0].direction, wc_lang.RateLawDirection.forward)
self.assertEqual(dissociate_prot1.rate_laws[0].expression.expression,
'k_cat_complex1_n_dissociation_prot1_degradation * complex1[n]')
self.assertEqual(dissociate_prot3.rate_laws[0].expression.expression,
Expand Down
6 changes: 6 additions & 0 deletions tests/eukaryote/test_initialize_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ def setUp(self):
complex2_conc2 = wc_kb.core.Concentration(cell=cell, species=complex2_spec2, value=0.)
complex2_conc2.id = complex2_conc2.serialize()

complex3 = wc_kb.core.ComplexSpeciesType(cell=cell, id='comp3', name='complex3',
subunits=[species_type_coeff1])

expr1 = wc_kb.core.ObservableExpression(expression = '2.5 * prot1[n] + 1.3 * prot3[m]',
species = [prot1_spec, prot3_spec])
observable1 = wc_kb.core.Observable(cell=cell, id='obs1', name='observable1', expression=expr1)
Expand Down Expand Up @@ -442,6 +445,9 @@ def test_gen_complexes(self):
comp2_model = model.species_types.get_one(id='comp2')
self.assertEqual(set([i.compartment.id for i in model.species.get(species_type=comp2_model)]), set(['n', 'e']))

comp3_model = model.species_types.get_one(id='comp3')
self.assertEqual(set([i.compartment.id for i in model.species.get(species_type=comp3_model)]), set(['n']))

def test_gen_distribution_init_concentrations(self):

test_conc = self.kb.cell.concentrations.get_one(value=0.5)
Expand Down
4 changes: 3 additions & 1 deletion wc_model_gen/eukaryote/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .core import EukaryoteModelGenerator
from .complexation import ComplexationSubmodelGenerator
from .initialize_model import InitializeModel
from .transcription import TranscriptionSubmodelGenerator
from .rna_degradation import RnaDegradationSubmodelGenerator
from .transcription import TranscriptionSubmodelGenerator
14 changes: 10 additions & 4 deletions wc_model_gen/eukaryote/complexation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from wc_onto import onto as wc_ontology
from wc_utils.util.units import unit_registry
import Bio.Alphabet
import Bio.Seq
import wc_model_gen.utils as utils
import scipy.constants
import wc_kb
Expand Down Expand Up @@ -123,7 +125,7 @@ def gen_reactions(self):
else:
codon_id = codon_table[subunit.species_type.id]

protein_seq = subunit.species_type.get_seq(table=codon_id, cds=cds).strip('*')
protein_seq = ''.join(i for i in subunit.species_type.get_seq(table=codon_id, cds=cds) if i!='*')
aa_content = {}
for aa in protein_seq:
aa_id = amino_acid_id_conversion[aa]
Expand All @@ -132,15 +134,19 @@ def gen_reactions(self):
else:
aa_content[aa_id] += 1

if compl_compartment.id == 'm':
degradation_comp = model.compartments.get_one(id='m')
else:
degradation_comp = model.compartments.get_one(id='l')
for aa_id, aa_count in aa_content.items():
model_aa = model.species_types.get_one(id=aa_id).species.get_one(
compartment=compl_compartment)
model_aa = model.species_types.get_one(id=aa_id).species.get_or_create(
compartment=degradation_comp)
model_rxn.participants.add(
model_aa.species_coefficients.get_or_create(
coefficient=aa_count))

h2o = model.species_types.get_one(id='h2o').species.get_one(
compartment=compl_compartment)
compartment=degradation_comp)
model_rxn.participants.add(
h2o.species_coefficients.get_or_create(
coefficient=-(sum(aa_content.values())-1)))
Expand Down
4 changes: 3 additions & 1 deletion wc_model_gen/eukaryote/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class EukaryoteModelGenerator(wc_model_gen.ModelGenerator):
* component
* InitializeModel
* TranscriptionSubmodelGenerator
* ComplexationSubmodelGenerator,
* TranscriptionSubmodelGenerator,
* RnaDegradationSubmodelGenerator
"""

DEFAULT_COMPONENT_GENERATORS = (
Expand Down
18 changes: 10 additions & 8 deletions wc_model_gen/eukaryote/initialize_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,12 +489,14 @@ def gen_species_type(self, kb_species_type, extra_compartment_ids=None):
if isinstance(kb_species_type, wc_kb.core.ComplexSpeciesType):
subunit_compartments = [[s.compartment.id for s in sub.species_type.species]
for sub in kb_species_type.subunits]

shared_compartments = set([])
for i in range(len(subunit_compartments)):
shared_compartments = (set(subunit_compartments[i])
if i==0 else shared_compartments).intersection(
set(subunit_compartments[i+1]) if i<(len(subunit_compartments)-1) else shared_compartments)
if len(subunit_compartments) == 1:
shared_compartments = set(subunit_compartments[0])
else:
shared_compartments = set([])
for i in range(len(subunit_compartments)):
shared_compartments = (set(subunit_compartments[i])
if i==0 else shared_compartments).intersection(
set(subunit_compartments[i+1]) if i<(len(subunit_compartments)-1) else shared_compartments)
# Combine compartments where all the subunits exist, where catalyzed reactions occur and the additionally defined extra
compartment_ids = set(list(shared_compartments) + [s.compartment.id for s in kb_species_type.species] +
(extra_compartment_ids or []))
Expand Down Expand Up @@ -560,8 +562,8 @@ def gen_distribution_init_concentrations(self):
conc_model.identifiers.append(identifier_model)

for chromosome in kb.cell.species_types.get(__type=wc_kb.core.DnaSpeciesType):
model_species_type = model.species_types.get_one(id=chromosome.id)
model_species = model.species.get(species_type=model_species_type)[0]
model_species_type = model.species_types.get_or_create(id=chromosome.id)
model_species = model.species.get_or_create(species_type=model_species_type)
conc_model = model.distribution_init_concentrations.create(
species=model_species,
mean=chromosome.ploidy,
Expand Down

0 comments on commit fac7e95

Please sign in to comment.