forked from MPUmri/RRIFT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc06_doRRIFT_downsampled.m
164 lines (147 loc) · 4.39 KB
/
c06_doRRIFT_downsampled.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
% This script applies RRIFT and the ETM on downsampled in-vivo data.
% Estimated runtime: 600 seconds
clearvars
fclose('all')
addpath('./mfiles')
inDir = './data/TCGA-GBM-Results/c01_preprocessed';
outMapDir = './data/TCGA-GBM-Results/c06_downsampled';
if ~exist(outMapDir)
mkdir(outMapDir)
end
matFiles = dir([inDir '/*.mat']);
tic
for q=1:length(matFiles)
curFile = matFiles(q).name;
outFile = fullfile(outMapDir,curFile);
load(fullfile(inDir,curFile));
% 'Ct','Cp','Crr','t','maskCt','maskCrr','maskCp'
Crr(Crr<0)=0;
Ct(Ct<0)=0;
CpPop = GeorgiouAif(t,t(7));
Cp(Cp<0)=0;
qtMask = max(Ct) > 0.01;
numGoodVox = sum(qtMask(:));
numVox = sum(maskCt(:));
Ct = Ct(:,qtMask);
maskCt(maskCt) = qtMask;
%%
numVox = sum(maskCt(:));
dFactors = 1:10;
pkETM = zeros(numVox,3,length(dFactors));
pkCE = zeros(numVox,5,length(dFactors));
for i=1:length(dFactors)
dFactor = dFactors(i);
phaseValues = randi([0 dFactor-1],numVox,1);
pkERRM = zeros(numVox,5);
for j=1:numVox
curT = downsample(t,dFactor, phaseValues(j));
curCt = downsample(Ct(:,j), dFactor, phaseValues(j));
curCp = downsample(Cp, dFactor, phaseValues(j));
curCrr = downsample(Crr, dFactor, phaseValues(j));
pkETM(j,:,i)=Tofts_LLSQ(curCt,curCp,curT,1);
pkERRM(j,:)=ERRM(curCt,curCrr,curT);
end
rawKepRR = pkERRM(:,5);
if std(rawKepRR)<1e-3
% If the estimated kepRR from ERRM is closely grouped, then use median
% This situation is very unlikely to happen in clinical data
% The practical purpose of this is that when simulating
% noiseless data, the interquartile mean can't be used because
% there is no fluctuation in the estimated kepRR from ERRM
estKepRR = nanmedian(rawKepRR);
else
% Find voxels where all estimates are real and positive
goodVals = pkERRM(:,1)>0 & pkERRM(:,2)>0 & pkERRM(:,3)>0 & pkERRM(:,4)>0 & pkERRM(:,5)>0 & imag(pkERRM(:,5))==0;
estKepRR = iqrMean(rawKepRR(goodVals));
end
for j=1:numVox
curT = downsample(t,dFactor, phaseValues(j));
curCt = downsample(Ct(:,j), dFactor, phaseValues(j));
curCp = downsample(Cp, dFactor, phaseValues(j));
curCrr = downsample(Crr, dFactor, phaseValues(j));
pkCE(j,:,i) = CERRM(curCt,curCrr,curT,estKepRR);
end
curT = downsample(t, dFactor,phaseValues(1));
curCrr = downsample(Crr, dFactor, phaseValues(1));
curCp = downsample(Cp, dFactor, phaseValues(1));
curCpPop = downsample(CpPop, dFactor, phaseValues(1));
fTail = find(curT>3,1);
estKtRRs(i) = RRIFT(curCp(fTail:end),curCrr(fTail:end),curT(fTail:end),estKepRR);
estKtRRsPop(i) = RRIFT(curCpPop(fTail:end),curCrr(fTail:end),curT(fTail:end),estKepRR);
estKepRRs(i) = estKepRR;
TRes(i) = (curT(2)-curT(1))*60;
pkCE(:,1,i) = pkCE(:,1,i)*estKtRRs(i);
pkCE(:,2,i) = pkCE(:,2,i)*(estKtRRs(i)/estKepRRs(i));
pkCE(:,4,i) = pkCE(:,4,i)*estKtRRs(i);
end
save(fullfile(outMapDir,curFile),'dFactors','TRes','estKtRRs','estKtRRsPop','estKepRRs',...
'maskCt','pkETM','pkCE','Crr','Cp','t');
end
toc
return
%%
errKep = PercentError(rrKep,etKep);
errKt = PercentError(rrKt,etKt);
errVe=PercentError(rrVe,etVe);
%%
plot(errKep)
%%
plot(errKt)
%%
plot(errVe)
%%
plot(1:27,errKep,1:27,errKt)
%%
gbmErrKep = errKep(1:17);
errMask = abs(gbmErrKep)<40;
goodErr = gbmErrKep(errMask);
badErr = gbmErrKep(~errMask);
scatter(1:length(goodErr), goodErr, 'filled')
hold on
scatter(1:length(badErr), badErr, 'filled')
xlim([0 12])
%%
x = abs(PercentError(rrKt,etKt)) < 40 & abs(PercentError(rrKep,etKep)) < 40;
sum(x)
%%
x = errMask;
for i=1:length(x)
if ~x(i)
continue
end
i
h=figure;
plot(tList{i},cpList{i})
hold on
plot(tList{i},estCpList{i})
waitfor(h)
end
%%
x = errMask;
for i=1:length(x)
if ~x(i)
continue
end
i
h=figure;
plot(tList{i},crrList{i})
hold on
plot(tList{i},emmCrrList{i})
waitfor(h)
end
%%
gVal = [2,3,4,5,6,14,16];
gVal2 = [2,3,4,5,6,14,16,7,8,13,15];
gVal=[2,3,4,5,6,7,8,10,13,14,16];
curVal = gVal;
for i=1:length(curVal)
curI = curVal(i)
estCrr = ToftsKety(cpList{curI},[ttKt(curI) ttKep(curI) etVp(curI)],tList{curI},0);
h=figure;
scatter(tList{curI},crrList{curI}); hold on;
plot(tList{curI},estCrr)
title(curI)
end
%%
gVal=[2,3,4,5,6,7,10,13,14,16];
scatter(ttVe(gVal),rrVe(gVal))