Browse Source

Upload scripts and db

Manuel Schottdorf 4 years ago
parent
commit
0b39861177
2 changed files with 263 additions and 0 deletions
  1. 30 0
      data.txt
  2. 233 0
      runme.py

+ 30 - 0
data.txt

@@ -0,0 +1,30 @@
+number	Folder			MEA		DIV	duration	disco		imaging		good_channels
+1	220416/m29166/		1_m29166	9	90		yes		no		21,31,61,12,22,42,23,63,73,85,16,47,67,87,28,38					DRIVEN!!!
+2	280416/m29166_spon/	1_m29166	15	60		yes		no		31,61,12,23,63,73,26,47,38,68							after RAND_short sim, 22 and 87 died out, removed from list.
+3	030516/m29166_spont/	1_m29166	20	35		yes		no		61,12,22,42,33,73,14,34,65,26,36,46,86,87,38
+4	060516/m29166_driven/	1_m29166	23	35		yes		yes		61,12,22,42,33,73,26,36,86,47,87,38
+5	130516/m29130/		2_m29130	9	30		yes		no		31,41,72,43,84,65,35
+6	130516/m29178/		a_m29178	9	40		control		no		61,71,13,63,16
+7	190516/m29117/		b_m29117	36	??		control		yes		41,42,52,62,43,54,24,74,84,45,25,17,67,87					DRIVEN!!!
+8	230516/m29081		3_m29081	12	60		yes		no		21,71,72,65,86,47,17
+9	230516/m29116		c_m29116	12	45		control		no		21,41,61,42,52,13,23,33,14,24,64,35,65,26,36,76,87,77,47,37,17,58,68
+10	230516/m29169		d_m29169	12	45		control		no		21,31,41,51,12,22,32,42,82,13,23,33,53,63,14,34,54,64,25,35,45,55,65,75,36,56,66,86,17,27,37,47,57,67,77,28,38,48,58,68
+11	310516/m29132/spont/	e_m29132	20	45		control		no		21,51,12,42,62,72,82,13,23,33,43,73,14,34,44,74,84,25,35,45,55,85,16,26,36,56,66,76,86,37,47,57,67,77,28,38,58,68,78
+12	310516/m29169/spont/	d_m29169	20	45		control		no		21,41,51,61,22,32,42,62,13,23,43,63,83,14,24,34,44,54,25,35,45,55,65,75,16,26,36,56,66,86,17,27,37,47,57,67,77,28,38,48,58,68
+13	140616/m29165_1/	4_m29165	13	50		yes		no		31,41,12,22,82,23,73,83,24,54,74,25,35,36,76,37,47,57,68
+14	140616/m29165_2/	4_m29165	13	70		yes		yes		74,25,47,68,76									Entire measurement died out, left out of analysis
+15	140616/m29168/		f_m29168	13	50		control		yes		71,12,42,13,23,33,43,63,14,24,34,74,84,45,85,16,46,86,47,38,48,68,78
+16	140616/m29166/		g_m29166	13	70		control		yes		21,31,41,51,61,12,52,62,72,82,73,14,24,54,64,65,85,56,66,86,47,67,77,38		DRIVEN?? Activity on analog check
+17	140616/m29151/		h_m29151	13	70		control		yes		21,12,22,42,62,33,53,73,34,44,25,35,45,75,16,46,86,27,77,87,28,38,48,68		DRIVEN?? Activity on analog check
+18	170616/m29130/spont/	i_m29130	16	30		control		yes		41,51,22,42,52,62,23,33,73,14,54,64,25,65,16,26,56,76,86,27,67,38,78		seems very non--stationary..
+19	280616/m29136/		k_m29136	13	120		control		no		21,41,51,61,71,12,22,32,42,52,72,82,13,33,43,53,63,73,83,24,44,54,64,74,84,25,35,45,55,65,75,85,16,26,36,46,56,76,86,17,27,37,47,57,67,77,87,38,58,68,78	After the recording we put culture on disco
+20	010716/m29136/spont/	5_m29136	16	30		yes		no		21,41,51,61,71,12,22,32,42,52,72,13,33,43,53,63,73,24,44,54,64,84,25,35,45,55,65,75,85,16,26,36,46,56,76,86,17,27,37,47,57,67,77,87,38,48,58,68,78		On disco since just 3 days
+21	010716/m29096/spont/	l_m29096	16	30		control		no		21,51,71,12,22,42,62,13,23,33,43,63,14,24,64,74,25,45,55,65,75,85,26,36,46,66,17,27,37,47,67,77,28,68,78	
+22	050716/m15808/spont/	m_m15808	20	30		control		yes		34										Very poor recording
+23	080716/m29136/spont/	5_m29136	23	30		yes		no		21,41,51,61,71,12,22,32,42,52,62,72,82,13,23,33,43,53,63,73,83,14,24,34,44,54,64,74,84,25,35,45,55,65,75,85,16,26,36,46,56,66,76,86,17,27,37,47,57,67,77,87,28,38,48,58,68	On disco since 10 days
+24	080716/m29096/spont/	l_m29096	23	30		control		no		21,31,51,71,12,22,32,42,72,82,13,43,53,63,83,14,44,54,74,25,35,45,55,65,75,85,16,36,76,17,37,47,57,77,28,38,58,68,78
+25	080716/m29133/		l_m29133	23	30		control		no		21,31,41,51,71,12,22,32,42,52,62,72,82,13,23,33,43,53,73,83,14,24,34,44,54,64,74,84,25,35,45,65,75,85,16,2636,46,56,66,76,86,17,27,37,47,57,67,77,87,28,38,48,58,68,78
+26	290716/spont/		5_m29136	44	60		yes		no		21,51,61,12,72,43,83,45,57,87							on disco since 31 days
+27	010816/spont/		5_m29136	47	60		yes		no		21,51,72,43,83,25,35,45,16,36,66,86,17,27,37,77,87,58				on disco since 34, but very strange PC of waveforms...
+28	030816/m29136/spont/	5_m29136	49	45		yes		no		51,12,22,72,43,83,24,44,25,17,27,37,77,87,58					since 36 days
+

+ 233 - 0
runme.py

@@ -0,0 +1,233 @@
+import pylab as pl
+import numpy as np
+from os import listdir, makedirs
+from os.path import isfile, join, isdir
+import seaborn as sns
+import scipy.optimize as opt
+
+
+from Helpers.file_helpers import data_dictionary_di
+
+experiments = [2,3,4,5,6,8,9,10,11,12,13,15,19,21,24,25]
+
+pathtofiles = '/Users/ms81/Desktop/Disco_plots'
+
+datapath = pathtofiles + '/Lightdisco_raw/'
+figure_path = pathtofiles + '/img/'
+
+
+days = []
+disco_flag = []
+culture_flag = []
+cvs = []
+info = []
+rates = []
+waveforms = []
+for ex in experiments:
+    print('Collecting...' + str(ex))
+    
+    di = data_dictionary_di(ex, verbose = 'True', infofile = '/Users/ms81/Desktop/Disco_plots/data.txt')
+    age = di[ex]['DIV']
+    discoflag = di[ex]['disco']
+    good_channels_file = di[ex]['channels']
+    culture = di[ex]['culture']
+    
+    saveresults = datapath + 'rawdata_' + str(ex)
+    a = np.load(saveresults + '.npy', encoding='latin1')
+    final_results = a.item()
+    elenumber = final_results['data_dict']['elenumber']
+    data = final_results['electrode_data']
+    sorted_dict = final_results['sorted_dict']
+    mean_waveforms = sorted_dict['mean_waveforms_good']
+
+    for ele in range(len(elenumber)):
+        if elenumber[ele] in good_channels_file:
+            spikes = data['Electrode_' + str(elenumber[ele])]
+            mu = np.mean(np.diff(spikes))
+            sigma = np.std(np.diff(spikes))
+            cv = sigma/mu
+            rate = len(spikes)/np.max(spikes)   #number of spike, until the last one
+            print( str(elenumber[ele]) + '  ' + str(cv) + '  ' + str(rate) )
+            cvs.append(cv)
+            rates.append(rate)
+            days.append(age)
+            info.append(elenumber[ele])
+            disco_flag.append(discoflag)
+            culture_flag.append(culture)
+            waveforms.append(mean_waveforms[ele])
+print('Collection done, now printing.')
+
+
+#~ sns.set_context("talk")
+sns.set_style("whitegrid")
+colors = sns.color_palette("Set3",n_colors=7)
+
+days_ref = []
+for s in days:
+    if s ==12 or s == 13 or s == 15 or s == 16:
+        days_ref.append(14)
+    if s == 20 or s == 23:
+        days_ref.append(21)
+    if s == 9:
+        days_ref.append(7)
+
+
+pl.figure(1, figsize = (15,5))
+pl.subplot(1,2,1)
+pl.title('CVs, Lightdisco vs. controls')
+sns.boxplot(x=days_ref, y=cvs, hue = disco_flag, palette=colors)
+pl.ylim([0,6])
+pl.xlabel('Age [DIV]')
+pl.ylabel('Coefficient of Variation')
+pl.subplot(1,2,2)
+pl.title('Firing rates, Lightdisco vs. controls')
+sns.boxplot(x=days_ref, y=rates, hue = disco_flag, palette="Set3")
+pl.ylim([0,5])
+pl.xlabel('Age [DIV]')
+pl.ylabel('Rates')
+pl.savefig(figure_path + 'fig1.pdf', bbox_inches='tight')
+pl.close()
+
+
+
+
+pl.figure(2, figsize = (15,5))
+pl.subplot(1,2,1)
+for i in range(len(days)):
+    if disco_flag[i] == 'yes':
+        pl.plot(days[i],cvs[i],'.', markerfacecolor = colors[int(culture_flag[i][0])])
+    else:
+        pl.plot(days[i]+.2,cvs[i],'b.')
+    #~ pl.text(days[i]+.5,cvs[i],info[i])
+pl.xlabel('DIV')
+pl.ylabel('Coefficient of Variation')
+pl.ylim([0,6])
+pl.subplot(1,2,2)
+for i in range(len(days)):
+    if disco_flag[i] == 'yes':
+        pl.plot(days[i],rates[i],'.', markerfacecolor = colors[int(culture_flag[i][0])])
+    else:
+        pl.plot(days[i]+.2,rates[i],'b.')
+    #~ pl.text(days[i]+.5,cvs[i],info[i])
+pl.xlabel('DIV')
+pl.ylabel('Firing Rate')
+pl.ylim([0,5])
+
+pl.savefig(figure_path + 'fig2.pdf', bbox_inches='tight')
+pl.close()
+
+
+pl.figure(3, figsize = (15,5))
+for i in range(len(days)):
+    if disco_flag[i] == 'yes':
+        pl.plot(cvs[i],rates[i],'r.')
+    else:
+        pl.plot(cvs[i],rates[i],'b.')
+pl.xlabel('CVs')
+pl.ylabel('Rate')
+pl.xlim([0,5])
+pl.ylim([0,15])
+pl.savefig(figure_path + 'fig3.pdf', bbox_inches='tight')
+pl.close()
+
+
+
+
+
+#This is the waveform figure
+
+
+def make_gaussian(xx, x0, stdx, a):
+    xx =  xx - x0
+    gauss = a*np.exp(-(xx*xx/(2.*stdx*stdx)))
+    return gauss
+
+
+ref = []
+fit = []
+fit_error = []
+discoshifted = []
+controlshifted = []
+c1, c2 = sns.color_palette("Set3", 2)
+
+
+pl.figure(4, figsize = (8,10))
+xx = np.linspace(0, 6, 150)    #0ms to 6 ms in 40mus steps
+for i in range(len(rates)):
+    wv = waveforms[i]
+    normalized = wv*1e6 #-wv/np.min(wv)
+    minwhere_ms = np.argmin(normalized)*6./150
+
+
+    popt, pcov = opt.curve_fit(make_gaussian, xx, wv, p0=(2,0.2,-1e-4))
+    perr = np.sqrt(np.diag(pcov))
+    gaussian_fitted = make_gaussian(xx, *popt)
+    fit.append(popt)
+    fit_error.append(perr)
+
+    if disco_flag[i] == 'yes':
+        pl.subplot(3,2,1)        
+        pl.plot(xx-minwhere_ms, normalized, color = c1, alpha = .1)
+        pl.ylim([-130,70])
+        ref.append(0)
+        wvsh = np.array([0 for i in range(300)])
+        start = int(minwhere_ms*150/6.)
+        wvsh[start:(150+start)] = normalized
+        discoshifted.append(wvsh)
+
+    else:
+        pl.subplot(3,2,2)
+        pl.plot(xx-minwhere_ms, normalized, color = c2, alpha = .05)
+        pl.ylim([-130,70])
+        ref.append(1)
+        wvsh = np.array([0 for i in range(300)])
+        start = int(minwhere_ms*150/6.)
+        wvsh[start:(150+start)] = normalized
+        controlshifted.append(wvsh)
+        
+fit = np.array(fit)
+pl.subplot(3,2,3)
+sns.boxplot(x=ref, y=np.abs(fit[:,1]), palette="Set3")
+pl.ylabel("width [ms]")
+pl.ylim([0,0.35])
+
+pl.subplot(3,2,4)
+sns.boxplot(x=ref, y=np.abs(fit[:,2])*1e6, palette="Set3")
+pl.ylabel("Amplitude [muV]")
+pl.ylim([0,160])
+
+pl.subplot(3,2,5)
+pl.fill_between(x=np.arange(300)*6./150, y1=np.mean(discoshifted,axis=0) - np.std(discoshifted,axis=0), y2=np.mean(discoshifted,axis=0) + np.std(discoshifted,axis=0),alpha=0.5,facecolor = c1)
+pl.plot(np.arange(300)*6./150,np.mean(discoshifted,axis=0),color = c1)
+pl.fill_between(x=np.arange(300)*6./150, y1=np.mean(controlshifted,axis=0) - np.std(controlshifted,axis=0), y2=np.mean(controlshifted,axis=0) + np.std(controlshifted,axis=0), alpha=0.5, facecolor = c2)
+pl.plot(np.arange(300)*6./150,np.mean(controlshifted,axis=0), color = c2)
+pl.xlim([2,8])
+
+
+pl.subplot(3,2,6)
+controldistro = np.mean(controlshifted,axis=0)
+dt = 6/150.
+ref = []
+dd = []
+for i in range(len(rates)):
+    wv = waveforms[i]
+    normalized = wv*1e6 #-wv/np.min(wv)
+    minwhere_ms = np.argmin(normalized)*6./150
+    if disco_flag[i] == 'yes':
+        ref.append(0)
+        wvsh = np.array([0 for i in range(300)])
+        start = int(minwhere_ms*150/6.)
+        wvsh[start:(150+start)] = normalized
+        dd.append(np.sqrt(dt*np.sum(controldistro - wvsh)**2))
+    else:
+        ref.append(1)
+        wvsh = np.array([0 for i in range(300)])
+        start = int(minwhere_ms*150/6.)
+        wvsh[start:(150+start)] = normalized
+        dd.append(np.sqrt(dt*np.sum(controldistro - wvsh)**2))
+
+
+sns.boxplot(x=ref, y=dd, palette="Set3")
+pl.ylabel("Deviation from control mean")
+pl.savefig(figure_path + 'fig4.pdf', bbox_inches='tight')
+pl.close()