-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenodsp_interface.h
318 lines (283 loc) · 9.46 KB
/
genodsp_interface.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
#ifndef genodsp_interface_H // (prevent multiple inclusion)
#define genodsp_interface_H
// establish ownership of global variables
#ifdef globals_owner
#define global
#else
#define global extern
#endif
//----------
//
// chromosome value vectors--
//
//----------
// item values (values along the chromosomes)
typedef double valtype;
#define string_to_valtype(s) ((valtype) string_to_double(s))
#define try_string_to_valtype(s,v) try_string_to_double(s,(valtype*)v)
#define valtypeFmt "%f"
#define valtypeFmtPrec "%.*f"
#define valtypeMax DBL_MAX
#define valtypePuny DBL_MIN
// chromosomes-of-interest
//
// chromsOfInterest is a linked list of the chromosomes, in the order they were
// input; operators that write chromosomes to a file should use this order
//
// chromsSorted is an array of the chromosomes, sorted from longest to shortest;
// operators that need to access the list of chromosomes should use this array
// instead of the linked list; the array is terminated by a NULL entry
typedef struct spec
{
struct spec* next; // next spec in a linked list
char* chrom; // chromosome name
int flag; // (internal use)
u32 start; // number of uninteresting bases at the start
// .. of the chromosome (these are not included
// .. in the vector)
u32 length; // the length of v[], i.e. the number of
// .. interesting bases in the chromosome;
// .. this is guaranteed to be non-zero
valtype* valVector; // vector of values
} spec;
#ifdef globals_owner
global spec* chromsOfInterest = NULL;
global spec** chromsSorted = NULL;
#else
global spec* chromsOfInterest;
global spec** chromsSorted;
#endif
//----------
//
// operators--
//
//----------
// dsp operator functions
//
// each operator consists of five functions
// short: short descriptive text (one line)
// usage: long descriptive text
// parse: parse command line arguments and allocate control record
// free: de-allocate control record
// apply: apply function to vector(s)
//
// headers for these functions are show later in this file
#define opfuncargs_short (char*,int,FILE*,char*)
#define opfuncargs_usage (char*,FILE*,char*)
#define opfuncargs_parse (char*,int,char**)
#define opfuncargs_free (struct dspop*)
#define opfuncargs_apply (struct dspop*,char*,u32,valtype*)
typedef void (*opfunc_short) opfuncargs_short;
typedef void (*opfunc_usage) opfuncargs_usage;
typedef struct dspop* (*opfunc_parse) opfuncargs_parse;
typedef void (*opfunc_free) opfuncargs_free;
typedef void (*opfunc_apply) opfuncargs_apply;
#define dspprototypes(funcName) \
void funcName##_short opfuncargs_short; \
void funcName##_usage opfuncargs_usage; \
struct dspop* funcName##_parse opfuncargs_parse; \
void funcName##_free opfuncargs_free; \
void funcName##_apply opfuncargs_apply;
// linked list for dsp operators
//
// the list will actually contain a mixture of records for different operators;
// each operator should define its own type (essentially a subtype of dspop), a
// struct with dspop as the first element
typedef struct dspop
{
struct dspop* next; // next operation in a linked list
char* name; // operation
opfunc_apply funcApply; // functions that perform the operation
opfunc_free funcFree;
int atRandom; // true => this function needs 'random' access
// .. to hop around the whole genome
} dspop;
typedef struct dspinfo
{
char* name; // operation
opfunc_short funcShort; // functions that perform the operation
opfunc_usage funcUsage;
opfunc_parse funcParse;
opfunc_free funcFree;
opfunc_apply funcApply;
} dspinfo;
#define dspinforecord(name,funcName) \
{ name, funcName##_short, funcName##_usage, funcName##_parse, funcName##_free, funcName##_apply }
#define dspinfoalias(name) \
{ name, NULL, NULL, NULL, NULL, NULL }
//----------
//
// miscellany--
//
//----------
#ifndef M_PI
#define M_PI 3.14159265358979323846264
#endif
// global command line options
#ifdef globals_owner
global int trackOperations = false;
global int reportComments = false;
global u32 reportInputProgress = 0;
#else
global int trackOperations;
global int reportComments;
global u32 reportInputProgress;
#endif
// values for showUncovered
#define uncovered_NA -1
#define uncovered_show 1
#define uncovered_hide 0
// values for read_interval's overlapOp
#define ri_overlapSum 0
#define ri_overlapMin 1
#define ri_overlapMax 2
//----------
//
// protypes for entries into genodsp.c--
//
//----------
void chastise (const char* format, ...);
spec* find_chromosome_spec (char* chrom);
void read_intervals (FILE* f, int valCol, int originOne,
int overlapOp, int clear, valtype missingVal);
int read_interval (FILE* f,
char* buffer, int bufferLen, int valCol,
char** chrom, u32* start, u32* end,
valtype* val);
void report_intervals (FILE* f,
int precision,
int noOutputValues, int collapseRuns,
int showUncovered, int originOne);
void read_all_chromosomes (char* filename);
void write_all_chromosomes (char* filename);
valtype* get_scratch_vector (void);
s32* get_scratch_ints (void);
void release_scratch_vector (valtype* v);
void release_scratch_ints (s32* v);
void set_named_global (char* name, valtype val);
valtype get_named_global (char* name, valtype defaultVal);
int named_global_exists (char* name, valtype* val);
void report_named_globals (FILE* f, char* indent);
void tracking_report (const char* format, ...);
int valtype_ascending (const void* v1, const void* v2);
////////////
//
// headers for dsp operator function groups--
//
////////////
//----------
//
// op_short--
// Print a short description of this operation, usually on one line.
//
//----------
//
// Arguments:
// char* name: The name of the operator (what the caller likes to call
// .. it).
// int nameWidth: The width of the name field. This routine has to add
// .. padding after the name field (and colon) so that the
// .. the description starts after this many characters
// .. (not counting indent)
// FILE* f: The stream to print to.
// char* indent: A prefix to print at the start of every line. Usually
// .. this is a string of spaces. This may be NULL, which
// .. should have the same effect as an empty string.
//
// Returns:
// (nothing)
//
//----------
//----------
//
// op_usage--
// Print a longer description of this operation. This should look like the
// typical usuage text for a command-line program, describing the arguments
// to use, etc.
//
//----------
//
// Arguments:
// char* name: The name of the operator (what the caller likes to call it).
// FILE* f: The stream to print to.
// char* indent: A prefix to print at the start of every line. Usually this
// .. is a string of spaces. This may be NULL, which should
// .. have the same effect as an empty string.
//
// Returns:
// (nothing)
//
//----------
//----------
//
// op_parse--
// Parse a command line for this operation, and allocate a control record.
//
//----------
//
// Arguments:
// char* name: The name of the operator (what the caller likes to call it).
// .. This is expected to be used only for presenting error
// .. messages to the user.
// int argc: Number of arguments in argv[].
// char** argv: Command line arguments. Note that, unlike the usual argv
// .. passed to main(), argv[0] contains an argument, *not*
// .. the program name.
//
// Returns:
// The operator's control record, allocated from the heap. This is compatible
// with a dspop record, but usually will be a type private to the operator,
// containing additional fields.
//
// This function must fill in one field in the common section of the record,
// atRandom, which tells the caller whether the operator performs on multiple
// vectors (atRandom=true) or single vectors (atRandom=false).
//
// The operator will be responsible for de-allocating this control record, in
// op_free().
//
//----------
//----------
//
// op_free--
// De-allocate memory allocated for this operation.
//
//----------
//
// Arguments:
// dspop* op: Pointer to the operator's control record to be de-
// .. allocated (the record was allocated by op_parse).
// .. This is compatible with a dspop record, but often
// .. this function will cast it to the type of its
// .. private control record. This routine must free the
// .. record and anything else allocated in the non-common
// .. part of the record.
//
// Returns:
// (nothing)
//
//----------
//----------
//
// op_apply--
// Apply operation to vector(s).
//
//----------
//
// Arguments:
// dspop* op: Pointer to the operator's control record that was
// .. allocated by op_parse. This is compatible with
// .. a dspop record, but usually this function will cast
// .. it to the type of its private control record.
// char* vName: The name of the vector. Typically a chromosome name,
// .. or "*" if the operator deals with multiple vectors.
// u32 vLen: Number of entries in v[]. If this is a "whole genome"
// operator, vLen is the maximum number of entries in any
// vector.
// valtype* v: The vector to operate opon.
//
// Returns:
// (nothing)
//
//----------
#endif // genodsp_interface_H