|
1 | | -% Method: baseline |
2 | | -% -Calculate baseline of chromatographic data |
| 1 | +% ------------------------------------------------------------------------ |
| 2 | +% Method : Chromatography.baseline |
| 3 | +% Description : Calculate baseline of chromatogram |
| 4 | +% ------------------------------------------------------------------------ |
3 | 5 | % |
| 6 | +% ------------------------------------------------------------------------ |
4 | 7 | % Syntax |
| 8 | +% ------------------------------------------------------------------------ |
5 | 9 | % data = obj.baseline(data) |
6 | | -% data = obj.baseline(data, 'OptionName', optionvalue...) |
| 10 | +% data = obj.baseline(data, Name, Value) |
7 | 11 | % |
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 |
13 | 18 | % |
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' |
20 | 26 | % |
| 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 | +% ------------------------------------------------------------------------ |
21 | 48 | % Examples |
| 49 | +% ------------------------------------------------------------------------ |
22 | 50 | % data = obj.baseline(data) |
23 | 51 | % data = obj.baseline(data, 'samples', [2:5, 8, 10]) |
24 | 52 | % 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) |
27 | 55 | % |
| 56 | +% ------------------------------------------------------------------------ |
28 | 57 | % References |
| 58 | +% ------------------------------------------------------------------------ |
29 | 59 | % P.H.C. Eilers, Analytical Chemistry, 75 (2003) 3631 |
| 60 | +% |
30 | 61 |
|
31 | 62 | function varargout = baseline(obj, varargin) |
32 | 63 |
|
|
36 | 67 | % Variables |
37 | 68 | samples = options.samples; |
38 | 69 | ions = options.ions; |
| 70 | + |
39 | 71 | asymmetry = options.asymmetry; |
40 | 72 | smoothness = options.smoothness; |
41 | 73 |
|
| 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 | + |
42 | 83 | % Calculate baseline |
43 | 84 | 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; |
48 | 86 |
|
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)), ']']); |
56 | 89 |
|
57 | 90 | % Check ion options |
58 | 91 | if isnumeric(ions) |
|
61 | 94 |
|
62 | 95 | % Input values |
63 | 96 | switch ions |
| 97 | + |
64 | 98 | case 'tic' |
65 | 99 | 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 | + |
66 | 105 | 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 | + |
68 | 119 | 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 |
70 | 133 | end |
71 | 134 |
|
72 | 135 | % Calculate baseline values |
73 | 136 | baseline = Baseline(y, 'smoothness', smoothness, 'asymmetry', asymmetry); |
74 | | - |
| 137 | + |
75 | 138 | % Output values |
76 | 139 | switch ions |
77 | | - case 'tic' |
78 | | - data(samples(i)).tic.baseline = baseline; |
| 140 | + |
| 141 | + case 'tic' |
| 142 | + data(samples(i)).tic.baseline = baseline; |
| 143 | + |
79 | 144 | case 'all' |
80 | 145 | data(samples(i)).xic.baseline = baseline; |
| 146 | + |
81 | 147 | otherwise |
82 | 148 | data(samples(i)).xic.baseline(:, options.ions) = baseline; |
83 | 149 | 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 |
84 | 180 | end |
85 | 181 |
|
86 | 182 | % Return data |
87 | 183 | 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'); |
88 | 198 | end |
89 | 199 |
|
90 | 200 |
|
|
96 | 206 |
|
97 | 207 | % Check input |
98 | 208 | if nargin < 1 |
99 | | - error('Not enough input arguments.'); |
| 209 | + error('Not enough input arguments...'); |
100 | 210 | elseif isstruct(varargin{1}) |
101 | 211 | data = obj.format('validate', varargin{1}); |
102 | 212 | else |
103 | | - error('Undefined input arguments of type ''data''.'); |
| 213 | + error('Undefined input arguments of type ''data''...'); |
104 | 214 | end |
105 | 215 |
|
106 | 216 | % Check user input |
|
109 | 219 | % Sample options |
110 | 220 | if ~isempty(input('samples')) |
111 | 221 | samples = varargin{input('samples')+1}; |
112 | | - |
| 222 | + |
113 | 223 | % Set keywords |
114 | 224 | samples_all = {'default', 'all'}; |
115 | | - |
| 225 | + |
116 | 226 | % Check for valid input |
117 | 227 | if any(strcmpi(samples, samples_all)) |
118 | 228 | samples = 1:length(data); |
119 | | - |
120 | | - % Check input type |
| 229 | + |
| 230 | + % Check input type |
121 | 231 | elseif ~isnumeric(samples) |
122 | 232 |
|
123 | 233 | % Check string input |
|
159 | 269 | % Check for valid input |
160 | 270 | if any(strcmpi(ions, ions_tic)) |
161 | 271 | options.ions = 'tic'; |
162 | | - |
| 272 | + |
163 | 273 | elseif any(strcmpi(ions, ions_all)) |
164 | 274 | options.ions = 'all'; |
165 | | - |
| 275 | + |
166 | 276 | elseif ~isnumeric(ions) && ~ischar(ions) |
167 | 277 | options.ions = 'tic'; |
168 | 278 | else |
169 | 279 | options.ions = ions; |
170 | 280 | end |
171 | | - |
| 281 | + |
172 | 282 | % Check input range |
173 | 283 | if isnumeric(options.ions) |
174 | 284 |
|
|
194 | 304 |
|
195 | 305 | % Check for valid input |
196 | 306 | if ~isnumeric(smoothness) |
197 | | - options.smoothness = obj.Defaults.baseline.smoothness; |
| 307 | + options.smoothness = obj.defaults.baseline_smoothness; |
198 | 308 | else |
199 | 309 | options.smoothness = smoothness; |
200 | 310 | end |
201 | 311 | else |
202 | | - options.smoothness = obj.Defaults.baseline.smoothness; |
| 312 | + options.smoothness = obj.defaults.baseline_smoothness; |
203 | 313 | end |
204 | 314 |
|
205 | 315 |
|
|
209 | 319 |
|
210 | 320 | % Check for valid input |
211 | 321 | if ~isnumeric(asymmetry) |
212 | | - options.asymmetry = obj.Defaults.baseline.asymmetry; |
| 322 | + options.asymmetry = obj.defaults.baseline_asymmetry; |
213 | 323 | else |
214 | 324 | options.asymmetry = asymmetry; |
215 | 325 | end |
216 | 326 | else |
217 | | - options.asymmetry = obj.Defaults.baseline.asymmetry; |
| 327 | + options.asymmetry = obj.defaults.baseline_asymmetry; |
218 | 328 | end |
219 | 329 |
|
220 | 330 | % Return input |
|
0 commit comments