-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiss.cpp
56 lines (47 loc) · 1.17 KB
/
miss.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
#include <stdio.h>
#include <math.h>
#include <random>
std::mt19937 rng;
char tlf[1048576];
int main(int argc, char** argv)
{
if (argc < 2)
{
fprintf(stderr, "Specify a missingness rate");
return -1;
}
double missingness;
if (sscanf(argv[1], "%lf", &missingness) != 1 || missingness < 0 || missingness > 1)
{
fprintf(stderr, "Argument %s not intepreted as a missingness rate from 0 to 1.\n", argv[1]);
return -1;
}
std::bernoulli_distribution missing(missingness);
int n;
fgets(tlf, 1048576, stdin);
if (sscanf(tlf, "%d", &n) != 1)
{
fprintf(stderr, "Unable to identify number of individuals from first line: %s", tlf);
return -1;
}
printf("%d\n", n);
for (int i = 0; i < n; i++)
{
fgets(tlf, 1048576, stdin);
char* tlf2 = tlf;
int tot = 0;
int mismatches = 0;
int pos;
int geno;
while (sscanf(tlf2, "%d%n", &geno, &pos) == 1)
{
tlf2 += pos;
if (missing(rng))
{
geno = -1;
}
printf("%d ", geno);
}
printf("\n");
}
}