-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmutils.h
More file actions
239 lines (219 loc) · 7.67 KB
/
Copy pathadmutils.h
File metadata and controls
239 lines (219 loc) · 7.67 KB
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
#include <ctype.h>
#include <nicklib.h>
#include <xsearch.h>
#define IDSIZE 129
#ifndef ADMUTILS
typedef struct {
char ID[IDSIZE];
char *egroup ;
char gender; /* 'M' or 'F' */
double theta_mode; /* most likely theta on mesh */
double lambda_mode; /* mean of log10(lambda) from probability distribution */
double Xtheta_mode; /* most likely theta on mesh */
double Xlambda_mode; /* most likely lambda on mesh */
int idnum ;
int affstatus; /* affected status */
int ignore ; /* YES => do not use */
int flag ;
double thetatrue ;
double Xthetatrue ;
double lambdatrue ;
double Xlambdatrue ;
double totgamms[3] ;
double totscore ;
double rawqval ;
double qval ;
int ishaploid ;
int hasxhets ;
int gkode ; /* codes for groups used ; gkode < 0 => ignore */
} Indiv;
typedef struct {
char ID[IDSIZE];
int chrom;
char cchrom[6] ;
double genpos;
double physpos;
double aa_cauc_freq; /* frequencies in ancestral pop to AA */
double aa_af_freq;
double cauc_freq; /* frequencies of variant allele */
double af_freq;
double cftrue ;
double aftrue ;
double aa_cftrue ;
double aa_aftrue ;
int markernum ; /* marker number */
char *pbuff ;
char *ebuff ; /* for random ethnic path */
char *probbuff ; /* for random ethnic path */
int isfake ; /* 1 if fake marker else 0 */
int isrfake ;
/* real marker treated as fake. Used for 2D scoring */
int ignore ;
int ngtypes ; /* number of gtypes */
int *gtypes ;
int af_nn[2] ;
int cauc_nn[2] ;
double *modelscores ;
double *totmodelscores ;
double score ;
double weight ;
double estgenpos ;
double estdis ;
double dis ;
double esum ;
double lsum ;
double gpsum ;
double gpnum ;
void *pcupt ;
int tagnumber ;
char alleles[2] ;
double cf[4] ;
int bcount[3] ;
int chimpfudge ;
char cbest ;
int scount ;
double *dwork ;
double dipscore[3] ;
double **diplike ;
} SNP;
// diplike is P(data|dip=d) dimension numindivs*3
typedef struct {
char ID[IDSIZE] ;
Indiv *father ;
Indiv *mother ;
Indiv *child ;
int findex ;
int mindex ;
int cindex ;
int base ;
} TRIO ;
// ?index into original Indiv array. base is work variable used in phasetrio to store init index in new array
typedef struct {
char gname[IDSIZE] ;
SNP **snpm ;
Indiv **indivm ;
int numsnps;
int numindivs ;
int rlen ;
int fdes ;
int snpindex ;
unsigned char *buff ;
} genofile ;
typedef struct {
double xd[4] ;
double xc[9] ;
double ap1 ;
double ap2 ;
double cp1 ;
double cp2 ;
double rpowersum ;
double crpowersum ;
double gammasum[2] ;
double gammanum[2] ;
int pubfmodern ;
} SNPMC ;
// gammasum for cases/controls
#endif
#define ADMUTILS
void loadstats(FILE *statsfile, Indiv *indiv_array, int *numindivs);
void loadXstats(FILE *Xstatsfile, Indiv *indiv_array, int numindivs, int *numloaded);
void sett1(double *tt, double theta, int numstates) ;
void sett1r(double *tt, double theta, int numstate, double risks) ;
void gettln(SNP *cupt, Indiv *indx,
double *ptheta, double *plambda, int *pnumstates, int *pignore) ;
void puttln(SNP *cupt, Indiv *indx,
double theta, double lambda) ;
/* UTILITY FUNCTIONS */
int countcol (char *fname);
int countcolumns (FILE *fp);
void fataly(const char *name);
int compare_doubles (const void *a, const void *b);
void pcheck (char *name, char x) ;
void printm(double **M, int numstates) ;
int numvalids(Indiv *indx, SNP **snpmarkers, int fc, int lc) ;
void gethpos(int *fc, int *lc, SNP **snpm, int numsnps,
int xchrom, int lo, int hi) ;
int numvalidgtypes(SNP *cupt) ;
double malefreq(Indiv **indivmarkers, int numindivs) ;
int isimatch(int a, int b) ;
void makedir(char *dirname) ;
int indxindex(char **namelist, int len, char *strid) ;
int indindex(Indiv **indivmarkers, int numindivs, char *indid) ;
int snpindex(SNP **snpmarkers, int numsnps, char *snpid) ;
void inddupcheck(Indiv **indivmarkers, int numindivs) ;
void freesnpindex() ;
int ignoresnp(SNP *cupt) ;
double entrop(double *a, int n) ;
double xxlog2(double t) ;
void testnan(double *a, int n) ;
void hap2dip(SNP *cupt) ;
void flipalleles(SNP *cupt) ;
void flipalleles_phased(SNP *cupt) ;
int getgtypes(SNP *cupt, int k) ;
void putgtypes(SNP *cupt, int k, int val) ;
int getep(SNP *cupt, int k) ;
void putep(SNP *cupt, int k, int val) ;
unsigned int hasharr(char **xarr, int nxarr) ;
void wbuff(unsigned char *buff, int num, int g) ;
int rbuff(unsigned char *buff, int num) ;
int ridfile(char *fname) ;
double hwcheck(SNP *cupt, double *cc) ;
double hwcheckx(SNP *cupt, Indiv **indm, double *cc) ;
void cntit(double *xc, SNP *cupt1, SNP *cupt2) ;
// dup routines
void setfastdupnum(int num) ;
void setfastdupthresh(double thresh, double kill) ;
void killxhets(SNP **snpmarkers, Indiv **indivmarkers, int numsnps, int numindivs) ;
void fastdupcheck(SNP **snpmarkers, Indiv **indivmarkers, int numsnps, int numindivs) ;
void grabgtypes(int *gtypes, SNP *cupt, int numindivs) ;
int kcode(int *w, int len, int base) ;
// void cdup(SNP **snpm, Indiv **indm, int nsnp, int *buff, int lbuff, int iter) ;
// void printdup(SNP **snpm, int nsnp, Indiv *inda, Indiv *indb, int nmatch, int nnomatch, int iter);
void killdup(Indiv *inda, Indiv *indb, SNP **snpm, int nsnp) ;
void slowdupcheck(SNP **snpm, Indiv **indm, int nsnp, int k1, int k2) ;
void cdup(SNP **snpm, Indiv **indm, int nsnp, int *buff, int lbuff) ;
void printdup(SNP **snpm, int numsnp, Indiv *inda, Indiv *indb, int nmatch, int nnomatch) ;
double kurtosis(double *a, int n) ;
int getlist(char *name, char **list) ;
void printvers(char *progname, char *vers) ;
int numvalidind(Indiv **indivmarkers, int numind) ;
void numvalidgtallind(int *x, SNP **snpm, int numsnps, int numind) ;
int numvalidgtind(SNP **snpm, int numsnps, int ind) ;
int numvalidgt(Indiv **indivmarkers, SNP *cupt) ;
int numvalidgtx(Indiv **indivmarkers, SNP *cupt, int affst) ;
int isxmale(SNP *cupt, Indiv *indx) ;
void printmatz(double *ww, char **eglist, int n) ;
void printmatz5(double *ww, char **eglist, int n) ;
void printmatz10(double *ww, char **eglist, int n) ;
char *get3(char *ss) ;
char *getshort(char *ss, int n) ;
int setid2pops(char *idpopstring, Indiv **indmarkers, int numindivs) ;
int gvalm(char cc, char cm, char c1, char c2, int minfilterval) ;
int fvalid(char cm, int minfilterval) ;
int setfalist(char **poplist, int npops, char *dbfile, char **iublist, char *table_path) ;
int getfalist(char **poplist, int npops, char *dbfile, char **iublist) ;
int cmap(SNP **snpmarkers, int numsnps) ;
void setinfiles(char **pind, char **psnp, char **pgeno, char *stem) ;
void setoutfiles(char **pind, char **psnp, char **pgeno, char *stem) ;
int getdbname(char *dbase, char *name, char **pfqname) ;
int loaddiplike (double *dip, unsigned char *sp) ;
int geteg(char *name, char **list) ;
int setgklist(Indiv **indm, int numindivs, char **eglist, int numeg) ;
int setgk(Indiv **indm, int numindivs, char *pname, char ***peglist, int *pnumeg) ;
void setpopsize(int *popsize, char **poplist, int numeg, Indiv **indivmarkers, int numindivs) ;
void atopchrom (char *ss, int chrom) ;
int ptoachrom (char *ss) ;
int strcmpreg(char *a, char *b) ;
int gkignore(Indiv **indivmarkers, int numindivs) ;
void checkwrite(char *fname) ;
void testindlen(Indiv **indm, int n) ;
void testsnplen(SNP **snpm, int n) ;
int getsnpvals(double *vals, SNP **snpmarkers, int numsnps, char *vname) ;
void setref(char **preffasta, char *iubfile, char *tag) ;
void setplimit (Indiv ** indivmarkers, int numindivs, char **eglist, int numeg, int plimit) ;
int getrb(int pos, char *string, int len) ;
#undef max
#define max(A,B) ((A) > (B) ? (A) : (B))
#define MAXNUMR 200
// max number models
#define CNULL '\0'