def estimate_phase_dev(cell, temperature): """ Final estimate for the circadian phase deviation. Parameters ---------- cell : string Cell condition. temperature : int Temperature condition. Returns ------- The standard deviation for the phase progression, and the periods. """ ######### CORRECTION BECAUSE NOT ENOUGH TRACES AT 34°C AND 40°C ######### print('CAUTION : Parameters for None temperature selected since not enough \ traces at 34°C and 40°C') temperature = None ##################### LOAD DATA ################## if cell == 'NIH3T3': path = "Data/NIH3T3.ALL.2017-04-04/ALL_TRACES_INFORMATION.p" dataClass=LoadData(path, 10000000, temperature = temperature, division = False) (ll_area, ll_signal, ll_nan_circadian_factor, ll_obs_phi, ll_peak, ll_idx_cell_cycle_start, T_theta, T_phi) = \ dataClass.load(load_annotation=True) #print(len(ll_area)) std, std_T = estimate_phase_dev_from_signal(ll_peak) elif cell == 'U2OS': path = "Data/U2OS-2017-03-20/ALL_TRACES_INFORMATION_march_2017.p" dataClass=LoadData(path, 10000000, temperature = temperature, division = True) (ll_area, ll_signal, ll_nan_circadian_factor, ll_obs_phi, ll_peak, ll_idx_cell_cycle_start, T_theta, T_phi) = \ dataClass.load(load_annotation=True) std, std_T = estimate_phase_dev_from_signal(ll_peak) #correction for the neglected coupling since dividing traces std = std*0.65 std_T = std_T *0.65 else: print("Cell type doesn't exist") ''' for (idx, l_signal), l_peak in zip(enumerate(ll_signal), ll_peak): plt.plot(l_signal) plt.plot(l_peak) plt.show() plt.close() if idx>17: break ''' return std, std_T
def estimate_OU_par(cell, temperature, W=None, gamma_A=0.03, gamma_B=0.03): """ Estimate mean and variance of OU processes given a set of conditions, according to which a set of traces is filtered. Parameters ---------- cell : string Cell type. temperature : integer Temperature condition. W : list Waveform. gamma_A : float Regression parameter for the amplitude. gamma_b : float Regression parameter for the background. Returns ------- The mean and standard deviations of the amplitude and the background. """ ######### CORRECTION BECAUSE NOT ENOUGH TRACES AT 34°C AND 40°C ######### print( 'CAUTION : Parameters for None temperature selected since not enough \ traces at 34°C and 40°C') temperature = None ##################### LOAD DATA ################ if cell == 'NIH3T3': path = "Data/NIH3T3.ALL.2017-04-04/ALL_TRACES_INFORMATION.p" dataClass = LoadData(path, 10000000, temperature=temperature, division=False) elif cell == 'U2OS': path = "Data/U2OS-2017-03-20/ALL_TRACES_INFORMATION_march_2017.p" dataClass = LoadData(path, 10000000, temperature=temperature, division=True) try: (ll_area, ll_signal, ll_nan_circadian_factor, ll_obs_phi, ll_peak, ll_idx_cell_cycle_start, T_theta, T_phi) = \ dataClass.load(load_annotation=True) except: dataClass.path = '../' + dataClass.path (ll_area, ll_signal, ll_nan_circadian_factor, ll_obs_phi, ll_peak, ll_idx_cell_cycle_start, T_theta, T_phi) = \ dataClass.load(load_annotation=True) return estimate_OU_par_from_signal(ll_signal, W, gamma_A, gamma_B)
def show_no_temperature_difference(): """ Plot the estimate of the phase at different temperatures. """ l_var = [] l_var_var = [] l_temp = [34,37,40] for temperature in l_temp: path = "Data/NIH3T3.ALL.2017-04-04/ALL_TRACES_INFORMATION.p" dataClass=LoadData(path, 10000000, temperature = temperature, division = False) (ll_area, ll_signal, ll_nan_circadian_factor, ll_obs_phi, ll_peak, \ ll_idx_cell_cycle_start, T_theta, T_phi) = \ dataClass.load(load_annotation=True) var,var_var = compute_phase_variance_with_confidence(ll_peak) l_var.append(var) l_var_var.append(var_var) plt.errorbar(l_temp, l_var, yerr = l_var_var, fmt='o') plt.xlim([33,41]) plt.xlabel("Temperature") plt.ylabel("Phase diffusion variance mean and deviation") plt.savefig('Results/RawData/var_diffusion.pdf') plt.show() plt.close()
def estimate_cycle_dev(cell, temperature): """ Final estimate for the cell-cycle phase deviation. Parameters ---------- cell : string Cell condition. temperature : int Temperature condition. Returns ------- The standard deviation for the phase progression, and the periods. """ ##################### LOAD DATA ################## if cell == 'NIH3T3': path = "Data/NIH3T3.ALL.2017-04-04/ALL_TRACES_INFORMATION.p" elif cell == 'U2OS': path = "Data/U2OS-2017-03-20/ALL_TRACES_INFORMATION_march_2017.p" dataClass=LoadData(path, 10000000, temperature = temperature, division = True) (ll_area, ll_signal, ll_nan_circadian_factor, ll_obs_phi, ll_peak, \ ll_idx_cell_cycle_start, T_theta, T_phi) = \ dataClass.load(load_annotation=True) std, std_T = estimate_phase_dev_from_div(ll_idx_cell_cycle_start) return std, std_T
def compute_likelihood_sigma(): """ Compute and plot the likelihood of the phase diffusion parameter, depending on the temperature. """ l_T = [34,37,40] l_likelihood_T = [] mean_IG = 24 domain_sigma = np.linspace(0.05, 0.3, 100) for T in l_T: path = "Data/NIH3T3.ALL.2017-04-04/ALL_TRACES_INFORMATION.p" dataClass=LoadData(path, 10000000, temperature = T, division = False) (ll_area, ll_signal, ll_nan_circadian_factor, ll_obs_phi, ll_peak, ll_idx_cell_cycle_start, T_theta, T_phi) = \ dataClass.load(load_annotation=True) l_T_clock=[] for l_peak in ll_peak: l_idx_peak = [idx for idx, i in enumerate(l_peak) if i==1] for t_peak_1, t_peak_2 in zip(l_idx_peak[:-1], l_idx_peak[1:]): #remove outliers T = (t_peak_2-t_peak_1)/2 if T<12 or T>38: #double or missing annotation pass else: l_T_clock.append(T ) l_likelihood = [] for sigma_theta in domain_sigma: lpx = np.log(1/sigma_theta) #lpx = 1 for T in l_T_clock: lpx = lpx + np.log(invgauss(T, mean_IG, 4*np.pi**2/sigma_theta**2)) l_likelihood.append( lpx/len(l_T_clock)) l_likelihood_T.append(l_likelihood) plt.plot(domain_sigma,l_likelihood_T[0], c = 'red', label = '34' ) plt.plot(domain_sigma,l_likelihood_T[1], c = 'blue',label = '37' ) plt.plot(domain_sigma,l_likelihood_T[2], c = 'orange',label = '40' ) plt.axvline(domain_sigma[np.argmax(l_likelihood_T[0])], c= 'red') plt.axvline(domain_sigma[np.argmax(l_likelihood_T[1])], c= 'blue') plt.axvline(domain_sigma[np.argmax(l_likelihood_T[2])], c= 'orange') plt.ylabel(r'$log(L(\sigma_\theta))$') plt.xlabel(r'$\sigma_\theta$' ) plt.legend() plt.savefig('Results/RawData/likelihood_sigma_theta.pdf') plt.show() plt.close()
def plot_hist_periods(cell, temperature, division): """ Given a cell condition, compute and plot a histgram of periods. Parameters ---------- cell : string Cell condition. """ ##################### LOAD DATA ################## if cell == 'NIH3T3': path = "../Data/NIH3T3.ALL.2017-04-04/ALL_TRACES_INFORMATION.p" else: path = "../Data/U2OS-2017-03-20/ALL_TRACES_INFORMATION_march_2017.p" dataClass = LoadData(path, 10000000, temperature=temperature, division=division) (ll_area, ll_signal, ll_nan_circadian_factor, ll_obs_phi, ll_peak, ll_idx_cell_cycle_start, T_theta, T_phi) \ = dataClass.load(load_annotation=True) if division: ##################### COMPUTE CELL CYCLE DISTRIBUTION ################## l_T_cell_cycle = [] for l_div_index in ll_idx_cell_cycle_start: for t1, t2 in zip(l_div_index[:-1], l_div_index[1:]): l_T_cell_cycle.append((t2 - t1) / 2) ##################### COMPUTE CIRCADIAN CLOCK DISTRIBUTION ################# l_T_clock = [] for l_peak in ll_peak: l_idx_peak = [idx for idx, i in enumerate(l_peak) if i == 1] for t_peak_1, t_peak_2 in zip(l_idx_peak[:-1], l_idx_peak[1:]): l_T_clock.append((t_peak_2 - t_peak_1) / 2) ##################### PLOT BOTH DISTRIBUTIONS ################## bins = np.linspace(8, 38, 40) if division: plt.hist(l_T_cell_cycle, bins, alpha=0.5, label='cell-cycle') plt.hist(l_T_clock, bins, alpha=0.5, label='clock') plt.legend(loc='upper right') if division: plt.savefig('../Results/RawData/Distributions_div_'+str(temperature)\ +"_"+cell+'.pdf', bbox_inches='tight') else: plt.savefig('../Results/RawData/Distributions_nodiv_'+str(temperature)\ +"_"+cell+'.pdf', bbox_inches='tight') plt.close()
def plot_raw_traces(cell, temperature, division, nb_traces = 10): ##################### LOAD DATA ################## if cell == 'NIH3T3': path = "../Data/NIH3T3.ALL.2017-04-04/ALL_TRACES_INFORMATION.p" else: path = "../Data/U2OS-2017-03-20/ALL_TRACES_INFORMATION_march_2017.p" dataClass=LoadData(path, nb_traces, temperature = temperature, division = division, several_cell_cycles = False) (ll_area, ll_signal, ll_nan_circadian_factor, ll_obs_phi, ll_peak, ll_idx_cell_cycle_start, T_theta, T_phi) = dataClass.load(load_annotation=True) if division: #keep only long traces and crop them to_keep = [i for i, l_signal in enumerate(ll_signal)\ if len(l_signal)>100] ll_signal = [ll_signal[i][:100] for i in to_keep] ll_area = [ll_area[i][:100] for i in to_keep] ll_nan_circadian_factor = \ [ll_nan_circadian_factor[i][:100] for i in to_keep] ll_obs_phi = [ll_obs_phi[i][:100] for i in to_keep] ll_peak = [ll_peak[i][:100] for i in to_keep] ll_idx_cell_cycle_start = [ [j for j in ll_idx_cell_cycle_start[i] \ if j<100] for i in to_keep] zp = zip(enumerate(ll_signal), ll_nan_circadian_factor, ll_peak, ll_idx_cell_cycle_start) for (idx, l_signal), l_nan_circadian_factor, l_peak, l_idx_cc in zp: tspan = np.linspace(0,len(l_signal)/2, len(l_signal)) l_idx_peak = [idx for idx, i in enumerate(l_peak) if i>0] l_t_nan_circadian = [] i_temp = None for idxx, (i1, i2) in enumerate(zip(l_nan_circadian_factor[:-1], l_nan_circadian_factor[1:] )): if not i1 and i2: i_temp = (idxx+1)/2 if i1 and i2: pass if i1 and not i2: if i_temp == None: print('BUG') else: l_t_nan_circadian.append((i_temp, idxx/2)) i_temp = None plt.subplot(210+ idx%2+1 ) plt.plot(tspan, l_signal, '.', color = 'red') for p in l_idx_peak: #plt.axvline(p/2) pass for d in l_idx_cc: plt.axvline(d/2, color = 'black') for a,b in l_t_nan_circadian: #plt.axvspan(a, b, color='lightblue', alpha=0.5, lw=0) pass if idx%2==1: plt.tight_layout() plt.savefig('../Results/RawData/RawTrace_div_'+str(idx)+'_'\ +str(temperature)+"_"+cell+'.pdf') plt.show() plt.close() else: #keep only long traces and crop them so they all have the same size #(CAUTION, CODE FOR PEAK NOT CORRECT) ll_signal = [l_signal[:100] for l_signal in ll_signal \ if len(l_signal)>100] #ll_peak= [l_peak[:100] for l_signal, l_peak in zip(ll_signal, ll_peak)\ #if len(l_signal)>100] for (idx, l_signal), l_peak, in zip(enumerate(ll_signal), ll_peak): tspan = np.linspace(0,len(l_signal)/2, len(l_signal)) l_idx_peak = [idx for idx, i in enumerate(l_peak) if i>0] plt.subplot(210+ idx%2+1 ) plt.plot(tspan, l_signal, '.', color = 'orange') for p in l_idx_peak: #plt.axvline(p/2) pass if idx%2==1: plt.tight_layout() plt.savefig('../Results/RawData/RawTrace_nodiv_'+str(idx)+'_'\ +str(temperature)+"_"+cell+'.pdf') plt.show() plt.close()