Skip to content

Commit

Permalink
Testing accuracy of seek, and correcting for off by one errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dzerbino committed Jan 7, 2021
1 parent af94ce0 commit 8f7b9a2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/bigBedReader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/bigWiggleReader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand Down
15 changes: 15 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 8f7b9a2

Please sign in to comment.