-
Notifications
You must be signed in to change notification settings - Fork 0
/
UFA_Export_Excel_74_tracts.m
167 lines (87 loc) · 4.7 KB
/
UFA_Export_Excel_74_tracts.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
% AUTHOR : Gaoxing Zheng
% Institution: Zhongshan Hospital, Fudan University
% EMAIL CONTACT: zheng_gao_xing@163.com
% DATE: 2022-04-14
function UFA_Export_Excel_74_tracts(OutputFolder)
%% WMHs metrics
Splited_string = strsplit(OutputFolder,'/');
Total_Result_WMHs = [];
Var_Name_WMHs = {};
WMH_table = importdata([OutputFolder,'/WMH_extraction/subjects/','WMH_spreadsheet.txt'],',',1);
for m = 1:length(WMH_table.textdata(1,2:end))
WMH_var = cell2mat(WMH_table.textdata(1,m+1));
eval([WMH_var,'=','[]',';'])
eval([WMH_var,'= [',WMH_var,';',num2str(WMH_table.data(1,m)),'];']);
Var_Name_WMHs = [Var_Name_WMHs, WMH_var];
Total_Result_WMHs = [Total_Result_WMHs,num2cell(WMH_table.data(1,m))];
end
%% whole_tract metrics
folderPath = [OutputFolder,'/WMA_clustering'];
tckFiles = dir(fullfile(folderPath, '*.tck'));
for i = 1:length(tckFiles)
oldName = tckFiles(i).name;
newName = regexprep(oldName, '[&-]', '_');
if ~strcmp(oldName, newName)
oldFilePath = fullfile(folderPath, oldName);
newFilePath = fullfile(folderPath, newName);
movefile(oldFilePath, newFilePath);
disp(['Rename tck file:' oldName ' -> ' newName]);
end
end
WM_tck_files = dir(fullfile(OutputFolder,'/WMA_clustering/*.tck'));
tract_name = {};
tract_couts = [];
tract_len = [];
for flag = 1:length(WM_tck_files)
fiber_name = WM_tck_files(flag).name;
fiber_name = fiber_name(1:length(fiber_name)-4);
unix(['tckstats ', [OutputFolder,'/WMA_clustering/',fiber_name,'.tck'],' -dump ',[OutputFolder,'/WMA_clustering/',fiber_name,'.txt'],' -force']);
fiber_txt = importdata([OutputFolder,'/WMA_clustering/',fiber_name,'.txt']);
if ~isempty(fiber_txt)
tract_name = [tract_name; fiber_name];
tract_couts = [tract_couts, length(fiber_txt)];
tract_len = [tract_len, median(fiber_txt)];
else
tract_name = [tract_name; fiber_name];
tract_couts = [tract_couts, nan];
tract_len = [tract_len, nan];
end
end
WM_Path = [OutputFolder,'/WMA_clustering'];
DWI_Path = [OutputFolder,'/DWI/Tracking'];
if exist([WM_Path,'/Stats_DTI'],'dir') == 0
mkdir([WM_Path,'/Stats_DTI'])
end
WM_FA = zeros(length(tract_name),1);
WM_MD = zeros(length(tract_name),1);
WM_AD = zeros(length(tract_name),1);
WM_RD = zeros(length(tract_name),1);
for label = 1:length(tract_name)
view_direction = tract_name{label};
unix(['tcksample ',[WM_Path,'/',view_direction,'.tck'],' ',[DWI_Path,'/dt_fa.mif'],' ',[WM_Path,'/Stats_DTI/FA_',view_direction,'.txt'],' -stat_tck median -force']);
unix(['tcksample ',[WM_Path,'/',view_direction,'.tck'],' ',[DWI_Path,'/dt_md.mif'],' ',[WM_Path,'/Stats_DTI/MD_',view_direction,'.txt'],' -stat_tck median -force']);
unix(['tcksample ',[WM_Path,'/',view_direction,'.tck'],' ',[DWI_Path,'/dt_ad.mif'],' ',[WM_Path,'/Stats_DTI/AD_',view_direction,'.txt'],' -stat_tck median -force']);
unix(['tcksample ',[WM_Path,'/',view_direction,'.tck'],' ',[DWI_Path,'/dt_rd.mif'],' ',[WM_Path,'/Stats_DTI/RD_',view_direction,'.txt'],' -stat_tck median -force']);
FA = importdata([WM_Path,'/Stats_DTI/FA_',view_direction,'.txt']);
MD = importdata([WM_Path,'/Stats_DTI/MD_',view_direction,'.txt']);
AD = importdata([WM_Path,'/Stats_DTI/AD_',view_direction,'.txt']);
RD = importdata([WM_Path,'/Stats_DTI/RD_',view_direction,'.txt']);
if ~isempty(FA) && ~isempty(MD) && ~isempty(AD) && ~isempty(RD)
WM_FA(label) = nanmedian(FA.data);
WM_MD(label) = nanmedian(MD.data);
WM_AD(label) = nanmedian(AD.data);
WM_RD(label) = nanmedian(RD.data);
else
WM_FA(label) = nan;
WM_MD(label) = nan;
WM_AD(label) = nan;
WM_RD(label) = nan;
end
end
Var_Name_WMHs = ['Subject_Name_and_ID', Var_Name_WMHs];
Total_Result_WMHs = [Splited_string{end-1}, Total_Result_WMHs];
Var_Name_DTI = ['Subject_Name_and_ID', strcat(tract_name','_FA'), strcat(tract_name','_MD'), strcat(tract_name','_AD'), strcat(tract_name','_RD'), strcat(tract_name','_Numbers'), strcat(tract_name','_Median_Length')];
Total_Result_DTI = [Splited_string{end-1}, num2cell(WM_FA'), num2cell(WM_MD'), num2cell(WM_AD'), num2cell(WM_RD'), num2cell(tract_couts), num2cell(tract_len)];
writecell([Var_Name_WMHs; Total_Result_WMHs],[OutputFolder,filesep,Splited_string{end-1},'_74_tracts.xlsx'],'Sheet',1);
writecell([Var_Name_DTI; Total_Result_DTI],[OutputFolder,filesep, Splited_string{end-1},'_74_tracts.xlsx'],'Sheet',2);
end