Skip to content

Commit

Permalink
Use symbols for visualizations, too
Browse files Browse the repository at this point in the history
  • Loading branch information
danvk committed May 6, 2015
1 parent 7dd8d2e commit 077e7a8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 24 deletions.
8 changes: 4 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ var pileup = require('./pileup');

var sources = [
{
viz: 'genome',
viz: pileup.viz.genome(),
isReference: true,
data: pileup.formats.twoBit({
url: '/hg19.2bit'
})
},
{
viz: 'variants',
viz: pileup.viz.variants(),
data: pileup.formats.vcf({
url: '/test/data/snv.chr17.vcf'
})
},
{
viz: 'genes',
viz: pileup.viz.genes(),
data: pileup.formats.bigBed({
url: '/ensGene.bb'
})
},
{
viz: 'pileup',
viz: pileup.viz.pileup(),
data: pileup.formats.bam({
url: '/test/data/synth3.normal.17.7500000-7515000.bam',
indexUrl: '/test/data/synth3.normal.17.7500000-7515000.bam.bai'
Expand Down
22 changes: 7 additions & 15 deletions src/pileup.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,14 @@ function findReference(tracks: VisualizedTrack[]): ?VisualizedTrack {
return _.findWhere(tracks, t => t.track.isReference);
}

function makeVisualization(track: Track): React.Component {
// TODO: switch to some kind of registration system?
switch (track.viz) {
case 'genome':
return GenomeTrack;
case 'genes':
return GeneTrack;
case 'variants':
return VariantTrack;
case 'pileup':
return PileupTrack;
}
}

function create(elOrId: string|Element, params: PileupParams): Pileup {
var el = typeof(elOrId) == 'string' ? document.getElementById(elOrId) : elOrId;
if (!el) {
throw new Error(`Attempted to create pileup with non-existent element ${elOrId}`);
}

var vizTracks = params.tracks.map(track => ({
visualization: makeVisualization(track),
visualization: track.viz,
source: track.data,
track
}));
Expand All @@ -79,5 +65,11 @@ module.exports = {
vcf: VcfDataSource.create,
twoBit: TwoBitDataSource.create,
bigBed: BigBedDataSource.create
},
viz: {
genome: () => GenomeTrack,
genes: () => GeneTrack,
variants: () => VariantTrack,
pileup: () => PileupTrack
}
};
2 changes: 1 addition & 1 deletion src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import type * as React from 'react';

export type Track = {
viz: string; // in the future: string|Object
viz: Object; // for now, a React class
data: Object; // This is a DataSource object
cssClass?: string;
}
Expand Down
8 changes: 4 additions & 4 deletions test/components-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,28 @@ function waitFor(predFn, timeoutMs) {
describe('pileup', function() {
var tracks = [
{
viz: 'genome',
viz: pileup.viz.genome(),
isReference: true,
data: pileup.formats.twoBit({
url: '/test/data/test.2bit'
})
},
{
viz: 'variants',
viz: pileup.viz.variants(),
data: pileup.formats.vcf({
url: '/test/data/snv.chr17.vcf'
})
},
{
viz: 'genes',
viz: pileup.viz.genes(),
data: pileup.formats.bigBed({
// This file contains just TP53, shifted so that it starts at the
// beginning of chr17 (to match test.2bit). See test/data/README.md.
url: '/test/data/tp53.shifted.bb'
})
},
{
viz: 'pileup',
viz: pileup.viz.pileup(),
data: pileup.formats.bam({
url: '/test/data/index_test.bam',
indexUrl: '/test/data/index_test.bam.bai'
Expand Down

0 comments on commit 077e7a8

Please sign in to comment.