-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvalFRAP.m
124 lines (102 loc) · 3.73 KB
/
EvalFRAP.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
% [normalized,TotalBleach,params]=EvalFRAP('filename',whichroi,maxframe,prebleach): Evaluates LSM FRAP data by requesting various ROIs and normalising and plotting and fitting the results.
% filename : LSM file to process
% whichroi (optional) : Name the ROI number (if multiples are present) where the bleach was.
% maxframe : limit the analysis to a maximal number of frames (default = -1 = all frames)
% prebleach : number of prebleach images (default = 5)
% fitdecay : if not zero, the decay curve will be fitted to an exponential decay and the fit used for bleach correction
% normalized : normalised FRAP data
% TotalBleach : Curve of total decay during experiment
% params : Fit results [BleachDepth, Recovery, t2]
% Written for Fernanda
%
function [normalized,timepoints,TotalBleach,params]=EvalFrap(filename,whichroi,maxframe,prebleach,fitdecay)
if nargin < 2
whichroi=-1; % all rois are valid
end
if nargin < 3
maxframe=-1; % all rois are valid
end
if nargin < 4
prebleach=5; % number of pre bleach images
end
if nargin < 5
fitdecay=0; % do not fit the decay curve
end
[data,ts,myroi,myroi2]=kLoadLSM(filename);
if maxframe > 0
data=data(:,:,:,0:maxframe-1);
ts=ts(0:maxframe-1);
end
% 'This is the bleach ROI'
roi=cat(3,myroi,myroi2);
if whichroi > 0
roi=roi(:,:,whichroi);
end
hasroi=sum(roi,[],[1 2]) > 0;
if sum(hasroi) ~= 1
roi
error('Data not exactly one ROI');
end
roi=sum(roi,[],3) > 0;
img = mean(data,[],4)
fprintf('Select a ROI to evaluate\n');
[evalROI,v] =diproi(gcf);
evalROI=repmat(evalROI,[1 1 size(data,4)]);
dat2=croptomask(squeeze(data),evalROI)
sz=size(data,4);
clear data
roi2c=croptomask(roi,squeeze(evalROI(:,:,0)));
clear roi
BleachROI=repmat(roi2c,[1 1 sz]);
% Align
fprintf('Aligning Data\n');
dat2c=kcorrelator(dat2,{'p',1;'fixplane',prebleach-1}); % Use plane 4 as reference plane
mImg2 = squeeze(mean(dat2c,[],3));
[datBg, bg, bg_im]=backgroundoffset(mImg2);
bg_im
fprintf('Background is %d\nSelect Reference ROI\n',bg)
mImg2
RefROI=diproi(gcf);
RefROI=repmat(RefROI,[1 1 sz]);
dat2cb=dat2c-bg;
bleach=squeeze(mean(dat2cb,BleachROI,[1 2]));
preBl = mean(bleach(0:prebleach-1));
ref=squeeze(mean(dat2cb,RefROI,[1 2])); % the decay curve in the reference region
preRef = mean(ref(0:prebleach-1)); % the pre bleach average in the reference
tsn=squeeze(ts-ts(prebleach));
tNor=squeeze(tsn(prebleach:end));
timepoints=tsn; % for return
if fitdecay ~= 0
[fittedDecay,params,myfunct,msevalue] = FitNlinData('c(1)+c(2)*exp(-x ./ c(3))',double([0 ref(prebleach) 100]),ref(prebleach:end),tNor);
fprintf('Fitted Decay : Offset : %g, Time: %g\n',params(1),params(3));
figure
plot(tsn,ref,'red');
hold on;
plot(tNor,fittedDecay,'blue');
xlabel('t [s]');
ylabel('Reference ROI');
ref(prebleach:end)=fittedDecay;
end
TotalBleach=ref/preRef
normalized = (bleach/preBl) * preRef /ref;
plot(tsn,normalized)
hold on
recNor=squeeze(normalized(prebleach:end));
tFitStart=tNor(end)/4;
[fitted,params,myfunct,msevalue] = FitNlinData('c(1)+(1-c(1))*c(2)*x./(c(3)+x)',double([recNor(1) recNor(end)-recNor(1) tFitStart]),recNor,tNor);
plot(tNor,fitted,'red')
legend(['Data Bacgkround ' num2str(bg)],['BleachDepth: ' num2str(params(1)) ', Recovery: ' num2str(params(2)) ', t2: ' num2str(params(3)) ' s'])
xlabel('t [s]')
ylabel('normalized recovery')
%dsjkshgdk
% save all that needs to be saved
filebase=filename(1:end-4);
print([filebase '_FRAP.eps'],'-depsc')
print([filebase '_FRAP.jpg'],'-djpeg90')
save([filebase '_fit.txt'],'params','-ASCII')
tosave=double([tNor;fitted])';
save([filebase '_fit_curve.txt'],'tosave','-ASCII')
tosave=double([tsn;normalized])';
save([filebase '_curve.txt'],'tosave','-ASCII')
tiffwrite([filebase '_BgROI.tif'],bg_im,'yes')
tiffwrite([filebase '_BgIm.tif'],mImg2,'yes')