-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfetch_odor_only_plots.m
291 lines (230 loc) · 10.2 KB
/
fetch_odor_only_plots.m
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
keyboard()
%% basic stats >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
global_init;
su_meta=ephys.util.load_meta('skip_stats',true,'adjust_white_matter',true);
wrs_meta=ephys.get_wrs_mux_meta('load_file',false,'save_file',false);
% pp=[wrs_meta.p_olf,wrs_meta.p_olf6];
% ss=[wrs_meta.o_pref_id,wrs_meta.o_pref_id6];
% switchsel=arrayfun(@(x) any(ss(x,pp(x,:)<0.05)==5) & any(ss(x,pp(x,:)<0.05)==6),1:size(pp,1));
% wrs_meta.switched(switchsel)=1;
% wrs_meta.p_olf=pp;
%% TCOM
com_map=wave.get_olf_com_map(wrs_meta,'curve',true);
grey_regs=ephys.getGreyRegs('range','grey');
[fcom.olf.collection,fcom.olf.com_meta]=wave.per_region_COM(...
com_map,'sel_type','olf','com_field','com');
ureg=intersect(grey_regs,fcom.olf.collection(:,2));
[~,tcidx]=ismember(ureg,fcom.olf.collection(:,2));
reg_com_maps.olf=containers.Map(...
ureg,num2cell(cellfun(@(x) x/4, fcom.olf.collection(tcidx,1))));
% on=nnz(ismember(wrs_meta.wave_id,5:6));
% alln=numel(wrs_meta.wave_id);
%% wave & stay
wave_n_stay=nnz(ismember(wrs_meta.wave_id,5:6) & wrs_meta.p_olf(:,3)<0.05 & all(wrs_meta.p_olf(:,4:6)<0.05,2));
%% show case >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
% #510
% idx=find(ismember(wrs_mux_meta.wave_id,5:6) & all(wrs_mux_meta.p_olf<1e-12,2));
if false
idx=[510];
for ii=reshape(idx,1,[])
scfh=ephys.sens_dur_SC(ii,su_meta,'skip_raster',false,'skip_fill',true);%
if ~isempty(scfh)
sgtitle(scfh, "SU #"+num2str(ii)+", OLF");
% keyboard();
end
end
end
% %% svm decoding
% [fh,olf_dec_olf]=wave.pct_decoding(sens_efsz,sens_win,'n_su',[10,50,100,200,300,500],'lblidx',5,'cmap','parula','new_data',true,'calc_dec',true,'rpt',100);
% [fh,dur_dec_dur]=wave.pct_decoding(dur_efsz,dur_win,'n_su',[10,50,100,200,300,500],'lblidx',8,'cmap','cool','new_data',true,'calc_dec',true,'rpt',100);
%
% %% cross decoding
% wave.pct_decoding(sens_efsz,sens_win,'n_su',[10,50,100,200,300,500],'lblidx',8,'cmap','parula','cross',true,'new_data',true,'calc_dec',true)
% title('Rank by odor-encoding, decoding duration')
% exportgraphics(gcf(),'pct_decoding.pdf','ContentType','vector','Append',true);
% wave.pct_decoding(dur_efsz,dur_win,'n_su',[10,50,100,200,300,500],'lblidx',5,'cmap','cool','cross',true,'new_data',true,'calc_dec',true)
% title('Rank by duration-encoding, decoding odor')
% exportgraphics(gcf(),'pct_decoding.pdf','ContentType','vector','Append',true);
%% correct error decoding >>>>>>>>>>>>>>>>>
% svm on neuron firing rates
if false
odor4odor=pct.pct_decoding_correct_error(wrs_mux_meta,5:6,'lblidx',5,'n_su',50);% odor
dur4odor=pct.pct_decoding_correct_error(wrs_mux_meta,7:8,'lblidx',5,'n_su',50);% odor
mux4odor=pct.pct_decoding_correct_error(wrs_mux_meta,1:4,'lblidx',5,'n_su',50);% odor
odor4dur=pct.pct_decoding_correct_error(wrs_mux_meta,5:6,'lblidx',8,'n_su',50);% dur
dur4dur=pct.pct_decoding_correct_error(wrs_mux_meta,7:8,'lblidx',8,'n_su',50);% dur
mux4dur=pct.pct_decoding_correct_error(wrs_mux_meta,1:4,'lblidx',8,'n_su',50);% dur
save('corr_err_wrs_mux_decoding.mat','odor4odor','dur4odor','mux4odor','odor4dur','dur4dur','mux4dur');
else
load('corr_err_wrs_mux_decoding.mat','odor4odor','dur4odor','mux4odor','odor4dur','dur4dur','mux4dur');
[~,~,p]=crosstab(1:2000>1000,[odor4odor.olf.c_result_50su;odor4odor.olf.e_result_50su])
[~,~,p]=crosstab(1:2000>1000,[odor4dur.dur.c_result_50su;odor4dur.dur.e_result_50su])
[~,~,p]=crosstab(1:2000>1000,[mux4odor.olf.c_result_50su;mux4odor.olf.e_result_50su])
[~,~,p]=crosstab(1:2000>1000,[mux4dur.dur.c_result_50su;mux4dur.dur.e_result_50su])
[~,~,p]=crosstab(1:2000>1000,[dur4odor.olf.c_result_50su;dur4odor.olf.e_result_50su])
[~,~,p]=crosstab(1:2000>1000,[dur4dur.dur.c_result_50su;dur4dur.dur.e_result_50su])
end
if false
fh=ephys.plot_decode_correct_error(odor4odor,odor4dur,dur4odor,dur4dur,mux4odor,mux4dur);
%% duration switch trial v continuation trial
ephys.plot_switch_cont_decoding(wrs_mux_meta,"type",'olf')
end
%% sust trans
% TODO olf only
if false %TODO update functions
fh=ephys.sust_trans_bar_w_mix(wrs_meta);
fh=ephys.sust_trans_correct_error(wrs_meta);
end
%% wave-half-half
if false
rpt=100;
com_halfs=cell(rpt,2);
for ii=1:rpt
[com_map_h1,com_map_h2]=wave.get_pct_com_map(wrs_mux_meta,'rnd_half',true);
com_halfs(ii,:)={com_map_h1,com_map_h2};
end
blame=vcs.blame();
save(sprintf('com_halfs_%d.mat',rpt),'com_halfs','blame')
end
if false
com_map_err=wave.get_pct_com_map(wrs_mux_meta,'err',true);
blame=vcs.blame();
save('com_error.mat','com_map_err','blame');
end
if false % TODO: udpate functions
while true
wave_half_half_fh=wave.plot_wave_half_half(wrs_mux_meta,'minr',0.90);
if ~isempty(wave_half_half_fh)
break;
end
end
stats_half_half_fh=wave.COM_half_half_wrs_mux();
end
%% wave
for hbound=0.8
fh=wave.plot_pct_wave(wrs_meta,com_map,'comb_set',3,'scale',[0,hbound],'gauss2d',true);
sgtitle(gcf(),"single-mod 0:"+num2str(hbound))
end
% <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
%% Proportion, GLM
[map_cells,pct_bar_fh]=ephys.pct_reg_bars(wrs_meta,'xyscale',{'linear','linear'},'only_odor',true); % only need map_cells for tcom-frac corr
pct_bar_fh.CurrentAxes.YLim(2)=0.7
map_cells=rmfield(map_cells,{'mixed','dur'});
mixed_TCOM_GLM_fh=wave.connectivity_proportion_GLM(map_cells,gather_config.corr_log_log, ...
'range','grey','data_type','pct-frac','stats_type','percentile');
%% TCOM, GLM >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
% joint 3s-6s trials
mixed_TCOM6_GLM_fh=wave.connectivity_proportion_GLM(reg_com_maps,gather_config.corr_ln_log, ...
'range','grey','data_type','wrs-TCOM','stats_type','wrs');
%% TCOM and proportion correlation % 4 panel scatters
% pct_tcom_fh3=struct();
% pct_tcom_fh6=struct();
% for typeidx=1:3
% type=subsref(["mixed","olf","dur"],struct(type='()',subs={{typeidx}}));
% conn_reg=subsref(["AON","AON","PIR"],struct(type='()',subs={{typeidx}}));
% ureg=intersect(ephys.getGreyRegs('range','grey'),...
% fcom3.(type).collection(:,2));
% ffrac.collection=...
% [num2cell(cellfun(@(x) x(1),map_cells.(type).values(ureg))),...
% ureg,...
% num2cell(ones(numel(ureg),1)*5),...
% num2cell(cellfun(@(x) x(3),map_cells.(type).values(ureg)))];
%
% [pct_tcom_fh3,t3]=wave.per_region_COM_frac(...
% fcom3.(type),ffrac,...
% 'hier_reg',conn_reg,...
% 'corr',gather_config.corr_type,...
% 'sel_type',type);
% sgtitle(pct_tcom_fh3,type+" 3sec")
%
% [pct_tcom_fh6,t6]=wave.per_region_COM_frac(...
% fcom.(type),ffrac,...
% 'hier_reg',conn_reg,...
% 'corr',gather_config.corr_type,...
% 'sel_type',type);
% sgtitle(pct_tcom_fh6,type+" 6sec")
%
% end
%% Functional coupling
fh4=bz.inter_wave_pct(wrs_meta); %congru vs incongru vs nonmem
fh4.fig.Children.Subtitle.String='Excitatory';
if false
fh4i=bz.inter_wave_pct(wrs_mux_meta,'inhibit',true);
fh4i.fig.Children.Subtitle.String='Inhibitory';
end
%% FIG 4 vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
% [sig,pair]=bz.load_sig_sums_conn_file('pair',true);
fcstats=fc.fc_com_reg_wave.stats(wrs_meta,com_map,reg_com_maps,'odor_only',true);
[barmm,barci,barcnt]=fc.fc_com_reg_wave.sums(fcstats,'odor_only',true);
fh=fc.fc_com_reg_wave.plot(barmm,barci,barcnt,'condense_plot',false,'odor_only',true,'omit_reg_wave',false);
if false
inter_wave_fh=bz.inter_wave_ext_bars(wrs_mux_meta); % dur, olf vs Isocortex, Straitum and Midbrain
%skipped for current manuscript
end
% bz.inter_wave_ext_bars()
% separate wave timing cdf
% wave.mix_single_wave_timing
if false %TODO: update functions
bz.conn_prob_spatial_dist(sig,pair);
%% FC_Decoding
bz.fccoding.plot_coding(wrs_mux_meta,'dtype','olf')
bz.fccoding.plot_coding(wrs_mux_meta,'dtype','dur')
%% FC_TCOM_hierachy
% [fc_com_pvsst_stats_mix,fh_mix]=pct.fc_com_pct(com_map,pct_meta,'pair_type','congru');
%
% [fc_com_pvsst_stats_mix,fh_mix]=pct.fc_com_pct(com_map,pct_meta,'pair_type','congru');
%
% [fc_com_pvsst_stats_mix,fh_mix]=pct.fc_com_pct(com_map,pct_meta,'pair_type','incong');
bz.fc_conn_screen(com_map,pct_meta,'title_suffix','expanded')
end
%% chain
chains_fwd=wave.COM_chain(wrs_meta,com_map,'odor_only',true);
chains_rev=wave.COM_chain(wrs_meta,com_map,'odor_only',true,'reverse',true);
wave.chain_stats(chains_fwd,chains_rev,su_meta,wrs_meta);
[gcf,grf]=groupcounts(cellfun(@(x) numel(unique(x)),chains_fwd.cids));
[gcr,grr]=groupcounts(cellfun(@(x) numel(unique(x)),chains_rev.cids));
for ii=reshape(union(grf,grr),1,[])
if ~ismember(ii,grr) || gcf(grf==ii)>gcr(grr==ii)
len_thresh=ii;
break
end
end
wave.chain_stats_regs(chains_fwd,su_meta,"len_thresh",len_thresh,"odor_only",true)
[sschain.out,unfound]=wave.chain_tag(chains_fwd,'skip_save',true,'len_thresh',len_thresh); % per-spk association
if false
save(fullfile('bzdata','chain_tag_fdr_6.mat'),'out','blame')
sschain=load(fullfile('bzdata','chain_tag_fdr_6.mat'),'out');
end
wave.motif_dynamic.single_spike_chains(sschain.out)
%% loops
% sums_all
load(fullfile('bzdata','sums_ring_stats_all.mat'),'sums_all');
bz.rings.ring_wave_freq(wrs_meta,'denovo',true,'burst',false,'repeats',20);
pstats=bz.rings.rings_time_constant.stats(sums_all,wrs_meta,'load_file',false,'skip_save',true,'odor_only',true);
if false
load(fullfile('bzdata','loops_stats_fdr_6.mat'),'pstats')
end
wave.motif_dynamic.single_spike_loops(pstats)
bz.rings.loop_occurrence_per_reg_su(sums_all,su_meta,wrs_meta,'odor_only',false);
if false
bz.rings.rings_su_wave_tcom_corr(sums_all)
end
%% chained loops
disconnected=wave.module_motif_asso_composite(sschain,pstats);
run_length=wave.chain_loop_stats(sschain,pstats,disconnected);
%% systematic deconstruction
wave.composite_thin_down(sschain,pstats)
wave.composite_thin_down.demo
wave.composite_thin_down
return
%%
wave.chains_loops_sc
wave.chain_SC %plot
%% w/ bursts
wave.chain_sust_tag(chains_fwd,'burstInterval',150)
wave.chain_sust_tag(chains_fwd,'burstInterval',300)
wave.chain_sust_tag(chains_fwd,'burstInterval',600)
% chains, inconsistent (reverse) direction
wave.chain_tag(chains_rev,'rev',true) % per-spk association
rev_out_150=wave.chain_sust_tag(chains_rev,'burstInterval',150,'rev',true);
%% exports