Skip to content

Commit 7fead8c

Browse files
committed
Merge branch 'release/v0.1.5'
2 parents c4838eb + 41632bf commit 7fead8c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+4991
-3036
lines changed

@Chromatography/Chromatography.m

100644100755
Lines changed: 337 additions & 86 deletions
Large diffs are not rendered by default.

@Chromatography/baseline.m

Lines changed: 155 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,63 @@
1-
% Method: baseline
2-
% -Calculate baseline of chromatographic data
1+
% ------------------------------------------------------------------------
2+
% Method : Chromatography.baseline
3+
% Description : Calculate baseline of chromatogram
4+
% ------------------------------------------------------------------------
35
%
6+
% ------------------------------------------------------------------------
47
% Syntax
8+
% ------------------------------------------------------------------------
59
% data = obj.baseline(data)
6-
% data = obj.baseline(data, 'OptionName', optionvalue...)
10+
% data = obj.baseline(data, Name, Value)
711
%
8-
% Options
9-
% 'samples' : 'all', [index]
10-
% 'ions' : 'all', 'tic', [index]
11-
% 'smoothness' : value (~10^3 to 10^9)
12-
% 'asymmetry' : value (~10^-1 to 10^-6)
12+
% ------------------------------------------------------------------------
13+
% Parameters
14+
% ------------------------------------------------------------------------
15+
% data (required)
16+
% Description : chromatography data
17+
% Type : structure
1318
%
14-
% Description
15-
% data : data structure
16-
% 'samples' : row index of samples (default = 'all')
17-
% 'ions' : column index of ions (default = 'tic')
18-
% 'smoothness' : smoothing parameter (default = 10^6)
19-
% 'asymmetry' : asymetry parameter (default = 10^-4)
19+
% ----------------------------------------------------------------------
20+
% Data Selection
21+
% ----------------------------------------------------------------------
22+
% 'samples' (optional)
23+
% Description : index of samples in data
24+
% Type : number | 'all'
25+
% Default : 'all'
2026
%
27+
% 'ions' (optional)
28+
% Description : index of ions in data
29+
% Type : number | 'all', 'tic'
30+
% Default : 'tic'
31+
%
32+
% ----------------------------------------------------------------------
33+
% Baseline Parameters
34+
% ----------------------------------------------------------------------
35+
% 'smoothness' (optional)
36+
% Description : smoothness parameter used for baseline calculation
37+
% Type : number
38+
% Default : 1E6
39+
% Range : 1E3 to 1E9
40+
%
41+
% 'asymmetry' (optional)
42+
% Description : asymmetry parameter used for baseline calculation
43+
% Type : number
44+
% Default : 1E-4
45+
% Range : 1E-3 to 1E-9
46+
%
47+
% ------------------------------------------------------------------------
2148
% Examples
49+
% ------------------------------------------------------------------------
2250
% data = obj.baseline(data)
2351
% data = obj.baseline(data, 'samples', [2:5, 8, 10])
2452
% data = obj.baseline(data, 'ions', [1:34, 43:100])
25-
% data = obj.baseline(data, 'ions', 'all', 'smoothness', 10^5)
26-
% data = obj.baseline(data, 'smoothness', 10^7, 'asymmetry', 10^-3)
53+
% data = obj.baseline(data, 'ions', 'all', 'smoothness', 1E5)
54+
% data = obj.baseline(data, 'smoothness', 1E8, 'asymmetry', 1E-3)
2755
%
56+
% ------------------------------------------------------------------------
2857
% References
58+
% ------------------------------------------------------------------------
2959
% P.H.C. Eilers, Analytical Chemistry, 75 (2003) 3631
60+
%
3061

3162
function varargout = baseline(obj, varargin)
3263

@@ -36,23 +67,25 @@
3667
% Variables
3768
samples = options.samples;
3869
ions = options.ions;
70+
3971
asymmetry = options.asymmetry;
4072
smoothness = options.smoothness;
4173

74+
count = 0;
75+
timer = 0;
76+
77+
fprintf([...
78+
'\n[BASELINE]\n',...
79+
'\nCalculating baselines for ', num2str(length(samples)), ' samples...\n',...
80+
'\nSmoothness : ', num2str(smoothness),...
81+
'\nAsymmetry : ', num2str(asymmetry), '\n\n']);
82+
4283
% Calculate baseline
4384
for i = 1:length(samples)
44-
45-
% Variables
46-
n = length(data(samples(i)).xic.values(:,1));
47-
m = length(data(samples(i)).xic.values(1,:));
85+
tic;
4886

49-
% Pre-allocate memory
50-
if isempty(data(samples(i)).xic.baseline)
51-
data(samples(i)).xic.baseline = zeros(n, m);
52-
53-
elseif length(data(samples(i)).xic.baseline(1,:)) ~= m
54-
data(samples(i)).xic.baseline = zeros(n, m);
55-
end
87+
% Display progess
88+
fprintf(['[', num2str(i), '/', num2str(length(samples)), ']']);
5689

5790
% Check ion options
5891
if isnumeric(ions)
@@ -61,30 +94,107 @@
6194

6295
% Input values
6396
switch ions
97+
6498
case 'tic'
6599
y = data(samples(i)).tic.values;
100+
101+
if isempty(data(samples(i)).xic.baseline)
102+
data(samples(i)).tic.baseline = zeros(size(y));
103+
end
104+
66105
case 'all'
67-
y = data(samples(i)).xic.values;
106+
107+
if ~isempty(data(samples(i)).xic.values)
108+
y = data(samples(i)).xic.values;
109+
110+
if isempty(data(samples(i)).xic.baseline)
111+
data(samples(i)).xic.baseline = zeros(size(y));
112+
end
113+
else
114+
timer = timer + toc;
115+
fprintf(' No data matches input criteria...\n');
116+
continue
117+
end
118+
68119
otherwise
69-
y = data(samples(i)).xic.values(:, options.ions);
120+
121+
if ~isempty(data(samples(i)).xic.values)
122+
y = data(samples(i)).xic.values(:, options.ions);
123+
124+
if isempty(data(samples(i)).xic.baseline)
125+
data(samples(i)).xic.baseline = zeros(size(y));
126+
end
127+
128+
else
129+
timer = timer + toc;
130+
fprintf(' No data matches input criteria...\n');
131+
continue
132+
end
70133
end
71134

72135
% Calculate baseline values
73136
baseline = Baseline(y, 'smoothness', smoothness, 'asymmetry', asymmetry);
74-
137+
75138
% Output values
76139
switch ions
77-
case 'tic'
78-
data(samples(i)).tic.baseline = baseline;
140+
141+
case 'tic'
142+
data(samples(i)).tic.baseline = baseline;
143+
79144
case 'all'
80145
data(samples(i)).xic.baseline = baseline;
146+
81147
otherwise
82148
data(samples(i)).xic.baseline(:, options.ions) = baseline;
83149
end
150+
151+
% Elapsed time
152+
timer = timer + toc;
153+
fprintf([' in ', num2str(timer,'%.1f'), ' sec']);
154+
155+
% Data processed (type|vectors)
156+
count = count + length(y(1,:));
157+
158+
if strcmpi(ions, 'tic')
159+
fprintf([' (TIC|', num2str(length(y(1,:))), ')\n']);
160+
else
161+
fprintf([' (XIC|', num2str(length(y(1,:))), ')\n']);
162+
end
163+
164+
% Update status
165+
if strcmpi(ions, 'tic')
166+
switch data(samples(i)).status.baseline
167+
case 'N'
168+
data(samples(i)).status.baseline = 'TIC';
169+
case 'XIC'
170+
data(samples(i)).status.baseline = 'Y';
171+
end
172+
else
173+
switch data(samples(i)).status.baseline
174+
case 'N'
175+
data(samples(i)).status.baseline = 'XIC';
176+
case 'TIC'
177+
data(samples(i)).status.baseline = 'Y';
178+
end
179+
end
84180
end
85181

86182
% Return data
87183
varargout{1} = data;
184+
185+
% Display summary
186+
if timer > 60
187+
elapsed = [num2str(timer/60, '%.1f'), ' min'];
188+
else
189+
elapsed = [num2str(timer, '%.1f'), ' sec'];
190+
end
191+
192+
fprintf(['\n',...
193+
'Samples : ', num2str(length(samples)), '\n',...
194+
'Elapsed : ', elapsed, '\n',...
195+
'Baselines : ', num2str(count), '\n']);
196+
197+
fprintf('\n[COMPLETE]\n\n');
88198
end
89199

90200

@@ -96,11 +206,11 @@
96206

97207
% Check input
98208
if nargin < 1
99-
error('Not enough input arguments.');
209+
error('Not enough input arguments...');
100210
elseif isstruct(varargin{1})
101211
data = obj.format('validate', varargin{1});
102212
else
103-
error('Undefined input arguments of type ''data''.');
213+
error('Undefined input arguments of type ''data''...');
104214
end
105215

106216
% Check user input
@@ -109,15 +219,15 @@
109219
% Sample options
110220
if ~isempty(input('samples'))
111221
samples = varargin{input('samples')+1};
112-
222+
113223
% Set keywords
114224
samples_all = {'default', 'all'};
115-
225+
116226
% Check for valid input
117227
if any(strcmpi(samples, samples_all))
118228
samples = 1:length(data);
119-
120-
% Check input type
229+
230+
% Check input type
121231
elseif ~isnumeric(samples)
122232

123233
% Check string input
@@ -159,16 +269,16 @@
159269
% Check for valid input
160270
if any(strcmpi(ions, ions_tic))
161271
options.ions = 'tic';
162-
272+
163273
elseif any(strcmpi(ions, ions_all))
164274
options.ions = 'all';
165-
275+
166276
elseif ~isnumeric(ions) && ~ischar(ions)
167277
options.ions = 'tic';
168278
else
169279
options.ions = ions;
170280
end
171-
281+
172282
% Check input range
173283
if isnumeric(options.ions)
174284

@@ -194,12 +304,12 @@
194304

195305
% Check for valid input
196306
if ~isnumeric(smoothness)
197-
options.smoothness = obj.Defaults.baseline.smoothness;
307+
options.smoothness = obj.defaults.baseline_smoothness;
198308
else
199309
options.smoothness = smoothness;
200310
end
201311
else
202-
options.smoothness = obj.Defaults.baseline.smoothness;
312+
options.smoothness = obj.defaults.baseline_smoothness;
203313
end
204314

205315

@@ -209,12 +319,12 @@
209319

210320
% Check for valid input
211321
if ~isnumeric(asymmetry)
212-
options.asymmetry = obj.Defaults.baseline.asymmetry;
322+
options.asymmetry = obj.defaults.baseline_asymmetry;
213323
else
214324
options.asymmetry = asymmetry;
215325
end
216326
else
217-
options.asymmetry = obj.Defaults.baseline.asymmetry;
327+
options.asymmetry = obj.defaults.baseline_asymmetry;
218328
end
219329

220330
% Return input

0 commit comments

Comments
 (0)