Skip to content

Commit

Permalink
Merge ad3cd3b into afe2971
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-gawron committed Jun 14, 2016
2 parents afe2971 + ad3cd3b commit 2037148
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main/sources/TwoBitDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,14 @@ var createFromTwoBitFile = function(remoteSource: TwoBit): TwoBitSource {
function fetch(range: ContigInterval) {
var span = range.length();
if (span > MAX_BASE_PAIRS_TO_FETCH) {
//inform that we won't fetch the data
o.trigger('newdatarefused', range);
return Q.when(); // empty promise
}
//now we can add region to covered regions
//doing it earlier would provide inconsistency
coveredRanges.push(range);
coveredRanges = ContigInterval.coalesce(coveredRanges);

remoteSource.getFeaturesInRange(range.contig, range.start(), range.stop())
.then(letters => {
Expand Down Expand Up @@ -138,8 +144,6 @@ var createFromTwoBitFile = function(remoteSource: TwoBit): TwoBitSource {

range = expandRange(range);
var newRanges = range.complementIntervals(coveredRanges);
coveredRanges.push(range);
coveredRanges = ContigInterval.coalesce(coveredRanges);

for (var newRange of newRanges) {
fetch(newRange);
Expand Down
35 changes: 35 additions & 0 deletions src/test/sources/TwoBitDataSource-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,41 @@ describe('TwoBitDataSource', function() {
});
});

/**
* Test case that visualize situation when we set range very big
* (in millions) and afterwards we set the range to small subrange
* of the huge range. The huge range shouldn't be fetched from
* 2bit file. But due to //github.com/hammerlab/pileup.js/issues/416
* every small request from the big range wasn't handled properly
* afterwardfs.
*
*/
it('should fetch base pairs (bug 416)', function(done) {
var source = getTestSource();
//this range shouldn't be fetched because is huge
var hugeRange= {contig: 'chr22', start: 0, stop: 114529884};

//small range that due to bug wasn't properly handled
var smallSubRange = {contig: 'chr22', start: 0, stop: 3};
source.on('newdata', () => {
//should be called only once when short chunk is requested
expect(source.getRange(smallSubRange)).to.deep.equal({
'chr22:0': 'N',
'chr22:1': 'T',
'chr22:2': 'C',
'chr22:3': 'A'
});
expect(source.getRangeAsString(smallSubRange)).to.equal('NTCA');
done();
});

//try to fetch huge chunk of data (should be skipped)
source.rangeChanged(hugeRange);

//and now try to fetch small chunk (should be fetched and proper newdata event should be dispatched)
source.rangeChanged(smallSubRange);
});

it('should fetch base pairs', function(done) {
var source = getTestSource();
var range = {contig: 'chr22', start: 0, stop: 3};
Expand Down
43 changes: 43 additions & 0 deletions src/test/viz/GenomeTrack-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ describe('GenomeTrack', function() {
drawnObjects(testDiv, '.reference').length > 0;
};

var referenceTrackLoaded = () => {
//this can be done in a preatier way
return testDiv.querySelector('canvas') !== null ;
};

it('should tolerate non-chr ranges', function() {
var p = pileup.create(testDiv, {
range: {contig: '17', start: 7500730, stop: 7500790},
Expand Down Expand Up @@ -82,6 +87,44 @@ describe('GenomeTrack', function() {
return ((els: any): HTMLInputElement[]);
};

/**
* Test case show situation when we zoom in from very global view
* (range span is milions of nucleotides) into very narrow view
* (tens of nucleotides).
*/
it('should zoom from huge zoom out', function() {

var p = pileup.create(testDiv, {
range: { contig: '17', start: 0, stop: 114529884 },
tracks: [{
data: referenceSource,
viz: pileup.viz.genome(),
isReference: true
}
]
});

expect(testDiv.querySelectorAll('.zoom-controls')).to.have.length(1);

var buttons = testDiv.querySelectorAll('.controls button');
var [goBtn, minusBtn, plusBtn] = buttons;
var [locationTxt] = getInputs('.controls input[type="text"]');
expect(goBtn.textContent).to.equal('Go');
expect(minusBtn.className).to.equal('btn-zoom-out');
expect(plusBtn.className).to.equal('btn-zoom-in');

return waitFor(referenceTrackLoaded, 2000).then(() => {
//in global view we shouldn't see reference track
expect(hasReference()).to.be.false;
p.setRange({contig: '17', start: 7500725, stop: 7500775});
}).delay(300).then(() => {
//after zoom in we should see reference track
expect(hasReference()).to.be.true;
expect(locationTxt.value).to.equal('7,500,725-7,500,775');
p.destroy();
});
});

it('should zoom in and out', function() {
var p = pileup.create(testDiv, {
range: {contig: '17', start: 7500725, stop: 7500775},
Expand Down

0 comments on commit 2037148

Please sign in to comment.