Skip to content

Commit

Permalink
Added division test to experiment.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrus-bio committed Sep 27, 2023
1 parent 3734247 commit 48bc9c6
Show file tree
Hide file tree
Showing 4 changed files with 845 additions and 215 deletions.
1 change: 1 addition & 0 deletions data/met_division_test_state.json

Large diffs are not rendered by default.

62 changes: 23 additions & 39 deletions ecoli/experiments/metabolism_redux_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ def run_ecoli_with_metabolism_redux(
# disables growth rate control
def run_ecoli_with_metabolism_redux_classic(
filename='metabolism_redux_classic',
total_time=2000,
total_time=10,
divide=True,
initial_state_file='wcecoli_t0',
initial_state_file='met_division_test_state',
progress_bar=True,
log_updates=False,
emitter='timeseries',
name='metabolism-redux-classic',
raw_output=False,
save=False,
save=True,
):
# filename = 'default'
sim = EcoliSim.from_file(CONFIG_DIR_PATH + filename + '.json')
Expand All @@ -73,7 +73,9 @@ def run_ecoli_with_metabolism_redux_classic(
sim.initial_state = get_state_from_file(path=f'data/{initial_state_file}.json')
sim.raw_output = raw_output
sim.save = save
sim.save_times = [500, 1000, 1500, 2000]
sim.save_times = [10]
sim.initial_state = get_state_from_file(path=f'data/{initial_state_file}.json')


# # simplify working with uptake
# sim.initial_state['environment']['exchange_data']['constrained'] = {}
Expand All @@ -83,8 +85,14 @@ def run_ecoli_with_metabolism_redux_classic(
# sim.initial_state['environment']['exchange_data']['unconstrained'].remove('GLC[p]')
# sim.initial_state['environment']['exchange_data']['unconstrained'].add('FRU[p]')

# this means that sims will not create conflicting random indices
if initial_state_file == 'wcecoli_t0':
sim.seed += 1
else:
sim.seed += int(sim.initial_state['agents']['0']['global_time'])

sim.build_ecoli()

sim.run()

query = []
Expand Down Expand Up @@ -112,13 +120,6 @@ def test_ecoli_with_metabolism_redux(
# run simulation and add asserts to output
sim.run()

# assert 'ecoli-metabolism-gradient-descent' in sim.ecoli['processes']
# assert 'ecoli-metabolism' not in sim.ecoli['processes']
# assert 'ecoli-metabolism-gradient-descent' in sim.ecoli['topology']
# assert 'ecoli-metabolism' not in sim.ecoli['topology']



@pytest.mark.slow
def test_ecoli_with_metabolism_redux_div(
filename='metabolism_redux',
Expand All @@ -134,12 +135,7 @@ def test_ecoli_with_metabolism_redux_div(
sim.build_ecoli()

sim.run()

# # assert that the processes were swapped
# assert 'ecoli-metabolism-gradient-descent' in sim.processes
# assert 'ecoli-metabolism' not in sim.processes
# assert 'ecoli-metabolism-gradient-descent' in sim.processes
# assert 'ecoli-metabolism' not in sim.processes


query = []
agents = sim.query()['agents'].keys()
Expand Down Expand Up @@ -173,44 +169,32 @@ def test_ecoli_with_metabolism_classic(
# run simulation and add asserts to output
sim.run()

# assert 'ecoli-metabolism-gradient-descent' in sim.ecoli['processes']
# assert 'ecoli-metabolism' not in sim.ecoli['processes']
# assert 'ecoli-metabolism-gradient-descent' in sim.ecoli['topology']
# assert 'ecoli-metabolism' not in sim.ecoli['topology']


@pytest.mark.slow
def test_ecoli_with_metabolism_classic_div(
filename='metabolism_redux_classic',
total_time=4,
total_time=10,
divide=True,
emitter='timeseries',
initial_state_file='met_division_test_state',
):
# TODO (Cyrus) - Add test that affirms structure of output query.
sim = EcoliSim.from_file(CONFIG_DIR_PATH + filename + '.json')
sim.total_time = total_time
sim.initial_state = get_state_from_file(path=f'data/{initial_state_file}.json')

sim.divide = divide
sim.emitter = emitter
sim.build_ecoli()

sim.run()
# this means that sims will not create conflicting random indices
sim.seed += int(sim.initial_state['agents']['0']['global_time'])

# # assert that the processes were swapped
# assert 'ecoli-metabolism-gradient-descent' in sim.processes
# assert 'ecoli-metabolism' not in sim.processes
# assert 'ecoli-metabolism-gradient-descent' in sim.processes
# assert 'ecoli-metabolism' not in sim.processes
sim.build_ecoli()

query = []
agents = sim.query()['agents'].keys()
for agent in agents:
query.extend([('agents', agent, 'listeners', 'fba_results'),
('agents', agent, 'listeners', 'mass'),
('agents', agent, 'bulk')])
output = sim.query(query)
sim.run()

# test that water is being used (model is running)
assert sum(output['agents'][agent]['listeners']['fba_results']['estimated_exchange_dmdt']['WATER[p]']) != 0
# assert division occured
assert len(sim.query()['agents']) == 3, "Cell did not divide in metabolism division test"

def run_ecoli_with_default_metabolism(
filename='default',
Expand Down
Loading

0 comments on commit 48bc9c6

Please sign in to comment.