forked from lh3/fastARG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharg_check.c
54 lines (52 loc) · 1.38 KB
/
arg_check.c
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
#include <stdio.h>
#include <stdlib.h>
#include "arg_data.h"
static void chkphase(const arg_data_t *src, arg_data_t *dst)
{
int i, j;
int n_switch = 0, n_het = 0;
if (src->m != dst->m || src->n != dst->n) {
fprintf(stderr, "[chkphase] inconsistent src and dst.\n");
exit(1);
}
if (src->n%2 != 0) {
fprintf(stderr, "[chkphase] # haplotypes is not even.\n");
exit(1);
}
for (j = 0; j < src->n; j += 2) {
char *ss0 = src->seq[j], *ss1 = src->seq[j+1];
char *sd0 = dst->seq[j], *sd1 = dst->seq[j+1];
int last = -1, curr, x = 0;
for (i = 0; i < src->m; ++i) {
if (ss0[i] == ss1[i]) continue;
if (sd0[i] == sd1[i]) {
fprintf(stderr, "[chkphase] inconsistent phase at (%d,%d)\n", j, i);
exit(1);
}
++n_het; ++x;
curr = (sd0[i] == ss0[i])? 0 : 1;
if (last >= 0 && last != curr) {
++n_switch;
x = 1;
}
last = curr;
}
}
fprintf(stderr, "[chkphase] # heterozygotes: %d\n", n_het);
fprintf(stderr, "[chkphase] # switches: %d\n", n_switch);
fprintf(stderr, "[chkphase] switch error: %.3lf\n", (double)n_switch/(n_het - src->n/2));
}
int main_chkphase(int argc, char *argv[])
{
arg_data_t *src, *dst;
if (argc < 3) {
fprintf(stderr, "Usage: fastARG chkphase <src.dat> <dst.dat>\n");
return 1;
}
src = arg_data_read(argv[1]);
dst = arg_data_read(argv[2]);
chkphase(src, dst);
arg_data_destroy(src);
arg_data_destroy(dst);
return 0;
}