Imported Upstream version 0.2.2
[tabix.git] / index.c
diff --git a/index.c b/index.c
index e5b227c1466eea9d8be901020ffc2726dc33cc9e..8eddcecb34bab21f8d4f6de7a88639f8c67d0358 100644 (file)
--- a/index.c
+++ b/index.c
@@ -19,7 +19,7 @@ typedef struct {
 } pair64_t;
 
 #define pair64_lt(a,b) ((a).u < (b).u)
-KSORT_INIT(off, pair64_t, pair64_lt)
+KSORT_INIT(offt, pair64_t, pair64_lt)
 
 typedef struct {
        uint32_t m, n;
@@ -192,17 +192,19 @@ static int get_intv(ti_index_t *idx, kstring_t *str, ti_intv_t *intv)
                                        }
                                } else if ((idx->conf.preset&0xffff) == TI_PRESET_VCF) {
                                        // FIXME: the following is NOT tested and is likely to be buggy
-                                       if (id == 5) { // ALT
-                                               char *t;
-                                               int max = 1;
-                                               for (s = str->s + b; s < str->s + i;) {
-                                                       if (s[i] == 'D') {
-                                                               long x = strtol(s + 1, &t, 10);
-                                                               if (x > max) max = x;
-                                                               s = t + 1;
-                                                       } else ++s;
+                                       if (id == 4) {
+                                               if (b < i) intv->end = intv->beg + (i - b);
+                                       } else if (id == 8) { // look for "END="
+                                               int c = str->s[i];
+                                               str->s[i] = 0;
+                                               s = strstr(str->s + b, "END=");
+                                               if (s == str->s + b) s += 4;
+                                               else if (s) {
+                                                       s = strstr(str->s + b, ";END=");
+                                                       if (s) s += 5;
                                                }
-                                               intv->end = intv->beg + max;
+                                               if (s) intv->end = strtol(s, &s, 0);
+                                               str->s[i] = c;
                                        }
                                }
                        }
@@ -804,7 +806,7 @@ ti_iter_t ti_iter_query(const ti_index_t *idx, int tid, int beg, int end)
        free(bins);
        {
                int l;
-               ks_introsort(off, n_off, off);
+               ks_introsort(offt, n_off, off);
                // resolve completely contained adjacent blocks
                for (i = 1, l = 0; i < n_off; ++i)
                        if (off[l].v < off[i].v)