From 5a3df4b6805b02ea9299549dda3e7d181fabeaf2 Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 16 Feb 2018 02:47:48 -0500 Subject: [PATCH] Parse autosql table --- src/JBrowse/Store/SeqFeature/BigBed.js | 2 +- src/JBrowse/Store/SeqFeature/BigWig.js | 37 +++++++++++++++++++ .../Store/SeqFeature/BigWig/RequestWorker.js | 21 +++++++++-- src/JBrowse/Store/SeqFeature/BigWig/Window.js | 3 +- 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/src/JBrowse/Store/SeqFeature/BigBed.js b/src/JBrowse/Store/SeqFeature/BigBed.js index dcbe0880eb..32ad5d78d8 100644 --- a/src/JBrowse/Store/SeqFeature/BigBed.js +++ b/src/JBrowse/Store/SeqFeature/BigBed.js @@ -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; } diff --git a/src/JBrowse/Store/SeqFeature/BigWig.js b/src/JBrowse/Store/SeqFeature/BigWig.js index 249ea512e2..09f63e4b23 100644 --- a/src/JBrowse/Store/SeqFeature/BigWig.js +++ b/src/JBrowse/Store/SeqFeature/BigWig.js @@ -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); @@ -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() { @@ -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 { diff --git a/src/JBrowse/Store/SeqFeature/BigWig/RequestWorker.js b/src/JBrowse/Store/SeqFeature/BigWig/RequestWorker.js index 1659b1e1a4..1914972b9a 100644 --- a/src/JBrowse/Store/SeqFeature/BigWig/RequestWorker.js +++ b/src/JBrowse/Store/SeqFeature/BigWig/RequestWorker.js @@ -304,6 +304,20 @@ 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; @@ -311,13 +325,14 @@ var RequestWorker = declare( null, 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]; diff --git a/src/JBrowse/Store/SeqFeature/BigWig/Window.js b/src/JBrowse/Store/SeqFeature/BigWig/Window.js index 817f3b730c..28c72ea4bc 100644 --- a/src/JBrowse/Store/SeqFeature/BigWig/Window.js +++ b/src/JBrowse/Store/SeqFeature/BigWig/Window.js @@ -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 ) )