Beispiel #1
0
def test_parameter_sampling_linear_pathway():
    this_model = build_linear_pathway_model()

    this_model.prepare(mca=True)
    this_model.compile_mca(sim_type=QSSA)

    flux_dict = {'E1': 1.0, 'E2': 1.0, 'E3': 1.0}
    concentration_dict = {'A': 10.0, 'B': 5.0, 'C': 1.0, 'D': 0.05}

    parameters = SimpleParameterSampler.Parameters(n_samples=10)
    sampler = SimpleParameterSampler(parameters)

    parameter_population_A = sampler.sample(this_model,
                                            flux_dict,
                                            concentration_dict,
                                            seed=10)

    parameter_population_B = sampler.sample(this_model,
                                            flux_dict,
                                            concentration_dict,
                                            seed=10)

    parameter_population_C = sampler.sample(this_model,
                                            flux_dict,
                                            concentration_dict,
                                            seed=20)

    assert (parameter_population_A == parameter_population_B)
    assert (not (parameter_population_B == parameter_population_C))
Beispiel #2
0
def test_oracle_ode():

    # Initialize parameter sampler
    sampling_parameters = SimpleParameterSampler.Parameters(n_samples=1)
    sampler = SimpleParameterSampler(sampling_parameters)

    # Sample the model
    parameter_population = sampler.sample(kmodel, flux_dict,
                                          concentration_dict)

    kmodel.compile_ode(sim_type=QSSA)
    kmodel.initial_conditions = TabDict([
        (k, v) for k, v in concentration_dict.items()
    ])

    solutions = []
    for parameters in parameter_population:
        kmodel.parameters = parameters
        this_sol_qssa = kmodel.solve_ode(np.linspace(0.0, 10.0, 1000),
                                         solver_type='cvode')
        solutions.append(this_sol_qssa)

    this_sol_qssa.plot('test.html')

    solpop = ODESolutionPopulation(solutions)
Beispiel #3
0
def test_oracle_parameter_sampling():

    # Initialize parameter sampler
    sampling_parameters = SimpleParameterSampler.Parameters(n_samples=100)
    sampler = SimpleParameterSampler(sampling_parameters)

    # Sample the model
    parameter_population = sampler.sample(kmodel, flux_dict,
                                          concentration_dict)
Beispiel #4
0
def test_oracle_mca():

    # Initialize parameter sampler
    sampling_parameters = SimpleParameterSampler.Parameters(n_samples=1)
    sampler = SimpleParameterSampler(sampling_parameters)

    # Sample the model
    parameter_population = sampler.sample(kmodel, flux_dict,
                                          concentration_dict)
    """
    Calculate control coefficients 
    """
    flux_control_coeff = kmodel.flux_control_fun(flux_dict, concentration_dict,
                                                 parameter_population)

    concentration_control_coeff = kmodel.concentration_control_fun(
        flux_dict, concentration_dict, parameter_population)
Beispiel #5
0
    'E2': parameters_2,
    'E3': parameters_3
})

this_model.prepare(mca=True)
#this_model.compile_mca()

this_model.compile_jacobian(type=SYMBOLIC, sim_type=QSSA)

flux_dict = {'E1': 1.0, 'E2': 1.0, 'E3': 1.0}
concentration_dict = {'A': 3.0, 'B': 2.0, 'C': 1.0, 'D': 0.5}

parameters = SimpleParameterSampler.Parameters(n_samples=10)
sampler = SimpleParameterSampler(parameters)

parameter_population = sampler.sample(this_model, flux_dict,
                                      concentration_dict)

#this_model.compile_ode(sim_type = QSSA)

# TODO can change this back to this_model.initial_conditions.A = 3.0 once
# tabdict is fixed
this_model.initial_conditions['A'] = 3.0
this_model.initial_conditions['B'] = 2.0
this_model.initial_conditions['C'] = 3.0
this_model.initial_conditions['D'] = 0.5

solutions = []
for parameters in parameter_population:
    # TODO system is too small for sparse eig handle properly
    this_model.parameters = parameters
    this_sol_qssa = this_model.solve_ode(np.linspace(0.0, 50.0, 500),
Beispiel #6
0
    flux_control_coeff_0 = kmodel.flux_control_fun(fluxes, concentrations,
                                                   model_parameters._data)

    # Choose a particular reaction we want to analyse
    df = flux_control_coeff_0.slice_by('flux', 'ENO')
    # Select only some of the Vmax's
    df = df[df.index.isin(outputs_to_analyse)]
    return df


# Initialize parameter sampler
sampling_parameters = SimpleParameterSampler.Parameters(n_samples=200)
sampler = SimpleParameterSampler(sampling_parameters)

# Sample the model (A matrix)
parameter_population = sampler.sample(kmodel, fluxes, concentrations)
parameter_population = ParameterValuePopulation(parameter_population, kmodel)

# Construct B,C matrices given parameter_population and parameters_to_resample
parameters_to_resample = [[
    kmodel.parameters.km_substrate_ENO,
], [
    kmodel.parameters.km_product_ENO,
], [
    kmodel.parameters.km_substrate_PGM,
], [
    kmodel.parameters.km_product_PGM,
], [
    kmodel.parameters.km_substrate1_PGK,
], [
    kmodel.parameters.km_substrate2_PGK,
Beispiel #7
0
    # Test weather the model stoichiometry is consistent with the steady-state
    dxdt = S.dot(fluxes)
    if np.any(abs(dxdt) > 1e-9*flux_scaling_factor):
        raise RuntimeError('dxdt for idx {} not equal to 0'
                           .format(np.where(abs(dxdt) > 1e-9*flux_scaling_factor)))

    indep_reactants = [kmodel.reactants.iloc(i)[0] for i in kmodel.independent_variables_ix]
    dxdt_red = kmodel.reduced_stoichiometry.todense().dot(fluxes)
    if np.any(abs(dxdt_red) > 1e-9*flux_scaling_factor):
        raise RuntimeError('dxdt reduced for idx {} not equal to 0'
                           .format(np.where(abs(dxdt_red) > 1e-9*flux_scaling_factor)))

    # Generate sampels and fetch slowest and fastest eigenvalues
    params, lamda_max, lamda_min = sampler.sample(kmodel, fluxes, concentrations,
                                                  only_stable=True,
                                                  min_max_eigenvalues=True)
    lambda_max_all.append(pd.DataFrame(lamda_max))
    lambda_min_all.append(pd.DataFrame(lamda_min))

    params_population = ParameterValuePopulation(params, kmodel)
    params_population.save(path_for_output.format(i))

    # Test if the resulting sets are NV=0
    fluxes_1 = fluxfun(concentrations, parameters=params_population['0'])
    fluxes_1 = pd.Series(fluxes_1)
    dxdt = S.dot(fluxes_1[kmodel.reactions])
    if np.any(abs(dxdt) > 1e-9*flux_scaling_factor):
        raise RuntimeError('dxdt for idx {} not equal to 0'
                           .format(np.where(abs(dxdt) > 1e-9*flux_scaling_factor)))