-
Notifications
You must be signed in to change notification settings - Fork 16
/
gene_core.h
124 lines (100 loc) · 6.3 KB
/
gene_core.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
#ifndef _CORE
#define _CORE
#include <stdio.h>
/*******************************************************************************************
*
* MY STANDARD TYPE DECLARATIONS
*
********************************************************************************************/
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef float float32;
typedef double float64;
/*******************************************************************************************
*
* MACROS TO HELP PARSE COMMAND LINE
*
********************************************************************************************/
extern char *Prog_Name; // Name of program, available everywhere
#define ARG_INIT(name) \
Prog_Name = Strdup(name,""); \
for (i = 0; i < 128; i++) \
flags[i] = 0;
#define ARG_FLAGS(set) \
for (k = 1; argv[i][k] != '\0'; k++) \
{ if (index(set,argv[i][k]) == NULL) \
{ fprintf(stderr,"%s: -%c is an illegal option\n",Prog_Name,argv[i][k]); \
exit (1); \
} \
flags[(int) argv[i][k]] = 1; \
}
#define ARG_POSITIVE(var,name) \
var = strtol(argv[i]+2,&eptr,10); \
if (*eptr != '\0' || argv[i][2] == '\0') \
{ fprintf(stderr,"%s: -%c '%s' argument is not an integer\n", \
Prog_Name,argv[i][1],argv[i]+2); \
exit (1); \
} \
if (var <= 0) \
{ fprintf(stderr,"%s: %s must be positive (%d)\n",Prog_Name,name,var); \
exit (1); \
}
#define ARG_NON_NEGATIVE(var,name) \
var = strtol(argv[i]+2,&eptr,10); \
if (*eptr != '\0' || argv[i][2] == '\0') \
{ fprintf(stderr,"%s: -%c '%s' argument is not an integer\n", \
Prog_Name,argv[i][1],argv[i]+2); \
exit (1); \
} \
if (var < 0) \
{ fprintf(stderr,"%s: %s must be non-negative (%d)\n",Prog_Name,name,var); \
exit (1); \
}
#define ARG_REAL(var) \
var = strtod(argv[i]+2,&eptr); \
if (*eptr != '\0' || argv[i][2] == '\0') \
{ fprintf(stderr,"%s: -%c '%s' argument is not a real number\n", \
Prog_Name,argv[i][1],argv[i]+2); \
exit (1); \
}
/*******************************************************************************************
*
* MEMORY ALLOCATION,FILE HANDLING, AND PRETTY PRINTING UTILITIES
*
********************************************************************************************/
// The following general utilities return NULL if any of their input pointers are NULL, or if they
// could not perform their function (in which case they also print an error to stderr).
void *Malloc(int64 size, char *mesg); // Guarded versions of malloc, realloc
void *Realloc(void *object, int64 size, char *mesg); // and strdup, that output "mesg" to
char *Strdup(char *string, char *mesg); // stderr if out of memory
char *Strndup(char *string, int len, char *mesg); // stderr if out of memory
char *PathTo(char *path); // Return path portion of file name "path"
char *Root(char *path, char *suffix); // Return the root name, excluding suffix, of "path"
// Catenate returns concatenation of path.sep.root.suffix in a *temporary* buffer
// Numbered_Suffix returns concatenation of left.<num>.right in a *temporary* buffer
char *Catenate(char *path, char *sep, char *root, char *suffix);
char *Numbered_Suffix(char *left, int num, char *right);
void Print_Number(int64 num, int width, FILE *out); // Print readable big integer
int Number_Digits(int64 num); // Return # of digits in printed number
/*******************************************************************************************
*
* ROUTINES FOR HANDLING DNA AND ARROW STRINGS
*
********************************************************************************************/
#define COMPRESSED_LEN(len) (((len)+3) >> 2)
void Compress_Read(int len, char *s); // Compress read in-place into 2-bit form
void Uncompress_Read(int len, char *s); // Uncompress read in-place into numeric form
void Print_Read(char *s, int width);
void Lower_Read(char *s); // Convert read from numbers to lowercase letters (0-3 to acgt)
void Upper_Read(char *s); // Convert read from numbers to uppercase letters (0-3 to ACGT)
void Number_Read(char *s); // Convert read from letters to numbers
void Change_Read(char *s); // Convert read from one case to the other
void Letter_Arrow(char *s); // Convert arrow pw's from numbers to uppercase letters (0-3 to 1234)
void Number_Arrow(char *s); // Convert arrow pw string from letters to numbers
#endif // _CORE