-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfigureS7.m
163 lines (136 loc) · 5.53 KB
/
figureS7.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
% this script fits a second level sequential HMM to an already inferred
% viterbi path sequence
for whichstudy=[3]
K2=4;
if ~exist('whichstudy','var')
whichstudy = 1; % 1 denotes the hmm model run in Higgins2020_neuron
end
config = getStudyDetails(whichstudy);
% other preliminary setup for plotting etc:
color_scheme = colorscheme(whichstudy);
load(config.metricfile)
if whichstudy<4
W=17;
load([config.resultsdir,'secondLevelHMM_Poiss_window',num2str(W),'_K',int2str(4),'_overlappingWindows','.mat'])
else
W=16;
load([config.resultsdir,'secondLevelHMM_Poiss_window',num2str(W),'_K',int2str(4),'_overlappingWindows','.mat']);
load([config.resultsdir,'Poissdata',int2str(W),overlapstring, '/filelist.mat'])
samp_2minute = config.sample_rate*2*60;
% for subnum=1:config.nSj
% fprintf(['\nSubj: ',int2str(subnum)]);
% load(mat_files_poiss{subnum},'Gamma');
end
%% Meta state profile
FO_2ndlevel = mean(GammaPoiss);
%FO_2ndlevel = mean(Gammatemp);
statedist_all = zeros(1,12);
for i=1:K2
statedist_all = statedist_all + FO_2ndlevel(i)*hmmPoiss.state(i).W.W_mean;
end
statedist_all = statedist_all ./ 125; % ratio rather than integer
for i=1:K2
colorweights(:,i) = hmmPoiss.state(i).W.W_mean ./ 125 - statedist_all;
end
colorweights = (colorweights-min(colorweights(:))+0.01);
colorweights = log(colorweights) - min(log(colorweights(:))) + 0.01;
colorweights = colorweights./(max(colorweights(:)+0.1));
fig=gcf;
CM = colormap(fig,hot(100));
if strcmp(config.reordering_states, 'coherence')
optimalseqfile = [config.resultsdir,'bestseq',int2str(whichstudy),'_coherence' ,'.mat'];
elseif strcmp(config.reordering_states, 'study1matched')
optimalseqfile = [config.resultsdir,'bestseq',int2str(whichstudy),'_study1matched' ,'.mat'];
end
load(optimalseqfile);
bestseq = bestsequencemetrics{1};
for i=1:K2
fig=setup_figure([],1,1);
ax(1) = axes('Position', [.05 .1 .8, .8])
for i2=1:12
CW{i2} = CM(ceil(length(CM)*colorweights(i2,i)),:);
end
cyclicalstatesubplot(bestseq,zeros(12),zeros(12),CW);
ax(2) = axes('Position', [.85 0.175 0.1, .6]); axis off
h=colorbar;
colormap(fig,hot(100))
save_figure(sprintf('/ohba/pi/mwoolrich/mvanes/Projects/Tinda/figures_paper/figureS7_study%d_metastate%d',whichstudy, i), [], false)
end
%% Life times
colors = [color_scheme,{[140,132,126]./255, [236,123,119]./255, [245,191,134]./255, [179,225,153]./255}, {[0,0,0]}];
clr = {[0 0.4470 0.7410], [0.8500 0.3250 0.0980], [0.9290 0.6940 0.1250], [0.4940 0.1840 0.5560], [0.4660 0.6740 0.1880], [0.3010 0.7450 0.9330]};
N = length(hmm_2ndlevel.cyctime_mu);
outliers = abs(1./hmm_2ndlevel.cyctime_mu(:,1) - mean(1./hmm_2ndlevel.cyctime_mu(:,1))) > 2*std(1./hmm_2ndlevel.cyctime_mu(:,1));
micro_lt = hmm_1stlevel.LT_mu(~outliers,:);
if mean(micro_lt)>1
micro_lt = micro_lt./config.sample_rate;
end
meta_lt = cat(1,hmm_2ndlevel.LT_all{:});
meta_lt = cellfun(@mean, meta_lt(~outliers,:))./config.sample_rate;
fig = setup_figure([],1,1);
lbl = {}
for ii=1:17
if ii<13
lbl{ii} = sprintf('State %d', ii);
elseif ii<17
lbl{ii} = sprintf('Meta state %d', ii-12);
else
lbl{ii} = 'Cycle time';
end
end
cycle_lt = hmm_2ndlevel.cyctime_mu(~outliers,:);
distributionPlot([micro_lt,meta_lt, cycle_lt],'showMM',0,'color',{colors{:}})
view([90, 90])
xticklabels(lbl)
ylabel('Mean Life/Cycle times (s)')
vline(12.5, '--k')
vline(16.5, '--k')
save_figure(sprintf('/ohba/pi/mwoolrich/mvanes/Projects/Tinda/figures_paper/figureS7_study%d_lifetimes',whichstudy ), [], false)
%% State visits
fig = setup_figure([],1,1);
distributionPlot(hmm_2ndlevel.microtransitions_mu(~outliers,:),'showMM',2, 'color', {[0 0 0], [.5,.5,.5]})
ylabel({'Mean number of state', 'visits per cycle'});
set(gca,'XTickLabel',{'Total', 'Unique'})
xlabel('State visits')
save_figure(sprintf('/ohba/pi/mwoolrich/mvanes/Projects/Tinda/figures_paper/figureS7_study%d_lifetimes',whichstudy ), [], false)
%% Phase shifts
fig = setup_figure([],1,1);
phases = linspace(-pi,5*pi/6,12);
disttoplot_manual = zeros(12,2);
for i=1:12
temp = exp(sqrt(-1)*(i+2)/12*2*pi);
disttoplot_manual(bestseq(i),:) = [real(temp),imag(temp)];
end
%circleposition = exp(j*(pi/2-[0:11]*2*pi/12));
%circleposition = circleposition(bestseq);
circleposition = disttoplot_manual(:,1) + sqrt(-1)*disttoplot_manual(:,2);
phaseshiftcounter = zeros(config.nSj,12);
phases = linspace(-pi,5*pi/6,12);
jointcounter = zeros(12,12,config.nSj);
for subnum=1:config.nSj
if whichstudy==4
clear vpath;
vpTemp = load(mat_files_orth{subnum},'vpath','T');
vpath{subnum} = vpTemp.vpath;
end
transitions = find(diff(vpath{subnum})~=0);
phaseshift = zeros(length(transitions),1);
for i=1:length(transitions)
phase_t = angle(circleposition(vpath{subnum}(transitions(i))));
phase_tplus1 = angle(circleposition(vpath{subnum}(transitions(i)+1)));
phaseshift(i) = phase_tplus1 - phase_t;
end
% unwrap phases onto same scale:
phaseshift(phaseshift > pi-0.01) = phaseshift(phaseshift > pi-0.01)-2*pi;
phaseshift(phaseshift < -pi-0.01) = phaseshift(phaseshift < -pi-0.01)+2*pi;
phaseshiftcounter(subnum,:) = hist(phaseshift,phases);
end
phaseshiftcounter = phaseshiftcounter ./ repmat(sum(phaseshiftcounter,2),1,12);
bar(phases,mean(phaseshiftcounter), 'k'), box off
xlabel('Phase Shift')
ylabel({'Proportion of', 'microstate transitions'})
labs = {'-\pi','-5\pi/6','-2\pi/3','-\pi/2','-\pi/3','-\pi/6','0','\pi/6','\pi/3','\pi/2','2\pi/3','5\pi/6'}
xticks([-pi:pi/6:pi])
xticklabels(labs)
xlabel('Phase shift')
end