Пример #1
0
    def integrate(self, algparams=None, normalized=False, **kwargs):
        self._algparams = algparams
        self._normalized = normalized
        if (not self._algparams):
            self._algparams = su.solver_opts(method='gsl', **kwargs)
        if self._model == 'lra':
            self.sol = lr_model(self.pars, self._algparams)
        elif self._model == 'chi':
            self.sol = chi_model(self.pars, self._algparams)
        elif self._model == 'gchi':
            self.sol = gchi_model(self.pars, self._algparams)
        elif self._model == 'pkc':
            self.sol = egchi_model(self.pars, self._algparams)

        if normalized:
            # Create in parallel an attribute "mm" (min/max) whereto save min and max of data to reverse normalization
            self.mm = {
                'ca':
                np.asarray([np.amin(self.sol['ca']),
                            np.amax(self.sol['ca'])])
            }
            self.sol['ca'] = normalize(self.sol['ca'])
            if self._model in ['chi', 'gchi', 'pkc']:
                self.mm['ip3'] = np.asarray(
                    [np.amin(self.sol['ip3']),
                     np.amax(self.sol['ip3'])])
                self.sol['ip3'] = normalize(self.sol['ip3'])
            if 'pkc' in self._model:
                self.mm['dag'] = np.asarray(
                    [np.amin(self.sol['dag']),
                     np.amax(self.sol['dag'])])
                self.mm['pkc'] = np.asarray(
                    [np.amin(self.sol['pkc']),
                     np.amax(self.sol['pkc'])])
                self.sol['dag'] = normalize(self.sol['dag'])
                self.sol['pkc'] = normalize(self.sol['pkc'])
Пример #2
0
def chi_optimize(method='pso',
                 parallel=False,
                 N_ind=100,
                 N_gen=30,
                 iset=0,
                 show_results=False,
                 dir='../data/',
                 file_name='chi_fit'):
    # Load experimental data
    N_set = 2
    ca_data = svu.loaddata('../data/herzog_data.pkl')[0]
    po_data = svu.loaddata('../data/fit_po.pkl')[0]
    lr_data = svu.loaddata('../data/fit_lra.pkl')[0]

    # Get boundary dictionary
    bounds_dict = models.model_bounds(model='chi')
    # Save effective bounds and scaling
    bounds, scaling = bounds_for_exploration(bounds_dict, normalized=False)

    # Prepare model parameters
    c0 = 5.0
    # c0 = 15.0
    params = np.asarray(np.r_[po_data[[0, 1, 0, 2, 3]], lr_data[[0, 1]], c0,
                              iset])
    args = (params, ca_data)

    #-----------------------------------------------------------------------------------------------------------
    # Effective evolution
    #-----------------------------------------------------------------------------------------------------------
    # Size parameters
    # N_var = problem_dimension(model='lra')
    N_individuals = N_ind
    N_var = problem_dimension(model='chi')
    N_generations = N_gen * N_var

    # Tolerances
    FTOL = 1e-6
    XTOL = 1e-6

    # prob = pg.problem(fit_problem('lra',args))
    prob = pg.problem(fit_problem('chi', args))

    # Optimization
    # NOTE: We keep each algorithm self contained here because different setting of parameters for evolution are
    # needed depending on the chose algorithm
    if method == 'pso':
        algo = pg.algorithm(
            pg.pso(gen=N_generations, variant=5, neighb_type=4, max_vel=0.8))
    elif method == 'bee':
        algo = pg.algorithm(pg.bee_colony(gen=N_generations, limit=2))
    elif method == 'de':
        algo = pg.algorithm(pg.de(gen=N_generations, ftol=FTOL, tol=XTOL))
        # Single-node optimation to run on local machine / laptop
        # N_individuals = 100
        # N_generations = 40 * N_var
        # verbosity = 20

    if not parallel:
        verbosity = 20
        algo.set_verbosity(verbosity)
        pop = pg.population(prob, size=N_individuals)
        pop = algo.evolve(pop)

        best_fitness = pop.get_f()[pop.best_idx()]
        print(best_fitness)

        x_rescaled = rescale_vector(pop.champion_x,
                                    model='chi',
                                    normalized=True,
                                    bounds=bounds,
                                    scaling=scaling)

        # Show results of fit
        if show_results:
            astro = models.Astrocyte(
                model='chi',
                d1=po_data[0],
                d2=po_data[1],
                d3=po_data[0],
                d5=po_data[2],
                a2=po_data[3],
                c0=c0,
                c1=0.5,
                rl=0.1,
                Ker=0.1,
                rc=lr_data[0],
                ver=lr_data[1],
                vbeta=x_rescaled[0],
                vdelta=x_rescaled[1],
                v3k=x_rescaled[2],
                r5p=x_rescaled[3],
                ICs=np.asarray([x_rescaled[6], x_rescaled[4], x_rescaled[5]]))

            options = su.solver_opts(t0=ca_data['time'][iset][0],
                                     tfin=ca_data['time'][iset][-1],
                                     dt=1e-4,
                                     atol=1e-8,
                                     rtol=1e-6,
                                     method="gsl_msadams")
            astro.integrate(algparams=options, normalized=True)

            ca_trace = ca_data['smoothed'][iset]
            plt.plot(ca_data['time'][0], ca_trace, 'k-', astro.sol['ts'],
                     astro.sol['ca'], 'r-')
            plt.show()

    else:
        # Parallel version to run on cluster
        N_evolutions = 100
        N_islands = 10
        # Initiate optimization
        algo = pg.algorithm(
            pg.pso(gen=N_generations, variant=5, neighb_type=4, max_vel=0.8))
        archi = pg.archipelago(n=N_islands,
                               algo=algo,
                               prob=prob,
                               pop_size=N_individuals)
        archi.evolve(N_evolutions)
        archi.wait()
        imin = np.argmin(archi.get_champions_f())
        x_rescaled = rescale_vector(archi.get_champions_x()[imin],
                                    model='chi',
                                    normalized=True,
                                    bounds=bounds,
                                    scaling=scaling)
        print archi.get_champions_f()[imin]
        print x_rescaled

    svu.savedata([x_rescaled], dir + file_name + '.pkl')
Пример #3
0
def fit_ca(x,
           params,
           ca_exp,
           model='chi',
           normalized=False,
           bounds=None,
           scaling=None):

    # This function minimizes the SE of normalized calcium traces and solution from integration of the chi model
    # Rescaled variables properly, according to normalization and config flags

    # Retrieve fixed parameters
    d1 = params[0]
    d2 = params[1]
    d3 = params[2]
    d5 = params[3]
    a2 = params[4]
    c0 = params[5]

    # Rescale from normalized to regular values
    x_rescaled = rescale_vector(x,
                                model=model,
                                normalized=normalized,
                                bounds=bounds,
                                scaling=scaling)
    if model == 'lra_fit':
        # Retrieve independent variables
        rc = x_rescaled[0]
        ver = x_rescaled[1]
        ip3 = x_rescaled[2]
        C0 = x_rescaled[3]
        h0 = x_rescaled[4]

        # Set new ICs (ca_trace is a handle to a spline object)
        ICs = np.asarray([C0, h0], dtype=float)

        # Generate astrocyte model
        astro = models.Astrocyte(model='lra',
                                 c1=0.5,
                                 rl=0.1,
                                 c0=c0,
                                 Ker=0.1,
                                 d1=d1,
                                 d2=d2,
                                 d3=d3,
                                 d5=d5,
                                 a2=a2,
                                 ICs=ICs,
                                 rc=rc,
                                 ver=ver,
                                 ip3=ip3)
    elif model == 'chi':
        # Retrieve case-specific fixed parameters
        rc = params[6]
        ver = params[7]
        iset = int(params[8])

        # Assign rescaled variables
        vbeta = x_rescaled[0]
        vdelta = x_rescaled[1]
        v3k = x_rescaled[2]
        r5p = x_rescaled[3]
        C0 = x_rescaled[4]
        h0 = x_rescaled[5]
        I0 = x_rescaled[6]

        # Set new ICs (ca_trace is a handle to a spline object)
        ICs = np.asarray([I0, C0, h0], dtype=float)
        # Generate astrocyte model
        astro = models.Astrocyte(model='chi',
                                 c1=0.5,
                                 rl=0.1,
                                 c0=c0,
                                 Ker=0.1,
                                 rc=rc,
                                 ver=ver,
                                 d1=d1,
                                 d2=d2,
                                 d3=d3,
                                 d5=d5,
                                 a2=a2,
                                 ICs=ICs,
                                 vbeta=vbeta,
                                 vdelta=vdelta,
                                 v3k=v3k,
                                 r5p=r5p)
    elif (model != 'pkc2') and ('pkc' in model):
        rc = params[6]
        ver = params[7]
        r5p = params[8]
        rtot = params[9]

        yrel = x_rescaled[0]
        vbeta = x_rescaled[1]
        vdelta = x_rescaled[2]
        v3k = x_rescaled[3]
        vkp = x_rescaled[4]
        vk = x_rescaled[5]
        vd = x_rescaled[6]
        # ICs
        C0 = x_rescaled[7]
        h0 = x_rescaled[8]
        I0 = x_rescaled[9]
        g0 = x_rescaled[10]
        D0 = x_rescaled[11]
        P0 = x_rescaled[12]

        # Set new ICs (ca_trace is a handle to a spline object)
        ICs = np.asarray([g0, I0, C0, h0, D0, P0], dtype=float)
        # Generate astrocyte model
        astro = models.Astrocyte(model='pkc',
                                 c1=0.5,
                                 rl=0.1,
                                 c0=c0,
                                 Ker=0.1,
                                 rc=rc,
                                 ver=ver,
                                 d1=d1,
                                 d2=d2,
                                 d3=d3,
                                 d5=d5,
                                 a2=a2,
                                 vbeta=vbeta,
                                 vdelta=vdelta,
                                 v3k=v3k,
                                 r5p=r5p,
                                 yrel=yrel,
                                 vkp=vkp,
                                 vk=vk,
                                 vd=vd,
                                 rtot=rtot,
                                 ICs=ICs)
    elif model == 'pkc2':
        rc = params[6]
        ver = params[7]
        vbeta = params[8]
        vdelta = params[9]
        v3k = params[10]
        r5p = params[11]
        rtot = params[12]

        yrel = x_rescaled[0]
        Kkc = x_rescaled[1]
        vkp = x_rescaled[2]
        vk = x_rescaled[3]
        vd = x_rescaled[4]
        # ICs
        C0 = x_rescaled[5]
        h0 = x_rescaled[6]
        I0 = x_rescaled[7]
        g0 = x_rescaled[8]
        D0 = x_rescaled[9]
        P0 = x_rescaled[10]

        # Set new ICs (ca_trace is a handle to a spline object)
        ICs = np.asarray([g0, I0, C0, h0, D0, P0], dtype=float)
        # Generate astrocyte model
        astro = models.Astrocyte(model='pkc',
                                 c1=0.5,
                                 rl=0.01,
                                 c0=c0,
                                 Ker=0.1,
                                 rc=rc,
                                 ver=ver,
                                 d1=d1,
                                 d2=d2,
                                 d3=d3,
                                 d5=d5,
                                 a2=a2,
                                 vbeta=vbeta,
                                 vdelta=vdelta,
                                 v3k=v3k,
                                 r5p=r5p,
                                 yrel=yrel,
                                 Kkc=Kkc,
                                 vkp=vkp,
                                 vk=vk,
                                 vd=vd,
                                 rtot=rtot,
                                 ICs=ICs)

    # Integrate
    if model in ['lra_fit', 'chi']:
        tfin = ca_exp['time'][0][-1]
    elif 'pkc' in model:
        tfin = ca_exp['time'][-1]

    # 'lra' and 'chi'
    ATOL = 1e-8
    RTOL = 1e-6
    # 'pkc'
    ATOL = 1e-4
    RTOL = 1e-4

    options = su.solver_opts(t0=0.0,
                             tfin=tfin,
                             dt=1e-2,
                             atol=ATOL,
                             rtol=RTOL,
                             method="gsl_msadams")
    astro.integrate(algparams=options, normalized=True)
    # Generate spline from solution for later comparison with experimental data
    ca_sol = interpolate.UnivariateSpline(astro.sol['ts'],
                                          astro.sol['ca'],
                                          k=3,
                                          s=0)
    pkc_sol = interpolate.UnivariateSpline(astro.sol['ts'],
                                           astro.sol['pkc'],
                                           k=3,
                                           s=0)

    if model == 'lra_fit':
        # Compute max/min
        # _, md = relextrema(ca_exp['ca'])
        mns, mxs = relextrema(astro.sol['ca'])
        index = np.sort(np.r_[ca_exp['mean_imin'], ca_exp['mean_imax']])
        # Fitness on max/min + number of oscillations
        fc = np.sum((ca_sol(ca_exp['time'][0][index]) -
                     ca_exp['mean_smoothed'][index])**2)
        fc += 1000. * ((np.size(mxs) - np.size(ca_exp['mean_imax']))**2 +
                       (np.size(mns) - np.size(ca_exp['mean_imin']))**2)
        # fc += 1000. * ((np.size(mxs) - np.size(ca_exp['mean_imax'])) ** 2)
        # Add mean oscillation amplitude
        # fc += 1500.*(1.-(np.mean(ca_exp['mean_smoothed'][ca_exp['mean_imax']]) - np.mean(ca_exp['mean_smoothed'][ca_exp['mean_imin']]))/(np.mean(astro.sol['ca'][mxs])-np.mean(astro.sol['ca'][mns])))**2
        # Add distance between oscillation amplitudes
        if (np.size(mxs) == np.size(
                ca_exp['mean_imax'])) and (np.size(mns) == np.size(
                    ca_exp['mean_imin'])):
            fc += 2000. * np.sum(
                (osc_amplitude(ca_exp['mean_smoothed'], ca_exp['mean_imin'],
                               ca_exp['mean_imax']) -
                 osc_amplitude(astro.sol['ca'], mns, mxs))**2)
        else:
            fc *= 1e6
        # print fc
    elif model == 'chi':
        # (Same as 'lra_fit' but considering iset)
        mns, mxs = relextrema(astro.sol['ca'])
        index = np.sort(np.r_[ca_exp['imin'][iset], ca_exp['imax'][iset]])
        # Fitness on max/min + number of oscillations
        fc = np.sum((ca_sol(ca_exp['time'][iset][index]) -
                     ca_exp['smoothed'][iset][index])**2)
        fc += 1000. * ((np.size(mxs) - np.size(ca_exp['imax'][iset]))**2 +
                       (np.size(mns) - np.size(ca_exp['imin'][iset]))**2)
        # fc += 1000. * ((np.size(mxs) - np.size(ca_exp['imax'][iset])) ** 2)
        # Add mean oscillation amplitude
        # fc += 1500.*(1.-(np.mean(ca_exp['smoothed'][ca_exp['imax'][iset]]) - np.mean(ca_exp['smoothed'][ca_exp['imin'][iset]]))/(np.mean(astro.sol['ca'][mxs])-np.mean(astro.sol['ca'][mns])))**2
        # Add distance between oscillation amplitudes and phase difference
        if (np.size(mxs) == np.size(
                ca_exp['imax'][iset])) and (np.size(mns) == np.size(
                    ca_exp['imin'][iset])):
            fc += 2000. * np.sum(
                (osc_amplitude(ca_exp['smoothed'][iset], ca_exp['imin'][iset],
                               ca_exp['imax'][iset]) -
                 osc_amplitude(astro.sol['ca'], mns, mxs))**2)
            fc += 2000. * np.sum(
                np.abs(ca_exp['time'][iset][ca_exp['imax'][iset]] -
                       astro.sol['ts'][mxs]))
        else:
            fc *= 1e6

    del astro  # Clean object
    return fc
Пример #4
0
def pkc_effect(sim=False):
    """
    Shows ExGChI and compare with data from Codazzi et al (CON 2001)
    """

    # Load relevant data
    ca_data = svu.loaddata('../data/codazzi_data.pkl')[0]
    po_data = svu.loaddata('../data/fit_po.pkl')[0]
    lr_data = svu.loaddata('../data/fit_lra.pkl')[0]
    chi_data = svu.loaddata('../data/chi_fit_0_bee.pkl')[0]

    if sim:
        print "1. Simulate PKC dynamics according to Codazzi"
        # yrel = 1.508
        yrel = 1.48
        # yrel = 1.448
        c0 = 5.0
        rc = 0.8 * lr_data[0]
        ver = lr_data[1]
        vbeta = 1.0
        vdelta = chi_data[1]
        v3k = 1.4 * chi_data[2]
        r5p = chi_data[3]

        vk = 1.0
        vkd = 0.28
        OmegaKD = 0.33
        vd = 0.45
        OmegaD = 0.26

        astro = models.Astrocyte(model='pkc',
                                 d1=po_data[0],
                                 d2=po_data[1],
                                 d3=po_data[0],
                                 d5=po_data[2],
                                 a2=po_data[3],
                                 c1=0.5,
                                 rl=0.01,
                                 Ker=0.1,
                                 rc=rc,
                                 ver=ver,
                                 Kkc=0.5,
                                 Kkd=0.1,
                                 Kdd=0.1,
                                 c0=c0,
                                 yrel=yrel,
                                 vbeta=vbeta,
                                 vdelta=vdelta,
                                 v3k=v3k,
                                 r5p=r5p,
                                 vk=vk,
                                 vkd=vkd,
                                 OmegaKD=OmegaKD,
                                 vd=vd,
                                 OmegaD=OmegaD,
                                 ICs=np.asarray(
                                     [0.0, 0.05, 0.05, 0.9, 0.0, 0.0]))

        # Preliminary integration to start from resting conditions
        options = su.solver_opts(t0=0.0,
                                 tfin=60.,
                                 dt=1e-4,
                                 atol=1e-4,
                                 rtol=1e-4,
                                 method="gsl_msadams")
        astro.integrate(algparams=options, normalized=False)
        # Update model with new ICs and add pulse train
        options = su.solver_opts(t0=0.0,
                                 tfin=ca_data['time'][-1],
                                 dt=1e-4,
                                 atol=1e-4,
                                 rtol=1e-4,
                                 method="gsl_msadams")
        astro.ICs = np.r_[astro.sol['rec'][-1], astro.sol['ip3'][-1],
                          astro.sol['ca'][-1], astro.sol['h'][-1],
                          astro.sol['dag'], astro.sol['pkc']]
        astro.integrate(algparams=options, normalized=False)
        sol_fit = astro.sol
        # _,sol_0,sol_1,sol_2 = svu.loaddata('../data/pkc_qual_fit.pkl')
        # svu.savedata([sol_fit,sol_0,sol_1,sol_2],'../data/pkc_qual_fit.pkl')

        # Second simulation
        print "2. Show effect of O_K"
        # First standard astrocyte without
        astro.pars['yrel'] = 1.55
        astro.pars['vkd'] = 0.0
        astro.pars['vk'] = 0.0
        options = su.solver_opts(t0=0.0,
                                 tfin=30,
                                 dt=1e-4,
                                 atol=1e-4,
                                 rtol=1e-4,
                                 method="gsl_msadams")
        astro.integrate(algparams=options, normalized=False)
        sol_0 = astro.sol

        astro.pars['vkd'] = 0.28
        astro.pars['vk'] = 1.0
        astro.integrate(algparams=options, normalized=False)
        sol_1 = astro.sol

        astro.pars['vk'] = 3.0
        astro.integrate(algparams=options, normalized=False)
        sol_2 = astro.sol

        # Save data
        svu.savedata([sol_fit, sol_0, sol_1, sol_2],
                     '../data/pkc_qual_fit.pkl')

        # # Third simulation (requires PyDSTool)
        print "3. Computing oscillation period (requires PyDSTool)"
        # Effective computation
        pkc0 = bif.compute_period(vkd=0.001, vk=0.001)
        svu.savedata([pkc0], '../data/pkc_period_Ok.pkl')
        pkc1 = bif.compute_period(vkd=0.28, vk=1.0)
        svu.savedata([pkc0, pkc1], '../data/pkc_period_Ok.pkl')
        pkc2 = bif.compute_period(vkd=0.28, vk=3.0)
        svu.savedata([pkc0, pkc1, pkc2], '../data/pkc_period_Ok.pkl')
        pkc3 = bif.compute_period(vkd=0.84, vk=1.0)
        svu.savedata([pkc0, pkc1, pkc2, pkc3], '../data/pkc_period_Ok.pkl')
        pkc4 = bif.compute_period(vkd=0.84, vk=3.0)
        svu.savedata([pkc0, pkc1, pkc2, pkc3, pkc4],
                     '../data/pkc_period_Ok.pkl')
    #---------------------------------------------------------------------
    # Plot figure
    #---------------------------------------------------------------------
    # Load MPL default style
    plt.style.use('figures.mplstyle')

    # Load data
    sol, pkc0, pkc1, pkc2 = svu.loaddata('../data/pkc_qual_fit.pkl')

    colors = {'ctrl': '0.7'}

    #---------------------------------------------------------------------------------------------------------
    # Fit with experimental data
    #---------------------------------------------------------------------------------------------------------
    fig, ax = plt.subplots(nrows=2,
                           ncols=1,
                           figsize=(6, 5.5),
                           sharex=False,
                           gridspec_kw={
                               'height_ratios': [1, 1],
                               'top': 0.96,
                               'bottom': 0.12,
                               'left': 0.15,
                               'right': 0.95
                           })

    # # Plot experimental data
    ax[0].plot(ca_data['original']['ca'][:, 0],
               normalize(ca_data['original']['ca'][:, 1]),
               'k-',
               label='Ca$^{2+}$')
    ax[0].plot(ca_data['original']['pkc'][:, 0],
               normalize(ca_data['original']['pkc'][:, 1]),
               'r-',
               label='cPKC$^*$')

    # Plot solution
    tclip = [3, 27]
    # # Mask
    cmn, _ = fd.relextrema(sol['ca'])
    pmn, _ = fd.relextrema(sol['pkc'])
    cbase = (sol['ca'][cmn].max() - sol['ca'][cmn].min()) / 2
    # pbase = (sol['pkc'][pmn].max() - sol['pkc'][pmn].min())/2
    cbase += sol['ca'][cmn].min()
    pbase = sol['pkc'][pmn].min()
    cmask = np.where((tclip[0] <= sol['ts']) & (sol['ts'] < tclip[1])
                     & (sol['ca'] > cbase))[0]
    pmask = np.where((tclip[0] <= sol['ts']) & (sol['ts'] < tclip[1])
                     & (sol['pkc'] > pbase))[0]
    # # Effective plotting
    ax[1].plot(sol['ts'][cmask] - sol['ts'][cmask[0]],
               normalize(sol['ca'][cmask], min=cbase), 'k-')
    ax[1].plot(sol['ts'][pmask] - sol['ts'][cmask[0]],
               normalize(sol['pkc'][pmask], min=pbase), 'r-')

    # Fit Check
    # ax[1].plot(sol['ts'], normalize(sol['ca']), 'k-')
    # ax[1].plot(sol['ts'], normalize(sol['pkc']), 'r-')
    # ax[0].plot(sol['ts'], sol['ca'], 'k-', sol['ts'][cmn], sol['ca'][cmn], 'ko', sol['ts'][[0,-1]], [cbase, cbase], 'b-', ms=6)
    # ax[0].plot(sol['ts'], sol['pkc'], 'r-', sol['ts'][pmn], sol['pkc'][pmn], 'ro', ms=6)

    # Adjust axes
    pu.adjust_spines(ax[0], ['left', 'bottom'])
    ax[0].set(xlim=(0., 140),
              xticks=np.arange(0, 141, 35),
              ylim=(-0.02, 1.05),
              yticks=np.arange(0, 1.1, 0.5),
              ylabel='Experimental\nTraces (n.u.)')
    pu.adjust_spines(ax[1], ['left', 'bottom'])
    ax[1].set(xlim=(0., 20),
              xticks=np.arange(0., 30, 5),
              ylim=(-0.02, 1.05),
              yticks=np.arange(0, 1.1, 0.5),
              xlabel='Time (s)',
              ylabel='Simulated\nTraces (n.u.)')
    # # Final adjustment of y-labels
    pu.adjust_ylabels(ax, x_offset=-0.08)
    # Add legend
    ax[0].legend(loc='upper right', facecolor='w', edgecolor='none')

    # Save figure
    plt.savefig('../Figures/f4_pkc_model.eps', dpi=600)

    # ---------------------------------------------------------------
    # Build effect of O_k on period
    # ---------------------------------------------------------------
    fig, ax = plt.subplots(nrows=3,
                           ncols=1,
                           figsize=(6, 4.5),
                           sharex=False,
                           gridspec_kw={
                               'height_ratios': [1, 1, 1],
                               'top': 0.96,
                               'bottom': 0.12,
                               'left': 0.17,
                               'right': 0.95
                           })

    # C
    ax[0].plot(pkc0['ts'], pkc0['ca'], '-', color=colors['ctrl'])
    ax[0].plot(pkc1['ts'], pkc1['ca'], 'k-')
    ax[0].plot(pkc2['ts'], pkc2['ca'], 'k-.')
    # D
    # First line is a dummy one to add proper legend in this plot rather than on the top one
    # ax[1].plot(pkc0['ts'][[0,1]],pkc0['dag'][[0,1]],'-',color=colors['ctrl'],label='$O_{K}=0$')
    ax[1].plot(pkc0['ts'],
               pkc0['dag'],
               '-',
               color=colors['ctrl'],
               label='$O_{K}=0$')
    ax[1].plot(pkc1['ts'],
               pkc1['dag'],
               'k-',
               label='$O_{K}=1.0$ $\mu$M$^{-1}$s$^{-1}$')
    ax[1].plot(pkc2['ts'],
               pkc2['dag'],
               'k-.',
               label='$O_{K}=3.0$ $\mu$M$^{-1}$s$^{-1}$')
    # P
    ax[2].plot(pkc0['ts'],
               pkc0['pkc'],
               '-',
               color=colors['ctrl'],
               label='$O_{K}=0$')
    ax[2].plot(pkc1['ts'],
               pkc1['pkc'],
               'k-',
               label='$O_{K}=1.0$ $\mu$M$^{-1}$s$^{-1}$')
    ax[2].plot(pkc2['ts'],
               pkc2['pkc'],
               'k-.',
               label='$O_{K}=3.0$ $\mu$M$^{-1}$s$^{-1}$')

    # Adjust axes
    pu.adjust_spines(ax[0], ['left'])
    ax[0].set(xlim=(0., 30),
              xticks=[],
              ylim=(-0.02, 0.6),
              yticks=np.arange(0, 0.61, 0.2),
              ylabel='Ca$^{2+}$\n($\mu$M)')
    pu.adjust_spines(ax[1], ['left'])
    ax[1].set(xlim=(0., 30),
              xticks=[],
              ylim=(-0.02, 0.41),
              yticks=np.arange(0, 0.4, 0.1),
              ylabel='DAG\n($\mu$M)')
    pu.adjust_spines(ax[2], ['left', 'bottom'])
    ax[2].set(
        xlim=(0., 30),
        xticks=np.arange(0., 31, 10),
        ylim=(-0.01, 0.075),
        yticks=np.arange(0, 0.071, 0.02),
        yticklabels=[str(int(i * 1e3)) for i in np.arange(0, 0.071, 0.02)],
        xlabel='Time (s)',
        ylabel='cPKC$^{*}$\n(nM)')
    # # Final adjustment of y-labels
    pu.adjust_ylabels(ax, x_offset=-0.08)
    # Add legend
    ax[2].legend(loc='upper right', facecolor='w', edgecolor='none')

    # Save figure
    plt.savefig('../Figures/f4_pkc_osc_1.eps', dpi=600)

    #---------------------------------------------------------------
    # Plot period of oscillations
    #---------------------------------------------------------------
    p0, p1, p2, p3, p4 = svu.loaddata('../data/pkc_period_Ok.pkl')

    fig, ax = plt.subplots(nrows=2,
                           ncols=1,
                           figsize=(6, 4.5),
                           sharex=False,
                           gridspec_kw={
                               'height_ratios': [1, 2],
                               'top': 0.96,
                               'bottom': 0.12,
                               'left': 0.17,
                               'right': 0.95
                           })

    for i, p in enumerate([p0, p1, p2, p3, p4]):
        # idx = (p['T'] > 3.5)
        idx = np.argsort(p['T'][(p['T'] > 3.5)])[::-1]
        if i == 3: idx = idx[0:-2]
        p['T'] = p['T'][idx]
        p['yrel'] = p['yrel'][idx]
    mask = lambda period: np.argsort(1.0 / period)
    ax[1].plot(p0['yrel'][mask(p0['T'])],
               p0['T'][mask(p0['T'])],
               '-',
               color=colors['ctrl'],
               label='O$_{KD}$=0')
    ax[1].plot(p1['yrel'][mask(p1['T'])],
               p1['T'][mask(p1['T'])],
               'k-',
               zorder=5,
               label='O$_{KD}$=0.28 $\mu$Ms$^{-1}$')
    ax[1].plot(p2['yrel'][mask(p2['T'])],
               p2['T'][mask(p2['T'])],
               'b-',
               zorder=5,
               label='O$_{KD}$=0.84 $\mu$Ms$^{-1}$')
    ax[1].plot(p3['yrel'][mask(p3['T'])], p3['T'][mask(p3['T'])], 'k-.')
    ax[1].plot(p4['yrel'][mask(p4['T'])], p4['T'][mask(p4['T'])], 'b-.')

    # Adjust axes
    ax[0].set_visible(False)
    pu.adjust_spines(ax[1], ['left', 'bottom'])
    ax[1].set(xlim=(1.4, 1.9),
              xticks=np.arange(1.4, 1.95, 0.1),
              ylim=(3.5, 15),
              yticks=np.arange(4, 15.1, 3),
              xlabel='Glu ($\mu$M)',
              ylabel='Oscillation Period (s)')

    # Add Legend
    ax[1].legend(loc='upper right', facecolor='w', edgecolor='none')

    # Save figure
    plt.savefig('../Figures/f4_pkc_osc_2.eps', dpi=600)

    plt.show()
Пример #5
0
def chi_model():
    """
    Provide sample fits for sole ChI model.

    """

    # Load MPL default style
    plt.style.use('figures.mplstyle')

    #--------------------------------------------------------------------------
    # Plot open probability
    #--------------------------------------------------------------------------
    p_open = svu.loaddata('../data/p_open.pkl')[0]
    po_data = svu.loaddata('../data/fit_po.pkl')[0]

    # Load significant data
    astro = models.Astrocyte(model='lra',
                             d1=po_data[0],
                             d2=po_data[1],
                             d3=po_data[0],
                             d5=po_data[2],
                             a2=po_data[3])

    # # p_open vs. IP3 was obtained with 0.25 uM free Ca2+
    astro.popen(0.25, p_open['ip3'][0])
    po_ip3 = astro.po
    # print po_ip3

    # p_open vs. Ca2+ was obtained with 1 uM IP3
    astro.popen(p_open['ca'][0], 1.0)
    po_ca = astro.po

    fig, ax = plt.subplots(nrows=1,
                           ncols=2,
                           figsize=(10, 4),
                           sharex=False,
                           gridspec_kw={
                               'top': 0.98,
                               'bottom': 0.15,
                               'left': 0.1,
                               'right': 0.98
                           })

    ax[0].plot(p_open['ip3'][0],
               p_open['ip3'][1],
               'k^',
               ms=10,
               ls='none',
               label=r'Ca$^{2+}$=25 nM')
    ax[0].plot(p_open['ca'][0],
               p_open['ca'][1],
               'ko',
               ms=10,
               ls='none',
               label=r'IP$_3$=1 $\mu$M')
    ax[0].plot(p_open['ip3'][0], po_ip3, 'k--')
    ax[0].plot(p_open['ca'][0], po_ca, 'k-')
    # Adjust axes
    pu.adjust_spines(ax[0], ['left', 'bottom'])
    xticks = 10**np.arange(-2, 2.1, 1)
    ax[0].set(xlim=(0.008, 500),
              ylim=(0., 0.5),
              yticks=np.arange(0., 0.51, 0.1),
              xscale='log',
              xlabel=r'Ca$^{2+}$, IP$_3$ ($\mu$M)',
              ylabel='IP$_3$R open probability')
    ax[0].set(xticks=xticks, xticklabels=([str(xt) for xt in xticks]))
    # Add legend
    ax[0].legend(loc='lower right', facecolor='w', edgecolor='none')

    #--------------------------------------------------------------------------
    # Plot ChI model from data
    #--------------------------------------------------------------------------
    # Load relevant data
    ca_data = svu.loaddata('../data/herzog_data.pkl')[0]
    lr_data = svu.loaddata('../data/fit_lra.pkl')[0]
    c0 = 5.0
    iset = 2

    colors = {
        'data': '0.65',
        'ca': 'k',
        'ip3': pu.hexc((44, 160, 44)),
        'h': pu.hexc((23, 190, 207))
    }

    # Colors for different data sets
    filename = 'chi_fit_0_bee'
    x_rescaled = svu.loaddata('../data/' + filename + '.pkl')[0]
    # Fitted data
    astro = models.Astrocyte(
        model='chi',
        d1=po_data[0],
        d2=po_data[1],
        d3=po_data[0],
        d5=po_data[2],
        a2=po_data[3],
        c0=c0,
        c1=0.5,
        rl=0.1,
        Ker=0.1,
        rc=lr_data[0],
        ver=lr_data[1],
        vbeta=x_rescaled[0],
        vdelta=x_rescaled[1],
        v3k=x_rescaled[2],
        r5p=x_rescaled[3],
        ICs=np.asarray([x_rescaled[6], x_rescaled[4], x_rescaled[5]]))
    options = su.solver_opts(t0=ca_data['time'][iset][0],
                             tfin=ca_data['time'][iset][-1],
                             dt=1e-4,
                             atol=1e-8,
                             rtol=1e-6,
                             method="gsl_msadams")
    astro.integrate(algparams=options, normalized=True)

    # Original data
    ax[1].plot(ca_data['time'][iset],
               ca_data['original'][iset],
               '.',
               ms=4,
               color=colors['data'],
               ls='none')
    # Fit data
    ax[1].plot(astro.sol['ts'],
               astro.sol['ca'],
               '-',
               color=colors['ca'],
               label='C')
    ax[1].plot(astro.sol['ts'],
               astro.sol['h'],
               '-',
               color=colors['h'],
               label='h')
    ax[1].plot(astro.sol['ts'],
               astro.sol['ip3'],
               '-',
               color=colors['ip3'],
               label='I')

    ax[1].set(xlim=(0, 30.),
              xticks=np.arange(0, 31, 5),
              ylim=(0., 1.01),
              yticks=np.arange(0., 1.1, 0.2),
              xlabel='Time (s)',
              ylabel='$ChI$ variables (n.u.)')
    pu.adjust_spines(ax[1], ['left', 'bottom'])
    pu.adjust_ylabels(ax, x_offset=-0.1)
    # Add legend
    ax[1].legend(loc='lower right', facecolor='w', edgecolor='none')

    del astro
    plt.savefig('../Figures/f1_chi_model.eps', dpi=600)
    plt.show()
Пример #6
0
def compute_thr(**kwargs):
    """
    Simulation routine to compute CICR threshold
    """

    # Load relevant data from fits
    po_data = svu.loaddata('../data/fit_po.pkl')[0]
    lr_data = svu.loaddata('../data/fit_lra.pkl')[0]
    chi_data = svu.loaddata('../data/chi_fit_0_bee.pkl')[0]

    # Control parameter set
    pars = models.gchi_parameters(d1=po_data[0],
                                  d2=po_data[1],
                                  d3=po_data[0],
                                  d5=po_data[2],
                                  a2=po_data[3],
                                  c0=10.0,
                                  c1=0.5,
                                  rl=0.1,
                                  Ker=0.1,
                                  rc=lr_data[0],
                                  ver=10.0,
                                  vbeta=0.8,
                                  vdelta=2 * chi_data[1],
                                  v3k=chi_data[3],
                                  r5p=chi_data[3])
    # Custom parameters
    pars = gu.varargin(pars, **kwargs)

    # Simulation duration
    t0 = 0.0
    tfin = 20.0

    # Generate model
    astro = models.Astrocyte(model='gchi',
                             d1=pars['d1'],
                             d2=pars['d2'],
                             d3=pars['d3'],
                             d5=pars['d5'],
                             a2=pars['a2'],
                             c0=pars['c0'],
                             c1=pars['c1'],
                             rl=pars['rl'],
                             Ker=pars['Ker'],
                             rc=pars['rc'],
                             ver=pars['ver'],
                             vbeta=pars['vbeta'],
                             vdelta=pars['vdelta'],
                             v3k=pars['v3k'],
                             r5p=pars['r5p'],
                             ICs=np.asarray([0.0, 0.05, 0.05, 0.9]))
    options = su.solver_opts(t0=t0,
                             tfin=30.,
                             dt=1e-4,
                             atol=1e-8,
                             rtol=1e-6,
                             method="gsl_msadams")
    # First run to seek resting state
    astro.integrate(algparams=options, normalized=False)
    # Update model with new ICs and add pulse train
    options = su.solver_opts(t0=t0,
                             tfin=tfin,
                             dt=1e-4,
                             atol=1e-8,
                             rtol=1e-6,
                             method="gsl_msadams")
    astro.ICs = np.r_[astro.sol['rec'][-1], astro.sol['ip3'][-1],
                      astro.sol['ca'][-1], astro.sol['h'][-1]]
    astro.pars['T'] = tfin
    astro.pars['pw'] = tfin
    yb = np.arange(0.5, 5.0, 0.05)
    # yb = np.arange(1.0, 3.0, 0.3)
    Nt = np.size(yb)
    # Allocate results
    ca_traces = [None] * Nt
    ip3_traces = [None] * Nt
    bias_traces = [None] * Nt
    for i in xrange(Nt):
        astro.pars['yb'] = yb[i]
        # Effective simulation
        astro.integrate(algparams=options, normalized=False)
        # Save results
        ca_traces[i] = astro.sol['ca']
        ip3_traces[i] = astro.sol['ip3']
        bias_traces[i] = astro.bias(twin=[t0, tfin], dt=0.01)

    traces = {
        'yb': yb,
        'ts': astro.sol['ts'],
        'ca': ca_traces,
        'ip3': ip3_traces,
        'bias': bias_traces
    }
    del astro
    gc.collect()
    return traces, pars
Пример #7
0
def gchi_model():
    """
    Simulation of the G-ChI model with some pulse function
    """

    # Load relevant data from fits
    po_data = svu.loaddata('../data/fit_po.pkl')[0]
    lr_data = svu.loaddata('../data/fit_lra.pkl')[0]
    chi_data = svu.loaddata('../data/chi_fit_0_bee.pkl')[0]

    # Sample parameters
    c0 = 10.0
    ver = 10.0
    vbeta = 0.8
    v3k = chi_data[3]
    # Simulation duration
    t0 = 0.0
    tfin = 10.0
    # Generate model
    astro = models.Astrocyte(model='gchi',
                             d1=po_data[0],
                             d2=po_data[1],
                             d3=po_data[0],
                             d5=po_data[2],
                             a2=po_data[3],
                             c0=c0,
                             c1=0.5,
                             rl=0.1,
                             Ker=0.1,
                             rc=lr_data[0],
                             ver=ver,
                             vbeta=vbeta,
                             vdelta=2 * chi_data[1],
                             v3k=v3k,
                             r5p=chi_data[3],
                             ICs=np.asarray([0.0, 0.05, 0.05, 0.9]))
    options = su.solver_opts(t0=t0,
                             tfin=30.,
                             dt=1e-4,
                             atol=1e-8,
                             rtol=1e-6,
                             method="gsl_msadams")
    # First run to seek resting state
    astro.integrate(algparams=options, normalized=False)
    # Update model with new ICs and add pulse train
    options = su.solver_opts(t0=t0,
                             tfin=tfin,
                             dt=1e-4,
                             atol=1e-8,
                             rtol=1e-6,
                             method="gsl_msadams")
    astro.ICs = np.r_[astro.sol['rec'][-1], astro.sol['ip3'][-1],
                      astro.sol['ca'][-1], astro.sol['h'][-1]]
    astro.pars['T'] = (tfin - t0) / (3.0 * tfin)
    astro.pars['pw'] = 0.15 * astro.pars['T']
    astro.pars['yb'] = 8.
    # Effective simulation
    astro.integrate(algparams=options, normalized=True)
    # Retrieve bias
    bias = astro.bias(twin=[t0, tfin], dt=0.01)
    # Retrieve production and degradation terms
    prod = astro.ip3_production()
    degr = astro.ip3_degradation()

    #---------------------------------------------------------------------
    # Plot figure
    #---------------------------------------------------------------------
    # Load MPL default style
    plt.style.use('figures.mplstyle')
    colors = {
        'data': '0.65',
        'ca': 'k',
        'ip3': pu.hexc((44, 160, 44)),
        'Jbeta': pu.hexc((255, 127, 14)),  # Orange
        'Jdelta': pu.hexc((31, 119, 180)),  # Tourquois
        'J3k': pu.hexc((214, 39, 40)),  # DarkRed
        'J5p': pu.hexc((227, 119, 194))  # Magenta
    }
    fig, ax = plt.subplots(nrows=5,
                           ncols=1,
                           figsize=(8, 6.5),
                           sharex=False,
                           gridspec_kw={
                               'height_ratios': [0.5, 3, 3, 3, 3],
                               'top': 0.96,
                               'bottom': 0.12,
                               'left': 0.14,
                               'right': 0.95
                           })

    # Plot stimulation
    ax[0].plot(bias[0], bias[1], 'k-')
    ax[0].set(xlim=(t0, tfin),
              xticks=[],
              ylim=(-0.2, 1.05 * astro.pars['yb']),
              yticks=[],
              ylabel='Glu\n($\mu$M)')
    pu.adjust_spines(ax[0], ['left'])

    # Plot receptor activation
    ax[1].plot(astro.sol['ts'], astro.sol['rec'], 'k-')
    pu.adjust_spines(ax[1], ['left'])
    ax[1].set(xlim=(t0, tfin),
              xticks=[],
              ylim=(0., 0.3),
              yticks=np.arange(0., 0.31, 0.1),
              ylabel='Ast. Rec.\n$\Gamma_A$')

    # Plot Ca2+ / IP3
    ax[2].plot(astro.sol['ts'],
               astro.sol['ca'],
               '-',
               color=colors['ca'],
               label='C')
    ax[2].plot(astro.sol['ts'],
               astro.sol['ip3'],
               '-',
               color=colors['ip3'],
               label='I')
    pu.adjust_spines(ax[2], ['left'])
    ax[2].set(xlim=(t0, tfin),
              xticks=[],
              ylim=(-0.05, 1.01),
              yticks=np.arange(0, 1.1, 0.5),
              ylabel='Ca$^{2+}$, IP$_3$\n(n.u.)')
    ax[2].legend(loc='lower right', facecolor='w', edgecolor='none')

    # Plot IP3 production
    ax[3].plot(astro.sol['ts'],
               prod['Jbeta'],
               '-',
               color=colors['Jbeta'],
               label=r'J$_\beta$')
    ax[3].plot(astro.sol['ts'],
               prod['Jdelta'],
               '-',
               color=colors['Jdelta'],
               label=r'J$_\delta$')
    ax[3].plot(astro.sol['ts'], prod['Jbeta'] + prod['Jdelta'], 'k--')
    pu.adjust_spines(ax[3], ['left'])
    ax[3].set(xlim=(t0, tfin),
              xticks=[],
              ylim=(-0.02, 0.2),
              yticks=np.arange(0, 0.21, 0.1),
              ylabel='IP$_3$ prod.\n($\mu$M/s)')
    ax[3].legend(loc='lower right', facecolor='w', edgecolor='none')

    # Plot IP3 degradation
    ax[4].plot(astro.sol['ts'],
               degr['J5p'],
               '-',
               color=colors['J5p'],
               label=r'J$_{5P}$')
    ax[4].plot(astro.sol['ts'],
               degr['J3k'],
               '-',
               color=colors['J3k'],
               label=r'J$_{3K}$')
    ax[4].plot(astro.sol['ts'], degr['J5p'] + degr['J3k'], 'k--')
    pu.adjust_spines(ax[4], ['left', 'bottom'])
    ax[4].set(xlim=(t0, tfin),
              xticks=np.arange(t0, tfin + 1, 2.),
              ylim=(-0.05, 0.22),
              yticks=np.arange(0, 0.21, 0.1),
              xlabel='Time (s)',
              ylabel='IP$_3$ degr.\n($\mu$M/s)')
    ax[4].legend(loc='lower right', facecolor='w', edgecolor='none')

    # Final adjustment of y-labels
    pu.adjust_ylabels(ax, x_offset=-0.07)

    del astro
    plt.savefig('../Figures/f2_gchi_model.eps', dpi=600)
    plt.show()
Пример #8
0
                                                       self.pars['K3'], 1)
        degr['J5p'] = self.pars['r5p'] * solution['ip3']
        return degr

    def __del__(self):
        del self.pars
        del self.ICs


if __name__ == "__main__":
    # -------------------------------------------------------------------------------------------------
    # Testing Astrocyte class
    # -------------------------------------------------------------------------------------------------
    options = su.solver_opts(t0=0.0,
                             tfin=30.0,
                             dt=1e-4,
                             atol=1e-8,
                             rtol=1e-6,
                             method="gsl_msadams")

    # ##LRA model
    astro = Astrocyte(model='lra', ip3=0.8)
    astro.integrate(algparams=options, normalized=True)
    plt.plot(astro.sol['ts'], astro.sol['ca'], 'y-', astro.sol['ts'],
             astro.sol['h'], 'm-')

    # ##CHI model
    # astro = Astrocyte(model='chi',vbeta=1)
    # astro.integrate(algparams=options)
    # plt.plot(astro.sol['ts'], astro.sol['ip3'], 'c-', astro.sol['ts'], astro.sol['ca'], 'y-', astro.sol['ts'], astro.sol['h'], 'm-')

    # # ##G-CHI model