Skip to content

Commit

Permalink
API v2
Browse files Browse the repository at this point in the history
  • Loading branch information
danvk committed May 5, 2015
1 parent 5ed02fa commit 2018a54
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 27 deletions.
1 change: 0 additions & 1 deletion src/BigBedDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ function create(remoteSource: BigBed): BigBedSource {
}

function createFromTrack(track: Track): BigBedSource {
if (track.type != 'genes') throw 'Miswired track';
var url = track.data.url;
if (!url) {
throw new Error(`Missing URL from track: ${JSON.stringify(track)}`);
Expand Down
1 change: 0 additions & 1 deletion src/TwoBitDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ var create = function(remoteSource: TwoBit): TwoBitSource {
};

function createFromTrack(track: Track): TwoBitSource {
if (track.type != 'reference') throw 'Miswired track';
var url = track.data.url;
if (!url) {
throw new Error(`Missing URL from track: ${JSON.stringify(track)}`);
Expand Down
1 change: 0 additions & 1 deletion src/VcfDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ function create(remoteSource: VcfFile): VcfDataSource {
}

function createFromTrack(track: Track): VcfDataSource {
if (track.type != 'variants') throw 'Miswired track';
var url = track.data.url;
if (!url) {
throw new Error(`Missing URL from track: ${JSON.stringify(track)}`);
Expand Down
10 changes: 6 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,28 @@ var pileup = require('./pileup');

var sources = [
{
type: 'reference',
viz: 'genome',
isReference: true,
data: {
url: '/hg19.2bit'
}
},
{
type: 'variants',
viz: 'variants',
data: {
url: '/test/data/snv.chr17.vcf'
}
},
{
type: 'genes',
viz: 'genes',
data: {
url: '/ensGene.bb'
}
},
{
type: 'pileup',
viz: 'pileup',
data: {
type: 'bam',
url: '/test/data/synth3.normal.17.7500000-7515000.bam',
indexUrl: '/test/data/synth3.normal.17.7500000-7515000.bam.bai'
},
Expand Down
56 changes: 40 additions & 16 deletions src/pileup.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,57 @@ type PileupParams = {
}

function findReference(tracks: VisualizedTrack[]): ?VisualizedTrack {
return _.findWhere(tracks, t => t.track.type == 'reference');
return _.findWhere(tracks, t => t.track.isReference);
}

var typeToSource = {
'2bit': TwoBitDataSource,
'bigbed': BigBedDataSource,
'vcf': VcfDataSource,
'bam': BamDataSource
};

var extToSource = {
'2bit': '2bit',
'2b': '2bit',
'bb': 'bigbed',
'vcf': 'vcf',
'bam': 'bam'
};

function getSource(track: Track): Object {
if (track.data.source) {
return track.data.source;
var data = track.data;
if (data.source) {
return data.source;
}

// TODO: switch to some kind of registration system?
switch (track.type) {
case 'reference':
return TwoBitDataSource.createFromTrack(track);
case 'genes':
return BigBedDataSource.createFromTrack(track);
case 'variants':
return VcfDataSource.createFromTrack(track);
case 'pileup':
return BamDataSource.createFromTrack(track);
var url = data.url;
if (!url) {
throw new Error(`You must specify either 'source' or 'url' in a data source (got ${data})`);
}

// Base the data source on 'type' if specified, otherwise deduce from extension.
if (data.type) {
var source = typeToSource[data.type.toLowerCase()];
if (source) {
return source.createFromTrack(track);
}

throw new Error(`Unknown track type: ${data.type}`);
}

throw new Error(`Unknown track type: ${track.type}`);
var ext = url.slice(url.lastIndexOf('.') + 1);
var type = extToSource[ext.toLowerCase()];
if (!type) {
throw new Error(`Unable to deduce data type frome extension ${ext}: ${url}}`);
}
return typeToSource[type].createFromTrack(track);
}

function makeVisualization(track: Track): React.Component {
// TODO: switch to some kind of registration system?
switch (track.type) {
case 'reference':
switch (track.viz) {
case 'genome':
return GenomeTrack;
case 'genes':
return GeneTrack;
Expand Down
9 changes: 5 additions & 4 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
import type * as React from 'react';

export type Track = {
type: string;
viz: string; // in the future: string|Object
data: {
url?: string,
source?: Object,
indexUrl?: string // e.g. for BamFile
type?: string;
url?: string;
source?: Object;
indexUrl?: string; // e.g. for BamFile
}; // either url: string or source: Object
cssClass?: string;
options?: Object;
Expand Down

0 comments on commit 2018a54

Please sign in to comment.