Repository navigation
Expand file tree
/
Copy pathExtractLF_BATCH.m
More file actions
103 lines (80 loc) · 3.34 KB
/
Copy pathExtractLF_BATCH.m
File metadata and controls
103 lines (80 loc) · 3.34 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
%---------------------
% Elasticity of Sperm
% Tania Mendonca, 2025
% Extract low 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,'.h5'));
foldername = strsplit(Path,"\");
% define output directory
[BasePath,CurrentFolder] = fileparts(cd);
Out = strcat(BasePath,'\', CurrentFolder, '_ExtractedData');
if ~exist(Out, 'dir')
mkdir(Out)
end
LF_Folder = strcat(Out,'\LF');
if ~exist(LF_Folder, 'dir')
mkdir(LF_Folder)
end
%%
for j = 1:length(NData)
j
% import data
info = h5info(fullfile(Path,NData{j}));
File = NData{j};
Filename = strsplit(File,".");
LF_Path = strcat(LF_Folder,'\',Filename{1},'_LF.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 diameter
beadDiameter = rad.Value(1);
catch
beadDiameter = 2;
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
lfx1 = h5read(File,'/Force LF/Force 1x'); % force on bead 1 along x
lfy1 = h5read(File,'/Force LF/Force 1y'); % force on bead 1 along y
lfx2 = h5read(File,'/Force LF/Force 2x'); % force on bead 2 along x
lfy2 = h5read(File,'/Force LF/Force 2y'); % force on bead 2 along y
fx1 = lfx1.Value; fx2 = lfx2.Value; fy1 = lfy1.Value; fy2 = lfy2.Value;
ld = h5read(File,'/Distance/Distance 1'); d = ld.Value; % displacement
lt = ld.Timestamp-ld.Timestamp(1); % time
rmv = find(d==0);
if ~isempty(rmv) % remove position errors
d(rmv) = [];
lt2 = lt; lt2(rmv) = [];
fd = fit(lt2,d,'linearinterp'); warning('off','last');
d = fd(double(lt)); tend = length(lt2);
else
tend = length(lt);
end
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
% downsample trap positions
tpx = interp1(1:length(tpx1),tpx1,linspace(1,length(tpx1),length(lt)));
tpy = interp1(1:length(tpy1),tpy1,linspace(1,length(tpy1),length(lt)));
[pks,locs] = findpeaks(tpy1-mean(tpy1),'MinPeakHeight',0.25,'MinPeakDistance',5e3)
LFdata = [double(lt(1:tend))*10^-9, fx1(1:tend), fy1(1:tend),...
fx2(1:tend), fy2(1:tend), d(1:tend), tpx(1:tend)', tpy(1:tend)']; % concatenate data
writematrix(LFdata,LF_Path);
end
writetable(metadata,strcat(Out,'\',foldername{end},'metadata.txt'));