Skip to content

Commit

Permalink
Merge b7d0d24 into 70e49fb
Browse files Browse the repository at this point in the history
  • Loading branch information
danvk committed Mar 20, 2015
2 parents 70e49fb + b7d0d24 commit d5c170a
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 24 deletions.
1 change: 1 addition & 0 deletions lib/mocha.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
declare function describe(description: string, spec: () => void): void;
declare function it(expectation: string, assertion: (done: () => void) => void): void;
declare function afterEach(fn: () => void): void;
9 changes: 3 additions & 6 deletions src/Root.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ var React = require('react'),
var Root = React.createClass({
propTypes: {
referenceSource: React.PropTypes.object.isRequired,
geneSource: React.PropTypes.object.isRequired
geneSource: React.PropTypes.object.isRequired,
initialRange: React.PropTypes.object.isRequired
},
getInitialState: function() {
return {
Expand All @@ -34,11 +35,7 @@ var Root = React.createClass({

source.on('contigs', () => {
// this is here to facilitate faster iteration
this.handleRangeChange({
contig: 'chr17',
start: 7512444,
stop: 7512484
});
this.handleRangeChange(this.props.initialRange);
});

var geneSource = this.props.geneSource;
Expand Down
3 changes: 2 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ var ensembl = new BigBed('/ensGene.bb');
var ensemblDataSource = createBigBedDataSource(ensembl);

React.render(<Root referenceSource={dataSource}
geneSource={ensemblDataSource} />,
geneSource={ensemblDataSource}
initialRange={{contig: "chr17", start: 7512444, stop: 7512484}} />,
document.getElementById('root'));

window.ensembl = ensembl;
Expand Down
5 changes: 1 addition & 4 deletions test/BigBed-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ var ContigInterval = require('../src/ContigInterval');

describe('BigBed', function() {
function getTestBigBed() {
// This file was generated using UCSC tools:
// cd kent/src/utils/bedToBigBed/tests; make
// It is compressed, little endian, has autoSQL and two blocks.
return new BigBed('/test/data/itemRgb.bb');
return new BigBed('/test/data/itemRgb.bb'); // See test/data/README.md
}

it('should extract features in a range', function(done) {
Expand Down
6 changes: 1 addition & 5 deletions test/BigBedDataSource-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ var BigBed = require('../src/BigBed'),

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
// See test/data/README.md
return createBigBedDataSource(new BigBed('/test/data/ensembl.chr17.bb'));
}

Expand Down
6 changes: 1 addition & 5 deletions test/TwoBit-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ 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');
return new TwoBit('/test/data/test.2bit'); // See test/data/README.md
}

it('should have the right contigs', function(done) {
Expand Down
89 changes: 89 additions & 0 deletions test/components-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* @flow */
'use strict';

var chai = require('chai');
var expect = chai.expect;

var Q = require('q');

var React = require('react/addons'),
TwoBit = require('../src/TwoBit'),
BigBed = require('../src/BigBed'),
Root = require('../src/Root'),
createTwoBitDataSource = require('../src/TwoBitDataSource'),
createBigBedDataSource = require('../src/BigBedDataSource');


var WAIT_FOR_POLL_INTERVAL_MS = 100;
function waitFor(predFn, timeoutMs) {
var def = Q.defer();

var checkTimeoutId = null;

var timeoutId = window.setTimeout(() => {
if (checkTimeoutId) window.clearTimeout(checkTimeoutId);
def.reject('Timed out');
}, timeoutMs);

var check = function() {
if (def.promise.isRejected()) return;
if (predFn()) {
def.resolve(null); // no arguments needed
window.clearTimeout(timeoutId);
} else {
checkTimeoutId = window.setTimeout(check, WAIT_FOR_POLL_INTERVAL_MS);
}
};
checkTimeoutId = window.setTimeout(check, 0);

return def.promise;
}


describe('Root component', function() {
var genome = new TwoBit('/test/data/test.2bit');
var dataSource = createTwoBitDataSource(genome);

// This file contains just the TP53 gene, shifted so that it starts at the
// beginning of chr17 (to match test.2bit). See test/data/README.md.
var ensembl = new BigBed('/test/data/tp53.shifted.bb');
var ensemblDataSource = createBigBedDataSource(ensembl);

var testDiv = document.getElementById('testdiv');

afterEach(function() {
testDiv.innerHTML = ''; // avoid pollution between tests.
});

it('should render reference genome and genes', function(done) {
this.timeout(5000);

var div = document.createElement('div');
div.setAttribute('style', 'width: 800px; height: 200px;');
testDiv.appendChild(div);

// TODO: changing to {start:1, stop:50} makes the test fail.
React.render(<Root referenceSource={dataSource}
geneSource={ensemblDataSource}
initialRange={{contig:"chr17", start: 100, stop: 150}} />, div);

var ready = (() =>
div.querySelectorAll('.basepair').length > 0 &&
div.querySelectorAll('.gene').length > 0
);

waitFor(ready, 5000)
.then(() => {
var basepairs = div.querySelectorAll('.basepair');
expect(basepairs).to.have.length.at.least(10);
var geneNames = div.querySelectorAll('.gene text');
expect(geneNames.length).to.equal(1);
expect(geneNames[0].textContent).to.equal('TP53');

// Note: there are 11 exons, but two are split into coding/non-coding
expect(div.querySelectorAll('.gene .exon').length).to.equal(13);
done();
})
.done();
});
});
4 changes: 1 addition & 3 deletions test/coverage.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
</head>
<body>
<div id="testdiv"></div>
<div id="mocha"></div>

<!-- Polyfills for PhantomJS -->
Expand All @@ -15,9 +16,6 @@
<!-- Mocha -->
<script src="../node_modules/mocha/mocha.js"></script>
<script>mocha.setup('bdd')</script>

<!--<script src="../build/cov/tests-debug.js"></script>-->
<!--<script src="../build/tests-debug.js"></script>-->
<script src="../build/cov/tests.js"></script>

<script>
Expand Down
49 changes: 49 additions & 0 deletions test/data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
This directory contains many small data files used in testing.

This file documents how they were generated.


#### test.2bit

This is a small subset of the hg19 reference genome. It contains small swaths
of chr1 and chr22 and a larger swath of chr17. It was generated from hg19.2bit
using UCSC tools:

curl -O http://www.biodalliance.org/datasets/hg19.2bit
twoBitToFa -seqList=./test/data/seqList.txt hg19.2bit /tmp/extract.fa
perl -i -pe 's/:.*//' /tmp/extract.fa
faToTwoBit /tmp/extract.fa test/data/test.2bit


#### itemRgb.bb, itemRgb.bed

This file was generated from UCSC test data:

cd kent/src/utils/bedToBigBed/tests
make
cp output/itemRgb.bb $PILEUP/test/data/

It is compressed, little endian, has autoSQL and two blocks.

`itemRgb.bed` is copied unmodified from `bedToBigBed/tests/input`.


#### ensembl.chr17.bb

This file is derived from `ensGene.bb`. It contains just the genes on chr17.

curl -O http://www.biodalliance.org/datasets/ensGene.bb
bigBedToBed ensGene.bb ensGene.bed
grep '^chr17\t' ensGene.bed > /tmp/ensGene17.bed
bedToBigBed -type=bed12+2 /tmp/ensGene17.bed <(echo "chr17 78774742") test/data/ensembl.chr17.bb

#### tp53.shifted.bb

This is a subset of `ensembl.chr17.bb`, shifted to match the coordinates in
`test.2bit`:

curl -O http://www.biodalliance.org/datasets/ensGene.bb
bigBedToBed ensGene.bb ensGene.bed
grep '^chr17\t' ensGene.bed | grep TP53 | perl -pe 's/(75\d{4,})/$1-7512444/ge' > /tmp/tp53.shifted.bed
bedToBigBed -type=bed12+2 /tmp/tp53.shifted.bed <(echo "chr17 78774742") test/data/tp53.shifted.bb

File renamed without changes.
Binary file added test/data/tp53.shifted.bb
Binary file not shown.
1 change: 1 addition & 0 deletions test/runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
</head>
<body>
<div id="testdiv"></div>
<div id="mocha"></div>

<!-- Polyfills for PhantomJS -->
Expand Down

0 comments on commit d5c170a

Please sign in to comment.