-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2022-08-05__Spiketrain-correlations.jl
188 lines (141 loc) · 4.67 KB
/
2022-08-05__Spiketrain-correlations.jl
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
# -*- coding: utf-8 -*-
# ---
# jupyter:
# jupytext:
# formats: ipynb,jl:light
# text_representation:
# extension: .jl
# format_name: light
# format_version: '1.5'
# jupytext_version: 1.13.7
# kernelspec:
# display_name: Julia 1.7.0
# language: julia
# name: julia-1.7
# ---
# # 2022-08-05 • Spiketrain correlations (of unconnected-but-detected)
# ## Imports
# +
#
# -
using Revise
using MyToolbox
using VoltoMapSim
# ## Params
# Based on Roxin; same as previous nb's.
d = 6
p = get_params(
duration = 10minutes,
p_conn = 0.04,
g_EE = 1 / d,
g_EI = 18 / d,
g_IE = 36 / d,
g_II = 31 / d,
ext_current = Normal(-0.5 * pA/√seconds, 5 * pA/√seconds),
E_inh = -80 * mV,
record_v = [1, 801],
);
# ## Run sim
s = cached(sim, [p.sim]);
s = augment_simdata(s, p);
# ## Bin spiketrains
function bin(spiketimes; duration, binsize)
# `spiketimes` is assumed sorted.
# `duration` is of the spiketimes signal and determines the number of bins.
num_bins = ceil(Int, duration / binsize)
spikecounts = fill(0, num_bins)
# loop counters:
spike = 1
bin_end_time = binsize
for bin in 1:num_bins
while spiketimes[spike] < bin_end_time
spikecounts[bin] += 1
spike += 1
if spike > length(spiketimes)
return spikecounts
end
end
bin_end_time += binsize
end
end;
# ### Test
events = s.spike_times[1][1:10]
show(events)
show(bin(events; duration=20, binsize=2))
# Looks good
# ### Apply
p.conntest.STA_window_length / ms
binned_spikes = [bin(s.spike_times[n], duration = 10minutes, binsize = 100ms) for n in s.neuron_IDs];
# ## Correlation with recorded neuron
m = 1; # analyzed neuron
cors = [cor(binned_spikes[m], binned_spikes[n]) for n in s.neuron_IDs]; # Pearson corr
# ## Split neurons by type
v = s.signals[m].v
ii = get_input_info(m, s, p);
ii.num_inputs
perf = cached(evaluate_conntest_perf, [v, ii.spiketrains, p], key = [p, m]);
perf.detection_rates
signif_unconn = ii.unconnected_neurons[findall(perf.p_values.unconn .< p.evaluation.α)];
tested_unconn = ii.unconnected_neurons[1:p.evaluation.N_tested_presyn]
insignif_unconn = [n for n in tested_unconn if n ∉ signif_unconn];
length(signif_unconn), length(insignif_unconn)
# ## Plot
using PyPlot
using VoltoMapSim.Plot
Plot.add_refline
function plotcors(cors, binsize_ms)
ax = ydistplot(
"Exc inputs" => cors[ii.exc_inputs],
"Inh inputs" => cors[ii.inh_inputs],
"Unconnected\nbut detected" => cors[signif_unconn],
"Unconnected,\nnot detected" => cors[insignif_unconn],
figsize = (6, 3),
hylabel = "Binned spiketrain correlations to neuron $m (binsize = $(binsize_ms) ms)",
ylabel = "Pearson correlation",
# ylim = [-0.04, +0.045],
)
Plot.add_refline(ax, 0, zorder=1, c="gray")
end
plotcors(cors, 100);
# ## More bin sizes
function plotcors_for(; binsize)
binned_spikes = [bin(s.spike_times[n], duration = 10minutes; binsize) for n in s.neuron_IDs]
cors = [cor(binned_spikes[m], binned_spikes[n]) for n in s.neuron_IDs]
plotcors(cors, binsize/ms)
end;
for binsize in [12.5, 25, 50, 100, 200] * ms
plotcors_for(; binsize)
end;
# ## Correlation with other inputs
# The guess: unconnected-but-detected are more correlated with actual inputs to the recorded neuron, than unconnected not detected are.
#
# To test, we compute spiketrain correlations between inputs (and not between an input and the recorded neuron as above).
all_inputs = [ii.exc_inputs; ii.inh_inputs];
signif_unconn_cors = vcat(
[
[cor(binned_spikes[m], binned_spikes[n]) for n in all_inputs]
for m in signif_unconn
]...
)
insignif_unconn_cors = vcat(
[
[cor(binned_spikes[m], binned_spikes[n]) for n in all_inputs]
for m in insignif_unconn
]...
);
function plotcors_between_inputs(insignif_unconn_cors, signif_unconn_cors, binsize_ms = 100)
ax = ydistplot(
"Unconnected,\nnot detected" => insignif_unconn_cors,
"Unconnected\nbut detected" => signif_unconn_cors,
figsize = (6, 3),
hylabel = "Binned spiketrain correlations with inputs to neuron $m \nBinsize = $binsize_ms ms",
ylabel = "Pearson correlation",
# ylim = [-0.04, +0.045],
)
Plot.add_refline(ax, 0, zorder=1, c="gray")
end
plotcors_between_inputs(insignif_unconn_cors, signif_unconn_cors);
# Remove outliers (manually) to zoom in
signif_unconn_cors__rm = signif_unconn_cors[signif_unconn_cors .< 0.1]
insignif_unconn_cors__rm = insignif_unconn_cors[insignif_unconn_cors .< 0.1]
plotcors_between_inputs(insignif_unconn_cors__rm, signif_unconn_cors__rm);