X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=samtools.git;a=blobdiff_plain;f=bedidx.c;h=ec75a1067f5905c69ead868ff42d2073189bb690;hp=92978318d4ccfbbabeeddd150458245f669062d8;hb=HEAD;hpb=0242bdf14e88f1058887598cbf898c0d0af01a82 diff --git a/bedidx.c b/bedidx.c index 9297831..ec75a10 100644 --- a/bedidx.c +++ b/bedidx.c @@ -4,6 +4,13 @@ #include #include +#ifdef _WIN32 +#define drand48() ((double)rand() / RAND_MAX) +#endif + +#include "ksort.h" +KSORT_INIT_GENERIC(uint64_t) + #include "kseq.h" KSTREAM_INIT(gzFile, gzread, 8192) @@ -53,6 +60,7 @@ void bed_index(void *_h) if (kh_exist(h, k)) { bed_reglist_t *p = &kh_val(h, k); if (p->idx) free(p->idx); + ks_introsort(uint64_t, p->n, p->a); p->idx = bed_index_core(p->n, p->a, &p->m); } } @@ -115,8 +123,10 @@ void *bed_read(const char *fn) if (ks_getuntil(ks, 0, str, &dret) > 0 && isdigit(str->s[0])) { beg = atoi(str->s); // begin if (dret != '\n') { - if (ks_getuntil(ks, 0, str, &dret) > 0 && isdigit(str->s[0])) + if (ks_getuntil(ks, 0, str, &dret) > 0 && isdigit(str->s[0])) { end = atoi(str->s); // end + if (end < beg) end = -1; + } } } }