-
Notifications
You must be signed in to change notification settings - Fork 8
/
SNP_Stat.h
148 lines (126 loc) · 3.11 KB
/
SNP_Stat.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
#ifndef _SNP_STAT_H_
#define _SNP_STAT_H_
#include <string.h>
#include "SNP_Meta.h"
#define DEPTH_THRES 65536
#define STEPS 100
#define UG UNIDENTIFIED_GENOTYPE
static const int Base2GTMap[] =
{
0, 1, 2, 3, 10, UG,
1, 4, 5, 6, 11, UG,
2, 5, 7, 8, 12, UG,
3, 6, 8, 9, 13, UG,
10, 11, 12, 13, 14, 15,
UG, UG, UG, UG, 15, UG
};
#undef UG
__inline__ int getGenotype(unsigned char b1, unsigned char b2)
{
return Base2GTMap[b1 * COUNTER_NUM + b2];
}
typedef struct WholeGenomeMeta
{
unsigned int zeroCount;
unsigned int depthTooHigh;
unsigned int depthTooLow;
unsigned int hom;
unsigned int het;
unsigned int tri;
unsigned int quad;
} WholeGenomeMeta;
typedef struct SnpMeta
{
unsigned int zeroCount;
unsigned int depthTooHigh;
unsigned int depthTooLow;
unsigned int hom;
unsigned int het;
unsigned int tri;
unsigned int quad;
unsigned int inconsistentDBnConsensusHom;
unsigned int notConsensusButRefHom;
unsigned int inconsistentDBnConsensusHet;
unsigned int valid;
unsigned int invalid;
} SnpMeta;
typedef struct SnpStats
{
unsigned int totalDepth[DEPTH_THRES + 1];
unsigned int baseDepth[DEPTH_THRES + 1];
unsigned int lh[STEPS + 1];
unsigned int sb[STEPS + 1];
unsigned int bqb[STEPS + 1];
} SnpStats;
typedef struct SnpProbs
{
double totalDepth[DEPTH_THRES + 1];
double baseDepth[DEPTH_THRES + 1];
double lh[STEPS + 1];
double sb[STEPS + 1];
double bqb[STEPS + 1];
} SnpProbs;
__inline__ int pVal2Index(double p)
{
return int(p * STEPS + 0.4999);
}
__inline__ int pValf2Index(float p)
{
return int(p * STEPS + 0.4999f);
}
#pragma pack(push)
#pragma pack(4)
typedef struct FourBasesDepth
{
unsigned short depth;
short id;
} FourBasesDepth;
#pragma pack(pop)
static __inline__ void sort4(FourBasesDepth *d)
{
#define mind(x, y) ((x.depth<y.depth)?x:y)
#define maxd(x, y) ((x.depth<y.depth)?y:x)
#define SWAP(x, y, _d) { FourBasesDepth tmp = maxd(_d[x], _d[y]); _d[y] = mind(_d[x], _d[y]); _d[x] = tmp; }
SWAP(0, 1, d);
SWAP(2, 3, d);
SWAP(0, 2, d);
SWAP(1, 3, d);
SWAP(1, 2, d);
#undef SWAP
#undef maxd
#undef mind
}
__inline__ void updateToStats(const FourBasesDepth *const d, int homOrHet,
SnpStats *const snpStats,
const GenotypeLikelihood *const genotypeLikelihood,
const StrandBias *const strandBias)
{
if (homOrHet == 0)
{
++snpStats->lh[pVal2Index(genotypeLikelihood->likelihood[getGenotype(d[0].id, d[0].id)])];
++snpStats->sb[pValf2Index(strandBias->bias[d[0].id])];
}
else if (homOrHet == 1)
{
++snpStats->lh[pVal2Index(genotypeLikelihood->likelihood[getGenotype(d[0].id, d[1].id)])];
++snpStats->sb[pValf2Index((strandBias->bias[d[0].id] + strandBias->bias[d[1].id]) * 0.5)];
}
else
{
fprintf(stderr, "[%s][%s][%d] Should never reach here.\n", __FILE__, __FUNCTION__, __LINE__);
exit(1);
}
}
__inline__ int myStrChr(const char *const str, const char c)
{
int x = strlen(str);
for (int i = 0; i < x; ++i)
{
if (str[i] == c)
{
return 1;
}
}
return 0;
}
#endif