data를 자석 높이별로 구분한 뒤, 분석하여 bead에 가해진 힘 결정
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%% Top level section 3: FX3_ANALYZE %%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if 1
%%% This is the third section in a series of routines to analyze
%%% force-extension data taken with the new multi bead code for MT
%%% (J. P. Cnossen, D. Dulin and N. H. Dekker Rev Sci Instrum 85, (2014).)
%%%
%%% This section assumes that you have read the (z-offset corrected) raw
%%% data traces
%%%
%%% Author: Jan Lipfert
%%% Date: 2013-09-16, updated 2014-07-17
clc;
plotflag = 1; %%% Whether or not to show the fits
%%% Some variables ----------------------------------------------
kT = 4.1;
Rbead = 1.4; % Bead radius in mum
%% 1um bead 사용시 수정해야 함
%%% ---------------------------------------------------------------
%%% Figure out where the magnets are moving, from the motor file
%%% This determines the "plateaus", where the nmagnet height is
%%% constant and where we we want to analyze the forces
%%% ---------------------------------------------------------------
Nsmooth_zmag = 200;
Nsmooth_dzmag = 200;
small = 10^(-5); %%% Threshold to determine where it is moving
%%% Some variables for error checking
Nmin_points_plat = 100; % Minimum number of points in a plateau
zmags = [];
if 1
zmag_smooth = smooth(zmag, Nsmooth_zmag, 'moving');
diff_zmag = smooth(diff(zmag_smooth), Nsmooth_dzmag, 'lowess');
%%% Find all the "plateaus", i.e. the sets of points where the magnets
%%% are not moving up or down
Nfirst =1; Nlast =1;
%%% Check whether we are starting in a plateau
if (abs(diff_zmag(1)) < small & abs(diff_zmag(2)) < small)
tplat(1).first = 1;
Nfirst = Nfirst +1;
end
for i=2:length(diff_zmag)
if (abs(diff_zmag(i)) < small & abs(diff_zmag(i-1)) > small)
tplat(Nfirst).first = i;
Nfirst = Nfirst +1;
end
if (abs(diff_zmag(i)) > small & abs(diff_zmag(i-1)) < small)
tplat(Nlast).last = i;
Nlast = Nlast +1;
end
end
%%% Check whether we are ending in a plateau
if (abs(diff_zmag(end)) < small & abs(diff_zmag(end-1)) < small)
tplat(Nlast).last = length(diff_zmag);
Nlast = Nlast +1;
end
Nplat = Nfirst-1;
display(['Found ' num2str(Nplat) ' Zmag plateaus']);
%display(['Nfirst ' num2str(Nfirst) ' Nlast ' num2str(Nlast)]);
%%% Throw out plateaus that have fewer than Nmin_points_plat points
%%% This is not quite it yet, since it keeps the plateaus separate that
%%% are interupted by a "fake" (i.e. too short) plateau, but getting it
%%% perfect is tricky
if 1
count = 1;
Ngoodplat = 0;
for j = 1:Nplat
if length(tplat(j).first:tplat(j).last) > Nmin_points_plat
plat(count).first = tplat(j).first;
plat(count).last = tplat(j).last;
Ngoodplat = Ngoodplat + 1;
count = count + 1;
else
display(['Plateau # ' num2str(j) ' has only ' num2str(length(Nmin_points_plat)) ' points!' ])
end
end
Nplat = Ngoodplat;
end
%%% Plot the magnet height information, after smoothing, with
%%% plateaus annotated
if 1
figure(1);clf; hold on; box on; %%% Magnet rot. vs. time
platind = find(abs(diff_zmag) < small);
faketime = 1:length(zmag_smooth);
plot(faketime , zmag_smooth, 'b-')
plot(faketime(platind), zmag_smooth(platind), 'r.')
for j = 1:Nplat
plot(faketime(plat(j).first) , zmag_smooth(plat(j).first), 'ko', 'markersize', 10)
plot(faketime(plat(j).last) , zmag_smooth(plat(j).last), 'mo', 'markersize', 10)
%%% Capture the output
zmags = [zmags zmag_smooth(plat(j).last)];
end
set(gca, 'fontsize', 14, 'fontweight', 'bold', 'linewidth', 1,'TickLength',[0.02 0.02])
xlabel('Time'); ylabel('Zmag')
title(['Red = plateaus; Black / magneta circles = start / stop; Found ' num2str(Nplat) ' plateaus.' ])
figure(2);clf; hold on; box on; %%% Derivative of magnet rot. vs. time
plot(1:length(diff_zmag) , diff_zmag, 'b-')
set(gca, 'fontsize', 14, 'fontweight', 'bold', 'linewidth', 1,'TickLength',[0.02 0.02])
xlabel('Time'); ylabel('dzmag/dt')
end
end
%%% ------- END PLATEAU FINDIND --------- %%%
%pause;
%%% ------------------------------------------------------- %%%
%%% Look over the beads and determine the force for each plateau
%%% ------------------------------------------------------- %%%
if 1
for i=1:Nbeads
bead(i).ext = zeros(1,Nplat);
bead(i).Fx_real = zeros(1,Nplat);
bead(i).Fy_real = zeros(1,Nplat);
bead(i).PSDforce = zeros(1,Nplat);
bead(i).AVforce = zeros(1,Nplat);
bead(i).fcorner = zeros(1,Nplat);
bead(i).SAforce = zeros(1,Nplat);
bead(i).fcorner2 = zeros(1,Nplat);
%%% Use the script "analyze_one_trace" to determine the force for each trace
for k=1:Nplat
if length(plat(k).first:plat(k).last) > Nmin_points_plat
[bead(i).ext(k),...
bead(i).Fx_real(k),...
bead(i).Fy_real(k),...
bead(i).PSDforce(k),...
PSDfit,...
bead(i).AVforce(k),...
AVfit,...
bead(i).fcorner(k),...
SAfit,...
bead(i).SAforce(k),...
bead(i).fcorner2(k)] = ...
analyze_one_trace(bead(i).time(plat(k).first:plat(k).last),...
bead(i).x(plat(k).first:plat(k).last),...
bead(i).y(plat(k).first:plat(k).last),...
bead(i).z(plat(k).first:plat(k).last),...
i, F_IND, freq, plotflag); %For this example, we replace x dimension with y dimension to keep the size of data small
display(['Working on bead # ' num2str(i) ', plateau number ' num2str(k)])
if plotflag == 1
% pause;
end
end
end
%% 각 높이에서 힘 및 코너 프리컨시 추출
%%% Fit a two exponential model to the data
%%% The model: F0 + Amp * exp(Zmag/l_decay) + Amp * exp(Zmag/l_decay)
%%% Note that this is just an empirical fit, no real physics
s=exp2fit(zmags, bead(i).PSDforce,2);
bead(i).PSD_F0 = s(1);
bead(i).PSD_Amp = s(2);
bead(i).PSD_2_decay = s(3);
bead(i).PSD_Amp_2 = s(4);
bead(i).PSD_2_decay_2 = s(5);
bead(i).PSD_Zfit = min(zmags):0.01:max(zmags);
bead(i).PSD_Ffit = s(1)+s(2)*exp(-bead(i).PSD_Zfit/s(3))+s(4)*exp(-bead(i).PSD_Zfit/s(5));
s=exp2fit(zmags, bead(i).AVforce,2);
bead(i).AV_F0 = s(1);
bead(i).AV_Amp = s(2);
bead(i).AV_2_decay = s(3);
bead(i).AV_Amp_2 = s(4);
bead(i).AV_2_decay_2 = s(5);
bead(i).AV_Zfit = min(zmags):0.01:max(zmags);
bead(i).AV_Ffit = s(1)+s(2)*exp(-bead(i).AV_Zfit/s(3))+s(4)*exp(-bead(i).AV_Zfit/s(5));
s=exp2fit(zmags, bead(i).SAforce,2);
bead(i).SA_F0 = s(1);
bead(i).SA_Amp = s(2);
bead(i).SA_2_decay = s(3);
bead(i).SA_Amp_2 = s(4);
bead(i).SA_2_decay_2 = s(5);
bead(i).SA_Zfit = min(zmags):0.01:max(zmags);
bead(i).SA_Ffit = s(1)+s(2)*exp(-bead(i).SA_Zfit/s(3))+s(4)*exp(-bead(i).SA_Zfit/s(5));
if 1
%%% Fit the WLC chain model to the data
%%% This is real physics and determines Lp (persistence length)
%%% and Lc (the contour length)
[bead(i).PSD_Lp, bead(i).PSD_Lc, bead(i).PSD_Forcefit, bead(i).PSD_Extfit] = inExtWLCfit(bead(i).ext, bead(i).PSDforce, 0.1);
[bead(i).AV_Lp, bead(i).AV_Lc, bead(i).AV_Forcefit, bead(i).AV_Extfit] = inExtWLCfit(bead(i).ext, bead(i).AVforce, 0.1);
[bead(i).SA_Lp, bead(i).SA_Lc, bead(i).SA_Forcefit, bead(i).SA_Extfit] = inExtWLCfit(bead(i).ext, bead(i).SAforce, 0.1);
end
%%% Show a Force vs. Zmag plot for this bead
if 1
%%% Plot F vs. Zmag, linear
figure(3); clf; hold on; box on;
plot(zmags, bead(i).Fx_real, 'ko', 'markersize', 15, 'linewidth', 1)
plot(zmags, bead(i).PSDforce, 'bo', 'markersize', 15, 'linewidth', 2)
plot(zmags, bead(i).AVforce, 'ro', 'markersize', 15, 'linewidth', 2)
plot(zmags, bead(i).SAforce, 'go', 'markersize', 15, 'linewidth', 2)
%%% Plot the fits
plot(bead(i).PSD_Zfit, bead(i).PSD_Ffit, 'b-', 'linewidth', 2)
plot(bead(i).AV_Zfit, bead(i).AV_Ffit, 'r-', 'linewidth', 2)
plot(bead(i).SA_Zfit, bead(i).SA_Ffit, 'g-', 'linewidth', 2)
set(gca, 'fontsize', 18, 'fontweight', 'bold', 'linewidth', 1,'TickLength',[0.02 0.02])
xlabel('Magnet position (mm)');
ylabel('Force (pN)');
legend('Real space', 'PSD', 'Allan', 'SA')
%%% Show the fitted parameter from the Allan variance fit in the title
title(['From AV fit: Amp=' num2str(bead(i).AV_Amp,3) '; l(decay)=' num2str(bead(i).AV_2_decay,3) '; Amp2=' num2str(bead(i).AV_Amp_2,3) '; l(decay)2=' num2str(bead(i).AV_2_decay_2,3) '; F0=' num2str(bead(i).AV_F0,2) ])
%%% Plot F vs. Zmag, log scaling
figure(4); clf; hold on; box on;
plot(zmags, bead(i).Fx_real, 'ko', 'markersize', 15, 'linewidth', 1)
plot(zmags, bead(i).PSDforce, 'bo', 'markersize', 15, 'linewidth', 2)
plot(zmags, bead(i).AVforce, 'ro', 'markersize', 15, 'linewidth', 2)
plot(zmags, bead(i).SAforce, 'go', 'markersize', 15, 'linewidth', 2)
%%% Plot the fits
plot(bead(i).PSD_Zfit, bead(i).PSD_Ffit, 'b-', 'linewidth', 2)
plot(bead(i).AV_Zfit, bead(i).AV_Ffit, 'r-', 'linewidth', 2)
plot(bead(i).SA_Zfit, bead(i).SA_Ffit, 'g-', 'linewidth', 2)
set(gca, 'fontsize', 18, 'fontweight', 'bold', 'linewidth', 1,'TickLength',[0.02 0.02])
xlabel('Magnet position (mm)');
ylabel('Force (pN)');
set(gca, 'yscale', 'log')
legend('Real space', 'PSD', 'Allan', 'SA')
title(['Bead # ' num2str(i)])
end
%%% Show a FX plot for this bead
if 1
%%% Plot force vs. DNA extension
figure(5); clf; hold on; box on;
plot(bead(i).ext, bead(i).Fx_real, 'ko', 'markersize', 15, 'linewidth', 1)
plot(bead(i).ext, bead(i).PSDforce, 'bo', 'markersize', 15, 'linewidth', 2)
plot(bead(i).ext, bead(i).AVforce, 'ro', 'markersize', 15, 'linewidth', 2)
plot(bead(i).ext, bead(i).SAforce, 'go', 'markersize', 15, 'linewidth', 2)
if 1
plot(bead(i).PSD_Extfit, bead(i).PSD_Forcefit, 'b-', 'markersize', 15, 'linewidth', 2)
plot(bead(i).AV_Extfit, bead(i).AV_Forcefit, 'r-', 'markersize', 15, 'linewidth', 2)
plot(bead(i).SA_Extfit, bead(i).SA_Forcefit, 'g-', 'markersize', 15, 'linewidth', 2)
end
set(gca, 'fontsize', 18, 'fontweight', 'bold', 'linewidth', 1,'TickLength',[0.02 0.02])
xlabel('Extension (um)');
ylabel('Force (pN)');
legend('Real space', 'PSD', 'Allan', 'SA', 'location', 'northwest')
title(['From AV fit: Lp=' num2str(bead(i).AV_Lp*1000,3) 'nm; Lc=' num2str(bead(i).AV_Lc,3) 'um' ])
%%% Log plot
figure(6); clf; hold on; box on;
plot(bead(i).ext, bead(i).Fx_real, 'ko', 'markersize', 15, 'linewidth', 1)
plot(bead(i).ext, bead(i).PSDforce, 'bo', 'markersize', 15, 'linewidth', 2)
plot(bead(i).ext, bead(i).AVforce, 'ro', 'markersize', 15, 'linewidth', 2)
plot(bead(i).ext, bead(i).SAforce, 'go', 'markersize', 15, 'linewidth', 2)
if 1
plot(bead(i).PSD_Extfit, bead(i).PSD_Forcefit, 'b-', 'markersize', 15, 'linewidth', 2)
plot(bead(i).AV_Extfit, bead(i).AV_Forcefit, 'r-', 'markersize', 15, 'linewidth', 2)
plot(bead(i).SA_Extfit, bead(i).SA_Forcefit, 'g-', 'markersize', 15, 'linewidth', 2)
end
set(gca, 'fontsize', 18, 'fontweight', 'bold', 'linewidth', 1,'TickLength',[0.02 0.02])
xlabel('Extension (um)');
ylabel('Force (pN)');
set(gca, 'yscale', 'log')
legend('Real space', 'PSD', 'Allan', 'SA', 'location', 'northwest')
title(['Bead # ' num2str(i)])
end
%%% Show a corner freq vs. Zmag plot for this bead
if 1
figure(7); clf; hold on; box on;
plot(zmags, bead(i).fcorner2, 'ro', 'markersize', 15, 'linewidth', 2)
set(gca, 'fontsize', 14, 'fontweight', 'bold', 'linewidth', 1,'TickLength',[0.02 0.02])
xlabel('Magnet position (mm)');
ylabel('f(corner, Hz)');
end
% pause;
end
end
% 2016.10.07 ??????
%% 분석된 값들 저장
outlength = length(zmags);
out = zeros(6,outlength);
out(1,:)=zmags;
out(2,:)=bead.Fx_real;
out(3,:)=bead.Fy_real;
out(4,:)=bead.PSDforce;
out(5,:)=bead.AVforce;
out(6,:)=bead.SAforce;
out = transpose(out);
out1 = zeros(3,2);
out1(1,1) = bead.PSD_Lp;
out1(2,1) = bead.AV_Lp;
out1(3,1) = bead.SA_Lp;
out1(1,2) = bead.PSD_Lc;
out1(2,2) = bead.AV_Lc;
out1(3,2) = bead.SA_Lc;
save('ForceValues.txt','out','out1','-ascii')
end
'Study > Magnetic tweezers' 카테고리의 다른 글
Low level functions in force analysis Matlab code by Nynke Dekker lab(2014-Dec-3) (0) | 2018.04.12 |
---|---|
FX4_ANALYZE_Lp_Lc (0) | 2018.04.12 |
FX2_LOAD_RAW (0) | 2018.04.12 |
FX1_DETERMINE_ZOFFSET (0) | 2018.04.12 |
force analysis Matlab code by Nynke Dekker lab(2014-Dec-3) (0) | 2018.04.12 |