-
Notifications
You must be signed in to change notification settings - Fork 8
/
interpreter.cpp
156 lines (136 loc) · 5.79 KB
/
interpreter.cpp
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
#include <stdio.h>
#include "interpreter.h"
static char genotypeString[] = "AA\0\0AC\0\0AG\0\0AT\0\0CC\0\0CG\0\0CT\0\0GG\0\0GT\0\0TT\0\0AX\0\0CX\0\0GX\0\0TX\0\0XX\0\0XY\0\0NN\0\0";
static char sym[] = {'A', 'C', 'G', 'T', 'X', 'Y', 'N'};
void printHeader(FILE *fout) {
fprintf(fout, "Chr\tPos\tRef\tPreBase\t");
fprintf(fout, "pAA\tpAC\tpAG\tpAT\tpCC\tpCG\tpCT\tpGG\tpGT\tpTT\tpAX\tpCX\tpGX\tpTX\tpXX\tpXY\t");
fprintf(fout, "GT\tOptb\tSuboptb\tpD\t");
fprintf(fout, "rfProb\trfMode\t");
fprintf(fout, "optIn/Del\tPatt\tHQ\tLQ\t");
fprintf(fout, "suboptIn/Del\tPatt\tHQ\tLQ\t");
fprintf(fout, "Depth\tA\tC\tG\tT\tA+\tA-\tC+\tC-\tG+\tG-\tT+\tT-\t");
fprintf(fout, "AA\tAC\tAG\tAT\tCC\tCG\tCT\tGG\tGT\tTT\tAX\tCX\tGX\tTX\tXX\tXY\t");
fprintf(fout, "SB-A\tSB-C\tSB-G\tSB-T\t");
fprintf(fout, "SB1-A\tSB1-C\tSB1-G\tSB1-T\t");
fprintf(fout, "SB2-A\tSB2-C\tSB2-G\tSB2-T\t");
fprintf(fout, "BQB-A\tBQB-C\tBQB-G\tBQB-T\t");
fprintf(fout, "BQB1-A\tBQB1-C\tBQB1-G\tBQB1-T\t");
fprintf(fout, "BQB2-A\tBQB2-C\tBQB2-G\tBQB2-T\t");
fprintf(fout, "RPB\t");
fprintf(fout, "LGC\tRGC\t");
fprintf(fout, "LG\tRG\t");
fprintf(fout, "ASC\t");
fprintf(fout, "LQ\tRQ\t");
fprintf(fout, "polyrun\t");
fprintf(fout, "totalHQ\ttotalLQ\n");
}
__inline__ void printBase(FILE *fout, unsigned char base) {
fprintf(fout, "%c", sym[base]);
}
__inline__ void printGenotype(FILE *fout, unsigned int genotype) {
fprintf(fout, "%s\t", &(genotypeString[genotype << 2]));
}
__inline__ void printGenotypeLikelihood(FILE *fout, double *lh) {
for (unsigned int i = 0; i < GENOTYPE_NUM; ++i) {
fprintf(fout, "%.4e\t", lh[i]);
}
}
__inline__ void printStrandBias(FILE *fout, StrandBias *sb) {
for (unsigned int i = 0; i < ALPHABET_SIZE; ++i) {
fprintf(fout, "%.4e\t", sb->bias[i]);
}
}
__inline__ void printBaseQualityBias(FILE *fout, BaseQualityBias *bqb) {
for (unsigned int i = 0; i < ALPHABET_SIZE; ++i) {
fprintf(fout, "%.4e\t", bqb->bias[i]);
}
}
__inline__ void printReadPositionBias(FILE *fout, DeltaStrandCount *rpb) {
fprintf(fout, "%.4f\t", rpb->lrRatio);
}
__inline__ void printGCCount(FILE *fout, GCCount *gc) {
fprintf(fout, "%.4f\t%.4f\t", gc->left, gc->right);
}
__inline__ void printGCount(FILE *fout, GCount *g) {
fprintf(fout, "%u\t%u\t", g->left, g->right);
}
__inline__ void printAverageStrandCount(FILE *fout, AverageStrandCount *asc) {
fprintf(fout, "%.4f\t", asc->lrRatio);
}
__inline__ void printReadQuality(FILE *fout, ReadQuality *rq) {
fprintf(fout, "%.4f\t%.4f\t", rq->left, rq->right);
}
__inline__ void printIndel(FILE *fout, char indelType, unsigned char indelLength, unsigned char *pattern,
unsigned int hqCount, unsigned int lqCount) {
if (indelType == '*') {
fprintf(fout, "*\t*\t*\t*\t");
} else {
fprintf(fout, "%u%c\t", indelLength, indelType);
for (unsigned int i = 0; i < indelLength; ++i) {
printBase(fout, (pattern[i >> 2] >> ((i & 3) << 1)) & 3);
}
fprintf(fout, "\t");
fprintf(fout, "%u\t%u\t", hqCount, lqCount);
}
}
__inline__ void printSnpCounter(FILE *fout, MetaSnpCounter *snpCounter) {
unsigned int depth = 0;
for (unsigned int i = 0; i < ALPHABET_SIZE; ++i) {
depth += snpCounter->W[i];
}
fprintf(fout, "%u\t", depth);
for (unsigned int i = 0; i < ALPHABET_SIZE; ++i) {
fprintf(fout, "%hu\t", snpCounter->W[i]);
}
for (unsigned int i = 0; i < ALPHABET_SIZE; ++i) {
fprintf(fout, "%hu\t%hu\t", snpCounter->F[i], snpCounter->R[i]);
}
}
void
printPossibleSNP(MetaReference *reference, MetaSnpCounter *snpCounter, SnpCallingInfo *scInfo, unsigned char isIndel,
char indelType1, unsigned char indelLength1, unsigned char *indelPattern1, unsigned int hqCount1,
unsigned int lqCount1, char indelType2, unsigned char indelLength2, unsigned char *indelPattern2,
unsigned int hqCount2, unsigned int lqCount2, GenotypeLikelihood *genotypeLikelihood,
StrandBias *strandBias, BaseQualityBias *baseQualityBias, DeltaStrandCount *deltaStrandCount,
GCCount *gcCount, GCount *gCount, AverageStrandCount *avgStrandCount, ReadQuality *rQuality,
unsigned short polyrun, unsigned int indelHqCount, unsigned int indelLqCount, FILE *fout) {
fprintf(fout, "%s\t", reference->chrName);
fprintf(fout, "%u\t", reference->chrPos);
fprintf(fout, "%c\t", sym[reference->refChar]);
if (isIndel) {
fprintf(fout, "%c\t", sym[reference->refChar]);
} else {
fprintf(fout, "*\t");
}
printGenotypeLikelihood(fout, scInfo->flh);
printGenotype(fout, scInfo->genotype);
fprintf(fout, "%.4e\t%.4e\t%.4e\t", scInfo->bestD, scInfo->secondD, scInfo->pD);
fprintf(fout, "%.4e\t%d\t", scInfo->rfProb, scInfo->rfMode);
printIndel(fout, indelType1, indelLength1, indelPattern1, hqCount1, lqCount1);
printIndel(fout, indelType2, indelLength2, indelPattern2, hqCount2, lqCount2);
printSnpCounter(fout, snpCounter);
printGenotypeLikelihood(fout, genotypeLikelihood->likelihood);
if (isIndel) {
printStrandBias(fout, &(strandBias[0]));
printStrandBias(fout, &(strandBias[1]));
printStrandBias(fout, &(strandBias[2]));
printBaseQualityBias(fout, &(baseQualityBias[0]));
printBaseQualityBias(fout, &(baseQualityBias[1]));
printBaseQualityBias(fout, &(baseQualityBias[2]));
} else {
printStrandBias(fout, &(strandBias[0]));
fprintf(fout, "*\t*\t*\t*\t");
fprintf(fout, "*\t*\t*\t*\t");
printBaseQualityBias(fout, &(baseQualityBias[0]));
fprintf(fout, "*\t*\t*\t*\t");
fprintf(fout, "*\t*\t*\t*\t");
}
printReadPositionBias(fout, deltaStrandCount);
printGCCount(fout, gcCount);
printGCount(fout, gCount);
printAverageStrandCount(fout, avgStrandCount);
printReadQuality(fout, rQuality);
fprintf(fout, "%hu\t", polyrun);
fprintf(fout, "%u\t%u\n", indelHqCount, indelLqCount);
}