]> git.donarmstrong.com Git - samtools.git/commitdiff
Make sure that the GT genotype field is the first
authorHeng Li <lh3@live.co.uk>
Fri, 10 Dec 2010 15:09:14 +0000 (15:09 +0000)
committerHeng Li <lh3@live.co.uk>
Fri, 10 Dec 2010 15:09:14 +0000 (15:09 +0000)
bamtk.c
bcftools/bcfutils.c
bcftools/call1.c

diff --git a/bamtk.c b/bamtk.c
index 9dbdfdeb5c19d50bb78e10501929ebaa2ffd4aea..da54ffd9d65c5a4afea3d54426cd36830eda3897 100644 (file)
--- 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[]);
index 4d6835da8206ea96542ce66e14124b4a388e70db..3c6ed735fdd352a850a56e91987d4d04ad71254d 100644 (file)
@@ -1,3 +1,4 @@
+#include <string.h>
 #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;
+}
index 012c2b32b7d9c731b1c509559b66f94320ae9cbb..b913c9a4990e1f59bbdde8667d6496f842c02d21 100644 (file)
@@ -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);