-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstruct.h
191 lines (156 loc) · 4.1 KB
/
struct.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
#ifndef _STRUCT_H
#define _STRUCT_H
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <math.h>
#include <ctype.h>
#include <stdarg.h>
#include <limits.h>
#include <sys/time.h>
#include <time.h>
#include "fib.h"
/***** Useful macros *****/
/* Compatibility of __attribute__ with non-GNU */
#ifndef __GNUC__
# define __attribute__(x) /* Nothing */
#endif
/* Pretend that C has boolean type */
#define TRUE 1
#define FALSE 0
#define boolean unsigned char
#ifndef __cplusplus
#ifndef bool
#define bool unsigned char
#endif
#endif
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(x) ((x)>0?(x):-(x))
/* Variable and array allocation */
#define AllocVar(pt) (pt = xmalloc(sizeof(*pt)))
#define AllocArray(pt, size) (pt = xmalloc(sizeof(*pt) * (size)))
#define ReAllocArray(pt, size) (pt = xrealloc(pt, sizeof(*pt) * (size)))
/* Strings */
/* strcmp: a zero value indicates that both strings are equal.
* a value greater than zero indicates that the first character that does not match has a greater value in str1 than in str2;
* And a value less than zero indicates the opposite.
*/
#define sameString(a, b) (strcmp((a), (b))==0)
/* Returns TRUE if two strings are same */
/* Debugging */
#define internalErr() errAbort("Internal error %s %d", __FILE__, __LINE__)
/* Constants */
#define LABEL_LEN 64
#ifndef NULL
#define NULL 0
#endif
/* Two major data types */
typedef float continuous;
typedef short discrete;
/* global data */
continuous **arr;
discrete **arr_c;
discrete *symbols;
char **genes;
char **conds;
char **sub_genes;
bool *sublist;
int rows, cols, sigma;
int TFindex;
int sub_genes_row;
/***** Structures *****/
struct dyStack
/* dynamically allocated stack */
{
int top; /* top element index */
int items[]; /* data storage */
};
/* edge between two genes */
typedef struct Edge{
int gene_one;
int gene_two;
int score;
} Edge;
/* biclustering block */
typedef struct Block{
struct dyStack *genes;
struct dyStack *conds;
int score;
int block_rows;
int block_cols;
int block_rows_pre;
int cond_low_bound;
double significance;
long double pvalue;
} Block;
/* holds running options */
typedef struct Prog_options{
char FN[LABEL_LEN];
char BN[LABEL_LEN];
char LN[LABEL_LEN];
bool IS_SWITCH;
bool IS_DISCRETE;
bool IS_TFname;
bool IS_pvalue;
bool IS_area;
bool IS_cond;
bool IS_list;
int COL_WIDTH;
int DIVIDED;
int SCH_BLOCK;
int RPT_BLOCK;
double FILTER;
double QUANTILE;
double TOLERANCE;
char TFname[LABEL_LEN];
FILE* FP;
FILE* FB;
FILE* FL;
} Prog_options;
typedef unsigned short int bits16;
enum {UP=1, DOWN=2, IGNORE=3};
Prog_options* po;
/***** Helper functions *****/
void progress(char *format, ...)
/* Print progress message */
__attribute__((format(printf, 1, 2)));
void verboseDot();
/* Print "i-am-alive" dot */
void err(char *format, ...)
/* Print error message but do not exit */
__attribute__((format(printf, 1, 2)));
void errAbort(char *format, ...)
/* Print error message to stderr and exit */
__attribute__((noreturn, format(printf, 1, 2)));
void uglyTime(char *label, ...);
/* Print label and how long it's been since last call. Call with
* a NULL label to initialize. */
void *xmalloc ( int size );
/* Wrapper for memory allocations */
void *xrealloc ( void* ptr, int size );
/* Wrapper for memory re-allocations */
/* Stack-related operations */
struct dyStack *dsNew(int size);
void dsPrint(struct dyStack *ds);
void dsPush(struct dyStack *ds,int element);
#define dsFree free
/* Release the stack data structure */
#define dsClear(pds) ((pds)->top = -1)
/* Remove all the data in the stack */
#define dsSize(pds) ((pds)->top + 1)
/* Return the size of the stack */
#define dsItem(pds, j) ((pds)->items[j])
/* Return the j-th item in the stack */
bool isInStack(struct dyStack *ds, int element);
int dsIntersect(struct dyStack *ds1, struct dyStack *ds2);
/* File-related operations */
void *addSuffix();
/* Return a string containing headsuffix */
FILE *mustOpen(const char *fileName, char *mode);
/* Open a file or die */
#endif