Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
balazs1987 committed Sep 18, 2018
1 parent 7746f76 commit cf2ab83
Show file tree
Hide file tree
Showing 14 changed files with 334 additions and 415 deletions.
Binary file modified tests/fixtures/min_kb.xlsx
Binary file not shown.
227 changes: 120 additions & 107 deletions tests/fixtures/min_kb_seq.fna

Large diffs are not rendered by default.

29 changes: 7 additions & 22 deletions tests/prokaryote/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import shutil
import os

class KbAndModelIOTestCase(unittest.TestCase):
class ModelIOTestCase(unittest.TestCase):

@classmethod
def setUpClass(cls):
Expand All @@ -20,33 +20,18 @@ def tearDownClass(cls):

def test_generate_read_write(self):

""" Generate KBs """
kb = wc_kb_gen.random.RandomKbGenerator(options={
'component': {
'GenomeGenerator': {
'genetic_code': 'reduced',
'mean_num_genes': 40,
'mean_gene_len': 70,
'num_tRNA': 4,
'num_rRNA': 0,
'num_ncRNA': 0,
'min_prots': 5,
'translation_table': 4,
'mean_copy_number': 100,
'mean_half_life': 100},
'PropertiesGenerator': {
'mean_cell_cycle_length': 100},
'ObservablesGenerator': {
'genetic_code': 'reduced'},
}}).run()
kb = wc_kb.io.Reader().run('tests/fixtures/min_kb.xlsx',
'tests/fixtures/min_kb_seq.fna',
strict=False)

self.assertIsInstance(kb, wc_kb.core.KnowledgeBase)

""" Generate and write models from KBs """
model = prokaryote.ProkaryoteModelGenerator(knowledge_base=kb).run()
wc_lang.io.Writer().run(model, os.path.join(self.dir, 'model.xlsx'), set_repo_metadata_from_path=False)

self.assertIsInstance(model, wc_lang.core.Model)
self.assertTrue(os.path.isfile(os.path.join(self.dir, 'model.xlsx')))

""" Read back KBs from disk """
#model_read = wc_lang.io.Reader().run('/media/sf_VM_share/model.xlsx')
model_read = wc_lang.io.Reader().run(os.path.join(self.dir, 'model.xlsx'))
self.assertIsInstance(model_read, wc_lang.core.Model)
65 changes: 27 additions & 38 deletions tests/prokaryote/test_metabolism.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,30 @@

class MetabolismSubmodelGeneratorTestCase(unittest.TestCase):

def test(self):
kb = wc_kb_gen.random.RandomKbGenerator(options={
'component': {
'GenomeGenerator': {
'mean_num_genes': 20,
'mean_gene_len': 50,
'num_ncRNA': 0,
'translation_table': 4,
'mean_copy_number': 100,
'mean_half_life': 100
},
'PropertiesGenerator': {
'mean_cell_cycle_length': 100,
},
},
}).run()

model = prokaryote.ProkaryoteModelGenerator(
knowledge_base=kb,
component_generators=[prokaryote.InitalizeModel,
prokaryote.MetabolismSubmodelGenerator]).run()

cell = kb.cell
prots = cell.species_types.get(__type=wc_kb.prokaryote_schema.ProteinSpeciesType)
submodel = model.submodels.get_one(id='metabolism')

# check parameters generated
self.assertEqual(model.parameters.get_one(id='fraction_dry_weight').value, 0.3)

# check species types and species generated
cytosol = model.compartments.get(id='c')[0]

for species in kb.cell.species_types.get(__type=wc_kb.core.MetaboliteSpeciesType):
model_species = model.species_types.get_one(id=species.id)
model_species_cytosol = model_species.species.get_one(
compartment=cytosol)
self.assertIsInstance(model_species, wc_lang.SpeciesType)
self.assertIsInstance(model_species_cytosol, wc_lang.Species)
@classmethod
def setUpClass(cls):
cls.kb = wc_kb.io.Reader().run('tests/fixtures/min_kb.xlsx',
'tests/fixtures/min_kb_seq.fna',
strict=False)

cls.model = prokaryote.ProkaryoteModelGenerator(
knowledge_base = cls.kb,
component_generators=[prokaryote.InitalizeModel,
prokaryote.MetabolismSubmodelGenerator],
options = {'component': {
'TranscriptionSubmodelGenerator': {
'rate_dynamics': 'phenomenological'}}}).run()

@classmethod
def tearDownClass(cls):
pass

def test_metabolite_species(self):

cytosol = self.model.compartments.get_one(id='c')
for species in self.kb.cell.species_types.get(__type=wc_kb.core.MetaboliteSpeciesType):
model_species_type = self.model.species_types.get_one(id=species.id)
model_specie = model_species_type.species.get_one(compartment=cytosol)

self.assertIsInstance(model_species_type, wc_lang.SpeciesType)
self.assertIsInstance(model_specie, wc_lang.Species)
51 changes: 30 additions & 21 deletions tests/prokaryote/test_model_gen_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,36 @@
import unittest
import wc_lang
import wc_utils.util.string

import wc_kb

class ModelGeneratorTestCase(unittest.TestCase):
def test(self):

rand_kb = random.RandomKbGenerator(options={
'component': {
'GenomeGenerator': {
'mean_num_genes': 30,
'mean_gene_len': 50,
'num_ncRNA': 0,
'translation_table': 4,
'mean_copy_number': 200,
'mean_half_life': 100},
'PropertiesGenerator': {
'mean_cell_cycle_length': 100,},
},
}).run()

model = prokaryote.ProkaryoteModelGenerator(rand_kb).run()
self.assertIsInstance(model.submodels.get_one(id='metabolism'), wc_lang.Submodel)

errors = obj_model.Validator().run(model, get_related=True)

@classmethod
def setUpClass(cls):
cls.kb = wc_kb.io.Reader().run('tests/fixtures/min_kb.xlsx',
'tests/fixtures/min_kb_seq.fna',
strict=False)

cls.model = prokaryote.ProkaryoteModelGenerator(knowledge_base = cls.kb).run()

@classmethod
def tearDownClass(cls):
pass

def test_submodels(self):
self.assertEqual(5, len(self.model.submodels))

def test_compartments(self):
cytosol = self.model.compartments.get_one(id='c')
extracellular_space = self.model.compartments.get_one(id='e')
self.assertIsInstance(cytosol, wc_lang.core.Compartment)
self.assertIsInstance(extracellular_space, wc_lang.core.Compartment)

def test_parameters(self):
cell_cycle_length = self.model.parameters.get_one(id='cell_cycle_length')
fraction_dry_weight = self.model.parameters.get_one(id='fraction_dry_weight')
self.assertIsInstance(cell_cycle_length, wc_lang.core.Parameter)
self.assertIsInstance(fraction_dry_weight, wc_lang.core.Parameter)

errors = obj_model.Validator().run(self.model, get_related=True)
self.assertEqual(errors, None, msg=wc_utils.util.string.indent_forest(errors))
111 changes: 46 additions & 65 deletions tests/prokaryote/test_prot_degradation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,82 +14,63 @@

class ProteinDegradationSubmodelGeneratorTestCase(unittest.TestCase):

def test(self):
"""
kb = wc_kb.io.Reader().run('tests/fixtures/core.xlsx',
'tests/fixtures/seq.fna', strict=False)
@classmethod
def setUpClass(cls):
cls.kb = wc_kb.io.Reader().run('tests/fixtures/min_kb.xlsx',
'tests/fixtures/min_kb_seq.fna',
strict=False)

model = prokaryote.ProkaryoteModelGenerator(
knowledge_base = kb,
component_generators = [prokaryote.InitalizeModel,
prokaryote.ProteinDegradationSubmodelGenerator]).run()
"""
cls.model = prokaryote.ProkaryoteModelGenerator(
knowledge_base = cls.kb,
component_generators=[prokaryote.InitalizeModel,
prokaryote.ProteinDegradationSubmodelGenerator],
options = {'component': {
'ProteinDegradationSubmodelGenerator': {
'rate_dynamics': 'phenomenological'}}}).run()

kb = wc_kb_gen.random.RandomKbGenerator(options={
'component': {
'GenomeGenerator': {
'mean_num_genes': 20,
'mean_gene_len': 50,
'num_ncRNA': 0,
'translation_table': 4,
'mean_copy_number': 100,
'mean_half_life': 100
},
'PropertiesGenerator': {
'mean_cell_cycle_length': 100,
},
},
}).run()
cls.model_mechanistic = prokaryote.ProkaryoteModelGenerator(
knowledge_base = cls.kb,
component_generators=[prokaryote.InitalizeModel,
prokaryote.ProteinDegradationSubmodelGenerator],
options = {'component': {
'ProteinDegradationSubmodelGenerator': {
'rate_dynamics': 'mechanistic'}}}).run()

model = prokaryote.ProkaryoteModelGenerator(
knowledge_base=kb,
component_generators=[prokaryote.InitalizeModel,
prokaryote.ProteinDegradationSubmodelGenerator]).run()
@classmethod
def tearDownClass(cls):
pass

cell = kb.cell
prots = cell.species_types.get(__type=wc_kb.prokaryote_schema.ProteinSpeciesType)
def test_species(self):
model = self.model
kb = self.kb
cell = self.kb.cell
cytosol = model.compartments.get_one(id='c')
submodel = model.submodels.get_one(id='protein_degradation')

# check compartments generated
cytosol = model.compartments.get_one(id='c')
self.assertEqual(cytosol.name, 'Cytosol')
# check reactions generated
self.assertEqual(len(submodel.reactions),
len(cell.species_types.get(__type=wc_kb.prokaryote_schema.ProteinSpeciesType)))

# check species types and species generated
atp = model.species_types.get_one(id='atp').species.get_one(compartment=cytosol)
adp = model.species_types.get_one(id='adp').species.get_one(compartment=cytosol)
pi = model.species_types.get_one(id='pi').species.get_one(compartment=cytosol)
h2o = model.species_types.get_one(id='h2o').species.get_one(compartment=cytosol)

# check species types and species generated
for species in kb.cell.species_types.get(__type=wc_kb.prokaryote_schema.ProteinSpeciesType):
model_species = model.species_types.get_one(id=species.id)
model_species_cytosol = model_species.species.get_one(
compartment=cytosol)
model_species_cytosol = model_species.species.get_one(compartment=cytosol)
self.assertIsInstance(model_species, wc_lang.SpeciesType)
self.assertIsInstance(model_species_cytosol, wc_lang.Species)

# check reactions generated
self.assertEqual(len(submodel.reactions), len(prots))
atp = model.species_types.get_one(
id='atp').species.get_one(compartment=cytosol)
adp = model.species_types.get_one(
id='adp').species.get_one(compartment=cytosol)
pi = model.species_types.get_one(
id='pi').species.get_one(compartment=cytosol)
h2o = model.species_types.get_one(
id='h2o').species.get_one(compartment=cytosol)
self.assertEqual(submodel.reactions[0].participants.get_one(
species=atp).coefficient, -1)
self.assertEqual(submodel.reactions[0].participants.get_one(
species=adp).coefficient, 1)
self.assertEqual(submodel.reactions[0].participants.get_one(
species=pi).coefficient, 1)
self.assertEqual(
+ submodel.reactions[0].participants.get_one(species=h2o).coefficient,
-(prots[0].get_len()-1))
for rxn in submodel.reactions:
self.assertEqual(rxn.participants.get_one(species=atp).coefficient, -1)
self.assertEqual(rxn.participants.get_one(species=adp).coefficient, 1)
self.assertEqual(rxn.participants.get_one(species=pi).coefficient, 1)

aa_species = model.species_types.get_one(
id='cys').species.get_one(compartment=cytosol)
self.assertEqual(submodel.reactions[0].participants.get_one(
species=aa_species).coefficient, prots[0].get_seq().count('C'))
# TODO: add coutn of AAs
#self.assertEqual(submodel.reactions[0].participants.get_one(
# species=aa_species).coefficient, prots[0].get_seq().count('C'))

for prot, rxn in zip(prots, submodel.reactions):
self.assertEqual(len(rxn.rate_laws), 1)
rl = rxn.rate_laws[0]
self.assertEqual(rl.direction.name, 'forward')
self.assertIsInstance(rl.k_m, float)
self.assertIsInstance(rl.k_cat, float)
def test_rate_laws(self):
pass #TODO
Loading

0 comments on commit cf2ab83

Please sign in to comment.