-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCal_Synch.hoc
268 lines (237 loc) · 7.01 KB
/
Cal_Synch.hoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
// Calculate firing rate
objref mitrate, granrate, spk, hist
spk = new Vector()
mitrate = new Vector()
granrate = new Vector()
T = (tstop-ttrans)/1000
proc firing_rate() { local i, n
for i = 0, nMit-1 {
n = 0
if (mit[i].spiketimes.size() > 0) {
spk = mit[i].spiketimes
ind = spk.indwhere(">", ttrans)
if (ind != -1) {
//print ind
n = spk.size()-ind
}
}
mitrate.append(n/T)
}
for i = 0, nGran-1 {
n = 0
if (gran[i].spiketimes.size() > 0) {
spk = gran[i].spiketimes
ind = spk.indwhere(">", ttrans)
if (ind != -1) {
//print ind
n = spk.size()-ind
}
}
granrate.append(n/T)
}
print "\n Individual MC somatic firing rate:"
mitrate.printf()
print "\n The average MC somatic rate is:"
print mitrate.mean()
print "\n Individual GC dendritic firing rate:"
granrate.printf()
print "\n The average GC dendritic rate is:"
print granrate.mean()
// Create histogram
minrate = mitrate.min()
maxrate = mitrate.max()
//hist = mitrate.histogram(minrate, maxrate, 10)
// Save results to file
outfile.wopen("data/Fmit")
mitrate.printf(outfile)
outfile.close()
outfile.wopen("data/Fgran")
granrate.printf(outfile)
outfile.close()
outfile.aopen(filename)
outfile.printf("\nMitral average rate: %10.3f\n", mitrate.mean())
outfile.printf("Std: %10.3f\n", mitrate.stdev())
outfile.printf("Granule average rate: %10.3f\n", granrate.mean())
outfile.printf("Std: %10.3f\n", granrate.stdev())
outfile.printf("\nIndividual mitral firing rate:\n")
mitrate.printf(outfile)
outfile.printf("Individual granule firing rate:\n")
granrate.printf(outfile)
outfile.close()
}
// Calculate synchronization index
objref outfile, lags, work
outfile = new File()
lags = new Vector()
work = new Vector()
proc print_si() { // 1 arg - fileroot
print "MC Soma synchronization index"
print phaselock_index_Mit()
print "MC Dend synchronization index"
print phaselock_index_Mit_dend()
print "GC Dend synchronization index"
print phaselock_index_Gran()
sprint(filename,"%s",$s1)
outfile.wopen(filename)
outfile.printf("MC Soma Phase-locking index: %10.3f\n",phaselock_index_Mit())
outfile.printf("MC Dend Phase-locking index: %10.3f\n",phaselock_index_Mit_dend())
outfile.printf("GC Dend Phase-locking index: %10.3f\n",phaselock_index_Gran())
outfile.close()
}
func phaselock_index_Mit() { local n,i1,j1,i2,j2
synchindex = 0
n = 0
for i1 = 0, nMit-1 {
if (mit[i1].spiketimes.size() > 0) {
for i2 = 0, nMit-1 {
if (i1 != i2) {
calc_phase_lags_Mit(i1,i2,ttrans)
if (lags.size() > 1) {
synchindex += lags.var()
n += 1
}
}
}
}
}
if (n > 0) {
synchindex = sqrt(synchindex/n)
return synchindex
} else {
return 1e6
}
}
func phaselock_index_Mit_dend() { local n,i1,j1,i2,j2
synchindex = 0
n = 0
for i1 = 0, nMit-1 {
if (mit[i1].dendspike.size() > 0) {
for i2 = 0, nMit-1 {
if (i1 != i2) {
calc_phase_lags_Mit_dend(i1,i2,ttrans)
if (lags.size() > 1) {
synchindex += lags.var()
n += 1
}
}
}
}
}
if (n > 0) {
synchindex = sqrt(synchindex/n)
return synchindex
} else {
return 1e6
}
}
func phaselock_index_Gran() { local n,i1,j1,i2,j2
synchindex = 0
n = 0
for i1 = 0, nGran-1 {
if (gran[i1].spiketimes.size() > 0) {
for i2 = 0, nGran-1 {
if (i1 != i2) {
calc_phase_lags_Gran(i1,i2,ttrans)
if (lags.size() > 1) {
synchindex += lags.var()
n += 1
}
}
}
}
}
if (n > 0) {
synchindex = sqrt(synchindex/n)
return synchindex
} else {
return 1e6
}
}
//=====================================================================================================
proc calc_phase_lags_Mit() { local i1,j1,i2,j2,k,minidx,min // 5 args - indices of mitral cells, transient time
if ($1 > nMit || $2 > nMit) {
print "Sorry - index out of range. Please try again."
return
}
i1 = int($1)
i2 = int($2)
lags.resize(0)
// for each spiketime in cell 1, find closest spike in cell 2
// Note: first and last spikes ignored since can't calculate previous ISI
if (mit[i2].spiketimes.size > 0) {
for k = 1,mit[i1].spiketimes.size()-2 {
if (mit[i1].spiketimes.x[k] > $3) {
work = mit[i2].spiketimes.c.add(-mit[i1].spiketimes.x[k])
minidx = work.c.abs.min_ind()
min = work.x[minidx]
isiprev = mit[i1].spiketimes.x[k-1]-mit[i1].spiketimes.x[k]
isinext = mit[i1].spiketimes.x[k+1]-mit[i1].spiketimes.x[k]
if (min > isiprev/2 && min < isinext/2) {
if (min < 0) {
lags.append(min/isiprev)
} else {
lags.append(min/isinext)
}
}
}
}
}
}
proc calc_phase_lags_Mit_dend() { local i1,j1,i2,j2,k,minidx,min // 5 args - indices of mitral cells, transient time
if ($1 > nMit || $2 > nMit) {
print "Sorry - index out of range. Please try again."
return
}
i1 = int($1)
i2 = int($2)
lags.resize(0)
// for each spiketime in cell 1, find closest spike in cell 2
// Note: first and last spikes ignored since can't calculate previous ISI
if (mit[i2].dendspike.size > 0) {
for k = 1,mit[i1].dendspike.size()-2 {
if (mit[i1].dendspike.x[k] > $3) {
work = mit[i2].dendspike.c.add(-mit[i1].dendspike.x[k])
minidx = work.c.abs.min_ind()
min = work.x[minidx]
isiprev = mit[i1].dendspike.x[k-1]-mit[i1].dendspike.x[k]
isinext = mit[i1].dendspike.x[k+1]-mit[i1].dendspike.x[k]
if (min > isiprev/2 && min < isinext/2) {
if (min < 0) {
lags.append(min/isiprev)
} else {
lags.append(min/isinext)
}
}
}
}
}
}
proc calc_phase_lags_Gran() { local i1,j1,i2,j2,k,minidx,min // 5 args - indices of mitral cells, transient time
if ($1 > nGran || $2 > nGran) {
print "Sorry - index out of range. Please try again."
return
}
i1 = int($1)
i2 = int($2)
lags.resize(0)
// for each spiketime in cell 1, find closest spike in cell 2
// Note: first and last spikes ignored since can't calculate previous ISI
if (gran[i2].spiketimes.size > 0) {
for k = 1,gran[i1].spiketimes.size()-2 {
if (gran[i1].spiketimes.x[k] > $3) {
work = gran[i2].spiketimes.c.add(-gran[i1].spiketimes.x[k])
minidx = work.c.abs.min_ind()
min = work.x[minidx]
isiprev = gran[i1].spiketimes.x[k-1]-gran[i1].spiketimes.x[k]
isinext = gran[i1].spiketimes.x[k+1]-gran[i1].spiketimes.x[k]
if (min > isiprev/2 && min < isinext/2) {
if (min < 0) {
lags.append(min/isiprev)
} else {
lags.append(min/isinext)
}
}
}
}
}
}