Skip to content

Commit

Permalink
BigBedDataSource-test
Browse files Browse the repository at this point in the history
  • Loading branch information
danvk committed Mar 18, 2015
1 parent 0346319 commit 9f7d45e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/BigBedDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ type BigBedSource = {
function parseBedFeature(f): Gene {
var position = new ContigInterval(f.contig, f.start, f.stop),
x = f.rest.split('\t'),
exonLengths = x[7].split(',').map(Number),
exonStarts = x[8].split(',').map(Number),
// exons arrays sometimes have trailing commas
exonLengths = x[7].replace(/,*$/, '').split(',').map(Number),
exonStarts = x[8].replace(/,*$/, '').split(',').map(Number),
exons = _.zip(exonStarts, exonLengths)
.map(function([start, length]) {
return new Interval(f.start + start, f.start + start + length);
Expand All @@ -76,7 +77,6 @@ function parseBedFeature(f): Gene {
function createBigBedDataSource(remoteSource: BigBed): BigBedSource {
// Collection of genes that have already been loaded.
var genes: Array<Gene> = [];
window.genes = genes;

// Ranges for which we have complete information -- no need to hit network.
var coveredRanges: Array<ContigInterval<string>> = []
Expand Down
48 changes: 48 additions & 0 deletions test/BigBedDataSource-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* @flow */
var chai = require('chai');
var expect = chai.expect;
var assert = chai.assert;

var BigBed = require('../src/BigBed'),
createBigBedDataSource = require('../src/BigBedDataSource'),
ContigInterval = require('../src/ContigInterval');

describe('BigBedDataSource', function() {
function getTestSource() {
// This file was created from Biodalliance's ensGene.bb via:
// bigBedToBed ensGene.bb ensGene.bed
// grep '^chr17 ' ensGene.bed > /tmp/ensGene17.bed
// bedToBigBed -type=bed12+2 /tmp/ensGene17.bed <(echo "chr17 78774742")
// test/data/ensembl.chr17.bb
return createBigBedDataSource(new BigBed('/test/data/ensembl.chr17.bb'));
}

// Shorthand
function ci(contig, start, stop) {
return new ContigInterval(contig, start, stop);
}

it('should extract features in a range', function(done) {
this.timeout(5000);
console.time('extract');
var source = getTestSource();

// No genes fetched initially
var tp53range = new ContigInterval('chr17', 7512444, 7517300)
var tp53 = source.getGenesInRange(tp53range);
expect(tp53).to.deep.equal([]);

// Fetching that one gene should cache its entire block.
source.on('newdata', () => {
console.timeEnd('extract');
var tp53s = source.getGenesInRange(tp53range);
expect(tp53s).to.have.length(1);

var tp53 = tp53s[0];
expect(tp53.name).to.equal('TP53');
expect(tp53.exons).to.have.length(11);
done();
});
source.rangeChanged(tp53range);
});
});
Binary file added test/data/ensembl.chr17.bb
Binary file not shown.

0 comments on commit 9f7d45e

Please sign in to comment.