Example #1
0
def objective_fn(position):
    """return the value of the objective function"""
    objective = []
    for k in conditions.keys():
        ysim = solve.simulate(position, observables=True, initial_conc=conditions[k])
        PARP_MLKL_signals   = ct.extract_records(ysim, ['Obs_cPARP', 'Obs_MLKL'])
        
        if (k == 'BidKO'):
            if max(PARP_MLKL_signals[0]>0):
                td_PARP = ct.calculate_time_delay(PARP_MLKL_signals[:,0], sims.tspan)
                td_MLKL = ct.calculate_time_delay(PARP_MLKL_signals[:,1], sims.tspan)
                if td_PARP < td_MLKL:
                    objective.append(abs(td_PARP - td_MLKL))
    
        else:
            ysim_array = ct.extract_records(ysim, ynorm[k][1])
            ysim_norm  = ct.normalize(ysim_array, option = 1)
            ysim_tp    = ct.cubic_spline(solve.options.tspan, ysim_norm, ynorm[k][0][:,0]*3600)
        
            if (k == 'Necr1'):
                objective.append(np.sum((ynorm[k][0][:,1] - ysim_tp) ** 2 / (2 * ynorm[k][0][:,2])))
        
            else:
                td_PARP = ct.calculate_time_delay(PARP_MLKL_signals[:,0], sims.tspan)
                td_MLKL = ct.calculate_time_delay(PARP_MLKL_signals[:,1], sims.tspan)
                if td_MLKL < td_PARP:
                    objective.append(np.sum((ynorm[k][0][:,1] - ysim_tp) ** 2 / (2 * ynorm[k][0][:,2]))+abs(td_PARP - td_MLKL))
                else:
                    objective.append(np.sum((ynorm[k][0][:,1] - ysim_tp) ** 2 / (2 * ynorm[k][0][:,2])))

    return np.sum(objective)
Example #2
0
def objective_fn(position):
    """return the value of the objective function"""
    ysim_norm = []
    for k in conditions.keys():
        ysim = solve.simulate(position,
                              observables=True,
                              initial_conc=conditions[k])
        ysim_array = ct.extract_records(ysim, ynorm[k][1])
        ysim_norm.append(ct.normalize(ysim_array, option=1))

    objective = []
    timepoints = [0, 21600, 43200, 86400]
    keys = conditions.keys()
    for i in range(len(ysim_norm)):
        ysim_tp = ct.cubic_spline(solve.options.tspan, ysim_norm[i],
                                  timepoints)  #ysim(t = expe. timepoints)

        # Modifiying the objective function to penalize, when an apoptotic cell behaves necrotically, and vice versa. I consider a cell apoptotic when the time-delay (i.e. the time at which the signal is at 50% maximum) of the apoptotic signal is less than that of the necrotic signal. This aproach works so long as the gain of the signals is not as senstive to conditions at the time-delay.

        PARP_MLKL_signals = ct.extract_records(ysim, ['Obs_cPARP', 'Obs_MLKL'])
        td_PARP = calculate_time_delay(PARP_MLKL_signals[:, 0])
        td_MLKL = calculate_time_delay(PARP_MLKL_signals[:, 1])

        if ((keys[i] == 'TKO') & (td_PARP < td_MLKL)
            ):  # | ((keys[i] == 'WT') & (td_PARP > td_MLKL)):
            objective.append(
                np.sum((ynorm[keys[i]][0][:, 1] - ysim_tp)**2 /
                       (2 * ynorm[keys[i]][0][:, 2])) + abs(td_PARP - td_MLKL))
        else:
            objective.append(
                np.sum((ynorm[keys[i]][0][:, 1] - ysim_tp)**2 /
                       (2 * ynorm[keys[i]][0][:, 2])))

    return np.sum(objective)
Example #3
0
def calculate_time_delay(signal):
    if np.isnan(np.sum(signal)):
        return None
    else:
        norm_signal = ct.normalize(signal, option = 0)
        norm_signal = norm_signal.tolist()
        idx         = norm_signal.index(min(norm_signal, key = lambda x: abs(x-0.5)))
        return ct.cubic_spline(norm_signal[idx-3:idx+3], solve.options.tspan[idx-3:idx+3], [0.5], degree = 1)
Example #4
0
def calculate_time_delay(signal):
    if np.isnan(np.sum(signal)):
        return None
    else:
        norm_signal = ct.normalize(signal, option = 0)
        norm_signal = norm_signal.tolist()
        idx         = norm_signal.index(min(norm_signal, key = lambda x: abs(x-0.5)))
        return ct.cubic_spline(norm_signal[idx-3:idx+3], solve.options.tspan[idx-3:idx+3], [0.5], degree = 1)
Example #5
0
 def assign_obs_values(self):
     #Chect to see that ysims, xsims not None
     self.signal = ct.extract_records(self.ysim, [i.strip() for i in self.observable.split(',')])
     if self.normalize:
         self.signal = ct.normalize(self.signal, option = self.normalize)
 
     if self.obs_func_input:
         if self.type == 'Quantitative':
             print max(self.signal)
         return self.obs_func(self.signal, self.obs_func_input, self.tspan)
     else:
         return self.obs_func(self.signal, self.tspan)
Example #6
0
def objective_fn(position):
    """return the value of the objective function"""
    objective = []
    for k in conditions.keys():
        ysim = solve.simulate(position, observables=True, initial_conc=conditions[k])
        ysim_array = ct.extract_records(ysim, ynorm[k][1])
        ysim_norm  = ct.normalize(ysim_array, option = 1)
        ysim_tp    = ct.cubic_spline(solve.options.tspan, ysim_norm, ynorm[k][0][:,0]*3600)
        
        objective.append(np.sum((ynorm[k][0][:,1] - ysim_tp) ** 2 / (2 * ynorm[k][0][:,2])))

    return np.sum(objective)
Example #7
0
def objective_fn(position):
    """return the value of the objective function"""
    objective = []
    for k in conditions.keys():
        ysim = solve.simulate(position,
                              observables=True,
                              initial_conc=conditions[k])
        ysim_array = ct.extract_records(ysim, ynorm[k][1])
        ysim_norm = ct.normalize(ysim_array, option=1)
        ysim_tp = ct.cubic_spline(solve.options.tspan, ysim_norm,
                                  ynorm[k][0][:, 0] * 3600)

        objective.append(
            np.sum((ynorm[k][0][:, 1] - ysim_tp)**2 / (2 * ynorm[k][0][:, 2])))

    return np.sum(objective)
Example #8
0
fitted_values = solve.cur_params(mcmc.position)[solve.estimate_idx]
for param, new_value in zip(sims.estimate_params, fitted_values):
    change = np.log10(new_value / param.value)
    values = (param.name, param.value, new_value, change)
    print '%-10s %-12.2g %-12.2g %-+6.2f' % values

#plot data
plt.ion()
tspan = sims.tspan/3600
initial_params = [p.value for p in sims.estimate_params]
ii = 0
colors = ['b', 'g', 'r', 'c']
for k in conditions.keys():
    plt.errorbar(ynorm[k][0][:,0], ynorm[k][0][:,1], yerr = ynorm[k][0][:,2], fmt = '%s.' % colors[ii], label = '%s data' % k)

    yinitial = ct.normalize(ct.extract_records(solve.simulate(np.log10(initial_params), observables = True, initial_conc = conditions[k]), ynorm[k][1]), option = 1)
    plt.plot(tspan, yinitial, '%s--' % colors[ii], label = 'initial %s' % k)

    yfinal = ct.normalize(ct.extract_records(solve.simulate(mcmc.position, observables=True, initial_conc=conditions[k]),ynorm[k][1]), option = 1)
    plt.plot(tspan, yfinal, '%s-' % colors[ii], label = 'final %s' % k)

    ii = ii+1

plt.xlabel('time [hrs]')
plt.title('Apoptotic and Necrotic Signals')
plt.legend(loc = 'lower left', bbox_to_anchor = (1.0, -0.02))


"""
TODO
Example #9
0
mcmc.run()

# print some information about the maximum-likelihood estimate parameter set
print
print '%-10s %-12s %-12s %s' % ('parameter', 'actual', 'fitted', 'log10(fit/actual)')
fitted_values = solve.cur_params(mcmc.position)[solve.estimate_idx]
for param, new_value in zip(sims.estimate_params, fitted_values):
    change = np.log10(new_value / param.value)
    values = (param.name, param.value, new_value, change)
    print '%-10s %-12.2g %-12.2g %-+6.2f' % values

# save data
initial_params = [p.value for p in sims.estimate_params]

for k in ydata.keys():
    yinitial = ct.normalize(ct.extract_records(solve.simulate(np.log10(initial_params), observables = True, initial_conc = conditions[k]), ynorm[k][1]), option = 1)
    pickle.dump(yinitial, open('%s_Initial_Values_%s.pkl' % (Exp_name, k), 'wb'))
    
    yfinal = ct.normalize(ct.extract_records(solve.simulate(mcmc.position, observables=True, initial_conc=conditions[k]),ynorm[k][1]), option = 1)
    pickle.dump(yfinal, open('%s_Final_Values_%s.pkl' % (Exp_name, k), 'wb'))

pickle.dump(mcmc.position, open('%s_Position.pkl' % Exp_name, 'wb'))


"""# plot data
plt.ion()
tspan = sims.tspan/3600
initial_params = [p.value for p in sims.estimate_params]
ii = 0
colors = ['b', 'g', 'r', 'c']