示例#1
0
def test_stochkit_earm_multi_initials():
    model = earm_1_0.model
    tspan = np.linspace(0, 1000, 10)
    sim = StochKitSimulator(model, tspan=tspan)
    unbound_L = model.monomers['L'](b=None)
    simres = sim.run(initials={unbound_L: [3000, 1500]},
                     n_runs=2, seed=_STOCHKIT_SEED, algorithm="ssa")
    df = simres.dataframe

    unbound_L_index = model.get_species_index(as_complex_pattern(unbound_L))

    # Check we have two repeats of each initial
    assert np.allclose(df.loc[(slice(None), 0), '__s%d' % unbound_L_index],
                       [3000, 3000, 1500, 1500])
示例#2
0
def test_stochkit_earm_multi_initials():
    model = earm_1_0.model
    tspan = np.linspace(0, 1000, 10)
    sim = StochKitSimulator(model, tspan=tspan)
    unbound_L = model.monomers['L'](b=None)
    simres = sim.run(initials={unbound_L: [3000, 1500]},
                     n_runs=2, seed=_STOCHKIT_SEED, algorithm="ssa")
    df = simres.dataframe

    unbound_L_index = model.get_species_index(as_complex_pattern(unbound_L))

    # Check we have two repeats of each initial
    assert np.allclose(df.loc[(slice(None), 0), '__s%d' % unbound_L_index],
                       [3000, 3000, 1500, 1500])
示例#3
0
def run(n_sim, model, tspan, simulator='cuda'):
    v = False
    if 'cl' in simulator:
        sim = OpenCLSSASimulator(model,
                                 tspan=tspan,
                                 verbose=v,
                                 precision=np.float64)
    elif simulator == 'cuda':
        sim = CudaSSASimulator(model,
                               tspan=tspan,
                               verbose=v,
                               precision=np.float64)
    elif simulator == 'bng':
        sim = BngSimulator(model, tspan=tspan, verbose=v)
    elif simulator == 'stochkit':
        sim = StochKitSimulator(model, tspan=tspan, verbose=v)
    else:
        return
    st = time.time()
    if simulator in ('bng', 'stochkit'):
        sim.run(tspan, n_runs=n_sim)
    else:
        # sim.run(tspan, number_sim=n_sim)
        traj = sim.run(tspan, number_sim=n_sim)
        # print(traj.dataframe.min())
    # quit()
    total_time = time.time() - st

    return total_time, sim._time
示例#4
0
def stochkit(model,
             start=0,
             finish=10,
             points=10,
             n_runs=20,
             path='/opt/conda/bin/'):
    set_path('stochkit_ssa', path)
    sims = StochKitSimulator(model,
                             linspace(start, finish,
                                      points + 1)).run(n_runs=n_runs).dataframe
    sims = modes(sims, n_runs)
    return {'sims': sims['sims'], 'avrg': sims['avrg'], 'stdv': sims['stdv']}
示例#5
0
def plot_mean_min_max(name, title=None):
    x = np.array([tr[:][name] for tr in trajectories]).T
    if not title:
        title = name
    plt.figure(title)
    plt.plot(tout.T, x, '0.5', lw=2, alpha=0.25)  # individual trajectories
    plt.plot(tout[0], x.mean(1), 'k--', lw=3, label="Mean")
    plt.plot(tout[0], x.min(1), 'b--', lw=3, label="Minimum")
    plt.plot(tout[0], x.max(1), 'r--', lw=3, label="Maximum")
    plt.legend(loc=0)
    plt.xlabel('Time')
    plt.ylabel('Population of %s' % name)


tspan = np.linspace(0, 20000, 1000)
sim = StochKitSimulator(model, tspan)
simres = sim.run(n_runs=20, seed=None, algorithm="ssa")

trajectories = simres.all
tout = simres.tout

plot_mean_min_max('Bid_unbound')
plot_mean_min_max('PARP_unbound')
plot_mean_min_max('mSmac_unbound')
plot_mean_min_max('tBid_total')
plot_mean_min_max('CPARP_total')
plot_mean_min_max('cSmac_total')

plt.show()
示例#6
0
#turn off graphs showing up
plt.ioff()

#Set Path to save figures
# path = '/home/asasla/main/ComplexII/'
path = '/Users/ariella/PycharmProjects/ComplexII/'

#RUN THROUGH EACH AMOUNT OF TNF: HOW DOES THAT AFFECT SSA VS ODE
# TNF_LOOP = [('100 ng/ml TNF', 9390), ('30 ng/ml TNF', 2817), ('10 ng/ml TNF', 939), ('1 ng/ml TNF', 94), ('.1 ng/ml TNF', 9)]

TNF_LOOP = [('1 ng/ml TNF', 94), ('.1 ng/ml TNF', 9)]

for tnf_title, dose in TNF_LOOP:

    #RUN STOCHASTIC SIMULATION ALGORITHM (SSA)
    ssa_sim = StochKitSimulator(model, tspan=tspan, verbose=True)
    ssa_sim_res = ssa_sim.run(initials={TNF(tnfr=None): dose},
                              n_runs=NUM_SSA_RUNS)
    df = ssa_sim_res.dataframe

    #FOR EACH OBSERVABLE AVERAGE THE SSA RUNS AT EACH TIME POINT
    avg = df.groupby(level='time').mean()

    #RUN ODE SIMULATION
    ode_sim = ScipyOdeSimulator(model, tspan=tspan)
    ode_sim_res = ode_sim.run(initials={TNF(tnfr=None): dose})

    #PLOT STOCHASTIC SIMULATION ALGORITHM (SSA) WITH AVG SSA (YELLOW) AND ODE (BLACK)
    # Array: [(Observable name, number to start y axis at, number to end y axis at)]
    obs_y_range = [('obsComplexI', float(dose), 0, .02),
                   ('obsComplexIIa', 8030.0, 0, 1),
示例#7
0
    cont = readlines(f)
    pop = popdict(cont, pop)
    enterdata(cont, i)
    i += 1

#Length of sim
tspan = np.linspace(0, 1440, 1441)

#Run ODE
print('simulating')
ode_sim = ScipyOdeSimulator(model, tspan=tspan)
ode_sim_res = ode_sim.run()
yout = ode_sim_res.all

#SSA Simulation
ssa_sim = StochKitSimulator(model, tspan=tspan, verbose=True)
ssa_sim_res = ssa_sim.run(n_runs=NUM_SSA_RUNS)
#ssa_sim_res = ssa_sim.run(initials={TNF(tnfr=None): dose}, n_runs=NUM_SSA_RUNS)
df = ssa_sim_res.dataframe

#FOR EACH OBSERVABLE AVERAGE THE SSA RUNS AT EACH TIME POINT
ssa_avg = df.groupby(level='time').mean()

for key in keys:
    print(key)
    if key in avgs:
        #if key != 'time':
        color = iter(plt.cm.rainbow(np.linspace(0, 1, len(datafiles) + 1)))
        f = plt.figure()
        ax = f.add_subplot(1, 1, 1)
        '''
示例#8
0
def test_stochkit_expressions():
    model = expression_observables.model
    tspan = np.linspace(0, 100, 11)
    sim = StochKitSimulator(model, tspan=tspan)
    assert np.allclose(sim.run().tout, tspan)
示例#9
0
def test_stochkit_earm():
    tspan = np.linspace(0, 1000, 10)
    sim = StochKitSimulator(earm_1_0.model, tspan=tspan)
    simres = sim.run(n_runs=2, seed=_STOCHKIT_SEED, algorithm="ssa")
    simres_tl = sim.run(n_runs=2, seed=_STOCHKIT_SEED, algorithm="tau_leaping")
示例#10
0

def plot_mean_min_max(name, title=None):
    x = np.array([tr[:][name] for tr in trajectories]).T
    if not title:
        title = name
    plt.figure(title)
    plt.plot(tout.T, x, '0.5', lw=2, alpha=0.25) # individual trajectories
    plt.plot(tout[0], x.mean(1), 'k--', lw=3, label="Mean")
    plt.plot(tout[0], x.min(1), 'b--', lw=3, label="Minimum")
    plt.plot(tout[0], x.max(1), 'r--', lw=3, label="Maximum")
    plt.legend(loc=0)
    plt.xlabel('Time')
    plt.ylabel('Population of %s' % name)

tspan = np.linspace(0, 20000, 1000)
sim = StochKitSimulator(model, tspan)
simres = sim.run(n_runs=20, seed=None, algorithm="ssa")

trajectories = simres.all
tout = simres.tout

plot_mean_min_max('Bid_unbound')
plot_mean_min_max('PARP_unbound')
plot_mean_min_max('mSmac_unbound')
plot_mean_min_max('tBid_total')
plot_mean_min_max('CPARP_total')
plot_mean_min_max('cSmac_total')

plt.show()
import numpy as np

from pysb.simulator import StochKitSimulator
from tyson_oscillator import model


def plot_mean_min_max(name, title=None):
    x = np.array([tr[:][name] for tr in trajectories]).T
    if not title:
        title = name
    plt.figure(title)
    plt.plot(tout.T, x, '0.5', lw=2, alpha=0.25) # individual trajectories
    plt.plot(tout[0], x.mean(1), 'k--', lw=3, label="Mean")
    plt.plot(tout[0], x.min(1), 'b--', lw=3, label="Minimum")
    plt.plot(tout[0], x.max(1), 'r--', lw=3, label="Maximum")
    plt.legend(loc=0)
    plt.xlabel('Time')
    plt.ylabel('Population of %s' % name)

tspan = np.linspace(0, 50, 5001)
sim = StochKitSimulator(model, verbose=True)
simres = sim.run(tspan=tspan, n_runs=5, seed=None, algorithm="ssa")
tout = simres.tout
trajectories = simres.all

plot_mean_min_max('__s0', str(model.species[0]))
plot_mean_min_max('YT')
plot_mean_min_max('M')

plt.show()
示例#12
0
def test_stochkit_expressions():
    model = expression_observables.model
    tspan = np.linspace(0, 100, 11)
    sim = StochKitSimulator(model, tspan=tspan)
    assert np.allclose(sim.run().tout, tspan)
示例#13
0
def test_stochkit_earm():
    tspan = np.linspace(0, 1000, 10)
    sim = StochKitSimulator(earm_1_0.model, tspan=tspan)
    simres = sim.run(n_runs=2, seed=_STOCHKIT_SEED, algorithm="ssa")
    simres_tl = sim.run(n_runs=2, seed=_STOCHKIT_SEED, algorithm="tau_leaping")
示例#14
0
from pysb.simulator import StochKitSimulator
from tyson_oscillator import model


def plot_mean_min_max(name, title=None):
    x = np.array([tr[:][name] for tr in trajectories]).T
    if not title:
        title = name
    plt.figure(title)
    plt.plot(tout.T, x, '0.5', lw=2, alpha=0.25)  # individual trajectories
    plt.plot(tout[0], x.mean(1), 'k--', lw=3, label="Mean")
    plt.plot(tout[0], x.min(1), 'b--', lw=3, label="Minimum")
    plt.plot(tout[0], x.max(1), 'r--', lw=3, label="Maximum")
    plt.legend(loc=0)
    plt.xlabel('Time')
    plt.ylabel('Population of %s' % name)


tspan = np.linspace(0, 50, 5001)
sim = StochKitSimulator(model, verbose=True)
simres = sim.run(tspan=tspan, n_runs=5, seed=None, algorithm="ssa")
tout = simres.tout
trajectories = simres.all

plot_mean_min_max('__s0', str(model.species[0]))
plot_mean_min_max('YT')
plot_mean_min_max('M')

plt.show()
示例#15
0
def test_stochkit_invalid_init_kwarg():
    StochKitSimulator(earm_1_0.model, tspan=range(100), spam='eggs')