Beispiel #1
0
def test_braid_both():
    import numpy as np
    from synergy.combination import BRAID
    from synergy.utils.dose_tools import grid

    E0, E1, E2, E3 = 1, 0.2, 0.1, 0
    h1, h2 = 2.3, 0.8
    C1, C2 = 1e-2, 1e-1
    kappa = 1
    delta = 0.5

    model = BRAID(E0=E0,
                  E1=E1,
                  E2=E2,
                  E3=E3,
                  h1=h1,
                  h2=h2,
                  C1=C1,
                  C2=C2,
                  kappa=1,
                  delta=delta,
                  variant="both")

    npoints = 8
    npoints2 = 12

    D1, D2 = grid(1e-3, 1e0, 1e-2, 1e1, npoints, npoints2)

    np.random.seed(0)
    E = model.E(D1, D2)
    Efit = E * (1 + (np.random.rand(len(D1)) - 0.5) / 10.)

    model.fit(D1, D2, Efit)

    assert model.r_squared > 0.9
Beispiel #2
0
def test_musyc_no_gamma():
    import numpy as np
    from synergy.combination import MuSyC
    from synergy.utils.dose_tools import grid

    E0, E1, E2, E3 = 1, 0.2, 0.1, 0
    h1, h2 = 2.3, 0.8
    C1, C2 = 1e-2, 1e-1
    alpha12, alpha21 = 3.2, 1.1

    model = MuSyC(E0=E0,
                  E1=E1,
                  E2=E2,
                  E3=E3,
                  h1=h1,
                  h2=h2,
                  C1=C1,
                  C2=C2,
                  alpha12=alpha12,
                  alpha21=alpha21,
                  variant="no_gamma")

    npoints = 8
    npoints2 = 12

    D1, D2 = grid(1e-3, 1e0, 1e-2, 1e1, npoints, npoints2)

    np.random.seed(0)
    E = model.E(D1, D2)
    Efit = E * (1 + (np.random.rand(len(D1)) - 0.5) / 10.)

    model.fit(D1, D2, Efit)

    assert model.r_squared > 0.9
Beispiel #3
0
def test_parametric_model_heatmap_replicates():
    from synergy.utils.dose_tools import grid
    from synergy.combination import MuSyC

    d1, d2 = grid(0.01, 10, 0.01, 10, 5, 5, include_zero=True, replicates=3)
    model = MuSyC(E0=1,
                  E1=0.2,
                  E2=0.5,
                  E3=0.1,
                  h1=1.4,
                  h2=0.9,
                  C1=0.2,
                  C2=0.2,
                  alpha12=2,
                  alpha21=0.5,
                  gamma12=1,
                  gamma21=1)
    model.plot_heatmap(d1, d2, fname="parametric.pdf")
    assert 1 == 1
def create_data(i):
    if i == 1:
        E0, E1, E2, E3 = 1., 0., 0., 0.
        h1, h2 = 1., 1.
        C1, C2 = 1e-2, 1e-1
        alpha12, alpha21 = 10., 1.
        gamma12, gamma21 = 1, 1
    elif i == 2:
        E0, E1, E2, E3 = 1., 0., 0., 0.
        h1, h2 = 1., 3.
        C1, C2 = 1e-2, 1e-1
        alpha12, alpha21 = 0.1, 1.
        gamma12, gamma21 = 1, 1
    elif i == 3:
        E0, E1, E2, E3 = 1., 0.4, 0.2, 0.
        h1, h2 = 2., 1.
        C1, C2 = 1e-2, 1e-1
        alpha12, alpha21 = 1., 1.
        gamma12, gamma21 = 1, 1

    musyc = MuSyC(E0=E0,
                  E1=E1,
                  E2=E2,
                  E3=E3,
                  h1=h1,
                  h2=h2,
                  C1=C1,
                  C2=C2,
                  alpha12=alpha12,
                  alpha21=alpha21,
                  gamma12=gamma12,
                  gamma21=gamma21)

    npoints1 = 8
    npoints2 = 10
    D1, D2 = grid(1e-4, 10, 1e-4, 10, npoints1, npoints2, include_zero=True)

    E = musyc.E(D1, D2)
    return D1, D2, E
Beispiel #5
0
E0 = 1
E1 = 0.5
E2 = 0.3
E3 = 0
h1 = 0.8
h2 = 2
C1 = 0.1
C2 = 0.1
alpha21 = 0.2
alpha12 = 10
gamma21 = 3
gamma12 = 0.7
r1r = 1
r2r = 1

d1, d2 = grid(1e-3, 1e2, 1e-3, 1e2, 20, 20)

model1 = MuSyC(E0=E0,
               E1=E1,
               E2=E2,
               E3=E3,
               h1=h1,
               h2=h2,
               C1=C1,
               C2=C2,
               alpha21=alpha21,
               alpha12=alpha12,
               gamma21=gamma21,
               gamma12=gamma12)

model2 = MuSyC2(E0=E0,
Beispiel #6
0
               E3=E3,
               h1=h1,
               h2=h2,
               C1=C1,
               C2=C2,
               alpha12=alpha12,
               alpha21=1.,
               gamma12=gamma12,
               gamma21=gamma21)

drug1 = Hill(E0=E0, Emax=E1, h=h1, C=C1)
drug2 = Hill(E0=E0, Emax=E2, h=h2, C=C2)

npoints = 12

D1, D2 = grid(1e-3, 1, 1e-2, 10, npoints, npoints)

E = model.E(D1, D2)
E_2 = model2.E(D1, D2)

schindler = Schindler()
schindler2 = Schindler()

schindler.fit(D1, D2, E, drug1_model=drug1, drug2_model=drug2)
schindler2.fit(D1, D2, E_2, drug1_model=drug1, drug2_model=drug2)

fig = plt.figure(figsize=(7, 6))

ax = fig.add_subplot(2, 2, 1)
model.plot_heatmap(D1, D2, ax=ax, title="Dose Surface", vmin=E3, vmax=E0)
ax.set_xticks([])
Beispiel #7
0
xE3 = [1,1,1,1,1,1,1,1,1]

xh1 = [3,1,1,3,3,3,3,3,2.7]
xh2 = [3,1,3,3,3,3,3,3,3.2]
xC1 = list(np.asarray([3,3,3,3,3,3,3,3,3])/2)
xC2 = list(np.asarray([3,3,3,3,3,3,3,3,3])/2-0.5)

#xkappa = [0,0,0,0.75,2.5,0,-0.3,-1.2,-0.5]
#xdelta = [1,1,1,1,1,1,1,1,1]

xkappa = [0,0,0,0.75,2.5,0,-0.3,-1.2,-0.5]
xdelta = [2,1,1,1,1,1,1,1,1]

npoints = 80

D1, D2 = grid(0,3,0,3,npoints,npoints,logscale=False)

fig = plt.figure(figsize=(8,8))

for i in range(9):
    ax = fig.add_subplot(3,3,1+i)

    E0 = xE0[i]
    E1 = xE1[i]
    E2 = xE2[i]
    E3 = xE3[i]

    h1 = xh1[i]
    h2 = xh2[i]
    C1 = xC1[i]
    C2 = xC2[i]
Beispiel #8
0
mtrue = MuSyC(E0=1,
              E1=0.05,
              E2=0.75,
              E3=0.1,
              h1=0.8,
              h2=1,
              C1=5e1,
              C2=1e3,
              alpha12=1,
              alpha21=20,
              gamma21=0.5,
              gamma12=1)
model = CombinationIndex()

d1, d2 = grid(1, 1e4, 1., 1e4, 10, 10, include_zero=True)
E = mtrue.E(d1, d2) * (1 + 0.05 * (2 * (np.random.rand(len(d1))) - 1))

model.fit(d1, d2, E)

fig, (ax1, ax2, ax3) = plt.subplots(nrows=1, ncols=3)
fig.set_size_inches(14, 4)
fig.tight_layout(pad=3.0)

# Plot raw data heatmap
plots.plot_heatmap(d1, d2, E, ax=ax1, cmap="RdYlGn", vmin=-1, vmax=1)
ax1.set_title("Experimental Data")

# Plot Reference model
model.plot_reference_heatmap(ax=ax2, cmap="RdYlGn", vmin=-1, vmax=1)
ax2.set_title("CI Model")
Beispiel #9
0
import numpy as np
from synergy.combination import Zimmer
from synergy.utils.dose_tools import grid

h1, h2 = 2.3, 0.8
C1, C2 = 1e-2, 1e-1
a12, a21 = -1., 1.
npoints = 10

truemodel = Zimmer(h1=h1, h2=h2, C1=C1, C2=C2, a12=a12, a21=a21)

D1, D2 = grid(1e-3, 1, 1e-2, 1, npoints, npoints, include_zero=True)
E = truemodel._model(D1, D2, h1, h2, C1, C2, a12, a21)

Efit = E * (1 + (np.random.rand(len(D1)) - 0.5) / 5.)

model = Zimmer()
model.fit(D1, D2, Efit, bootstrap_iterations=100)
print(model)
if model.converged:
    print(model.get_parameter_range().T)
Beispiel #10
0
musyc = MuSyC(E0=E0,
              E1=E1,
              E2=E2,
              E3=E3,
              h1=h1,
              h2=h2,
              C1=C1,
              C2=C2,
              alpha12=alpha12,
              alpha21=alpha21,
              gamma12=gamma12,
              gamma21=gamma21)

npoints1 = 8
npoints2 = 10
D1, D2 = grid(1e-4, 10, 1e-4, 10, npoints1, npoints2, include_zero=True)

E = musyc.E(D1, D2)

# Build ZIP model
model = ZIP()

#Efit = E*(1+(np.random.rand(len(D1))-0.5)/10.)
Efit = E

# Output data to test in synergyfinder R package
df = to_synergyfinder(D1, D2, Efit * 100)
df.to_csv("synergyfinder_comparison/zip_test_data.csv", index=None)

synergy = model.fit(D1, D2, Efit, use_jacobian=True)
Beispiel #11
0
              h1=h1,
              h2=h2,
              C1=C1,
              C2=C2,
              alpha12=alpha12,
              alpha21=alpha21,
              gamma12=gamma12,
              gamma21=gamma21)

replicates = 2
npoints = 6
npoints2 = 8
D1, D2 = dose_tools.grid(1e-3,
                         1,
                         1e-2,
                         10,
                         npoints,
                         npoints2,
                         replicates=replicates,
                         include_zero=True)

D1 = D1 / 3.

E = model.E(D1, D2)
Efit = E * (1 + (np.random.rand(len(D1)) - 0.5) / 5.)

scatter_points = pd.DataFrame({
    'drug1.conc': D1,
    'drug2.conc': D2,
    'effect': Efit
})
model.fit(D1, D2, Efit)
Beispiel #12
0
                  E3=E3,
                  h1=h1,
                  h2=h2,
                  C1=C1,
                  C2=C2,
                  alpha12=alpha12,
                  alpha21=alpha21,
                  gamma12=gamma12,
                  gamma21=gamma21)

npoints = 8
npoints2 = 8
d1, d2 = grid(C1 / 1e2,
              C1 * 1e2,
              C2 / 1e2,
              C2 * 1e2,
              npoints,
              npoints2,
              include_zero=True)

E = truemodel.E(d1, d2)

noise = 0.05
E_fit = E + noise * (E0 - E3) * (2 * np.random.rand(len(E)) - 1)

model = MuSyC()
model.fit(d1, d2, E_fit, bootstrap_iterations=100)

#print(model)
#if model.converged:
#    print(model.get_parameter_range().T)
from synergy.combination import MuSyC
from synergy.utils import plots
from synergy.utils.dose_tools import grid

# Shows that alpha and gamma are orthogonal synergy parameters

E0, E1, E2, E3 = 1, 0.3, 0.1, 0.0
h1, h2 = 2.3, 0.8
C1, C2 = 1e-2, 1e-1
#alpha12, alpha21 = 3.2, 1.1
#gamma12, gamma21 = 1, 1

npoints = 50
npoints2 = 50
d1, d2 = grid(1e-3 / 3, 1 / 3, 1e-3, 10, npoints, npoints2, include_zero=False)

MuSyC(E0=E0,
      E1=E1,
      E2=E2,
      E3=E3,
      h1=h1,
      h2=h2,
      C1=C1,
      C2=C2,
      alpha12=1,
      alpha21=1,
      gamma12=1,
      gamma21=1).plot_surface_plotly(d1,
                                     d2,
                                     fname="1_1_1_1.html",
Beispiel #14
0
              E1=E1,
              E2=E2,
              E3=E3,
              h1=h1,
              h2=h2,
              C1=C1,
              C2=C2,
              alpha12=alpha12,
              alpha21=alpha21,
              gamma12=gamma12,
              gamma21=gamma21)

npoints = 8
npoints2 = 12

D1, D2 = grid(1e-3 / 3, 1 / 3, 1e-2, 10, npoints, npoints2, include_zero=True)

E = model.E(D1, D2)
Efit = E * (1 + (np.random.rand(len(D1)) - 0.5) / 5.)

model.fit(D1, D2, Efit)
#%timeit model.fit(D1, D2, Efit)
#%timeit model.fit(D1, D2, Efit, use_jacobian=False)
# With Jacobian
# noise /5.
# 73.5 ms ± 965 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
# 63.7 ms ± 203 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)

# Without Jacobian (frequently has "covariance of parameters" warning)
# noise /5.
# 26.1 ms ± 385 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
Beispiel #15
0
                  E1=E1,
                  E2=E2,
                  E3=E3,
                  h1=h1,
                  h2=h2,
                  C1=C1,
                  C2=C2,
                  alpha12=alpha12,
                  alpha21=alpha21,
                  gamma12=gamma12,
                  gamma21=gamma21)

npoints = 8
npoints2 = 8
d1, d2 = grid(C1 / 1e2,
              C1 * 1e2,
              C2 / 1e2,
              C2 * 1e2,
              npoints,
              npoints2,
              include_zero=True)

E = truemodel.E(d1, d2)

noise = 0.05
E_fit = E + noise * (E0 - E3) * (2 * np.random.rand(len(E)) - 1)

model = MuSyC(variant="no_gamma")
model.fit(d1, d2, E_fit, bootstrap_iterations=100)

print(model.summary())
Beispiel #16
0
               E1=E1,
               E2=E2,
               E3=E3,
               h1=h1,
               h2=h2,
               C1=C1,
               C2=C2,
               kappa=0,
               delta=10)
model2 = BRAID(E0=E0,
               E1=E1,
               E2=E2,
               E3=E3,
               h1=h1,
               h2=h2,
               C1=C1,
               C2=C2,
               kappa=10,
               delta=1)

D1, D2 = grid(C1 / 100, C1 * 100, C2 / 100, C2 * 100, 8, 8)

fig = plt.figure(figsize=(8, 5))

ax = fig.add_subplot(121)
model1.plot_heatmap(D1, D2, ax=ax)

ax = fig.add_subplot(122)
model2.plot_heatmap(D1, D2, ax=ax)

plt.show()