]> git.donarmstrong.com Git - samtools.git/blobdiff - bcftools/bcfutils.c
* 0.1.16-dev (r969:252)
[samtools.git] / bcftools / bcfutils.c
index 91cc2c23ccb33c66c944fe013df1e92a84867858..fec06ba2131df14d0a2236c012d696ad233647ca 100644 (file)
@@ -5,6 +5,7 @@
 #include "khash.h"
 KHASH_MAP_INIT_STR(str2id, int)
 
+// FIXME: valgrind report a memory leak in this function. Probably it does not get deallocated...
 void *bcf_build_refhash(bcf_hdr_t *h)
 {
        khash_t(str2id) *hash;
@@ -168,6 +169,27 @@ int bcf_fix_pl(bcf1_t *b)
        return 0;
 }
 
+int bcf_smpl_covered(const bcf1_t *b)
+{
+       int i, j, n = 0;
+       uint32_t tmp;
+       bcf_ginfo_t *gi;
+       // pinpoint PL
+       tmp = bcf_str2int("PL", 2);
+       for (i = 0; i < b->n_gi; ++i)
+               if (b->gi[i].fmt == tmp) break;
+       if (i == b->n_gi) return 0;
+       // count how many samples having PL!=[0..0]
+       gi = b->gi + i;
+       for (i = 0; i < b->n_smpl; ++i) {
+               uint8_t *PLi = ((uint8_t*)gi->data) + i * gi->len;
+               for (j = 0; j < gi->len; ++j)
+                       if (PLi[j]) break;
+               if (j < gi->len) ++n;
+       }
+       return n;
+}
+
 static void *locate_field(const bcf1_t *b, const char *fmt, int l)
 {
        int i;