-
Notifications
You must be signed in to change notification settings - Fork 6
/
struct.h
171 lines (139 loc) · 3.71 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
#ifndef _STRUCT_H
#define _STRUCT_H
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include <type_traits> // std::remove_reference
#include <vector>
/***** 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
/* 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 */
/* Constants */
#define LABEL_LEN 64
#ifndef NULL
#define NULL 0
#endif
/* Two major data types */
typedef float continuous;
typedef short discrete;
/* global data */
extern continuous **arr;
extern discrete **arr_c;
extern discrete *symbols;
extern char **genes_n;
extern char **conds_n;
extern char **sub_genes;
extern bool *sublist;
extern int rows, cols, sigma;
extern int sub_genes_row;
/***** Structures *****/
typedef int edge_scroe_t;
/* edge between two genes */
typedef struct Edge {
Edge(const int gene_one, const int gene_two, const edge_scroe_t score)
: gene_one(gene_one), gene_two(gene_two), score(score) {}
int gene_one;
int gene_two;
edge_scroe_t score;
} Edge;
/* biclustering block */
struct BlockBase {
std::vector<int> genes;
std::vector<int> conds;
double score;
int block_rows_pre;
int core_rownum;
int core_colnum;
};
/* KL biclustering block */
struct Block : BlockBase {
double significance;
};
/* biclustering block in version 1*/
struct Block1 : BlockBase {};
/* holds running options */
typedef struct Prog_options {
char FN[LABEL_LEN];
char BN[LABEL_LEN];
bool IS_SWITCH;
bool IS_DISCRETE;
bool IS_cond;
bool IS_spearman;
bool IS_new_discrete;
bool IS_MaxMin;
bool IS_rpkm;
bool IS_Fast;
int COL_WIDTH;
int DIVIDED;
std::size_t SCH_BLOCK;
std::size_t RPT_BLOCK;
int EM;
double FILTER;
double QUANTILE;
double TOLERANCE;
FILE *FP;
FILE *FB;
} Prog_options;
typedef unsigned short int bits16;
enum { UP = 1, DOWN = 2, IGNORE = 3 };
extern Prog_options *po;
/***** Helper functions *****/
void progress(const char *format, ...)
/* Print progress message */
__attribute__((format(printf, 1, 2)));
void verboseDot();
/* Print "i-am-alive" dot */
void err(const char *format, ...)
/* Print error message but do not exit */
__attribute__((format(printf, 1, 2)));
void errAbort(const char *format, ...)
/* Print error message to stderr and exit */
__attribute__((noreturn, format(printf, 1, 2)));
void uglyTime(const 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 */
void dsPrint(const std::vector<int> &ds);
#define dsSize(pds) (pds.size())
/* Return the size of the stack */
#define dsItem(pds, j) (pds[j])
/* Return the j-th item in the stack */
bool isInStack(const std::vector<int> &ds, int element);
int dsIntersect(const std::vector<int> &ds1, const std::vector<int> &ds2);
/* File-related operations */
FILE *mustOpen(const char *fileName, const char *mode);
/* Open a file or die */
#endif