diff --git a/src/bigBedReader.c b/src/bigBedReader.c index 7446ba1..7510a1c 100644 --- a/src/bigBedReader.c +++ b/src/bigBedReader.c @@ -43,7 +43,8 @@ static int readIteratorEntries(bwOverlapIterator_t *iter, char * chrom, int stre } static int readBigBedRegion(BigBedReaderData * data, char * chrom, int start, int stop) { - bwOverlapIterator_t *iter = bbOverlappingEntriesIterator(data->fp, chrom, start, stop, 0, MAX_BLOCKS); + // BigBed format 1 indexed, hence the -1s + bwOverlapIterator_t *iter = bbOverlappingEntriesIterator(data->fp, chrom, start - 1, stop - 1, 0, MAX_BLOCKS); if (!iter) return 0; @@ -74,7 +75,7 @@ void * readBigBed(void * ptr) { qsort(chrom_lengths, data->fp->cl->nKeys, sizeof(Chrom_length), compare_chrom_lengths); for (chrom_index = 0; chrom_index < data->fp->cl->nKeys; chrom_index++) - if (readBigBedRegion(data, chrom_lengths[chrom_index].chrom, 0, chrom_lengths[chrom_index].length)) + if (readBigBedRegion(data, chrom_lengths[chrom_index].chrom, 1, chrom_lengths[chrom_index].length)) break; free(chrom_lengths); diff --git a/src/bigWiggleReader.c b/src/bigWiggleReader.c index 6b4f336..11b430f 100644 --- a/src/bigWiggleReader.c +++ b/src/bigWiggleReader.c @@ -50,7 +50,7 @@ static int readIteratorIntervals(bwOverlapIterator_t *iter, char * chrom, int st } static int readBigWiggleRegion(BigWiggleReaderData * data, char * chrom, int start, int stop) { - bwOverlapIterator_t *iter = bwOverlappingIntervalsIterator(data->fp, chrom, start, stop, MAX_BLOCKS); + bwOverlapIterator_t *iter = bwOverlappingIntervalsIterator(data->fp, chrom, start - 1, stop - 1, MAX_BLOCKS); if (!iter) return 0; @@ -69,7 +69,7 @@ static int readBigWiggleChromosome(BigWiggleReaderData * data, char * chrom, int int start; int stretch=10000; - for (start = 0; start < length; start+=stretch) { + for (start = 1; start < length; start+=stretch) { if (readBigWiggleRegion(data, chrom, start, start+stretch)) return 1; } diff --git a/test/test.py b/test/test.py index 6d327ff..dc7c24f 100644 --- a/test/test.py +++ b/test/test.py @@ -51,6 +51,21 @@ def testOutput(cmd): # Testing VCF and BCF assert test('../bin/wiggletools do isZero diff vcf.vcf bcf.bcf') == 0 +# Testing BAM & BedGraph +assert test('../bin/wiggletools do isZero seek GL000200.1 1 1000 diff bam.bam pileup.bg') == 0 + +# Testing BAM & CRAM +assert test('../bin/wiggletools do isZero seek GL000200.1 1 1000 diff bam.bam cram.cram') == 0 + +# Testing Bed and BigBed +assert test('../bin/wiggletools do isZero seek chr1 2 6 diff overlapping.bed overlapping.bb') == 0 + +# Testing Wig and BigWig +assert test('../bin/wiggletools do isZero seek chr1 2 6 diff variableStep.bw variableStep.wig') == 0 + +# Testing VCF and BCF +assert test('../bin/wiggletools do isZero seek chr1 2 6 diff vcf.vcf bcf.bcf') == 0 + # Testing sum, scale and multiplexers assert test('../bin/wiggletools do isZero diff sum fixedStep.bw fixedStep.bw : scale 2 fixedStep.bw') == 0