From: Heng Li Date: Fri, 10 Dec 2010 15:09:14 +0000 (+0000) Subject: Make sure that the GT genotype field is the first X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=2a95d0bc3c8e9badd7ae09067d9b4914ed1448f7;p=samtools.git Make sure that the GT genotype field is the first --- diff --git a/bamtk.c b/bamtk.c index 9dbdfde..da54ffd 100644 --- a/bamtk.c +++ b/bamtk.c @@ -9,7 +9,7 @@ #endif #ifndef PACKAGE_VERSION -#define PACKAGE_VERSION "0.1.12-2 (r877)" +#define PACKAGE_VERSION "0.1.12-3 (r878)" #endif int bam_taf2baf(int argc, char *argv[]); diff --git a/bcftools/bcfutils.c b/bcftools/bcfutils.c index 4d6835d..3c6ed73 100644 --- a/bcftools/bcfutils.c +++ b/bcftools/bcfutils.c @@ -1,3 +1,4 @@ +#include #include "bcf.h" #include "kstring.h" #include "khash.h" @@ -107,3 +108,26 @@ int bcf_gl2pl(bcf1_t *b) } return 0; } +/* FIXME: this function will fail given AB:GTX:GT. BCFtools never + * produces such FMT, but others may do. */ +int bcf_fix_gt(bcf1_t *b) +{ + char *s; + int i; + uint32_t tmp; + bcf_ginfo_t gt; + // check the presence of the GT FMT + if ((s = strstr(b->fmt, ":GT")) == 0) return 0; // no GT or GT is already the first + if (s[3] != '\0' && s[3] != ':') return 0; // :GTX in fact + tmp = bcf_str2int("GT", 2); + for (i = 0; i < b->n_gi; ++i) + if (b->gi[i].fmt == tmp) break; + if (i == b->n_gi) return 0; // no GT in b->gi; probably a bug... + gt = b->gi[i]; + // move GT to the first + for (; i > 0; --i) b->gi[i] = b->gi[i-1]; + b->gi[0] = gt; + memmove(b->fmt + 3, b->fmt, s + 1 - b->fmt); + b->fmt[0] = 'G'; b->fmt[1] = 'T'; b->fmt[2] = ':'; + return 0; +} diff --git a/bcftools/call1.c b/bcftools/call1.c index 012c2b3..b913c9a 100644 --- a/bcftools/call1.c +++ b/bcftools/call1.c @@ -206,6 +206,7 @@ int bcfview(int argc, char *argv[]) { extern int bcf_2qcall(bcf_hdr_t *h, bcf1_t *b); extern void bcf_p1_indel_prior(bcf_p1aux_t *ma, double x); + extern int bcf_fix_gt(bcf1_t *b); bcf_t *bp, *bout = 0; bcf1_t *b, *blast; int c; @@ -372,6 +373,7 @@ int bcfview(int argc, char *argv[]) b->n_gi = 0; b->fmt[0] = '\0'; } + bcf_fix_gt(b); vcf_write(bout, h, b); } if (vc.prior_file) free(vc.prior_file);