Skip to content

Commit

Permalink
Merge 441974a into dd04040
Browse files Browse the repository at this point in the history
  • Loading branch information
danvk committed Mar 13, 2015
2 parents dd04040 + 441974a commit 2340cb1
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ typings
build

# Genomics
*.2bit
*.bb
*.bed
/*.2bit
/*.bb
/*.bed
18 changes: 14 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,30 @@ module.exports = function(grunt) {
},
mocha_phantomjs: {
run: {
src: ['test/runner.html']
options: {
urls: ['http://localhost:9501/test/runner.html']
}
},
cov: {
src: ['test/coverage.html'],
options: {
urls: ['http://localhost:9501/test/coverage.html'],
reporter: 'node_modules/mocha-lcov-reporter/lib/lcov.js',
output: 'build/bundled.lcov',
silent: true
}
}
},
connect: {
server: {
options: {
port: 9501
}
}
}
});

grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-flow-type-check');
grunt.loadNpmTasks('grunt-mocha-phantomjs');
Expand All @@ -111,8 +121,8 @@ module.exports = function(grunt) {
grunt.registerTask('watchFlow', ['flow:app:start', 'watch:flow']);
grunt.registerTask('prod', ['browserify:dist', 'uglify:dist']);
grunt.registerTask('browsertests', ['browserify:test']);
grunt.registerTask('test', ['browsertests', 'mocha_phantomjs:run']);
grunt.registerTask('test', ['browsertests', 'connect', 'mocha_phantomjs:run']);
grunt.registerTask('travis', ['flow', 'test']);
grunt.registerTask('coverage',
['browsertests', 'exorcise:bundle', 'jscoverage', 'mocha_phantomjs:cov']);
['browsertests', 'exorcise:bundle', 'jscoverage', 'connect', 'mocha_phantomjs:cov']);
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"flow-bin": "^0.4.0",
"grunt": "^0.4.5",
"grunt-browserify": "^3.3.0",
"grunt-contrib-connect": "^0.9.0",
"grunt-contrib-uglify": "^0.8.0",
"grunt-contrib-watch": "^0.6.1",
"grunt-env": "^0.4.2",
Expand Down
10 changes: 3 additions & 7 deletions src/RemoteFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,11 @@ class RemoteFile {
xhr.setRequestHeader('Range', `bytes=${start}-${stop}`);
var remoteFile = this;
xhr.onload = function(e) {
// The actual length of the response may be less than requested if it's
// too short, e.g. if we request bytes 0-1000 of a 500-byte file.
var buffer = this.response;
var expectLength = stop - start + 1,
actualLength = buffer.byteLength;
if (actualLength != expectLength) {
deferred.reject(`Server returned incorrect number of bytes for ${this.url}. Requested ${start}-${stop} (${expectLength} bytes) but received ${actualLength}.`);
return;
}

var newChunk = { start, stop, buffer };
var newChunk = { start, stop: start + buffer.byteLength - 1, buffer };
remoteFile.chunks.push(newChunk);
deferred.resolve(new DataView(buffer));
};
Expand Down
49 changes: 49 additions & 0 deletions test/TwoBit-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
var chai = require('chai');
var expect = chai.expect;
var assert = chai.assert;

var TwoBit = require('../src/TwoBit');

describe('TwoBit', function() {
function getTestTwoBit() {
// This file was generated using UCSC tools:
// twoBitToFa -seqList=./test/seqList.txt hg19.2bit /tmp/extract.fa
// perl -i -pe 's/:.*//' /tmp/extract.fa
// faToTwoBit /tmp/extract.fa test/data/test.2bit
return new TwoBit('/test/data/test.2bit');
}

it('should have the right contigs', function(done) {
var twoBit = getTestTwoBit();
twoBit.getContigList()
.then(contigs => {
expect(contigs).to.deep.equal(['chr1', 'chr17', 'chr22']);
done();
})
.done();
});

it('should extract unknowns', function(done) {
// This test mirrors dalliance's (chr22:19178140-19178170)
var twoBit = getTestTwoBit();
twoBit.getFeaturesInRange('chr22', 1, 31)
.then(basePairs => {
expect(basePairs).to.equal('NTCACAGATCACCATACCATNTNNNGNNCNA');
done();
})
.done();
});

it('should reject invalid contigs', function(done) {
var twoBit = getTestTwoBit();
twoBit.getFeaturesInRange('chrZ')
.then(() => { assert.fail('Should have thrown'); })
.catch(err => {
expect(err).to.match(/Invalid contig/);
})
.fin(done)
.done();
});

// TODO: masked regions
});
Binary file added test/data/test.2bit
Binary file not shown.
3 changes: 3 additions & 0 deletions test/seqList.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
chr1:19178000-19178170
chr17:7512444-7531642
chr22:19178139-19179170

0 comments on commit 2340cb1

Please sign in to comment.