Skip to content
2 changes: 1 addition & 1 deletion css/dalliance-scoped.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
display: -webkit-inline-flex;
flex-direction: column;
-webkit-flex-direction: column;
max-height: 500px;
max-height: 1000px;
width: 100%;
outline: none;
}
Expand Down
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
browser: require('./js/cbrowser').Browser,
chainset: require('./js/chainset').Chainset,
sourcesAreEqual: require('./js/sourcecompare').sourcesAreEqual,
makeElement: require('./js/utils').makeElement
};
119 changes: 119 additions & 0 deletions js/bedwig.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ if (typeof(require) !== 'undefined') {

var utils = require('./utils');
var shallowCopy = utils.shallowCopy;

var revalidator = require('revalidator');
}


Expand Down Expand Up @@ -162,6 +164,87 @@ BedParseSession.prototype.parse = function(line) {

BedParseSession.prototype.flush = function() {};

BedParseSession.prototype.schema = {
properties: {
segment: {
description: 'the name of the region containing the feature',
type: 'string',
required: true
},
min: {
description: 'the start position of the feature (0-based)',
type: 'integer',
minimum: 1,
required: true
},
max: {
description: 'the end position of the feature (1-based)',
type: 'integer',
required: true
},
label: {
description: 'the label for a feature',
type: 'string'
},
score: {
description: 'score of a feature',
type: 'float'
},
orientation: {
description: 'strand of feature',
type: 'string',
enum: ['+','-','.']
},
itemRGB: {
description: 'rgb color to draw feature',
type: 'string',
pattern: '^rgb\([0-9]+,[0-9]+,[0-9]+)$'
},
type: {
description: 'type of feature',
type: 'string',
enum: ['transcript','translation']
},
readingFrame: {
description: 'open reading frame at the start of the interval',
type: 'integer',
minimum: 0,
maximum: 2
},
groups: {
description: 'list of groups that a feature belongs to',
type: 'array',
items: {
type: 'object',
properties: {
id: {
type: 'string',
required: true
},
label: {
type: 'string',
required: true
},
type: {
type: 'string',
required: true
}
}
}
}
}
};

BedParseSession.prototype.validate = function(f) {
// use revalidator.validate to check if feature f is valid
var check = revalidator.validate(f, this.schema);
if (check.valid) {
this.sink(f);
} else {
console.log(check.errors);
}
}

function WigParseSession(parser, sink) {
this.parser = parser;
this.sink = sink;
Expand Down Expand Up @@ -234,6 +317,42 @@ WigParseSession.prototype.parse = function(line) {

WigParseSession.prototype.flush = function() {};

WigParseSession.prototype.schema = {
properties: {
segment: {
description: 'the name of the region containing the feature',
type: 'string',
required: true
},
min: {
description: 'the start position of the feature',
type: 'integer',
minimum: 1,
required: true
},
max: {
description: 'the end position of the feature',
type: 'integer',
required: true
},
score: {
description: 'score of a feature',
type: 'float',
required: true
}
}
};

WigParseSession.prototype.validate = function(f) {
// use revalidator.validate to check if feature f is valid
var check = revalidator.validate(f, this.schema);
if (check.valid) {
this.sink(f);
} else {
console.log(check.errors);
}
}

BedWigParser.prototype.getStyleSheet = function(callback) {
var thisB = this;
var stylesheet = new DASStylesheet();
Expand Down
42 changes: 34 additions & 8 deletions js/cbrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,39 @@ function Browser(opts) {
if (opts.baseColors) {
this.baseColors = opts.baseColors
} else {
this.baseColors = {
A: 'green',
C: 'blue',
G: 'orange',
T: 'red',
'-' : 'hotpink', // deletion
'I' : 'red' // insertion
};
if (opts.aminoAcids) {
this.baseColors = {
F: 'rgb(182, 201, 237)',
L: 'rgb(213, 236, 213)',
I: 'rgb(239, 213, 211)',
M: 'rgb(255, 23, 0)',
V: 'rgb(255, 172, 0)',
S: 'rgb(255, 244, 19)',
P: 'rgb(138, 189, 67)',
T: 'rgb(36, 153, 57)',
A: 'rgb(0, 166, 236)',
Y: 'rgb(0, 101, 178)',
H: 'rgb(215, 206, 182)',
Q: 'rgb(252, 176, 124)',
N: 'rgb(159, 148, 186)',
K: 'rgb(133, 117, 67)',
D: 'rgb(108, 242, 51)',
E: 'rgb(0, 253, 255)',
C: 'rgb(248, 129, 51)',
W: 'rgb(243, 68, 252)',
R: 'rgb(207, 207, 207)',
G: 'rgb(166, 213, 227)'
};
} else {
this.baseColors = {
A: 'green',
C: 'blue',
G: 'orange',
T: 'red',
'-' : 'hotpink', // deletion
'I' : 'red' // insertion
};
}
}

if (opts.viewStart !== undefined && typeof(opts.viewStart) !== 'number') {
Expand Down Expand Up @@ -2653,6 +2678,7 @@ if (typeof(module) !== 'undefined') {
var sa = require('./sourceadapters');
var TwoBitSequenceSource = sa.TwoBitSequenceSource;
var EnsemblSequenceSource = sa.EnsemblSequenceSource;
var EnsemblProteinSequenceSource = sa.EnsemblProteinSequenceSource;
var DASSequenceSource = sa.DASSequenceSource;

var KnownSpace = require('./kspace').KnownSpace;
Expand Down
26 changes: 18 additions & 8 deletions js/memstore.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ function MemStoreFeatureSource(source) {
this.source = source;
FeatureSourceBase.call(this);
this.storeHolder = new Awaited();

this.parser = dalliance_makeParser(source.payload);
if (!this.parser) {
throw "Unsupported memstore payload: " + source.payload;
Expand All @@ -164,17 +165,24 @@ function MemStoreFeatureSource(source) {
} else {
var store = new MemStore();
var features = [];
var lines = resp.split('\n');

var session = thisB.parser.createSession(function(f) {features.push(f)});
for (var li = 0; li < lines.length; ++li) {
var line = lines[li];
if (line.length > 0) {
session.parse(line);
}

if (err === 'already parsed') {
resp.forEach(function(feat) {
session.validate(feat);
});
}
session.flush();
else {
var lines = resp.split('\n');

for (var li = 0; li < lines.length; ++li) {
var line = lines[li];
if (line.length > 0) {
session.parse(line);
}
}
session.flush();
}
store.addFeatures(features);

thisB.storeHolder.provide(store);
Expand All @@ -191,6 +199,8 @@ MemStoreFeatureSource.prototype._load = function(callback) {
return callback(r.result, r.error);
}
r.readAsText(this.source.blob);
} else if (this.source.features) {
return callback(this.source.features, 'already parsed');
} else {
if (this.source.credentials)
var opts = {credentials : this.source.credentials};
Expand Down
62 changes: 57 additions & 5 deletions js/sourceadapters.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* -*- mode: javascript; c-basic-offset: 4; indent-tabs-mode: nil -*- */
//* -*- mode: javascript; c-basic-offset: 4; indent-tabs-mode: nil -*- */

//
// Dalliance Genome Explorer
Expand Down Expand Up @@ -108,7 +108,11 @@ Browser.prototype.createSources = function(config) {
if (config.twoBitURI || config.twoBitBlob) {
ss = new TwoBitSequenceSource(config);
} else if (config.ensemblURI) {
ss = new EnsemblSequenceSource(config);
if (config.aminoAcids) {
ss = new EnsemblProteinSequenceSource(config);
} else {
ss = new EnsemblSequenceSource(config);
}
} else {
ss = new DASSequenceSource(config);
}
Expand Down Expand Up @@ -590,9 +594,7 @@ TwoBitSequenceSource.prototype.getSeqInfo = function(chr, cnt) {
};

function EnsemblSequenceSource(source) {
this.source = source;
// http://data.gramene.org/ensembl/info/assembly/triticum_aestivum/2B?content-type=application/json
// http://data.gramene.org/ensembl/sequence/region/triticum_aestivum/2B:8001..18000:1?content-type=application/json
this.source = source;
}

EnsemblSequenceSource.prototype.fetch = function(chr, min, max, pool, callback) {
Expand Down Expand Up @@ -642,6 +644,55 @@ EnsemblSequenceSource.prototype.getSeqInfo = function(chr, cnt) {
req.send();
};

function EnsemblProteinSequenceSource(source) {
this.source = source;
}

EnsemblProteinSequenceSource.prototype.fetch = function(chr, min, max, pool, callback) {
var url = this.source.ensemblURI + '/sequence/id/' + chr + '?type=protein&content-type=application/json';
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status >= 300) {
var err = 'Error code ' + req.status;
try {
var jr = JSON.parse(req.response);
if (jr.error) {
err = jr.error;
}
} catch (ex) {};

callback(err, null);
} else {
var jr = JSON.parse(req.response);
var sequence = new DASSequence(chr, 1, jr.seq.length + 1, 'PEP', jr.seq);
return callback(null, sequence);
}
}
}
req.open('GET', url, true);
req.responseType = 'text';
req.send('');
}

EnsemblProteinSequenceSource.prototype.getSeqInfo = function(chr, cnt) {
var url = this.source.ensemblURI + '/sequence/id/' + chr + '?type=protein&content-type=application/json';
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status >= 300) {
cnt();
} else {
var jr = JSON.parse(req.response);
cnt({length:jr.seq.length});
}
}
}
req.open('GET', url, true);
req.responseType = 'text';
req.send('');
}

DASFeatureSource.prototype.getScales = function() {
return [];
};
Expand Down Expand Up @@ -1753,6 +1804,7 @@ if (typeof(module) !== 'undefined') {

TwoBitSequenceSource: TwoBitSequenceSource,
EnsemblSequenceSource: EnsemblSequenceSource,
EnsemblProteinSequenceSource: EnsemblProteinSequenceSource,
DASSequenceSource: DASSequenceSource,
MappedFeatureSource: MappedFeatureSource,
CachingFeatureSource: CachingFeatureSource,
Expand Down
Loading