コード例 #1
0
ファイル: ex3.py プロジェクト: yannikschaelte/SSA
def run():
    reactants0 = np.array([[1, 1]])
    products0 = np.array([[0, 2]])

    reactants1 = np.array([[1, 0]])
    products1 = np.array([[0, 1]])

    x0 = np.array([40, 3])
    t_max = 0.1

    k0 = np.array([2.3])
    k1 = np.array([30.0])

    nr = 5

    output = ssa.output.FullOutput()

    model0 = ssa.Model(reactants0, products0, x0, t_max, k0, output, n_procs=2)
    result0 = model0.simulate(n_reps=nr)
    _, axes = plt.subplots(1, 2)
    ssa.plot(result0, show=False, ax=axes[0])

    model1 = ssa.Model(reactants1, products1, x0, t_max, k1, output, n_procs=2)
    result1 = model1.simulate(n_reps=nr)
    ssa.plot(result1, show=False, ax=axes[1])

    plt.savefig("ex3.png")
コード例 #2
0
def run():
    reactants = np.array([[1, 1, 0, 0], [0, 0, 1, 0], [0, 0, 1, 0]])
    products = np.array([[0, 0, 1, 0], [1, 1, 0, 0], [0, 1, 0, 1]])

    volume = 1e-15

    x0 = np.array([5e-7, 2e-7, 0, 0])
    x0 = ssa.util.molar_concentration_to_molecule_number(x0, volume=volume)

    k = np.array([1e6, 1e-4, 0.1])
    k = ssa.util.k_det_to_k_stoch(k, reactants=reactants, volume=volume)

    print(x0, k)

    t_max = 50

    model = ssa.Model(reactants=reactants,
                      products=products,
                      x0=x0,
                      k=k,
                      t_max=t_max)
    result = model.simulate(n_reps=20)
    x_names = ["S", "E", "SE", "P"]
    ssa.plot(result, x_names=x_names, show=False)
    plt.savefig("michaelis_menten.png")
コード例 #3
0
def run():
    reactants = np.array([[2, 0], [0, 1]])
    products = np.array([[0, 1], [2, 0]])

    volume = 1e-15
    use_na = True

    k_det = np.array([5e5, 0.2])
    k1 = ssa.util.k_det_to_k_stoch(
        k_det, reactants=reactants, volume=volume, use_na=use_na
    )
    k2 = np.array([1.66e-3, 0.2])
    print(k1, k2)

    x0_molar_concentration = np.array([5e-7, 0])
    x01 = ssa.util.molar_concentration_to_molecule_number(
        x0_molar_concentration, volume=volume, use_na=use_na
    )
    x02 = np.array([301.1, 0])
    print(x01, x02)
    t_max = 10.0

    model = ssa.Model(
        reactants=reactants, products=products, k=k2, x0=x02, t_max=t_max, n_procs=2
    )
    result = model.simulate(n_reps=5)
    ssa.plot(result, show=False)
    plt.savefig("dimerization_kinetics.png")
コード例 #4
0
ファイル: ex0.py プロジェクト: yannikschaelte/SSA
def run():
    reactants = np.array([[0, 0], [1, 0], [1, 0], [0, 1]])
    products = np.array([[1, 0], [1, 1], [0, 0], [0, 0]])
    x0 = np.array([0, 0])

    k = np.array([1.0, 1.0, 0.1, 0.04])
    t_max = 2e2
    timepoints = np.linspace(0, t_max, 1000)

    # model = ssa.Model(reactants, products, x0, t_max, k, output = ssa.output.FullOutput(), n_procs=2)
    model = ssa.Model(
        reactants,
        products,
        x0,
        t_max,
        k,
        output=ssa.output.ArrayOutput(timepoints),
        n_procs=2,
    )
    result = model.simulate(n_reps=100)

    for j in range(len(result.list_ts)):
        pass
    ssa.plot(result, show=False)
    plt.savefig("ex0.png")
コード例 #5
0
ファイル: sir.py プロジェクト: yannikschaelte/SSA
def run():
    reactants = np.array([[1, 1, 0], [0, 1, 0]])
    products = np.array([[0, 2, 0], [0, 0, 1]])
    x0 = np.array([299, 1, 0])
    t_max = 1.0
    k = np.array([0.3, 5])
    x_names = ["Susceptible", "Infected", "Recovered"]
    model = ssa.Model(reactants, products, x0=x0, t_max=t_max, k=k)
    result = model.simulate(n_reps=20)
    ssa.plot(result, x_names=x_names, set_xlim_to_t_max=False, show=False)
    plt.savefig("sir.png")
コード例 #6
0
def run():
    reactants = np.array([[0, 0], [1, 0], [0, 1]])
    products = np.array([[1, 0], [0, 1], [0, 0]])

    k = np.array([1.0, 0.1, 0.05])
    x0 = np.array([100, 0])
    t_max = 100

    model = ssa.Model(reactants=reactants, products=products, k=k, x0=x0, t_max=t_max)
    result = model.simulate(n_reps=20)
    ssa.plot(result, show=False)
    plt.savefig("mono_molecular_chain.png")
コード例 #7
0
ファイル: ex1.py プロジェクト: yannikschaelte/SSA
def run():
    model = ssa.Model(reactants,
                      products,
                      x0,
                      t_max,
                      k,
                      output=ssa.output.FullOutput())
    # model = ssa.Model(reactants, products, x0, t_max, k, output = ssa.output.ArrayOutput(timepoints))
    result = model.simulate(n_reps=10)

    for j in range(len(result.list_ts)):
        # print(result.list_ts[j][-10:])
        # print(result.list_xs[j][-10:])
        pass
コード例 #8
0
 def model(p):
     # anything (e.g. pd.DataSeries) -> OrderedDict
     p = OrderedDict([('transcription', p.get('transcription', 10)),
                      ('decay', p.get('decay', 0.1))])
     k = np.array(list(p.values()))  # order should be correct
     ssa_model = ssa.Model(reactants=self.reactants,
                           products=self.products,
                           t_max=self.t_max,
                           x0=self.x0,
                           k=k,
                           output=self.output)
     result = ssa_model.simulate(n_reps=1)
     return {
         't': result.list_ts[0],
         'mrna': result.list_xs[0].flatten()
     }
コード例 #9
0
 def model(p):
     k = np.array([p['k1'], p['k2'], p['k3'], p['k4']])
     k = np.exp(k)
     ssa_model = ssa.Model(reactants=self.reactants,
                           products=self.products,
                           t_max=self.t_max,
                           x0=self.x0,
                           k=k,
                           output=self.output)
     result = ssa_model.simulate(n_reps=1)
     #import matplotlib.pyplot as plt
     #plt.plot(result.list_xs)
     res = {
         't': result.list_ts[0],
         'S1': result.list_xs[0][:, 0].flatten()
     }  # 'S2': result.list_xs[0][:, 1].flatten()}
     print(res)
     return res
コード例 #10
0
def run():
    reactants = np.array([[1, 0, 0], [0, 1, 0]])
    products = np.array([[0, 1, 0], [0, 0, 1]])
    x0 = np.array([100, 0, 0])

    k = np.array([1.0, 1.0])
    t_max = 10
    timepoints = np.linspace(0, t_max, 1000)

    model = ssa.Model(
        reactants, products, x0, t_max, k, output=ssa.output.FullOutput(), n_procs=2
    )
    # model = ssa.Model(reactants, products, x0, t_max, k, output = ssa.output.ArrayOutput(timepoints), n_procs=1)
    result = model.simulate(n_reps=10)

    for j in range(len(result.list_ts)):
        pass
    ssa.plot(result, show=True, show_mean=True, show_std=True)
コード例 #11
0
def run():
    reactants = np.array([[0], [1]])
    products = np.array([[1], [0]])

    x_names = "mRNA"

    t_max = 1e2
    x0 = np.array([0])
    k = np.array([10, 0.1])

    model = ssa.Model(reactants=reactants,
                      products=products,
                      t_max=t_max,
                      x0=x0,
                      k=k)
    result = model.simulate(n_reps=10)
    ssa.plot(result)

    plt.savefig("transcription.png")
コード例 #12
0
ファイル: predator_prey.py プロジェクト: yannikschaelte/SSA
def run():
    reactants = np.array([[1, 0], [1, 1], [0, 1]])
    products = np.array([[2, 0], [0, 2], [0, 0]])

    x0 = np.array([50, 100])
    k = np.array([1, 0.005, 0.6])
    t_max = 30
    output = ssa.output.FullOutput()

    model = ssa.Model(reactants,
                      products,
                      x0=x0,
                      k=k,
                      t_max=t_max,
                      output=output,
                      n_procs=2)
    result = model.simulate(n_reps=10)
    ssa.plot(result, show=False)
    plt.savefig("ex4.png")
コード例 #13
0
def run():
    reactants = np.array([[0, 0], [1, 0], [1, 0], [0, 1]])
    products = np.array([[1, 0], [0, 0], [1, 1], [0, 0]])

    t_max = 100
    x0 = np.array([0, 0])
    k = np.array([3, 0.1, 0.2, 0.05])

    output = ssa.output.ArrayOutput(np.linspace(0, t_max, 100))
    output = ssa.output.FullOutput()

    model = ssa.Model(
        reactants=reactants, products=products, t_max=t_max, x0=x0, k=k, output=output
    )
    result = model.simulate(n_reps=10)

    x_names = ["mRNA", "Protein"]
    ssa.plot(result, show=False, x_names=x_names)
    plt.savefig("one_state_gene_expression.png")
コード例 #14
0
def run():
    # activation, deactivation, transcription-act,
    #  transcription-deact, translation, mRNA decay,
    #  protein decay
    reactants = np.array([
        [1, 0, 0, 0],
        [0, 1, 0, 0],
        [0, 1, 0, 0],
        [1, 0, 0, 0],
        [0, 0, 1, 0],
        [0, 0, 1, 0],
        [0, 0, 0, 1],
    ])
    products = np.array([
        [0, 1, 0, 0],
        [1, 0, 0, 0],
        [0, 1, 1, 0],
        [1, 0, 1, 0],
        [0, 0, 1, 1],
        [0, 0, 0, 0],
        [0, 0, 0, 0],
    ])

    k = np.array([0.5, 0.5, 20, 0.0001, 15, 1, 2])
    x0 = np.array([1, 0, 0, 0])
    t_max = 30

    output = ssa.output.ArrayOutput(np.linspace(0, t_max, 1000))

    x_names = ["inactive promoter", "active promoter", "mRNA", "protein"]

    model = ssa.Model(reactants=reactants,
                      products=products,
                      k=k,
                      x0=x0,
                      t_max=t_max,
                      output=output)
    result = model.simulate(n_reps=1)
    ssa.plot(result, x_names=x_names, show=False)
    plt.savefig("two_state_gene_expression.png")
コード例 #15
0
def run():
    reactants = np.array([[0], [1]])
    products = np.array([[1], [0]])

    t_max = 120
    x0 = np.array([0])
    k = np.array([1, 0.05])

    output = ssa.output.ArrayOutput(np.linspace(0, t_max, 100))
    output = ssa.output.FullOutput()

    model = ssa.Model(reactants=reactants,
                      products=products,
                      t_max=t_max,
                      x0=x0,
                      k=k,
                      output=output)
    result = model.simulate(n_reps=10)

    x_names = ["mRNA"]
    ssa.plot(result, show=False, x_names=x_names)
    plt.savefig("mrna_transcription.png")