/
callContinuous.m_backup3
225 lines (166 loc) · 5.19 KB
/
callContinuous.m_backup3
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
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; %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
%% 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 (MSD video of sorts)
% 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
for ii = analyze
for jj = 1:length(xPos{ii})
vx{ii}(jj) = (xPosLong{ii}(jj+startIndex+1) - xPosLong{ii}(jj+startIndex-1))/(2*dt);
vy{ii}(jj) = (yPosLong{ii}(jj+startIndex+1) - yPosLong{ii}(jj+startIndex-1))/(2*dt);
end
% 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} = smooth(v{ii},20);
end
%% Calculate angle by linear fit of neighborhood
for ii = analyze
theta{ii} = findAngle(vx{ii},vy{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/2 | abs(theta{ii}(jj)-theta0)>3*pi/2
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),segDir{ii},segDistance{ii},segTime{ii},percentActive(ii)] = segFind(meanLogSlope{ii},direction{ii},xPos{ii},yPos{ii},smoothFactor,dt);
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})
title('Plot by segment transport state')
pause
%plotByDir(xPos{ii},yPos{ii},direction{ii})
%pause
clf
end
%% Plot by mean segment direction
for ii = analyze
plotBySegDir(xPos{ii},yPos{ii},event{ii},segDir{ii})
title('Plot by segment direction, green away from body')
pause
clf
end
%
% hist(meanRunV(analyze)./meanStagV(analyze))
% pause
%% Plot histogram of distance travelled in active segments
for ii = analyze
hist(segDistance{ii}(find(segType{ii}==3)))
pause
end
close all
%% Summary of variables:
%
% xPos: x-position of particle [m]
% yPos: y-position of particle [m]
% dt: video timestep [sec]
% dx/dy: pixel size [m]
% analyze: vector of indices for particles to be analyzed
% maxTau: max timescale to calculate MSD. Determines width of window
% sampled around each point, and consequentially the number of time points
% that are discarded at the beginning of xPos and yPos
% xPosLong: After discarding maxTau/dt/2 at beginning of xPos and yPos,
% xPosLong contains the entire original position vector, in case needed
% startIndex
% MSD: Mean square displacement
% meanLogSlope: slope of linear fit of loglog for MSD
% tau: timescale, abscissa of MSD
% slopeMin: minimum timescale in range of MSD used to calculate
% meanLogSlope
% slopeMax: max timescale tau in range of MSD used to calculate
% meanLogSlope
% theta: angle of
% vSmooth
% direction
% meanRunV
% meanStagV
% event
% segLength
% segType
% nSeg
%segDir
% segDistance
% segTime
% percentActive