f2e106b897f58f772d3a25713bb3ede142ae4bd5 braney Mon Jun 13 15:58:12 2016 -0700 add next/prev item navigation to longTabix support diff --git src/lib/bedTabix.c src/lib/bedTabix.c index a5b4dfc..dcd0c10 100644 --- src/lib/bedTabix.c +++ src/lib/bedTabix.c @@ -1,41 +1,55 @@ #include "bedTabix.h" struct bedTabixFile *bedTabixFileMayOpen(char *fileOrUrl, char *chrom, int start, int end) { struct lineFile *lf = lineFileTabixMayOpen(fileOrUrl, TRUE); if (lf == NULL) return NULL; struct bedTabixFile *btf; AllocVar(btf); btf->lf = lf; if (isNotEmpty(chrom) && start != end) { lineFileSetTabixRegion(lf, chrom, start, end); } return btf; } +struct bed *bedTabixReadFirstBed(struct bedTabixFile *btf, char *chrom, int start, int end, struct bed * (*loadBed)(void *tg)) +/* Read in first bed in range (for next item).*/ +{ +int wordCount; +char *words[100]; + +if (!lineFileSetTabixRegion(btf->lf, chrom, start, end)) + return NULL; +if ((wordCount = lineFileChopTab(btf->lf, words)) > 0) + return loadBed(words); +return NULL; +} + struct bed *bedTabixReadBeds(struct bedTabixFile *btf, char *chrom, int start, int end, struct bed * (*loadBed)(void *tg)) +/* Read in all beds in range.*/ { struct bed *bedList = NULL; int wordCount; char *words[100]; if (!lineFileSetTabixRegion(btf->lf, chrom, start, end)) return NULL; while ((wordCount = lineFileChopTab(btf->lf, words)) > 0) { struct bed *bed = loadBed(words); slAddHead(&bedList, bed); } return bedList; } void bedTabixFileClose(struct bedTabixFile **pBtf) { lineFileClose(&((*pBtf)->lf)); *pBtf = NULL; }