-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsem_w8s_no_plot.m
More file actions
178 lines (148 loc) · 7.08 KB
/
sem_w8s_no_plot.m
File metadata and controls
178 lines (148 loc) · 7.08 KB
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
function [clean_ll_w_t_l, clean_LL_diff] = sem_w8s(cut_or_not,ll_w_t,ll_w_t_labels,LL_s,ytl_LL,yt_LL,u2_s,sfx,perdur,vid_period,S,u3_s)
format longG
%Created by NS & Dr. Jon Kleen, Updated 5/26 by NS
clean_ll_w_t_l = {};
label_count = 0;
ll_w_t(ll_w_t == 0) = NaN;
[LL_row, LL_col]= size(LL_s);
%subtract start of video from symptom time onset
ll_w_t = ll_w_t - vid_period(1);
LL_meandiff = nan(LL_row,1,3); % Initialize first column only
%align ll_w_t with ll_w_t_labels
for n = 1:length(ll_w_t_labels) % loop for symptom
if ischar(ll_w_t_labels{n})
label_count = label_count + 1; %collect number of present labels
clean_ll_w_t_l{label_count} = ll_w_t_labels{n}; % collect present symptoms for x labels
if any(ll_w_t(:,n,1)) | any(ll_w_t(:,n,2)) | any(ll_w_t(:,n,3))
if any(ll_w_t(:,n,1)) % electrode X semiology X AUTOMATISM
if round([ll_w_t(1,n,1)+perdur]*sfx) <= LL_col %avoid exceeding array bounds
%differences of the average!!! --
%mean of true start and end start - mean of true start and before start
LL_meandiff(:,n,1)=mean(LL_s(:,round([ll_w_t(1,n,1) ]*sfx):round([ll_w_t(1,n,1)+perdur]*sfx)),2) ...
- mean(LL_s(:,round([ll_w_t(1,n,1)-perdur]*sfx):round([ll_w_t(1,n,1) ]*sfx)),2);
elseif round([ll_w_t(1,n,1)+perdur]*sfx) > LL_col
LL_meandiff(:,n,1)=mean(LL_s(:,round([ll_w_t(1,n,1) ]*sfx):LL_col ),2) ...
- mean(LL_s(:,round([ll_w_t(1,n,1)-perdur]*sfx):round([ll_w_t(1,n,1) ]*sfx)),2);
end
end
if any(ll_w_t(:,n,2)) % electrode X semiology X TONIC
if round([ll_w_t(1,n,2)+perdur]*sfx) <= LL_col %avoid exceeding array bounds
LL_meandiff(:,n,2)=mean(LL_s(:,round([ll_w_t(1,n,2) ]*sfx):round([ll_w_t(1,n,2)+perdur]*sfx)),2) ...
- mean(LL_s(:,round([ll_w_t(1,n,2)-perdur]*sfx):round([ll_w_t(1,n,2) ]*sfx)),2);
elseif round([ll_w_t(1,n,1)+perdur]*sfx) > LL_col
LL_meandiff(:,n,3)=mean(LL_s(:,round([ll_w_t(1,n,2) ]*sfx):LL_col ),2) ...
- mean(LL_s(:,round([ll_w_t(1,n,2)-perdur]*sfx):round([ll_w_t(1,n,2) ]*sfx)),2);
end
end
if any(ll_w_t(:,n,3)) % electrode X semiology X CLONIC
if round([ll_w_t(1,n,3)+perdur]*sfx) <= LL_col %avoid exceeding array bounds
LL_meandiff(:,n,3)=mean(LL_s(:,round([ll_w_t(1,n,3) ]*sfx):round([ll_w_t(1,n,3)+perdur]*sfx)),2) ...
- mean(LL_s(:,round([ll_w_t(1,n,3)-perdur]*sfx):round([ll_w_t(1,n,3) ]*sfx)),2);
elseif round([ll_w_t(1,n,3)+perdur]*sfx) > LL_col
LL_meandiff(:,n,3)=mean(LL_s(:,round([ll_w_t(1,n,3) ]*sfx):LL_col ),2) ...
- mean(LL_s(:,round([ll_w_t(1,n,3)-perdur]*sfx):round([ll_w_t(1,n,3) ]*sfx)),2);
end
end
else
LL_meandiff(:,n,:) = nan;
end
else
LL_meandiff(:,n,:) = nan;
end
end
[~,col,page] = size(LL_meandiff);
clean_LL_diff = nan(LL_row,label_count,3); %initialize 3d matrix of symptoms present
clean_col = 0;
for c = 1:col
if any(LL_meandiff(:,c,1)) | any(LL_meandiff(:,c,2)) | any(LL_meandiff(:,c,3))
clean_col = clean_col + 1;
if any(LL_meandiff(:,c,1))
clean_LL_diff(:,clean_col,1) = LL_meandiff(:,c,1);
end
if any(LL_meandiff(:,c,2))
clean_LL_diff(:,clean_col,2) = LL_meandiff(:,c,2);
end
if any(LL_meandiff(:,c,3))
clean_LL_diff(:,clean_col,3) = LL_meandiff(:,c,3);
end
end
end
%EXPORT CLEAN_LL_DIFF TO BRAIN W8S TO PLOT W8 CHANGE FOR SPECIFIC SYMPTOM
%writematrix(clean_LL_diff,'q8_clean_LL_diff.csv') %need to make specific for file
%GROUP ELECTRODES BY YTL_LL NEUROANAT LABELS
% NEURO ANAT - overall decrease or increase
[c_row, c_col,c_page] = size(clean_LL_diff);
% rows = # of neuroanat labels
% cols = # of symptoms
% pages = auto, tonic, clonic
% cell = weight change before and after first symptom occurance
anat_w8s = zeros(length(ytl_LL),c_col,c_page);
elec_w8s = zeros(c_row,c_col,3);
y_count = 0;
%anat_elec:
%4 dimensional matrix to collect electrode weight changes of all symptoms in auto, tonic,& clonic
%col 1 col 2 col 3
% label number anatomy string electrode weight change
% 3D page 1 - # of symptoms
% each symptom
% 4D page 1 - 3 of auto, tonic, clonic
anat_elec = cell(c_row,3,c_col,c_page); %112x2 anat label number, anat label text for each electrode in row
for pages = 1:c_page
for columns = 1:c_col
for y_label = 1:length(ytl_LL)
if y_label < length(ytl_LL)
for elec = u2_s(y_label):u2_s(y_label+1)
y_count = y_count + 1;
anat_elec{elec,1,columns,pages} = u3_s(elec);
if u3_s(elec) == y_label
anat_elec{elec,2,columns,pages} = ytl_LL{y_label};
anat_elec{elec,3,columns,pages} = clean_LL_diff(elec,columns,pages);
anat_w8s(y_label,columns,pages) = anat_w8s(y_label,columns,pages) + anat_elec{elec,3,columns,pages};
% if anat_elec{elec,3,columns,pages} > 0
% %group into vector?
% elseif anat_elec{elec,3,columns,pages} < 0
% else
% end
end
end
else
for elec = u2_s(y_label):c_row
y_count = y_count + 1;
anat_elec{elec,1,columns,pages} = u3_s(elec);
anat_elec{elec,2,columns,pages} = ytl_LL{y_label};
anat_elec{elec,3,columns,pages} = clean_LL_diff(elec,columns,pages);
anat_w8s(y_label,columns,pages) = (anat_w8s(y_label,columns,pages) + anat_elec{elec,3,columns,pages})/y_count;
end
end
y_count = 0;
end
end
end
% Plot
% figure;
%
% for i=1:c_page
% subplot(c_page,1,i);
% pcolorjk(squeeze(clean_LL_diff(:,:,i)));
% colorbar;
% caxis(S.cax);
% shading flat;
% cmocean('balance');
% sgtitle('Electrode Weights')
% sgt.FontSize = 20;
% %y
% set(gca,'ytick',yt_LL,'yticklabel',ytl_LL,'ydir','reverse','yaxislocation','right','fontsize',8)
%
% %x
% set(gca,'xtick',[1.5:1:length(clean_ll_w_t_l)+.5],'xticklabel',clean_ll_w_t_l)
% hold on;
% plot(xlim,[u2_s u2_s],'k-')
% yline([min(xlim):1:max(xlim)],'k-',.01)
% if i == 1
% title('Automatism')
% elseif i == 2
% title('Tonic')
% elseif i == 3
% title('Clonic')
% end
% end