Repository navigation
Expand file tree
/
Copy pathExtractHF_BATCH.m
More file actions
122 lines (94 loc) · 3.84 KB
/
Copy pathExtractHF_BATCH.m
File metadata and controls
122 lines (94 loc) · 3.84 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
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
%---------------------
% Viscoelasticity of Sperm Cells
% Tania Mendonca
% Extract high frequency force-displacement data from .h5 file
%---------------------
clear all
close all
% load data
[Path] = uigetdir;
Files = dir(Path);
l = [Files.isdir]; g = l == 0; H = Files(g);
I = unique({H.name}); %NData = I(contains(I,'Bright-field'));
NData = I(contains(I,'.h5')& contains(I,'Sperm'));
foldername = strsplit(Path,"\");
% define output directories
[BasePath,CurrentFolder] = fileparts(cd);
Out = strcat(BasePath,'\', CurrentFolder, '_ExtractedData');
if ~exist(Out, 'dir')
mkdir(Out)
end
HF_Folder = strcat(Out,'\HF');
if ~exist(HF_Folder, 'dir')
mkdir(HF_Folder)
end
%%
for j = 1:length(NData)
j
% import data
info = h5info(NData{j});
File = NData{j};
Filename = strsplit(File,".");
HF_Path = strcat(HF_Folder,'\',Filename{1},'_HF.txt');
%% Get Metadata
temp = h5read(File,'/Temperature/Objective'); % objective temperature
ObjTemp = temp.Value(1);
indexes = reshape(contains({info.Groups.Name}, '/Calibration'),...
size(info.Groups));
TrapStiff1 = h5readatt(File,info.Groups(indexes).Groups(1).Groups(1).Name,...
'kappa (pN/nm)'); % trap 1 stiffness
TrapStiff2 = h5readatt(File,info.Groups(indexes).Groups(1).Groups(4).Name,...
'kappa (pN/nm)'); % trap 2 stiffness
try
rad = h5read(File,'/Bead diameter/Template 1'); % bead radius
beadDiameter = rad.Value(1);
catch
beadDiameter = 3;
end
% create metadata file
metadata(j,:) = table({Filename{1}}, TrapStiff1,TrapStiff2,...
beadDiameter, ObjTemp,...
'VariableNames',{'FileName','Trap Stiffness Bead 1 [pN]',...
'Trap Stiffness Bead 2 [pN]','Bead Diameter [um]',...
'Objective Temperature [oC]'});
%% Extract low frequency force displacement values
fx1 = h5read(File,'/Force HF/Corrected Force 1x'); % force on bead 1 along x
fy1 = h5read(File,'/Force HF/Force 1y'); % force on bead 1 along y
fx2 = h5read(File,'/Force HF/Corrected Force 2x'); % force on bead 2 along x
fy2 = h5read(File,'/Force HF/Force 2y'); % force on bead 2 along y
%fx1 = lfx1.Value; fx2 = lfx2.Value; fy1 = lfy1.Value; fy2 = lfy2.Value;
tpx1 = h5read(File,'/Trap position/1X'); % trap position on moving bead along x
tpy1 = h5read(File,'/Trap position/1Y'); % trap position on moving bead along y
ld = h5read(File,'/Distance/Distance 1'); % displacement
d = ld.Value; lt = ld.Timestamp-ld.Timestamp(1);
% sample time
t1 = h5readatt(File,'/Force HF/Force 2x','Start time (ns)');
t2 = h5readatt(File,'/Force HF/Force 2x','Stop time (ns)');
s = h5readatt(File,'/Force HF/Force 2x','Sample rate (Hz)');
t = 0:(1e9/s):t2-(t1+(1e9/s));
rmv = find(d==0);
if ~isempty(rmv)
d(rmv) = [];
lt(rmv) = [];
end
% convert data from force to displacement (F=dx*k)
x1 = hf1/TrapStiff1; x2 = hf2/TrapStiff2;
%xdif = (x1+x2)-mean(x1+x2);
lx1 = f1/TrapStiff1; lx2 = f/TrapStiff2;
bp1 = h5read(File,'/Bead position/Bead 1 X');
bp2 = h5read(File,'/Bead position/Bead 2 X');
tp1 = bp1.Value + (-lx1*1e-3); tp2 = bp2.Value + (lx2*1e-3);
ftp1 = fit(lt,tp1,'linearinterp'); ftp2 = fit(lt,tp2,'linearinterp');
warning('off','last');
htp1 = ftp1(double(t)); htp2 = ftp2(double(t));warning('off','last');
hd = (htp2-(x2*1e-3))-(htp1-(-x1*1e-3))-3;
% fd = fit(lt,d,'smoothingspline','SmoothingParam',2e-22);
% hd = fd(double(t));
% plots
figure
plot(lt,d,t,hd)
xlabel('Time [s]'); ylabel('Distance [\mum]')
HFdata = [double(t(:))*1e-9, fx1, fy1, fx2, fy2, hd, tpx1, tpy1]; % concatenate data
writematrix(HFdata,HF_Path);
end
writetable(metadata,strcat(Out,'\',foldername{end},'metadata.txt'));