|
a |
|
b/convert_IIC_perhour.m |
|
|
1 |
% Wei-Long Zheng, MGH |
|
|
2 |
% Email: weilonglive@gmail.com |
|
|
3 |
|
|
|
4 |
clear |
|
|
5 |
feature_hour_folder = '\Features\YNH\'; |
|
|
6 |
feature_folder = '\Features_CNN_IIIC\YNH\'; |
|
|
7 |
save_folder = '\'; |
|
|
8 |
pts_info = readtable('ICARE_CaseData_Final_20181108.csv'); |
|
|
9 |
|
|
|
10 |
list = dir([feature_folder,'*.mat']); |
|
|
11 |
isfile=~[list.isdir]; |
|
|
12 |
featurenames={list(isfile).name}; |
|
|
13 |
num_file = length(featurenames); |
|
|
14 |
filenames = featurenames; |
|
|
15 |
max_hour = 0; |
|
|
16 |
for i = 1:num_file |
|
|
17 |
underlineLocations = find(filenames{i} == '_'); |
|
|
18 |
pt_name{i} = filenames{i}(1:underlineLocations(1)-1); |
|
|
19 |
load ([feature_hour_folder,filenames{i}],'eeg_hour'); |
|
|
20 |
if ~isempty(eeg_hour) |
|
|
21 |
if max_hour<eeg_hour{end,1} |
|
|
22 |
max_hour = eeg_hour{end,1}; |
|
|
23 |
end |
|
|
24 |
end |
|
|
25 |
end |
|
|
26 |
|
|
|
27 |
[unique_names, idx ,idx2] = uniquecell(pt_name); |
|
|
28 |
num_pts = length(unique_names); |
|
|
29 |
feature_all = NaN(num_pts,max_hour); |
|
|
30 |
score_all = NaN(num_pts,max_hour); |
|
|
31 |
cpc_scores = zeros(num_pts,1); |
|
|
32 |
features = cell(1,6); |
|
|
33 |
feature_score = cell(1,6); |
|
|
34 |
for ifea = 1:6 |
|
|
35 |
features{ifea} = feature_all; |
|
|
36 |
feature_score{ifea} = score_all; |
|
|
37 |
end |
|
|
38 |
|
|
|
39 |
select_pts = table(); |
|
|
40 |
|
|
|
41 |
for i = 1:num_pts |
|
|
42 |
current_pts = unique_names{i}; |
|
|
43 |
indx = ~cellfun(@isempty, strfind(pts_info.sid,current_pts)); |
|
|
44 |
indx_tmp = find(indx==true); |
|
|
45 |
bestCpcBy6Mo = pts_info.bestCpcBy6Mo(indx_tmp(1)); |
|
|
46 |
cpc_scores(i) = bestCpcBy6Mo; |
|
|
47 |
unique_names_cpc{i} = [unique_names{i},'(',num2str(bestCpcBy6Mo),')']; |
|
|
48 |
file_index = find(idx2==i); |
|
|
49 |
|
|
|
50 |
for j = 1:length(file_index) |
|
|
51 |
|
|
|
52 |
load([feature_hour_folder,filenames{file_index(j)}],'eeg_hour'); |
|
|
53 |
load([feature_folder,filenames{file_index(j)}],'prediction'); |
|
|
54 |
|
|
|
55 |
load(['Z:\Projects\Weilong\Cardiac_arrest_EEG\Features\YNH\',filenames{file_index(j)}],'eeg_masks') |
|
|
56 |
|
|
|
57 |
col_num_count = 0; |
|
|
58 |
for k = 1:size(eeg_hour,1) |
|
|
59 |
if ~isempty(eeg_hour{k,1}) |
|
|
60 |
index = cellfun(@(x)isequal(x,eeg_hour{k,1}),eeg_hour); |
|
|
61 |
[row,col] = find(index); |
|
|
62 |
|
|
|
63 |
current_mask = eeg_masks(k,col); |
|
|
64 |
% current_feature = eeg_feature(k,col); |
|
|
65 |
weight_clean = zeros(1,length(col)); |
|
|
66 |
feature_raw = zeros(1,length(col)); |
|
|
67 |
end_index = min((col_num_count+length(col))*30,size(prediction,1)); |
|
|
68 |
current_feature = prediction(col_num_count*30+1:end_index,:); % convert 10s to 5min |
|
|
69 |
col_num_count = col_num_count+length(col); |
|
|
70 |
|
|
|
71 |
for ifeature = 1:6 |
|
|
72 |
for m = 1:length(col) |
|
|
73 |
% if ~isempty(current_feature{m}) |
|
|
74 |
indx = ~cellfun(@isempty, strfind(string(current_mask{m}),'normal')); |
|
|
75 |
weight_clean(m) = sum(indx)/length(indx); |
|
|
76 |
|
|
|
77 |
% feature_raw(m) = mean(current_feature{m}(5:13:end)); |
|
|
78 |
end_tmp = min(m*30,size(current_feature,1)); |
|
|
79 |
feature_raw(m) = mean(current_feature((m-1)*30+1:end_tmp,ifeature)); |
|
|
80 |
|
|
|
81 |
% feature_raw(m) = mean(mean(current_feature{m})); %burst suppression ratio |
|
|
82 |
% end |
|
|
83 |
end |
|
|
84 |
% if sum(feature_raw)~=0 |
|
|
85 |
weight_clean_norm = weight_clean/sum(weight_clean); |
|
|
86 |
feature_clean = sum(weight_clean_norm.*feature_raw); |
|
|
87 |
|
|
|
88 |
% if max(weight_clean)<0.5 |
|
|
89 |
% feature_all(i,eeg_hour{k,1}) = NaN; |
|
|
90 |
% else |
|
|
91 |
% feature_all(i,eeg_hour{k,1}) = feature_clean; |
|
|
92 |
% end |
|
|
93 |
features{ifeature}(i,eeg_hour{k,1}) = feature_clean; |
|
|
94 |
feature_score{ifeature}(i,eeg_hour{k,1}) = max(weight_clean); |
|
|
95 |
% end |
|
|
96 |
end |
|
|
97 |
end |
|
|
98 |
end |
|
|
99 |
end |
|
|
100 |
end |
|
|
101 |
% features{ifeature} = feature_all; |
|
|
102 |
% feature_score{ifeature} = score_all; |
|
|
103 |
% end |
|
|
104 |
|
|
|
105 |
save([save_folder,'ynh_iic_pattern'],'features','feature_score','cpc_scores','unique_names','unique_names_cpc','-v7.3'); |
|
|
106 |
% writetable(select_pts,'ynh_pts.csv'); |