forked from samtools/bcftools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmissing2ref.c
More file actions
44 lines (36 loc) · 777 Bytes
/
missing2ref.c
File metadata and controls
44 lines (36 loc) · 777 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <htslib/vcf.h>
#include <inttypes.h>
bcf_hdr_t *hdr;
int *gts = NULL, mgts = 0;
uint64_t nchanged = 0;
const char *about(void)
{
return "Set missing genotypes (\"./.\") to ref allele (\"0/0\").\n";
}
void init(bcf_hdr_t *h)
{
hdr = h;
}
int process(bcf1_t *rec)
{
int ngts = bcf_get_genotypes(hdr, rec, >s, &mgts);
int i, changed = 0;
for (i=0; i<ngts; i++)
{
if ( gts[i]==bcf_gt_missing )
{
gts[i] = bcf_gt_unphased(0);
changed++;
}
}
nchanged += changed;
if ( changed ) bcf_update_genotypes(hdr, rec, gts, ngts);
return 0;
}
void destroy(void)
{
fprintf(stderr,"Filled %"PRId64" REF alleles\n", nchanged);
free(gts);
}