forked from CamachoDejay/polymer3D
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtestMSDAnalysis.m
More file actions
90 lines (73 loc) · 2.67 KB
/
testMSDAnalysis.m
File metadata and controls
90 lines (73 loc) · 2.67 KB
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
% This code aim at analyzing trajectories and extracting useful metric out
% of the traces (e.g. Diffusion coefficient, viscosity,...)
%
% This code works well with the trackRes output that most of the tracking
% codes output, it just need to be given the path to the folder where the
% trackRes.mat is store, and a few input which are summarized in the frame
% below, the rest is handled by the code internally.
%
clc ;
clear ;
close all;
%% USER INPUT
expTime = 0.02; %in sec
T = 293; %temperature in Kelvin
R = 0.075; %Radius of particle in um;
fitRDiff = 4; %in Fraction of the data
fitRConf = 0.1;%in Fraction of the data
minSize = 10;
ext = '.mat';
path = 'E:\Results\SPT trapping\Trapping 640\pH 3';
%% Loading
folder = dir(path);
idx = contains({folder.name},'trackRes.mat');
folder(~idx) = [];
f2Load = [folder(1).folder filesep folder(1).name];
tmpData = load(f2Load);
name = fieldnames(tmpData);
data = tmpData.(name{1});
%% Processing
currMov = data(1).traces;
allHeight = cellfun(@height,currMov(:,1));
idx = allHeight>minSize;
currMov = currMov(idx,1);
for i = 1: size(data,2)
warning('only analyzing 2D now')
%get CM of all particles
coord = zeros(length(currMov),2);
for j = 1:length(currMov)
coord(j,:) = [mean(currMov{j}.col),mean(currMov{j}.row)];%,mean(currMov{j}.z)];
end
CM = mean(coord,1);
allRes = struct('msd',zeros(length(coord),1),'tau',zeros(length(coord),1),...
'D',0,'n',0,'alpha',0,'rConf',0,'stiff',0);
allRes(length(currMov)).msd = zeros(length(coord),1);
for j = 1:length(currMov)
currPart = currMov{j};
coord = [currPart.col, currPart.row];
coord = coord-CM;
msd = MSD.calc(coord/10^3);%convert to um;
D = MSD.getDiffCoeff(msd,1:length(msd),fitRDiff,'2D');
D = D/expTime;%convert from frame to s-1
n = MSD.getViscosity(D,R,T);
alpha = MSD.getDiffTypeAlpha(msd,expTime);
if alpha < 1
rConf = MSD.getConfRad(msd,fitRConf,expTime);
else
rConf = NaN;
end
stiff = MSD.getTrapStiffness(coord*10^(-9),T);%convert to meter
allRes(j).msd = msd; % in um^2
allRes(j).tau = (1:length(msd))'*expTime; % in sec
allRes(j).D = D;% in um^2 /sec
allRes(j).n = n;% in um^2 /sec
allRes(j).alpha = alpha;%dimension less
allRes(j).rConf = rConf;% in um
allRes(j).stiff = stiff;% in pN/um
end
allData(i).fileName = data(i).fileName;
allData(i).msdRes = allRes;
end
filename = [path filesep 'msdRes.mat'];
save(filename,'allData');
h = msgbox('Data succesfully saved');