-
Notifications
You must be signed in to change notification settings - Fork 8
/
SNP_Caller.cpp
620 lines (546 loc) · 20.9 KB
/
SNP_Caller.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
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <math.h>
#include <float.h>
#include <string.h>
#include "SNP_Caller.h"
#include "SNPFunctions.h"
#include "interpreter.h"
struct FourBasesDepth_s_ {
short depth;
short id;
};
static __inline__ void sort4_(FourBasesDepth_s_ *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) { FourBasesDepth_s_ tmp = maxd(d[x], d[y]); d[y] = mind(d[x], d[y]); d[x] = tmp; }
SWAP(0, 1);
SWAP(2, 3);
SWAP(0, 2);
SWAP(1, 3);
SWAP(1, 2);
#undef SWAP
#undef maxd
#undef mind
}
static const unsigned char offsetASiteLHSBBQB_[12] = {0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44};
static __inline__ float offsetFloatSingle_(void *ptr, unsigned int a1) {
return *(float *) (((char *) ptr) + (int) offsetASiteLHSBBQB_[a1]);
}
void resetBufferStatus(SNPMetaBuffer *buffer) {
buffer->status = NOT_READY;
}
SNPMetaBuffer *createSNPMetaBuffer(MetaReference *reference,
MetaSnpCounter *snpCounter,
GenotypeLikelihood *genotypeLikelihood,
SnpCallingInfo *scInfo,
MetaWindowInfo *mwInfo,
IndelInfo *indelInfo) {
SNPMetaBuffer *buffer = (SNPMetaBuffer *) malloc(sizeof(SNPMetaBuffer));
buffer->reference = reference;
buffer->snpCounter = snpCounter;
buffer->genotypeLikelihood = genotypeLikelihood;
buffer->scInfo = scInfo;
buffer->mwInfo = mwInfo;
buffer->indelInfo = indelInfo;
buffer->status = NOT_READY;
return buffer;
}
void freeSNPMetaBuffer(SNPMetaBuffer *buffer) {
free(buffer);
}
void setReadySNPMetaBufferStatus(SNPMetaBuffer *buffer,
unsigned int batchSize,
unsigned int startIdx) {
buffer->batchSize = batchSize;
buffer->startIdx = startIdx;
buffer->status = READY;
}
void setFinishSNPMetaBufferStatus(SNPMetaBuffer *buffer) {
buffer->status = FINISHED;
}
void waitFinishSNPMetaBuffer(SNPMetaBuffer *buffer) {
while (1) {
if (buffer->status == NOT_READY || buffer->status == FINISHED) {
break;
}
sleep(1);
}
}
SNPMetaBuffer *getIdleSNPMetaBuffer(SNPMetaBuffer *buffer0, SNPMetaBuffer *buffer1) {
while (1) {
if (buffer0->status == NOT_READY) {
return buffer0;
}
if (buffer1->status == NOT_READY) {
return buffer1;
}
if (buffer0->status == FINISHED || buffer1->status == FINISHED) {
return NULL;
}
sleep(1);
}
}
void outputPossibleSNPs(MetaReference *reference, unsigned char preBase,
MetaSnpCounter *snpCounter, SnpCallingInfo *scInfo,
IndelInfo *indelInfo, unsigned int &indelInfoIndex,
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,
unsigned char isIndel,
FILE *snpOutput) {
unsigned char buffer[1024];
unsigned short bufferSize = 0;
memcpy(buffer + bufferSize, reference, sizeof(MetaReference));
bufferSize += sizeof(MetaReference);
memcpy(buffer + bufferSize, &preBase, sizeof(unsigned char));
bufferSize += sizeof(unsigned char);
memcpy(buffer + bufferSize, snpCounter, sizeof(MetaSnpCounter));
bufferSize += sizeof(MetaSnpCounter);
#ifdef GENOTYPE_16
if (isIndel) {
char indelType = indelInfo->array[indelInfoIndex++];
if (indelType != 'I' && indelType != 'D') {
fprintf(stderr, "Error in Indel Type %d\n", indelType);
exit(1);
}
unsigned char indelLength = indelInfo->array[indelInfoIndex++];
memcpy(buffer + bufferSize, &indelType, sizeof(char));
bufferSize += sizeof(char);
memcpy(buffer + bufferSize, &indelLength, sizeof(unsigned char));
bufferSize += sizeof(unsigned char);
memcpy(buffer + bufferSize, &(indelInfo->array[indelInfoIndex]), sizeof(unsigned char) * (indelLength + 3) / 4);
bufferSize += sizeof(unsigned char) * (indelLength + 3) / 4;
indelInfoIndex += (indelLength + 3) / 4;
memcpy(buffer + bufferSize, &(indelInfo->array[indelInfoIndex]), sizeof(unsigned short) * 2);
bufferSize += sizeof(unsigned short) * 2;
indelInfoIndex += 4;
if (isIndel == 3) {
char indelType = indelInfo->array[indelInfoIndex++];
if (indelType != 'I' && indelType != 'D') {
fprintf(stderr, "Error in Indel Type %d\n", indelType);
exit(1);
}
unsigned char indelLength = indelInfo->array[indelInfoIndex++];
memcpy(buffer + bufferSize, &indelType, sizeof(char));
bufferSize += sizeof(char);
memcpy(buffer + bufferSize, &indelLength, sizeof(unsigned char));
bufferSize += sizeof(unsigned char);
memcpy(buffer + bufferSize, &(indelInfo->array[indelInfoIndex]), sizeof(unsigned char) * (indelLength + 3) / 4);
bufferSize += sizeof(unsigned char) * (indelLength + 3) / 4;
indelInfoIndex += (indelLength + 3) / 4;
memcpy(buffer + bufferSize, &(indelInfo->array[indelInfoIndex]), sizeof(unsigned short) * 2);
bufferSize += sizeof(unsigned short) * 2;
indelInfoIndex += 4;
} else {
char indelType = '*';
memcpy(buffer + bufferSize, &indelType, sizeof(char));
bufferSize += sizeof(char);
}
} else {
char indelType = '*';
memcpy(buffer + bufferSize, &indelType, sizeof(char));
bufferSize += sizeof(char);
}
#endif
memcpy(buffer + bufferSize, scInfo, sizeof(SnpCallingInfo));
bufferSize += sizeof(SnpCallingInfo);
memcpy(buffer + bufferSize, genotypeLikelihood, sizeof(GenotypeLikelihood));
bufferSize += sizeof(GenotypeLikelihood);
if (isIndel) {
memcpy(buffer + bufferSize, strandBias, sizeof(StrandBias) * 3);
bufferSize += sizeof(StrandBias) * 3;
memcpy(buffer + bufferSize, baseQualityBias, sizeof(BaseQualityBias) * 3);
bufferSize += sizeof(BaseQualityBias) * 3;
} else {
memcpy(buffer + bufferSize, strandBias, sizeof(StrandBias));
bufferSize += sizeof(StrandBias);
memcpy(buffer + bufferSize, baseQualityBias, sizeof(BaseQualityBias));
bufferSize += sizeof(BaseQualityBias);
}
memcpy(buffer + bufferSize, deltaStrandCount, sizeof(DeltaStrandCount));
bufferSize += sizeof(DeltaStrandCount);
memcpy(buffer + bufferSize, gcCount, sizeof(GCCount));
bufferSize += sizeof(GCCount);
memcpy(buffer + bufferSize, gCount, sizeof(GCount));
bufferSize += sizeof(GCount);
memcpy(buffer + bufferSize, avgStrandCount, sizeof(AverageStrandCount));
bufferSize += sizeof(AverageStrandCount);
memcpy(buffer + bufferSize, rQuality, sizeof(ReadQuality));
bufferSize += sizeof(ReadQuality);
memcpy(buffer + bufferSize, &polyrun, sizeof(unsigned short));
bufferSize += sizeof(unsigned short);
memcpy(buffer + bufferSize, &indelHqCount, sizeof(unsigned int));
bufferSize += sizeof(unsigned int);
memcpy(buffer + bufferSize, &indelLqCount, sizeof(unsigned int));
bufferSize += sizeof(unsigned int);
if (bufferSize > 1024) {
fprintf(stderr, "Buffer overflow\n");
}
fwrite(buffer, sizeof(unsigned char), bufferSize, snpOutput);
}
void computeMeta(unsigned int index, unsigned int batchSize, MetaReference *reference,
MetaSnpCounter *snpCounter, SnpCallingInfo *scInfo,
MetaWindowInfo *mwInfo,
IndelInfo *indelInfo, unsigned int &indelInfoIndex,
GenotypeLikelihood *genotypeLikelihood,
StrandBias *strandBias,
BaseQualityBias *baseQualityBias,
DeltaStrandCount *deltaStrandCount,
GCCount *gcCount, GCount *gCount,
AverageStrandCount *avgStrandCount,
ReadQuality *rQuality,
FILE *snpOutput) {
char isIndel = 0;
unsigned char nextBp = 0;
#ifdef GENOTYPE_16
if (scInfo[index].genotype > 9 && mwInfo[index + SNP_META_WINDOW_SIZE].isValid >= 2) {
char indelType = indelInfo->array[indelInfoIndex];
unsigned char indelLength = indelInfo->array[indelInfoIndex + 1];
if (indelType == 'D') {
nextBp = indelLength;
}
isIndel = mwInfo[index + SNP_META_WINDOW_SIZE].isValid;
} else if (scInfo[index].genotype > 9) {
if (scInfo[index].genotype != UNIDENTIFIED_GENOTYPE) {
fprintf(stderr, "Error in selecting Genotype : %u\n", reference[index].amb);
exit(1);
}
} else if (mwInfo[index + SNP_META_WINDOW_SIZE].isValid == 2) {
jumpIndelInfoIndex(indelInfo, indelInfoIndex);
} else if (mwInfo[index + SNP_META_WINDOW_SIZE].isValid == 3) {
jumpIndelInfoIndex(indelInfo, indelInfoIndex);
jumpIndelInfoIndex(indelInfo, indelInfoIndex);
}
#endif
if (isIndel) {
if (index != 0) {
computeStrandBias(&(snpCounter[index - 1]), &(strandBias[0]));
} else {
memset(&(strandBias[0]), 0, sizeof(StrandBias));
}
if (index + nextBp < batchSize) {
computeStrandBias(&(snpCounter[index + nextBp]), &(strandBias[1]));
} else {
memset(&(strandBias[1]), 0, sizeof(StrandBias));
}
computeStrandBias(&(snpCounter[index]), &(strandBias[2]));
if (index != 0) {
computeBaseQualityBias(&(snpCounter[index - 1]), &(baseQualityBias[0]));
} else {
memset(&(baseQualityBias[0]), 0, sizeof(BaseQualityBias));
}
if (index + nextBp < batchSize) {
computeBaseQualityBias(&(snpCounter[index + nextBp]), &(baseQualityBias[1]));
} else {
memset(&(baseQualityBias[1]), 0, sizeof(BaseQualityBias));
}
computeBaseQualityBias(&(snpCounter[index]), &(baseQualityBias[2]));
} else {
computeStrandBias(&(snpCounter[index]), &(strandBias[0]));
computeBaseQualityBias(&(snpCounter[index]), &(baseQualityBias[0]));
}
int strandSum[2] = {0};
int deltaSum[2] = {0};
int depthSum[2] = {0};
unsigned char gcSum[2] = {0};
unsigned char gSum[2] = {0};
unsigned char validSum[2] = {0};
float avgSC[2] = {0.0f};
float avgD[2] = {0.0f};
unsigned int i;
for (i = index - SNP_META_WINDOW_SIZE; i < index; ++i) {
if (mwInfo[i].isValid) {
unsigned int strandCount0 = mwInfo[i].posStrandCount + mwInfo[i].negStrandCount;
strandSum[0] += strandCount0;
depthSum[0] += mwInfo[i].weightedCount;
gcSum[0] += mwInfo[i].gcStrandCount;
validSum[0] += 1;
if (mwInfo[i + 1].isValid) {
unsigned int strandCount1 = mwInfo[i + 1].posStrandCount + mwInfo[i + 1].negStrandCount;
deltaSum[0] += (strandCount0 > strandCount1 ? strandCount0 - strandCount1 : strandCount1 - strandCount0);
}
}
}
for (i = index + nextBp; i < index + nextBp + SNP_META_WINDOW_SIZE; ++i) {
if (mwInfo[i].isValid) {
unsigned int strandCount0 = mwInfo[i].posStrandCount + mwInfo[i].negStrandCount;
strandSum[1] += strandCount0;
depthSum[1] += mwInfo[i].weightedCount;
gcSum[1] += mwInfo[i].gcStrandCount;
validSum[1] += 1;
if (mwInfo[i + 1].isValid) {
unsigned int strandCount1 = mwInfo[i + 1].posStrandCount + mwInfo[i + 1].negStrandCount;
deltaSum[1] += (strandCount0 > strandCount1 ? strandCount0 - strandCount1 : strandCount1 - strandCount0);
}
}
}
if (deltaSum[0] | deltaSum[1]) {
deltaStrandCount->lrRatio = (deltaSum[0] - deltaSum[1] + 0.0f) / (deltaSum[0] + deltaSum[1]);
} else {
deltaStrandCount->lrRatio = 0.0f;
}
if (validSum[0]) {
gcCount->left = (gcSum[0] + 0.0f) / validSum[0];
avgSC[0] = (strandSum[0] + 0.0f) / validSum[0];
avgD[0] = (depthSum[0] + 0.0f) / validSum[0];
} else {
gcCount->left = 0.0f;
}
if (validSum[1]) {
gcCount->right = (gcSum[1] + 0.0f) / validSum[1];
avgSC[1] = (strandSum[1] + 0.0f) / validSum[1];
avgD[1] = (depthSum[1] + 0.0f) / validSum[1];
} else {
gcCount->right = 0.0f;
}
if (fabs(avgSC[0] + avgSC[1]) > FLT_EPSILON) {
avgStrandCount->lrRatio = (avgSC[0] - avgSC[1]) / (avgSC[0] + avgSC[1]);
if (fabs(avgSC[0]) > FLT_EPSILON) {
rQuality->left = avgD[0] / avgSC[0];
} else {
rQuality->left = 0.0f;
}
if (fabs(avgSC[1]) > FLT_EPSILON) {
rQuality->right = avgD[1] / avgSC[1];
} else {
rQuality->right = 0.0f;
}
} else {
avgStrandCount->lrRatio = 0.0f;
}
for (i = index - 3; i < index; ++i) {
if (mwInfo[i].isValid) {
gSum[0] += mwInfo[i].gStrandCount;
}
}
for (i = index + nextBp; i < index + nextBp + 3; ++i) {
if (mwInfo[i].isValid) {
gSum[1] += mwInfo[i].gStrandCount;
}
}
gCount->left = gSum[0];
gCount->right = gSum[1];
FourBasesDepth_s_ v[4];
v[0].depth = snpCounter[index].W[0];
v[0].id = 0;
v[1].depth = snpCounter[index].W[1];
v[1].id = 1;
v[2].depth = snpCounter[index].W[2];
v[2].id = 2;
v[3].depth = snpCounter[index].W[3];
v[3].id = 3;
sort4_(v);
outputPossibleSNPs(&(reference[index]), mwInfo[index + SNP_META_WINDOW_SIZE].preBase,
&(snpCounter[index]),
&(scInfo[index]),
indelInfo, indelInfoIndex,
&(genotypeLikelihood[index]),
strandBias, baseQualityBias, deltaStrandCount,
gcCount, gCount, avgStrandCount,
rQuality, mwInfo[index + SNP_META_WINDOW_SIZE].polyrun,
mwInfo[index + SNP_META_WINDOW_SIZE].indelHqCount,
mwInfo[index + SNP_META_WINDOW_SIZE].indelLqCount,
isIndel,
snpOutput);
}
void filterSNP(MetaReference *reference, MetaSnpCounter *snpCounter,
GenotypeLikelihood *genotypeLikelihood, SnpCallingInfo *scInfo,
MetaWindowInfo *mwInfo, IndelInfo *indelInfo,
unsigned int batchSize, unsigned int startIdx,
FILE *snpOutput, unsigned int *attriSize) {
unsigned int filterTable[ALPHABET_SIZE] = {0, 4, 7, 9};
StrandBias strandBias[3];
BaseQualityBias baseQualityBias[3];
DeltaStrandCount deltaStrandCount;
GCCount gcCount;
GCount gCount;
AverageStrandCount avgStrandCount;
ReadQuality rQuality;
unsigned int indelInfoIndex = 0;
unsigned int i;
unsigned int bound = startIdx + batchSize;
unsigned int mwIdx;
for (i = startIdx; i < bound; ++i) {
mwIdx = i + SNP_META_WINDOW_SIZE;
if (mwInfo[mwIdx].isValid &&
!(filterTable[reference[i].refChar] == scInfo[i].genotype || scInfo[i].genotype >= UNIDENTIFIED_GENOTYPE)) {
(*attriSize)++;
computeMeta(i, batchSize, reference, snpCounter,
scInfo, mwInfo,
indelInfo, indelInfoIndex,
genotypeLikelihood,
strandBias, baseQualityBias, &deltaStrandCount,
&gcCount, &gCount, &avgStrandCount,
&rQuality,
snpOutput);
} else if (mwInfo[mwIdx].isValid == 2) {
jumpIndelInfoIndex(indelInfo, indelInfoIndex);
} else if (mwInfo[mwIdx].isValid == 3) {
jumpIndelInfoIndex(indelInfo, indelInfoIndex);
jumpIndelInfoIndex(indelInfo, indelInfoIndex);
}
if (indelInfoIndex > indelInfo->size) {
fprintf(stderr, "Error in reading IndelInfo : size = %u, [%u, %u]\n", indelInfo->size, i, bound);
exit(1);
}
}
}
void filterSNPPipeline(SNPMetaBuffer *buffer0, SNPMetaBuffer *buffer1,
FILE *snpOutput,
unsigned int *attriSize) {
if (!buffer0 || !buffer1) {
fprintf(stderr, "Null Pointer Exception : SNPMetaBuffer\n");
exit(1);
}
SNPMetaBuffer *buffer;
while (1) {
while (1) {
if (buffer0->status == NOT_READY && buffer1->status == NOT_READY) {
sleep(1);
} else if (buffer0->status == READY && buffer1->status == READY) {
if (buffer0->reference->amb < buffer1->reference->amb) {
buffer = buffer0;
} else {
buffer = buffer1;
}
break;
} else if (buffer0->status == READY) {
buffer = buffer0;
break;
} else if (buffer1->status == READY) {
buffer = buffer1;
break;
} else
{
return;
}
}
filterSNP(buffer->reference, buffer->snpCounter,
buffer->genotypeLikelihood, buffer->scInfo,
buffer->mwInfo, buffer->indelInfo,
buffer->batchSize, buffer->startIdx,
snpOutput, attriSize);
buffer->status = NOT_READY;
}
}
void *filterSNPWrapper(void *ptr) {
SnpCallerWrapperObj *obj = (SnpCallerWrapperObj *) ptr;
filterSNPPipeline(obj->buffer0, obj->buffer1, obj->snpOutput, obj->attriSize);
free(obj);
return NULL;
}
void startFilterSNPThread(SNPMetaBuffer *buffer0, SNPMetaBuffer *buffer1,
FILE *snpOutput,
unsigned int *attriSize,
pthread_t &thread) {
SnpCallerWrapperObj *obj = (SnpCallerWrapperObj *) malloc(sizeof(SnpCallerWrapperObj));
obj->buffer0 = buffer0;
obj->buffer1 = buffer1;
obj->snpOutput = snpOutput;
obj->attriSize = attriSize;
int t;
t = pthread_create(&thread, NULL, filterSNPWrapper, obj);
if (t) {
fprintf(stderr, "Error in creating SNP Calling Thread.\n");
}
}
void calRandomForestpPedictProb(const char *snp_noRF_filename,
const char *snp_filename,
unsigned int attriSize, char verbose) {
FILE *snpOutput = fopen(snp_noRF_filename, "rb");
FILE *newSnpOutput = fopen(snp_filename, "w");
printf("Called Entries : %u\n", attriSize);
if (snpOutput == NULL) {
fprintf(stderr, "[SNP] %s does not exist\n", snp_noRF_filename);
exit(1);
}
if (newSnpOutput == NULL) {
fprintf(stderr, "[SNP] %s does not exist\n", snp_filename);
exit(1);
}
float rfProb = 0;
int rfMode = 0;
MetaReference reference;
unsigned char preBase;
MetaSnpCounter snpCounter;
char indelType[2];
unsigned char indelLength[2];
unsigned char indelPattern[2][MAX_PATTERN_LENGTH];
unsigned short hqCount[2], lqCount[2];
unsigned char isIndel = 0;
if (verbose) { printf("Outputing Results...\n"); }
printHeader(newSnpOutput);
for (unsigned int i = 0; i < attriSize; i++) {
fread(&reference, sizeof(MetaReference), 1, snpOutput);
fread(&preBase, sizeof(unsigned char), 1, snpOutput);
fread(&snpCounter, sizeof(MetaSnpCounter), 1, snpOutput);
isIndel = 0;
indelType[0] = '*';
indelType[1] = '*';
for (unsigned int j = 0; j < 2; j++) {
fread(&(indelType[j]), sizeof(char), 1, snpOutput);
if (indelType[j] == '*') {
break;
} else {
isIndel = 1;
fread(&(indelLength[j]), sizeof(unsigned char), 1, snpOutput);
fread(indelPattern[j], sizeof(unsigned char), (indelLength[j] + 3) / 4, snpOutput);
fread(&(hqCount[j]), sizeof(unsigned short), 1, snpOutput);
fread(&(lqCount[j]), sizeof(unsigned short), 1, snpOutput);
}
}
SnpCallingInfo scInfo;
GenotypeLikelihood genotypeLikelihood;
StrandBias strandBias[3];
BaseQualityBias baseQualityBias[3];
DeltaStrandCount deltaStrandCount;
GCCount gcCount;
GCount gCount;
AverageStrandCount avgStrandCount;
ReadQuality rQuality;
unsigned short polyrun;
unsigned int indelHqCount;
unsigned int indelLqCount;
fread(&scInfo, sizeof(SnpCallingInfo), 1, snpOutput);
scInfo.rfProb = rfProb;
scInfo.rfMode = rfMode;
fread(&genotypeLikelihood, sizeof(GenotypeLikelihood), 1, snpOutput);
if (isIndel) {
fread(strandBias, sizeof(StrandBias), 3, snpOutput);
fread(baseQualityBias, sizeof(BaseQualityBias), 3, snpOutput);
} else {
fread(strandBias, sizeof(StrandBias), 1, snpOutput);
fread(baseQualityBias, sizeof(BaseQualityBias), 1, snpOutput);
}
fread(&deltaStrandCount, sizeof(DeltaStrandCount), 1, snpOutput);
fread(&gcCount, sizeof(GCCount), 1, snpOutput);
fread(&gCount, sizeof(GCount), 1, snpOutput);
fread(&avgStrandCount, sizeof(AverageStrandCount), 1, snpOutput);
fread(&rQuality, sizeof(ReadQuality), 1, snpOutput);
fread(&polyrun, sizeof(unsigned short), 1, snpOutput);
fread(&indelHqCount, sizeof(unsigned int), 1, snpOutput);
fread(&indelLqCount, sizeof(unsigned int), 1, snpOutput);
printPossibleSNP(&reference, &snpCounter, &scInfo, isIndel, indelType[0], indelLength[0], indelPattern[0],
hqCount[0], lqCount[0], indelType[1], indelLength[1], indelPattern[1], hqCount[1], lqCount[1],
&genotypeLikelihood, strandBias, baseQualityBias,
&deltaStrandCount, &gcCount, &gCount, &avgStrandCount, &rQuality, polyrun, indelHqCount,
indelLqCount, newSnpOutput);
}
fclose(snpOutput);
fclose(newSnpOutput);
}
void closeFilterSNPThread(pthread_t &filterSnpThread) {
if (pthread_join(filterSnpThread, NULL)) {
fprintf(stderr, "[SNP] Error in joining SNP Calling Thread.\n");
}
}