-
Notifications
You must be signed in to change notification settings - Fork 0
/
MicrotubuleGenerator.m
88 lines (76 loc) · 2.92 KB
/
MicrotubuleGenerator.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
% Code for generating 3D microtubule model
% INPUT
% ************************************************************************
% xsize, ysize, zsize: size of output matrix
% sim_num: number of microtubules
% step_num: total step used for simulation (length?)
%
% OUTPUT
% ************************************************************************
% img: 3D matrix
%
% originally from Fang Huang and Jiaxi Zhao,
% modified by HAO, Xiang
% Aug 31, 2016
function img = MicrotubuleGenerator(xsize,ysize,zsize,sim_num,step_num)
%% parameters
l = 1; % nm
KT = 4.1; % pN/nm
A = 1000;
forces = zeros(1,sim_num);
%% Part 1: Construct a random microtubule map from result generated by WLC
[wlcseries] = WLCmicrotubules(forces,KT,A,l,step_num);
len = size(wlcseries,3);
wlc_centers=mean(wlcseries,1);
normalized_wlc=wlcseries-repmat(wlc_centers,[step_num 1 1]);
randomshift=rand(size(wlc_centers))*1000-500;
random_wlc=normalized_wlc+repmat(randomshift,[step_num 1 1]);
%% Part 2: Shift Origin & normalize chain
% randomized
% shift origin
random_wlc(:,1,:) = random_wlc(:,1,:)-min(min(random_wlc(:,1,:)));
random_wlc(:,2,:) = random_wlc(:,2,:)-min(min(random_wlc(:,2,:)));
random_wlc(:,3,:) = random_wlc(:,3,:)-min(min(random_wlc(:,3,:)));
% normalize chain
random_wlc(:,1,:) = random_wlc(:,1,:)/max(max(abs(random_wlc(:,1,:))));
random_wlc(:,2,:) = random_wlc(:,2,:)/max(max(abs(random_wlc(:,2,:))));
random_wlc(:,3,:) = random_wlc(:,3,:)/max(max(abs(random_wlc(:,3,:))));
% plot randomized chain
figure
hold on
for ii=1:len
plot(random_wlc(:,1,ii),random_wlc(:,2,ii),'color',rand(3,1),'linewidth',2)
end
% normalized
% shift origin
normalized_wlc(:,1,:) = normalized_wlc(:,1,:)-min(min(normalized_wlc(:,1,:)));
normalized_wlc(:,2,:) = normalized_wlc(:,2,:)-min(min(normalized_wlc(:,2,:)));
normalized_wlc(:,3,:) = normalized_wlc(:,3,:)-min(min(normalized_wlc(:,3,:)));
% normalize chain
normalized_wlc(:,1,:) = normalized_wlc(:,1,:)/max(max(abs(normalized_wlc(:,1,:))));
normalized_wlc(:,2,:) = normalized_wlc(:,2,:)/max(max(abs(normalized_wlc(:,2,:))));
normalized_wlc(:,3,:) = normalized_wlc(:,3,:)/max(max(abs(normalized_wlc(:,3,:))));
% plot normalized chain (normalized)
figure
hold on
for ii=1:len
plot(normalized_wlc(:,1,ii),normalized_wlc(:,2,ii),'color',rand(3,1),'linewidth',2)
end
%% Part 3: Generate 3D image
img_original = zeros(xsize,ysize,zsize);
for i = 1:sim_num
for j = 1:step_num
xcart = round(xsize*normalized_wlc(j,1,i)) + 1;
ycart = round(ysize*normalized_wlc(j,2,i)) + 1;
zcart = round(zsize*normalized_wlc(j,3,i)) + 1;
img_original(xcart,ycart,zcart) = 1;
end
end
img_original = img_original(1:xsize,1:ysize,1:zsize);
img = img_original;
% img = imgaussfilt3(img_original,1);
%
% mkdir('./result');
% save(['./result/microtubule_model_',num2str(sim_num),'_' date '.mat'],'img','img_original','-v7.3');
% threeDViewer(img);
end