/
callContinuous.m_backup2
145 lines (115 loc) · 3.53 KB
/
callContinuous.m_backup2
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
clear
clc
% Note: this method truncates 'startIndex' points from beginning and end of
% all vectors.
%% Load data
x = pwd;
cd ~/doc/research/projects/vesicleTransport/sampleData
load 1_03min_stretch20_pdms_200fps_extrac.mat
cd(x)
%% Define direction away from cell body, [0,2pi], 0 associated with positive x-direction
theta0 = 0.6266; %radians
%% Add vesicleTransport library to path
addpath ~/git/vesicleTransport
%% Fix default figure position for erdos
set(0,'defaultfigureposition',[330 330 560 420])
%% Constants:
fps = 200;
dt = 1/fps;
dx = 162E-9;
dy = dx;
%% Put position data in xPos, yPos vectors for each particle
%for ii = 1:nParticles
% p{ii} = [xPos{ii},yPos{ii}];
%end
%% Build particle list:
%buildParticleListManual; % FUNCTION TO MANUALLY SELECT PARTICLES
%analyze = indexVec;
analyze = [2 6];% 7 18 6 179 15 69 204];
%analyze = [2 4 6 7 8 10 13 15 18 69 86 94 110 195 204 395 397 403 425 475 476 578 626];
%% Declare continuout MSD parameters
maxTau = 260E-3;
startIndex = round(maxTau/2/dt);
slopeMin = 100E-3;
slopeMax = 200E-3;
%% Calculat meanLogSlope
for ii = analyze
ii
xPosLong{ii} = xPos{ii};
yPosLong{ii} = yPos{ii};
[MSD{ii}, meanLogSlope{ii}, tau{ii}, xPos{ii}, yPos{ii}, t{ii}] = continuousMSD(xPos{ii}, yPos{ii}, maxTau, slopeMin, slopeMax, dt);
end
%% Calculate angle by linear fit of neighborhood
for ii = analyze
theta{ii} = findAngle(xPosLong{ii},yPosLong{ii},startIndex)
end
%% Smooth meanLogSlope
for ii = analyze
meanLogSlopeSmooth{ii} = smooth(meanLogSlope{ii},20);
indexP = meanLogSlopeSmooth{ii}<1.0;
% plot(xPos{ii}(indexP),yPos{ii}(indexP),'r',xPos{ii}(~indexP),yPos{ii}(~indexP),'g')
% pause
end
%
%% Plot things
% for ii = 300:1458
% loglog(tau{2}{ii},MSD{2}{ii},'b',tau{6}{ii},MSD{6}{ii},'r')
% axis([0 1 1E-16 1E-14])
% pause
% end
%% Raw velocity calculation and estimation of runV, stagV
for ii = analyze
vx{ii} = smooth(diff(xPos{ii})/dt,30);
vy{ii} = smooth(diff(yPos{ii})/dt,30);
v{ii} = sqrt(vx{ii}.^2+vy{ii}.^2);
vSmooth{ii} = v{ii};
end
%% Determine direction. 1 -> moving away from cell body. 0 -> moving toward cell body for ii = analyze
for ii = analyze
for jj = 1:length(theta{ii})
if abs(theta{ii}(jj)-theta0)<pi/4 | abs(theta{ii}(jj)-theta0)>3*pi/4
direction{ii}(jj) = 1;
else
direction{ii}(jj) = 0;
end
end
end
%% Find mean run velocity and mean stag velocity for entire trajectory
for ii = analyze
accumA = 0;
countA = 0;
accumP = 0;
countP = 0;
lengthVec = length(v{ii});
for jj = 1:lengthVec %startIndex:length(v{ii}-startIndex)
if meanLogSlope{ii}(jj) > 1
accumA = accumA + vSmooth{ii}(jj);
countA = countA +1;
else
accumP = accumP + vSmooth{ii}(jj);
countP = countP +1;
end
end
meanRunV(ii) = accumA/countA;
meanStagV(ii) = accumP/countP;
end
%% Find and run basic processing on individual segments
smoothFactor = 30; %% Important!
for ii = analyze
[event{ii},segLength{ii},segType{ii},nSeg(ii)] = segFind(meanLogSlope{ii},smoothFactor);
end
% Note: event is identical to ix{} in DPsimplify output
% Note: setType = 1 implies passive motion, 2 implies undetermined, and 3
% implies active transport
%% Plot trajectories, color coded by transport state
figure
for ii = analyze
plotBySeg(xPos{ii}, yPos{ii},event{ii},segType{ii})
pause
%plotByDir(xPos{ii},yPos{ii},direction{ii})
%pause
clf
end
hist(meanRunV(analyze)./meanStagV(analyze))
pause
close all