Exemple #1
0
def test_flagella_metabolism(seed=1):
    random.seed(seed)
    np.random.seed(seed)

    # make the compartment and state
    compartment = FlagellaExpressionMetabolism({'divide': False})
    initial_state = get_flagella_metabolism_initial_state()
    name = compartment.name
    # run simulation
    settings = {
        'total_time': 60,
        'emit_step': COMPARTMENT_TIMESTEP,
        'initial_state': initial_state,
    }
    timeseries = simulate_compartment_in_experiment(compartment, settings)

    # remove non-numerical data for timeseries comparison, convert to path_timeseries
    del timeseries['chromosome']
    del timeseries['ribosomes']
    del timeseries['dimensions']
    del timeseries['boundary']['divide']
    del timeseries['fields']
    del timeseries['null']
    path_timeseries = path_timeseries_from_embedded_timeseries(timeseries)

    # # save reference timeseries
    # out_dir = os.path.join(COMPARTMENT_OUT_DIR, name)
    # if not os.path.exists(out_dir):
    #     os.makedirs(out_dir)
    # save_flat_timeseries(path_timeseries, out_dir)

    reference = load_timeseries(
        os.path.join(REFERENCE_DATA_DIR, name + '.csv'))
    assert_timeseries_close(path_timeseries, reference)
def test_experiment(seed=1):
    random.seed(seed)
    np.random.seed(seed)
    if not os.path.exists(OUT_DIR):
        os.makedirs(OUT_DIR)
    data, _ = run_experiment(
        start_locations=[[0.3, 0.3], [0.5, 0.5]],
        growth_rate=0.001,
    )
    path_ts = path_timeseries_from_data(data)
    filtered = {
        path: timeseries
        for path, timeseries in path_ts.items()
        # Angles are computed randomly by multibody physics
        if path[-1] != 'angle'
    }
    processed_for_csv = process_path_timeseries_for_csv(filtered)
    save_flat_timeseries(processed_for_csv, OUT_DIR, 'test_output.csv')
    test_output = load_timeseries(os.path.join(OUT_DIR, 'test_output.csv'))
    expected = load_timeseries(os.path.join(REFERENCE_DATA_DIR, NAME + '.csv'))
    assert_timeseries_close(
        test_output,
        expected,
        default_tolerance=(1 - 1e-5),
    )
Exemple #3
0
def test_transport_metabolism_experiment(seed=1):
    random.seed(seed)
    np.random.seed(seed)
    experiment_name = 'transport_metabolism_experiment'
    agent_config = agents_library['transport_metabolism']
    agents_config = [agent_config]
    environment_config = environments_library['shallow_iAF1260b']
    experiment_settings = get_experiment_settings(total_time=60)

    # simulate
    data = run_lattice_experiment(
        agents_config=agents_config,
        environment_config=environment_config,
        # initial_state=initial_state,
        # initial_agent_state=initial_agent_state,
        experiment_settings=experiment_settings,
    )
    path_ts = path_timeseries_from_data(data)
    del path_ts[('agents', 'transport_metabolism', 'boundary', 'divide')]  # these contain 'False'

    # save timeseries as csv
    processed_for_csv = process_path_timeseries_for_csv(path_ts)
    make_dir(OUT_DIR)
    save_flat_timeseries(
        processed_for_csv,
        OUT_DIR,
        experiment_name + '.csv')

    # compare timeseries to reference
    test_output = load_timeseries(os.path.join(OUT_DIR, experiment_name + '.csv'))
    expected = load_timeseries(os.path.join(REFERENCE_DATA_DIR, experiment_name + '.csv'))
    assert_timeseries_close(
        test_output, expected,
        default_tolerance=(1 - 1e-5),
    )
def metabolism_similar_to_reference():
    config = get_iAF1260b_config()
    metabolism = Metabolism(config)
    timeseries = run_metabolism(metabolism, reference_sim_settings)

    reference = load_timeseries(os.path.join(REFERENCE_DATA_DIR,
                                             NAME + '.csv'))
    assert_timeseries_close(timeseries, reference)
def test_convenience_kinetics_correlated_to_reference():
    timeseries = test_convenience_kinetics()
    flattened = flatten_timeseries(timeseries)
    reference_timeseries = load_timeseries(
        os.path.join(REFERENCE_DATA_DIR, NAME + '.csv'))
    assert_timeseries_close(flattened,
                            reference_timeseries,
                            tolerances={
                                'internal_pyr_c': 9,
                                'internal_pep_c': 9,
                                'internal_g6p_c': 9,
                            })
def test_antibiotics_composite_similar_to_reference():
    timeseries = run_antibiotics_composite()
    flattened = flatten_timeseries(timeseries)
    reference = load_timeseries(
        os.path.join(REFERENCE_DATA_DIR, Antibiotics.name + '.csv'))
    assert_timeseries_close(flattened,
                            reference,
                            tolerances={
                                'cell_counts_AcrAB-TolC': 99999,
                                'cell_counts_antibiotic': 999,
                                'cell_counts_AcrAB-TolC_RNA': 9,
                                'cell_counts_porin': 9999,
                            })
def test_antibiotic_transport():
    timeseries = run_antibiotic_transport()
    flattened = flatten_timeseries(timeseries)
    reference = load_timeseries(os.path.join(
        REFERENCE_DATA_DIR, AntibioticTransport.name + '.csv'))
    assert_timeseries_close(flattened, reference)
Exemple #8
0
def test_convenience_kinetics_correlated_to_reference():
    timeseries = test_convenience_kinetics()
    flattened = flatten_timeseries(timeseries)
    reference_timeseries = load_timeseries(
        os.path.join(REFERENCE_DATA_DIR, NAME + '.csv'))
    assert_timeseries_close(flattened, reference_timeseries)