Skip to content

Commit

Permalink
reorganizing dynamic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
balazs1987 committed Dec 11, 2018
1 parent a6bd7d6 commit c85ef60
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 112 deletions.
128 changes: 29 additions & 99 deletions tests/prokaryote/dynamics/test_dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,108 +19,48 @@
import shutil
import os

class PhenomenologicalTestCaseTranscription(unittest.TestCase):
class PhenomenologicalTestCase(unittest.TestCase):

@classmethod
def setUpClass(cls):
cls.dir = tempfile.mkdtemp()

cls.kb = wc_kb.io.Reader().run('tests/fixtures/min_model_kb.xlsx',
'tests/fixtures/min_model_kb_seq.fna',
strict=False)

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

@classmethod
def tearDownClass(cls):
shutil.rmtree(cls.dir)

def test_exp_growth_transcription(self):
checkpoint_period = 10
end_time = 100

simulation = Simulation(self.model)
results = simulation.run(end_time, self.dir, checkpoint_period)
self.assertIsInstance(results, tuple)

num_events = results[0]
run_results_dir = results[1]
run_results = RunResults(run_results_dir)
df = run_results.get('populations')

# Collect RNA species IDs
cytosol = self.model.compartments.get_one(id='c')
rna_ids=[]
for rna in self.model.species_types.get(type = wc_lang.SpeciesTypeType.rna):
rna_ids.append(rna.species.get_one(compartment=cytosol).id)

avg_init_rna_cn = np.mean(df.loc[0.0,rna_ids].values)
avg_final_rna_cn = np.mean(df.loc[100.0,rna_ids].values)

print(simulation.provide_event_counts())
print('\n INIT:', avg_init_rna_cn)
print('\n FINAL:', avg_final_rna_cn)

# Check if RNA content has doubled after CC - 15% tolerance
self.assertTrue(abs(2*avg_init_rna_cn-avg_final_rna_cn) < avg_init_rna_cn*0.2)

class PhenomenologicalTestCaseTranscriptionTranslation(unittest.TestCase):
def test_growth_transcription(self):

@classmethod
def setUpClass(cls):
cls.dir = tempfile.mkdtemp()

cls.kb = wc_kb.io.Reader().run('tests/fixtures/min_model_kb.xlsx',
# Construct model
self.kb = wc_kb.io.Reader().run('tests/fixtures/min_model_kb.xlsx',
'tests/fixtures/min_model_kb_seq.fna',
strict=False)

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

@classmethod
def tearDownClass(cls):
shutil.rmtree(cls.dir)

@unittest.skip('disable while testing')
def test_exp_growth_transcription(self):
# Simulate model
checkpoint_period = 10
end_time = 100

simulation = Simulation(self.model)
results = simulation.run(end_time, self.dir, checkpoint_period)
self.assertIsInstance(results, tuple)

# Check results
num_events = results[0]
run_results_dir = results[1]
run_results = RunResults(run_results_dir)
df = run_results.get('populations')

# Collect RNA species IDs
cytosol = self.model.compartments.get_one(id='c')
rna_ids=[]
for rna in self.model.species_types.get(type = wc_lang.SpeciesTypeType.rna):
Expand All @@ -129,36 +69,31 @@ def test_exp_growth_transcription(self):
avg_init_rna_cn = np.mean(df.loc[0.0,rna_ids].values)
avg_final_rna_cn = np.mean(df.loc[100.0,rna_ids].values)

# Collect protein species IDs
protein_ids=[]
for protein in self.model.species_types.get(type = wc_lang.SpeciesTypeType.protein):
protein_ids.append(protein.species.get_one(compartment=cytosol).id)

avg_init_protein_cn = np.mean(df.loc[0.0, protein_ids].values)
avg_final_protein_cn = np.mean(df.loc[100.0, protein_ids].values)

print(simulation.provide_event_counts())
print('\n INIT:', avg_init_rna_cn)
print('\n FINAL:', avg_final_rna_cn)
print('\n INIT:', avg_init_protein_cn)
print('\n FINAL:', avg_final_protein_cn)
print('\n INIT AVG RNA COPY NUMBERS:', avg_init_rna_cn)
print('\n FINAL AVG RNA COPY NUMBERS:', avg_final_rna_cn)

# Check if RNA, protein content has doubled after CC - 15% tolerance
self.assertTrue(abs(2*avg_init_rna_cn-avg_final_rna_cn) < avg_init_rna_cn*0.15)
self.assertTrue(abs(2*avg_init_protein_cn-avg_final_protein_cn) < avg_init_protein_cn*0.15)

class MechanisticDynamicsTestCase(unittest.TestCase):

@classmethod
def setUpClass(cls):
cls.dir = tempfile.mkdtemp()

cls.kb = wc_kb.io.Reader().run('tests/fixtures/min_model_kb.xlsx',
@classmethod
def tearDownClass(cls):
shutil.rmtree(cls.dir)

def test_growth_transcription(self):

# Construct model
self.kb = wc_kb.io.Reader().run('tests/fixtures/min_model_kb.xlsx',
'tests/fixtures/min_model_kb_seq.fna',
strict=False)

cls.model = prokaryote.ProkaryoteModelGenerator(
knowledge_base = cls.kb,
self.model = prokaryote.ProkaryoteModelGenerator(
knowledge_base = self.kb,
component_generators=[prokaryote.InitalizeModel,
prokaryote.TranscriptionSubmodelGenerator,
prokaryote.RnaDegradationSubmodelGenerator,
Expand All @@ -169,34 +104,29 @@ def setUpClass(cls):
'RnaDegradationSubmodelGenerator': {
'rate_dynamics': 'mechanistic'}}}).run()

@classmethod
def tearDownClass(cls):
shutil.rmtree(cls.dir)

@unittest.skip('disable while testing')
def test_exponential_growth(self):
# Simulate model
checkpoint_period = 10
end_time = 100

simulation = Simulation(self.model)
results = simulation.run(end_time, self.dir, checkpoint_period)
self.assertIsInstance(results, tuple)

# Check results
num_events = results[0]
run_results_dir = results[1]

run_results = RunResults(run_results_dir)
rna_ids=[]
df = run_results.get('populations')

cytosol = self.model.compartments.get_one(id='c')
rna_ids=[]
for rna in self.model.species_types.get(type = wc_lang.SpeciesTypeType.rna):
rna_ids.append(rna.species[0].id)
rna_ids.append(rna.species.get_one(compartment=cytosol).id)

avg_init_rna_cn = np.mean(df.loc[0.0,rna_ids].values)
avg_final_rna_cn = np.mean(df.loc[100.0,rna_ids].values)

print(simulation.provide_event_counts())
print('\n INIT:', avg_init_rna_cn)
print('\n FINAL:', avg_final_rna_cn)
print('\n INIT AVG RNA COPY NUMBERS:', avg_init_rna_cn)
print('\n FINAL AVG RNA COPY NUMBERS:', avg_final_rna_cn)

# Check if RNA content has doubled after CC - 15% tolerance
self.assertTrue(abs(2*avg_init_rna_cn-avg_final_rna_cn) < avg_init_rna_cn*0.2)
self.assertTrue(abs(2*avg_init_rna_cn-avg_final_rna_cn) < avg_init_rna_cn*0.15)
26 changes: 13 additions & 13 deletions wc_model_gen/prokaryote/metabolism.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def calc_H_trasfer_rate(self):
# Each transfer reactions transports 10 TPs, thus the final /10
cc_length = self.knowledge_base.cell.properties.get_one(id='cell_cycle_length').value
h_transfer_rate = n_h_transfer/cc_length/self.reaction_scale
#print('h_transfer_rate: ', h_transfer_rate)
print('h_transfer_rate: ', h_transfer_rate)
return h_transfer_rate

def calc_MPP_trasfer_rate(self):
Expand All @@ -221,7 +221,7 @@ def calc_MPP_trasfer_rate(self):
cc_length = self.knowledge_base.cell.properties.get_one(id='cell_cycle_length').value
mpp_transfer_rate = (tpp_in_cell/cc_length/self.reaction_scale)

#print('mpp_transfer_rate: ', mpp_transfer_rate)
print('mpp_transfer_rate: ', mpp_transfer_rate)
return mpp_transfer_rate

def calc_AA_trasfer_rate(self):
Expand All @@ -237,7 +237,7 @@ def calc_AA_trasfer_rate(self):
cc_length = self.knowledge_base.cell.properties.get_one(id='cell_cycle_length').value
aa_transfer_rate = (aa_in_cell/cc_length/self.reaction_scale)

#print('aa_transfer_rate: ', aa_transfer_rate)
print('aa_transfer_rate: ', aa_transfer_rate)
return aa_transfer_rate

def calc_MPP_conversion_rate(self):
Expand All @@ -254,7 +254,7 @@ def calc_MPP_conversion_rate(self):
cc_length = self.knowledge_base.cell.properties.get_one(id='cell_cycle_length').value
mpp_conversion_rate = n_mpp_to_convert/cc_length/self.reaction_scale

#print('mpp_conversion_rate: ', mpp_conversion_rate)
print('mpp_conversion_rate: ', mpp_conversion_rate)
return mpp_conversion_rate # This is only the rate from degradation, needs to add new mpp conversion!

def calc_TPP_per_rna(self):
Expand All @@ -273,7 +273,7 @@ def calc_TPP_per_rna(self):

avg_tpp_per_rna = n_tpp/4/len(rnas_kb)

#print('avg_tpp_per_rna: ', avg_tpp_per_rna)
print('avg_tpp_per_rna: ', avg_tpp_per_rna)
return avg_tpp_per_rna

def calc_AA_per_prot(self):
Expand All @@ -294,7 +294,7 @@ def calc_AA_per_prot(self):

avg_aa_per_prot = n_aa/(n_trnas*len(proteins_kb))

#print('avg_aa_per_prot: ', avg_aa_per_prot)
print('avg_aa_per_prot: ', avg_aa_per_prot)
return avg_aa_per_prot

def calc_H_per_transcript(self):
Expand All @@ -309,7 +309,7 @@ def calc_H_per_transcript(self):

avg_H_per_transcription = np.mean(h_per_transcription)

#print('avg_H_per_transcription: ', avg_H_per_transcription)
print('avg_H_per_transcription: ', avg_H_per_transcription)
return avg_H_per_transcription

def calc_GTP_per_translate(self):
Expand All @@ -324,7 +324,7 @@ def calc_GTP_per_translate(self):

avg_gtp_per_translate = np.mean(gtp_per_translation)

#print('avg_gtp_per_translate: ', avg_gtp_per_translate)
print('avg_gtp_per_translate: ', avg_gtp_per_translate)
return avg_gtp_per_translate

def calc_rna_degrad_rxns(self):
Expand All @@ -347,7 +347,7 @@ def calc_rna_degrad_rxns(self):
rna_copy_num = round(conc * volume * Avogadro)
n_rna_deg_rxns += ((cc_length / half_life) * rna_copy_num)

#print('n_rna_deg_rxns: ', n_rna_deg_rxns)
print('n_rna_deg_rxns: ', n_rna_deg_rxns)
return n_rna_deg_rxns

def calc_prot_degrad_rxns(self):
Expand All @@ -373,7 +373,7 @@ def calc_prot_degrad_rxns(self):
n_prot_deg_rxns += ((cc_length / half_life) * prot_copy_num)

#n_prot_deg_rxns = round(n_prot_deg_rxns)
#print('n_prot_deg_rxns: ', n_prot_deg_rxns)
print('n_prot_deg_rxns: ', n_prot_deg_rxns)
return n_prot_deg_rxns

def calc_rna_copy_num(self):
Expand All @@ -390,7 +390,7 @@ def calc_rna_copy_num(self):

avg_rna_copy_num = np.mean(rna_copy_num)

#print('avg_rna_copy_num: ', avg_rna_copy_num)
print('avg_rna_copy_num: ', avg_rna_copy_num)
return avg_rna_copy_num

def calc_prot_copy_num(self):
Expand All @@ -408,7 +408,7 @@ def calc_prot_copy_num(self):

avg_prot_copy_num = np.mean(prot_copy_num)

#print('avg_prot_copy_num: ', avg_prot_copy_num)
print('avg_prot_copy_num: ', avg_prot_copy_num)
return avg_prot_copy_num

def calc_GTP_corr_rate(self):
Expand All @@ -423,5 +423,5 @@ def calc_GTP_corr_rate(self):

gtp_corr_rate = (total_translation_gtp/cc_length/self.reaction_scale)

#print('gtp_corr_rate: ', gtp_corr_rate)
print('gtp_corr_rate: ', gtp_corr_rate)
return gtp_corr_rate

0 comments on commit c85ef60

Please sign in to comment.