Skip to content

Commit

Permalink
Parse autosql table
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Feb 16, 2018
1 parent 72a0381 commit 5a3df4b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/JBrowse/Store/SeqFeature/BigBed.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ return declare(BigWig,
if (nzl) {
cirLen = this.zoomLevels[0].dataOffset - this.unzoomedIndexOffset;
}
this.unzoomedView = new Window( this, this.unzoomedIndexOffset, cirLen, false );
this.unzoomedView = new Window( this, this.unzoomedIndexOffset, cirLen, false, this.autoSql );
}
return this.unzoomedView;
}
Expand Down
37 changes: 37 additions & 0 deletions src/JBrowse/Store/SeqFeature/BigWig.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ return declare([ SeqFeatureStore, DeferredFeaturesMixin, DeferredStatsMixin ],
this.totalSummaryOffset = data.getUint64();
this.uncompressBufSize = data.getUint32();


// dlog('bigType: ' + this.type);
// dlog('chromTree at: ' + this.chromTreeOffset);
// dlog('uncompress: ' + this.uncompressBufSize);
Expand All @@ -152,6 +153,19 @@ return declare([ SeqFeatureStore, DeferredFeaturesMixin, DeferredStatsMixin ],
this.zoomLevels.push({reductionLevel: zlReduction, dataOffset: zlData, indexOffset: zlIndex});
}

var string = "";
var c = 0;
data.getBytes(72);


while(true) {
c = data.getChar();
if(c.charCodeAt() == 0) break;
string += c;
}
this.parseAutoSql(string);


// parse the totalSummary if present (summary of all data in the file)
if( this.totalSummaryOffset ) {
(function() {
Expand Down Expand Up @@ -340,6 +354,29 @@ return declare([ SeqFeatureStore, DeferredFeaturesMixin, DeferredStatsMixin ],
return this.getUnzoomedView();
},

parseAutoSql: function(string) {
var res = string.split('\n');
this.autoSql = {
name: /table (\w+)/.exec(res[0])[1],
description: /"([\w\s]+)"/.exec(res[1])[1],
fields: []
};
var i = 3;
var field;
while(res[i].trim() != ')') {
if(field = /([\w\[\]0-9]+)\s*(\w+)\s*;\s*"(.*)"/.exec(res[i].trim())) {
this.autoSql.fields.push({
type: field[1],
name: field[2],
description: field[3]
});
} else {
console.warn('autosql line not parsed', res[i]);
}
i++;
}
},


saveStore: function() {
return {
Expand Down
21 changes: 18 additions & 3 deletions src/JBrowse/Store/SeqFeature/BigWig/RequestWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,20 +304,35 @@ var RequestWorker = declare( null,
} else if (chromId == this.chr && start <= this.max && end >= this.min) {
// Complex-BED?
// FIXME this is currently a bit of a hack to do Clever Things with ensGene.bb
var auto = this.window.autoSql;
for(var i = 0; i < auto.fields.length-3; i++) {
featureOpts[auto.fields[i+3].name] = bedColumns[i];
}
delete featureOpts.blockCount;
delete featureOpts.blockSizes;
delete featureOpts.thickStart;
delete featureOpts.thickEnd;
delete featureOpts.reserved;
delete featureOpts.chromStarts;
delete featureOpts.strand;
delete featureOpts.score;
delete featureOpts.name;
delete featureOpts.override_color;

var thickStart = bedColumns[3]|0;
var thickEnd = bedColumns[4]|0;
var blockCount = bedColumns[6]|0;
var blockSizes = bedColumns[7].split(',');
var blockStarts = bedColumns[8].split(',');

var grp = {

var grp = dojo.mixin(featureOpts, {
id: bedColumns[0]+'_'+chromId+'_'+start+'_'+end,
type: 'mRNA',
notes: [],
strand: featureOpts.orientation=="+"?1:-1,
strand: featureOpts.orientation == "+"?1:-1,
subfeatures: []
};
});

if (bedColumns.length > 10) {
var geneId = bedColumns[9];
Expand Down
3 changes: 2 additions & 1 deletion src/JBrowse/Store/SeqFeature/BigWig/Window.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ return declare( null,
* Explorer by Thomas Down.
* @constructs
*/
constructor: function(bwg, cirTreeOffset, cirTreeLength, isSummary) {
constructor: function(bwg, cirTreeOffset, cirTreeLength, isSummary, autoSql) {
this.bwg = bwg;
this.autoSql = autoSql;
if( !( cirTreeOffset >= 0 ) )
throw "invalid cirTreeOffset!";
if( !( cirTreeLength > 0 ) )
Expand Down

0 comments on commit 5a3df4b

Please sign in to comment.