示例#1
0
def test_run_simulation():
    run_simulation(model)
    simulated_value = np.load(
        os.path.join(
            model.path,
            "simulation_data",
            "simulations_original.npy",
        ))
    assert np.isfinite(simulated_value).all()
示例#2
0
def test_example_plot():
    assert run_simulation(model, viz_type="original") is None
    res = np.load(
        os.path.join(model.path, "simulation_data",
                     "simulations_original.npy"))

    fig = plt.figure(figsize=(9, 9))
    plt.rcParams["font.family"] = "Arial"
    plt.rcParams["font.size"] = 18
    plt.rcParams["axes.linewidth"] = 2
    plt.rcParams["lines.linewidth"] = 3
    plt.rcParams["lines.markersize"] = 16
    plt.subplots_adjust(wspace=0, hspace=0.3)

    for i, obs_name in enumerate(model.observables):
        plt.subplot(2, 1, i + 1)
        for j, (color,
                label) in enumerate(zip(["k", "r"], ["TNFα", "TNFα + DCF"])):
            plt.plot(model.problem.t, res[i, :, j], color=color, label=label)
        plt.title(f"{obs_name}".replace("_", " "))
        plt.xticks([0, 50, 100, 150, 200])
        if i == 0:
            plt.yticks([0, 0.05, 0.10, 0.15])
            plt.legend(loc="upper left", frameon=False)
    fig.text(0.5, 0.05, "time [min]", ha="center")
    fig.text(0.0,
             0.5,
             "concentration [a.u.]",
             va="center",
             rotation="vertical")
    plt.show()
示例#3
0
def test_example_plot():
    assert run_simulation(model) is None
    res = np.load(
        os.path.join(model.path, "simulation_data",
                     "simulations_original.npy"))

    plt.figure(figsize=(8, 8))
    plt.rcParams["font.family"] = "Arial"
    plt.rcParams["xtick.direction"] = "in"
    plt.rcParams["ytick.direction"] = "in"
    plt.rcParams["font.size"] = 18
    plt.rcParams["lines.linewidth"] = 4
    plt.rcParams["lines.markersize"] = 16

    plt.subplots_adjust(wspace=0.25, hspace=0.3)

    for i, obs_name in enumerate(model.observables):
        plt.subplot(2, 2, i + 1)
        for j, color in enumerate([
                "darkblue", "cornflowerblue", "yellowgreen", "goldenrod",
                "brown"
        ]):
            plt.plot(model.problem.t, res[i, :, j], color=color)
        plt.xlim(0, 480)
        plt.xticks([0, 120, 240, 360, 480], fontweight="bold")
        plt.ylim(0, 1)
        plt.yticks([0, 0.2, 0.4, 0.6, 0.8, 1.0], fontweight="bold")
        plt.title(f"{obs_name}", fontweight="bold")
        if i % 2 == 0:
            plt.ylabel("Intensity (A.U.)", fontweight="bold")
        if i > 1:
            plt.xlabel("                           time (min)",
                       fontweight="bold")
    plt.show()
示例#4
0
def test_external_optimizer():
    optimizer = ExternalOptimizer(model, differential_evolution)
    res = optimizer.run(
        model.problem.objective,
        model.problem.bounds,
        strategy="best2bin",
        maxiter=5,
        popsize=3,
        tol=1e-4,
        mutation=0.1,
        recombination=0.5,
        polish=False,
        workers=-1,
    )
    assert isinstance(res, OptimizeResult)
    optimizer.import_solution(res.x, x_id=0)
    n_iter: int = 0
    with open(
            os.path.join(model.path, "out", "0", "optimization.log"),
            mode="r",
            encoding="utf-8",
    ) as f:
        log_file = f.readlines()
    for message in log_file:
        if len(message.strip()) > 0:
            n_iter += 1
    for fname in [
            "count_num.npy",
            "generation.npy",
            f"fit_param{n_iter}.npy",
    ]:
        assert os.path.isfile(os.path.join(model.path, "out", "0", f"{fname}"))
    assert run_simulation(model, viz_type="0") is None
    assert os.path.isdir(os.path.join(model.path, "figure", "simulation", "0"))
示例#5
0
def test_run_simulation():
    with pytest.warns(RuntimeWarning) as record:
        run_simulation(model, viz_type="original")
    # check that the message matches
    assert record[-1].message.args[0] in [
        "Simulation failed. #original",
        "invalid value encountered in true_divide",
    ]
    run_simulation(model, viz_type="average", stdev=True)
    assert os.path.isfile(
        os.path.join(
            model.path,
            "simulation_data",
            "simulations_all.npy",
        ))
    for obs_name in model.observables:
        assert os.path.isfile(
            os.path.join(model.path, "figure", "simulation", "average",
                         f"{obs_name}.png"))
示例#6
0
def test_run_simulation():
    assert run_simulation(model) is None
    res = np.load(
        os.path.join(model.path, "simulation_data",
                     "simulations_original.npy"))

    plt.figure(figsize=(10, 10))
    plt.rcParams["font.size"] = 14
    plt.rcParams["font.family"] = "Arial"
    plt.rcParams["mathtext.fontset"] = "custom"
    plt.rcParams["mathtext.it"] = "Arial:italic"
    plt.rcParams["axes.linewidth"] = 2
    plt.rcParams["xtick.major.width"] = 2
    plt.rcParams["ytick.major.width"] = 2
    plt.rcParams["lines.linewidth"] = 2
    plt.subplots_adjust(wspace=0.3, hspace=0.8)

    yticks = {
        "Ski": [0, 1, 2],
        "Skil": [0, 1, 2, 3],
        "Dnmt3a": [0, 0.5, 1, 1.5],
        "Sox4": [0, 1, 2],
        "Jun": [0, 1, 2, 3],
        "Smad7": [0, 1, 2, 3],
        "Klf10": [0, 2, 4],
        "Bmp4": [0, 1, 2],
        "Cxcl15": [-1.5, -1, -0.5, 0, 0.5],
        "Dusp5": [-1.5, -1, -0.5, 0],
        "Tgfa": [-1.5, -1, -0.5, 0, 0.5],
        "Pdk4": [-3, -2, -1, 0],
    }

    for i, gene_name in enumerate(model.observables):
        plt.subplot(4, 3, i + 1)
        plt.gca().spines["right"].set_visible(False)
        plt.gca().spines["top"].set_visible(False)
        for j, color in enumerate(["brown", "royalblue", "darkgreen", "k"]):
            plt.plot(model.problem.t, res[i, :, j], color=color, linewidth=1.5)
            plt.title(fr"$\it{gene_name}$")
            plt.yticks(yticks[gene_name])
        if i >= 9:
            plt.xlabel("time (min)")
        plt.xticks([0, 200, 400, 600])
        if i % 3 == 0:
            plt.ylabel("gene expression(log2)")
    plt.show()
示例#7
0
def test_example_plot():
    assert run_simulation(model, viz_type="original") is None
    res = np.load(
        os.path.join(model.path, "simulation_data",
                     "simulations_original.npy"))

    plt.rcParams["font.size"] = 16
    fig, ax1 = plt.subplots(figsize=(6, 4))
    ax2 = ax1.twinx()

    ax1.plot(model.problem.t, res[model.observables.index("Cry_mRNA"), :], "c")
    ax1.plot(model.problem.t, res[model.observables.index("Per_mRNA"), :], "m")
    ax1.set_xlim([0, 72])
    ax1.set_xticks([0, 12, 24, 36, 48, 60, 72])
    ax1.set_xlabel("Time (h)")
    ax1.set_ylim([0, 5])
    ax1.set_ylabel(r"$\it{Per}$" + " " + r"$\sf{(M_P)}$" + " and " +
                   r"$\it{Cry}$" + " " + r"$\sf{(M_C)}$" + "\nmRNAs, nM")
    ax2.plot(model.problem.t, res[model.observables.index("Bmal1_mRNA"), :],
             "y")
    ax2.set_ylim([7, 10])
    ax2.set_yticks([7, 8, 9, 10])
    ax2.set_ylabel(r"$\it{Bmal1}$" + " mRNA " + r"$\sf{(M_B)}$" + ", nM")
    plt.show()
示例#8
0
def test_run_simulation():
    run_simulation(model, viz_type="original")
    run_simulation(model, viz_type="1")
    run_simulation(model, viz_type="2")
    run_simulation(model, viz_type="3")
    run_simulation(model, viz_type="average", stdev=True)
    run_simulation(model, viz_type="best", show_all=True)
    for npy_file in [
        "simulations_original.npy",
        "simulations_1.npy",
        "simulations_2.npy",
        "simulations_3.npy",
        "simulations_all.npy",
        "simulations_best.npy",
    ]:
        simulated_value = np.load(os.path.join(model.path, "simulation_data", npy_file))
        assert np.isfinite(simulated_value).all()
    for viz_type in ["original", "1", "2", "3", "average", "best"]:
        for obs_name in model.observables:
            assert os.path.isfile(
                os.path.join(model.path, "figure", "simulation", f"{viz_type}", f"{obs_name}.png")
            )
示例#9
0
def test_run_simulation():
    run_simulation(mapk_cascade, viz_type='original')
    run_simulation(mapk_cascade, viz_type='average', stdev=True)
    run_simulation(mapk_cascade, viz_type='best', show_all=True)
示例#10
0
#Model construction
import Hass_2017

Hass_2017.show_info()
model = Hass_2017.create()

#Parameter estimation
from biomass import optimize
# Estimate 10 parameter sets simultaneously
optimize(model=model,
         start=1,
         end=10,
         options={
             "popsize": 5,
             "max_generation": 1000,
             "allowable_error": 0.5,
             "local_search_method": "mutation",
             "n_children": 200
         })

#Visualization of simulation results
from biomass import run_simulation

run_simulation(model, viz_type="average", show_all=False, stdev=True)

#Sensitivity analysis
from biomass import run_analysis

run_analysis(model, target="reaction", metric='integral', style='barplot')
示例#11
0
def test_run_simulation():
    run_simulation(circadian_clock, viz_type='original')
示例#12
0
def test_run_simulation():
    run_simulation(tgfb_smad, viz_type='original')
示例#13
0
import sys
import os
sys.path.append("Hass_2017")

from biomass import run_simulation

import Hass_2017

model = Hass_2017.create()
#run_simulation(model, viz_type='original') #defult pdf format
run_simulation(model, viz_type="original", save_format="png")
#run_simulation(model, viz_type="original", save_format="png",show_all=True)
#run_simulation(model, viz_type="average", save_format="png")
#run_simulation(model, viz_type="best", save_format="png")
#run_simulation(model, viz_type="experiment", save_format="png")