forked from nputs/Gannet2.0_nicksversion
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathExportToCSV.m
203 lines (177 loc) · 11 KB
/
ExportToCSV.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
function ExportToCSV(MRS_struct, target, kk, module)
round2 = @(x) round(x*1e3)/1e3;
vox = MRS_struct.p.Vox{kk};
for trg = 1:length(target)
if ~strcmpi(target{trg},'GABAGlx')
metab = target{trg};
end
if strcmp(MRS_struct.p.vendor,'Siemens_rda')
out.matlabVersion = cellstr(repmat(version('-release'), [length(MRS_struct.metabfile)/2 1]));
out.GannetVersion = cellstr(repmat('3', [length(MRS_struct.metabfile)/2 1]));
out.date = cellstr(repmat(date, [length(MRS_struct.metabfile)/2 1]));
else
out.matlabVersion = cellstr(repmat(version('-release'), [length(MRS_struct.metabfile) 1]));
out.GannetVersion = cellstr(repmat('3', [length(MRS_struct.metabfile) 1]));
out.date = cellstr(repmat(date, [length(MRS_struct.metabfile) 1]));
end
%%% 1. Extract data from GannetFit %%%
if strcmp(MRS_struct.p.vendor,'Siemens_rda')
out.filename = MRS_struct.metabfile(1:2:end);
else
out.filename = MRS_struct.metabfile(:);
end
out.AvgDeltaF0 = MRS_struct.out.AvgDeltaF0(:);
if strcmpi(target{trg},'GABAGlx')
if strcmp(MRS_struct.p.Reference_compound,'H2O')
out.GABA.ConcIU = MRS_struct.out.(vox).GABA.ConcIU(:);
out.GABA.ConcCr = MRS_struct.out.(vox).GABA.ConcCr(:);
out.GABA.FitError_W = MRS_struct.out.(vox).GABA.FitError_W(:);
out.GABA.FitError_Cr = MRS_struct.out.(vox).GABA.FitError_Cr(:);
out.GABA.FWHM = MRS_struct.out.(vox).GABA.FWHM(:);
out.GABA.SNR = MRS_struct.out.(vox).GABA.SNR(:);
out.Glx.ConcIU = MRS_struct.out.(vox).Glx.ConcIU(:);
out.Glx.ConcCr = MRS_struct.out.(vox).Glx.ConcCr(:);
out.Glx.FitError_W = MRS_struct.out.(vox).Glx.FitError_W(:);
out.Glx.FitError_Cr = MRS_struct.out.(vox).Glx.FitError_Cr(:);
out.Glx.FWHM = MRS_struct.out.(vox).Glx.FWHM(:);
out.Glx.SNR = MRS_struct.out.(vox).Glx.SNR(:);
else
out.GABA.ConcCr = MRS_struct.out.(vox).GABA.ConcCr(:);
out.GABA.FitError_Cr = MRS_struct.out.(vox).GABA.FitError_Cr(:);
out.GABA.FWHM = MRS_struct.out.(vox).GABA.FWHM(:);
out.GABA.SNR = MRS_struct.out.(vox).GABA.SNR(:);
out.Glx.ConcCr = MRS_struct.out.(vox).Glx.ConcCr(:);
out.Glx.FitError_Cr = MRS_struct.out.(vox).Glx.FitError_Cr(:);
out.Glx.FWHM = MRS_struct.out.(vox).Glx.FWHM(:);
out.Glx.SNR = MRS_struct.out.(vox).Glx.SNR(:);
end
else
if strcmp(MRS_struct.p.Reference_compound,'H2O')
out.(metab).ConcIU = MRS_struct.out.(vox).(metab).ConcIU(:);
out.(metab).ConcCr = MRS_struct.out.(vox).(metab).ConcCr(:);
out.(metab).FitError_W = MRS_struct.out.(vox).(metab).FitError_W(:);
out.(metab).FitError_Cr = MRS_struct.out.(vox).(metab).FitError_Cr(:);
out.(metab).FWHM = MRS_struct.out.(vox).(metab).FWHM(:);
out.(metab).SNR = MRS_struct.out.(vox).(metab).SNR(:);
else
out.(metab).ConcCr = MRS_struct.out.(vox).(metab).ConcCr(:);
out.(metab).FitError_Cr = MRS_struct.out.(vox).(metab).FitError_Cr(:);
out.(metab).FWHM = MRS_struct.out.(vox).(metab).FWHM(:);
out.(metab).SNR = MRS_struct.out.(vox).(metab).SNR(:);
end
end
if strcmp(MRS_struct.p.Reference_compound,'H2O')
out.water.FWHM = MRS_struct.out.(vox).water.FWHM(:);
out.water.SNR = MRS_struct.out.(vox).water.SNR(:);
end
out.NAA.FWHM = MRS_struct.out.(vox).NAA.FWHM(:);
out.NAA.SNR = MRS_struct.out.(vox).NAA.SNR(:);
if strcmpi(target{trg},'GABAGlx')
if strcmp(MRS_struct.p.Reference_compound,'H2O')
T = table(out.matlabVersion, out.GannetVersion, out.date, out.filename, round2(out.AvgDeltaF0), ...
round2(out.GABA.ConcIU), round2(out.GABA.ConcCr), round2(out.GABA.FitError_W), round2(out.GABA.FitError_Cr), round2(out.GABA.FWHM), round2(out.GABA.SNR), ...
round2(out.Glx.ConcIU), round2(out.Glx.ConcCr), round2(out.Glx.FitError_W), round2(out.Glx.FitError_Cr), round2(out.Glx.FWHM), round2(out.Glx.SNR), ...
round2(out.water.FWHM), round2(out.water.SNR), round2(out.NAA.FWHM), round2(out.NAA.SNR), ...
'VariableNames', {'MATLAB_version', 'Gannet_version', 'DateofAnalysis', 'Filename', 'Avg_Delta_F0', ...
'GABA_ConcIU', 'GABA_ConcCr', 'GABA_FitError_W', 'GABA_FitError_Cr', 'GABA_FWHM','GABA_SNR', ...
'Glx_ConcIU', 'Glx_ConcCr', 'Glx_FitError_W', 'Glx_FitError_Cr', 'Glx_FWHM','Glx_SNR', ...
'H2O_FWHM', 'H2O_SNR', 'NAA_FWHM', 'NAA_SNR'});
else
T = table(out.matlabVersion, out.GannetVersion, out.date, out.filename, round2(out.AvgDeltaF0), ...
round2(out.GABA.ConcCr), round2(out.GABA.FitError_Cr), round2(out.GABA.FWHM), round2(out.GABA.SNR), ...
round2(out.Glx.ConcCr), round2(out.Glx.FitError_Cr), round2(out.Glx.FWHM), round2(out.Glx.SNR), ...
round2(out.NAA.FWHM), round2(out.NAA.SNR), ...
'VariableNames', {'MATLAB_version', 'Gannet_version', 'DateofAnalysis', 'Filename', 'Avg_Delta_F0', ...
'GABA_ConcCr', 'GABA_FitError_Cr', 'GABA_FWHM','GABA_SNR', ...
'Glx_ConcCr', 'Glx_FitError_Cr', 'Glx_FWHM','Glx_SNR', ...
'NAA_FWHM', 'NAA_SNR'});
end
else
if strcmp(MRS_struct.p.Reference_compound,'H2O')
T = table(out.matlabVersion, out.GannetVersion, out.date, out.filename, round2(out.AvgDeltaF0), ...
round2(out.(metab).ConcIU), round2(out.(metab).ConcCr), round2(out.(metab).FitError_W), round2(out.(metab).FitError_Cr), round2(out.(metab).FWHM), round2(out.(metab).SNR), ...
round2(out.water.FWHM), round2(out.water.SNR), round2(out.NAA.FWHM), round2(out.NAA.SNR), ...
'VariableNames', {'MATLAB_version', 'Gannet_version', 'DateofAnalysis', 'Filename', 'Avg_Delta_F0', ...
[metab '_ConcIU'], [metab '_ConcCr'], [metab '_FitError_W'], [metab '_FitError_Cr'], [metab '_FWHM'], [metab '_SNR'], ...
'H2O_FWHM', 'H2O_SNR', 'NAA_FWHM', 'NAA_SNR'});
else
T = table(out.matlabVersion, out.GannetVersion, out.date, out.filename, round2(out.AvgDeltaF0), ...
round2(out.(metab).ConcCr), round2(out.(metab).FitError_Cr), round2(out.(metab).FWHM), round2(out.(metab).SNR), ...
round2(out.NAA.FWHM), round2(out.NAA.SNR), ...
'VariableNames', {'MATLAB_version', 'Gannet_version', 'DateofAnalysis', 'Filename', 'Avg_Delta_F0', ...
[metab '_ConcCr'], [metab '_FitError_Cr'], [metab '_FWHM'], [metab '_SNR'], ...
'NAA_FWHM', 'NAA_SNR'});
end
end
% Break loop if function invoked in GannetFit
if strcmpi(module,'fit')
csv_name = ['MRS_struct_' target{trg} '_' vox '.csv'];
writetable(T, csv_name);
continue
end
%%% 2. Extract data from GannetSegment %%%
if strcmp(MRS_struct.p.Reference_compound,'H2O')
if strcmpi(target{trg},'GABAGlx')
out.GABA.ConcIU_CSFcorr = MRS_struct.out.(vox).GABA.ConcIU_CSFcorr(:);
out.Glx.ConcIU_CSFcorr = MRS_struct.out.(vox).Glx.ConcIU_CSFcorr(:);
else
out.(metab).ConcIU_CSFcorr = MRS_struct.out.(vox).(metab).ConcIU_CSFcorr(:);
end
end
out.tissue.fGM = MRS_struct.out.(vox).tissue.GMfra(:);
out.tissue.fWM = MRS_struct.out.(vox).tissue.WMfra(:);
out.tissue.fCSF = MRS_struct.out.(vox).tissue.CSFfra(:);
if strcmpi(target{trg},'GABAGlx')
if strcmp(MRS_struct.p.Reference_compound,'H2O')
U = table(round2(out.GABA.ConcIU_CSFcorr), round2(out.Glx.ConcIU_CSFcorr), ...
round2(out.tissue.fGM), round2(out.tissue.fWM), round2(out.tissue.fCSF), ...
'VariableNames', {'GABA_ConcIU_CSFcorr', 'Glx_ConcIU_CSFcorr', ...
'fGM', 'fWM', 'fCSF'});
else
U = table(round2(out.tissue.fGM), round2(out.tissue.fWM), round2(out.tissue.fCSF), ...
'VariableNames', {'fGM', 'fWM', 'fCSF'});
end
else
if strcmp(MRS_struct.p.Reference_compound,'H2O')
U = table(round2(out.(metab).ConcIU_CSFcorr), ...
round2(out.tissue.fGM), round2(out.tissue.fWM), round2(out.tissue.fCSF), ...
'VariableNames', {[metab '_ConcIU_CSFcorr'], ...
'fGM', 'fWM', 'fCSF'});
else
U = table(round2(out.tissue.fGM), round2(out.tissue.fWM), round2(out.tissue.fCSF), ...
'VariableNames', {'fGM', 'fWM', 'fCSF'});
end
end
T = [T U]; %#ok<*AGROW>
% Break loop if function invoked in GannetSegment
if strcmpi(module,'segment')
csv_name = ['MRS_struct_' target{trg} '_' vox '.csv'];
writetable(T, csv_name);
continue
end
%%% 3. Extract data from GannetQuantify %%%
if strcmpi(target{trg},'GABAGlx')
out.GABA.ConcIU_TissCorr = MRS_struct.out.(vox).GABA.ConcIU_TissCorr(:);
out.GABA.ConcIU_AlphaTissCorr = MRS_struct.out.(vox).GABA.ConcIU_AlphaTissCorr(:);
out.GABA.ConcIU_AlphaTissCorr_GrpNorm = MRS_struct.out.(vox).GABA.ConcIU_AlphaTissCorr_GrpNorm(:);
out.Glx.ConcIU_TissCorr = MRS_struct.out.(vox).Glx.ConcIU_TissCorr(:);
out.Glx.ConcIU_AlphaTissCorr = MRS_struct.out.(vox).Glx.ConcIU_AlphaTissCorr(:);
out.Glx.ConcIU_AlphaTissCorr_GrpNorm = MRS_struct.out.(vox).Glx.ConcIU_AlphaTissCorr_GrpNorm(:);
else
out.(metab).ConcIU_TissCorr = MRS_struct.out.(vox).(metab).ConcIU_TissCorr(:);
out.(metab).ConcIU_AlphaTissCorr = MRS_struct.out.(vox).(metab).ConcIU_AlphaTissCorr(:);
out.(metab).ConcIU_AlphaTissCorr_GrpNorm = MRS_struct.out.(vox).(metab).ConcIU_AlphaTissCorr_GrpNorm(:);
end
if strcmpi(target{trg},'GABAGlx')
V = table(round2(out.GABA.ConcIU_TissCorr), round2(out.GABA.ConcIU_AlphaTissCorr), round2(out.GABA.ConcIU_AlphaTissCorr_GrpNorm), ...
round2(out.Glx.ConcIU_TissCorr), round2(out.Glx.ConcIU_AlphaTissCorr), round2(out.Glx.ConcIU_AlphaTissCorr_GrpNorm), ...
'VariableNames', {'GABA_ConcIU_TissCorr', 'GABA_ConcIU_AlphaTissCorr', 'GABA_ConcIU_AlphaTissCorr_GrpNorm', ...
'Glx_ConcIU_TissCorr', 'Glx_ConcIU_AlphaTissCorr', 'Glx_ConcIU_AlphaTissCorr_GrpNorm'});
else
V = table(round2(out.(metab).ConcIU_TissCorr), round2(out.(metab).ConcIU_AlphaTissCorr), round2(out.(metab).ConcIU_AlphaTissCorr_GrpNorm), ...
'VariableNames', {[metab '_ConcIU_TissCorr'], [metab '_ConcIU_AlphaTissCorr'], [metab '_ConcIU_AlphaTissCorr_GrpNorm']});
end
T = [T V];
csv_name = ['MRS_struct_' target{trg} '_' vox '.csv'];
writetable(T, csv_name);
end