-
Notifications
You must be signed in to change notification settings - Fork 3
/
eval.h
454 lines (327 loc) · 14.1 KB
/
eval.h
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
// --------------------------------------------------------------------
//
// This file is part of Luna.
//
// LUNA is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Luna is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Luna. If not, see <http://www.gnu.org/licenses/>.
//
// Please see LICENSE.txt for more details.
//
// --------------------------------------------------------------------
#ifndef __LUNA_EVAL_H__
#define __LUNA_EVAL_H__
#include <string>
#include <map>
#include <set>
#include <vector>
#include <sstream>
struct edf_t;
//
// Helper to parse command syntax
//
struct param_t
{
public:
void add( const std::string & option , const std::string & value = "" );
void add_hidden( const std::string & option , const std::string & value = "" );
int size() const;
void parse( const std::string & s );
void update( const std::string & id , const std::string & wc );
void clear();
bool has(const std::string & s ) const;
bool empty(const std::string & s ) const;
// if ! has(X) return F
// else return yesno(value(X))
bool yesno(const std::string & s ) const;
std::string value( const std::string & s , const bool uppercase = false ) const;
bool single() const;
std::string single_value() const ;
std::string single_pair(std::string * ) const ;
std::string requires( const std::string & s , const bool uppercase = false ) const;
int requires_int( const std::string & s ) const;
double requires_dbl( const std::string & s ) const;
std::string dump( const std::string & indent = " ", const std::string & delim = "\n" ) const;
std::set<std::string> strset( const std::string & k , const std::string delim = "," , const bool uppercase = false ) const;
std::set<std::string> strset_xsigs( const std::string & k , const std::string delim = "," , const bool uppercase = false ) const;
std::vector<std::string> strvector( const std::string & k , const std::string delim = "," , const bool uppercase = false ) const;
std::vector<std::string> strvector_xsigs( const std::string & k , const std::string delim = "," , const bool uppercase = false ) const;
std::vector<double> dblvector( const std::string & k , const std::string delim = "," ) const;
std::vector<int> intvector( const std::string & k , const std::string delim = "," ) const;
std::set<std::string> keys() const;
private:
std::map<std::string,std::string> opt;
std::set<std::string> hidden;
};
class cmd_t
{
public:
cmd_t( const bool silent = false );
cmd_t( const std::string & str , const bool silent = true );
static void add_cmdline_cmd( const std::string & c ) ;
static void parse_special( const std::string & s , const std::string & delim );
static void attach_ivars( const std::string & file );
static void attach_idmapper( const std::string & file );
static std::string remap_id( const std::string & id )
{
if ( idmapper.find( id ) == idmapper.end() ) return id;
return idmapper.find( id )->second;
}
// these cannot be used as variable names in scripts
static void register_specials();
// by default (str == NULL) read from command line arguments,
// then from STDIN; otherwise, parse the commands in the
// text string
bool read( const std::string * str = NULL ,
bool silent = false );
void reset() ;
static void define_channel_type_variables( edf_t & );
void replace_wildcards( const std::string & id );
bool eval( edf_t & ) ;
bool empty() const ;
bool valid() const ;
bool badline() const ;
std::string offending() const ;
int num_cmds() const ;
std::string cmd(const int i) ;
param_t & param(const int i) ;
bool process_edfs() const ;
bool is( const int n , const std::string & s ) const;
std::string data() const ;
bool quit() const ;
void quit(bool b) ;
//
// Static members (i.e. from command line)
//
static std::string input;
// project-level variables
static std::map<std::string,std::string> vars;
// individual-specific vars
static std::map<std::string,std::map<std::string,std::string> > ivars;
// make combined map var map (for use externally, e.g. PREDICT model reader)
static std::map<std::string,std::string> indiv_var_map( const std::string & id );
static std::map<std::string,int> pull_ivar( const std::vector<std::string> & ids ,
const std::string & phe );
static bool pull_ivar( const std::string & id , const std::string & phe , double * x );
static bool pull_ivar_bool( const std::string & id , const std::string & phe );
// id-mapper
static std::map<std::string,std::string> idmapper;
static std::string cmdline_cmds;
static std::string stout_file;
static std::string stout_template;
static bool append_stout_file;
static bool plaintext_mode;
static std::string plaintext_root;
static bool has_indiv_wildcard;
static std::string resolved_outdb( const std::string & id , const std::string & str );
// command-specific parameters (i.e. from command-file)
static std::set<std::string> signallist;
static std::map<std::string,std::string> label_aliases;
static std::map<std::string,std::vector<std::string> > primary_alias;
static std::map<std::string,std::string> primary_upper2orig;
static void signal_alias( const std::string & s );
static const std::set<std::string> & signals() ;
static void clear_signals() ;
static std::string signal_string() ;
static void clear_static_members() ;
static bool is_special( const std::string & v )
{ return specials.find( v ) != specials.end() ; }
private:
// a command is a single input (0+ EDFs) linked to 1 or more
// commands, that are performed sequentially on each EDF
std::string line; // raw input from STDIN, stored to report in case of error
bool error;
bool will_quit;
std::vector<std::string> cmds;
std::vector<param_t> params;
static std::set<std::string> commands;
static void populate_commands() ;
static std::set<std::string> specials;
};
//
// Primary commands
//
void proc_summaries( edf_t & , param_t & );
void proc_aliases( edf_t & , param_t & );
void proc_headers( edf_t & , param_t & );
void proc_set_headers( edf_t & , param_t & );
void proc_set_ivar( edf_t & , param_t & );
void proc_validate( edf_t & , param_t & );
void proc_desc( edf_t & , param_t & );
void proc_dump_vars( edf_t & , param_t & );
void proc_show_channel_map();
void proc_has_signals( edf_t & , param_t & );
void proc_stats( edf_t & , param_t & );
void proc_dupes( edf_t & , param_t & );
void proc_list_annots( edf_t & , param_t & );
void proc_espan( edf_t & , param_t & );
void proc_write_annots( edf_t & , param_t & );
void proc_make_annots( edf_t & , param_t & );
void proc_extend_annots( edf_t & , param_t & );
void proc_list_all_annots( edf_t & , param_t & );
void proc_list_spanning_annots( edf_t & , param_t & );
void proc_force_edf( edf_t & , param_t & );
void proc_edf_minus( edf_t & , param_t & );
void proc_set_timestamps( edf_t & , param_t & );
void proc_tag( param_t & );
void set_tag( const std::string & t = "." );
void proc_anon( edf_t & , param_t & );
void proc_write( edf_t & , param_t & );
void proc_restructure( edf_t & , param_t & );
void proc_drop_signals( edf_t & , param_t & );
void proc_rename( edf_t & , param_t & );
void proc_enforce_signals( edf_t & , param_t & );
void proc_copy_signal( edf_t & , param_t & );
void proc_read_signal( edf_t & , param_t & );
void proc_order_signals( edf_t & , param_t & );
void proc_scale( edf_t & , param_t & , const std::string & s );
void proc_setscale( edf_t & , param_t & );
void proc_minmax( edf_t & , param_t & );
void proc_standardize( edf_t & , param_t & );
void proc_flip( edf_t & , param_t & );
void proc_rectify( edf_t & , param_t & );
void proc_reverse( edf_t & , param_t & );
void proc_reference( edf_t & , param_t & );
void proc_dereference( edf_t & , param_t & );
void proc_adjust( edf_t & , param_t & );
void proc_rerecord( edf_t & edf , param_t & param );
void proc_canonical( edf_t & edf , param_t & param );
void proc_remap_annots( edf_t & edf , param_t & param );
void proc_set_annot_metadata( edf_t & , param_t & );
void proc_dump( edf_t & , param_t & );
void proc_dump_mask( edf_t & , param_t & );
void proc_annot_mask( edf_t & , param_t & );
//void proc_chep( edf_t & , param_t & ); // now in timeline_t
void proc_chep_mask( edf_t & , param_t & );
void proc_file_mask( edf_t & , param_t & );
void proc_file_annot( edf_t & , param_t & );
void proc_sleep_stage( edf_t & , param_t & , bool verbose = false );
void proc_suds( edf_t & , param_t & );
void proc_make_suds( edf_t & , param_t & );
void proc_self_suds( edf_t & , param_t & );
void proc_resoap( edf_t & , param_t & );
void proc_rebase_soap( edf_t & , param_t & );
void proc_place_soap( edf_t & , param_t & );
void proc_ecycle( edf_t & , param_t & );
void proc_runpops( edf_t & , param_t & );
void proc_pops( edf_t & , param_t & );
void proc_eval_stages( edf_t & , param_t & );
void proc_copy_suds_cmdline();
void proc_combine_suds_cmdline();
void proc_hypoxic_burden( edf_t & , param_t & );
void proc_annotate( edf_t & , param_t & );
void proc_annot2signal( edf_t & , param_t & );
void proc_signal2annot( edf_t & , param_t & );
void proc_sig_annot_mean( edf_t & , param_t & );
void proc_annot2cache( edf_t & , param_t & );
void proc_cache2annot( edf_t & , param_t & );
void proc_sig_tabulate( edf_t & edf , param_t & param );
void proc_record_dump( edf_t & , param_t & );
void proc_record_table( edf_t & , param_t & );
void proc_dump_segs( edf_t & , param_t & );
void proc_intervals( param_t & , const std::string & );
void proc_align( edf_t & edf , param_t & param );
void proc_align_epochs( edf_t & edf , param_t & param );
void proc_align_annots( edf_t & edf , param_t & param );
void proc_insert( edf_t & edf , param_t & param );
void proc_epoch_dump( edf_t & , param_t & );
void proc_epoch_matrix( edf_t & , param_t & );
void proc_head_matrix( edf_t & , param_t & );
void proc_epoch_mask( edf_t & , param_t & );
void proc_mask( edf_t & , param_t & );
void proc_eval( edf_t & , param_t & );
void proc_derive( edf_t & , param_t & );
void proc_epoch( edf_t & , param_t & );
void proc_slice( edf_t & , param_t & , int );
void proc_freeze( edf_t & , param_t & );
void proc_thaw( edf_t & , param_t & );
void proc_clean_freezer( edf_t & , param_t & );
void proc_trans( edf_t & , param_t & );
void proc_combine( edf_t & , param_t & );
void proc_timetrack( edf_t & , param_t & );
void proc_continuous( edf_t & , param_t & );
void proc_covar( edf_t & , param_t & );
void proc_artifacts( edf_t & , param_t & );
void proc_trim( edf_t & , param_t & );
void proc_rms( edf_t & , param_t & );
void proc_mse( edf_t & , param_t & );
void proc_lzw( edf_t & , param_t & );
void proc_zratio( edf_t & , param_t & );
void proc_correct( edf_t & , param_t & );
void proc_resample( edf_t & , param_t & );
void proc_zoh( edf_t & , param_t & );
void proc_moving_average( edf_t & , param_t & );
void proc_filter( edf_t & , param_t & );
void proc_filter_legacy( edf_t & , param_t & );
void proc_filter_design( edf_t & , param_t & );
void proc_filter_design_cmdline();
void proc_cwt_design( edf_t & , param_t & );
void proc_cwt_design_cmdline();
void proc_psd( edf_t & , param_t & );
void proc_fft( edf_t & , param_t & );
void proc_mtm( edf_t & , param_t & );
void proc_irasa( edf_t & , param_t & );
void proc_1overf_norm( edf_t & , param_t & );
void proc_tv_denoise( edf_t & , param_t & );
void proc_otsu( edf_t & , param_t & );
void proc_cwt( edf_t & , param_t & );
void proc_hilbert( edf_t & , param_t & );
void proc_sync(edf_t & , param_t & );
void proc_tsync(edf_t & , param_t & );
void proc_xcorr(edf_t & , param_t & );
void proc_qdynam(edf_t & , param_t & );
void proc_predict( edf_t & , param_t & );
void proc_psc( edf_t & , param_t & );
void proc_microstates( edf_t & , param_t & );
void proc_asymm( edf_t & , param_t & );
void proc_tlock( edf_t & , param_t & );
void proc_peaks( edf_t & , param_t & );
void proc_peri( edf_t & , param_t & );
void proc_zpeaks( edf_t & , param_t & );
void proc_sedf( edf_t & , param_t & );
void proc_tclst( edf_t & , param_t & );
void proc_fiplot( edf_t & , param_t & );
void proc_mi( edf_t & , param_t & );
void proc_svd( edf_t & , param_t & );
void proc_ica( edf_t & , param_t & );
void proc_emd( edf_t & , param_t & );
void proc_dfa( edf_t & , param_t & );
void proc_attach_clocs( edf_t & , param_t & );
void proc_surface_laplacian( edf_t & , param_t & );
void proc_leave_one_out( edf_t & , param_t & );
void proc_chep_based_interpolation( edf_t & , param_t & );
void proc_correl( edf_t & , param_t & );
void proc_coh( edf_t & , param_t & );
void proc_elec_distance( edf_t & , param_t & );
void proc_acf( edf_t & , param_t & );
void proc_psi( edf_t & , param_t & );
void proc_conncoupl( edf_t & , param_t & );
void proc_pac( edf_t & , param_t & );
void proc_cfc( edf_t & , param_t & );
void proc_ged( edf_t & , param_t & );
void proc_ecgsuppression( edf_t & , param_t & );
void proc_bpm( edf_t & , param_t & );
void proc_spindles( edf_t & , param_t & );
void proc_coupling( edf_t & , param_t & );
void proc_ripples( edf_t & , param_t & );
void proc_generic_coupling( edf_t & , param_t & );
void proc_polarity( edf_t & , param_t & );
void proc_slowwaves( edf_t & , param_t & );
void proc_cwt( edf_t & , param_t & );
void proc_rems( edf_t & , param_t & );
void proc_dump_cache( edf_t & , param_t & );
void proc_siggen( edf_t & , param_t & );
void proc_simul( edf_t & , param_t & );
void proc_spike( edf_t & , param_t & );
void proc_shift( edf_t & , param_t & );
void proc_scramble( edf_t & , param_t & );
#endif