Skip to content

Commit

Permalink
add warning when users open bam or bigwig files with no data for the …
Browse files Browse the repository at this point in the history
…current reference sequence, closes #178
  • Loading branch information
rbuels committed Feb 28, 2013
1 parent f12b3ee commit 461444d
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 15 deletions.
4 changes: 4 additions & 0 deletions release-notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
main browser window, and a description to be shown in a pop-up
dialog when the title is clicked (issue #206).

* Where possible (i.e. supported by the data store), JBrowse will now
pop up a warning if a local data file is opened that contains no
data for the current reference sequence (issue #178).

1.8.1 2013-02-12 12:56:24 EST5EDT

* Added support for `cigarAttribute` and `mdAttributes` configuration
Expand Down
30 changes: 28 additions & 2 deletions src/JBrowse/GenomeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ define([
'JBrowse/View/Track/GridLines',
'JBrowse/BehaviorManager',
'JBrowse/View/Animation/Zoomer',
'JBrowse/View/Animation/Slider'
'JBrowse/View/Animation/Slider',
'JBrowse/View/InfoDialog'
], function(
declare,
array,
Expand All @@ -21,7 +22,8 @@ define([
GridLinesTrack,
BehaviorManager,
Zoomer,
Slider
Slider,
InfoDialog
) {

var dojof = Util.dojof;
Expand Down Expand Up @@ -1983,6 +1985,7 @@ GenomeView.prototype._getTracks = function( /**Array[String]*/ trackNames ) {
* rendering of this track
*/
GenomeView.prototype.renderTrack = function( /**Object*/ trackConfig ) {
var thisB = this;

if( !trackConfig )
return null;
Expand Down Expand Up @@ -2025,6 +2028,29 @@ GenomeView.prototype.renderTrack = function( /**Object*/ trackConfig ) {
if( typeof store.setTrack == 'function' )
store.setTrack( track );

// if we can, check that the current reference sequence is
// contained in the store
if( store.getRefSeqs ) {
var foundRef, curRefName = this.ref.name;
store.getRefSeqs(
function( ref ) {
foundRef = foundRef || ref.name == curRefName;
},
function() {
if( ! foundRef )
new InfoDialog({
title: 'Reference warning',
content: 'WARNING: The data for track "'
+(trackConfig.key||trackConfig.label)
+'" contains no data for the current'
+' reference sequence ('
+thisB.ref.name
+').'
}).show();
}
);
}

trackDiv.track = track;

var heightUpdate = dojo.hitch( this, 'trackHeightUpdate', trackName );
Expand Down
12 changes: 12 additions & 0 deletions src/JBrowse/Store/SeqFeature/BAM.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ var BAMStore = declare( [ SeqFeatureStore, DeferredStatsMixin, DeferredFeaturesM
});
},

/**
* Fetch the list of reference sequences represented in the store.
*/
getRefSeqs: function( seqCallback, finishCallback, errorCallback ) {
var thisB = this;
this._deferred.stats.then( function() {
array.forEach( thisB.bam.indexToChr || [], function( rec ) {
seqCallback({ name: rec.name, length: rec.length, start: 0, end: rec.length });
});
finishCallback();
}, errorCallback );
},

/**
* Fetch a region of the current reference sequence and use it to
Expand Down
30 changes: 22 additions & 8 deletions src/JBrowse/Store/SeqFeature/BigWig.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ return declare([ SeqFeatureStore, DeferredFeaturesMixin, DeferredStatsMixin ],
*/
_readChromTree: function(callback) {
var thisB = this;
this.chromsToIDs = {};
this.idsToChroms = {};
this.refsByNumber = {};
this.refsByName = {};

var udo = this.unzoomedDataOffset;
while ((udo % 4) != 0) {
Expand Down Expand Up @@ -207,16 +207,18 @@ return declare([ SeqFeatureStore, DeferredFeaturesMixin, DeferredStatsMixin ],
key += String.fromCharCode(charCode);
}
}
var chromId = readInt( ba, offset );
var chromSize = readInt( ba, offset+4 );
var refId = readInt( ba, offset );
var refSize = readInt( ba, offset+4 );
offset += 8;

//dlog(key + ':' + chromId + ',' + chromSize);
thisB.chromsToIDs[key] = chromId;
var refRec = { name: key, id: refId, length: refSize };

//dlog(key + ':' + refId + ',' + refSize);
thisB.refsByName[key] = refRec;
if (key.indexOf('chr') == 0) {
thisB.chromsToIDs[key.substr(3)] = chromId;
thisB.refsByName[key.substr(3)] = refRec;
}
thisB.idsToChroms[chromId] = key;
thisB.refsByNumber[refId] = refRec;
} else {
// parse index node
offset += keySize;
Expand All @@ -233,6 +235,18 @@ return declare([ SeqFeatureStore, DeferredFeaturesMixin, DeferredStatsMixin ],
});
},

getRefSeqs: function( seqCallback, finishCallback, errorCallback ) {
var thisB = this;
this._deferred.features.then(function() {
var refs = thisB.refsByName;
for( var name in refs ) {
if( refs.hasOwnProperty(name) )
seqCallback( refs[name] );
}
finishCallback();
}, errorCallback );
},

_getFeatures: function( query, featureCallback, endCallback, errorCallback ) {

var chrName = query.ref;
Expand Down
2 changes: 1 addition & 1 deletion src/JBrowse/Store/SeqFeature/BigWig/RequestWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ var RequestWorker = declare( null,
}

var f = new Feature();
f.segment = this.window.bwg.idsToChroms[this.chr];
f.segment = (this.window.bwg.refsByNumber[this.chr]||{}).name;
f.min = fmin;
f.max = fmax;
f.type = 'remark';
Expand Down
8 changes: 4 additions & 4 deletions src/JBrowse/Store/SeqFeature/BigWig/Window.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ return declare( null,

readWigData: function(chrName, min, max, callback) {
// console.log( 'reading wig data from '+chrName+':'+min+'..'+max);
var chr = this.bwg.chromsToIDs[chrName];
if (chr === undefined) {
var chr = this.bwg.refsByName[chrName];
if ( ! chr ) {
// Not an error because some .bwgs won't have data for all chromosomes.

// dlog("Couldn't find chr " + chrName);
// dlog('Chroms=' + miniJSONify(this.bwg.chromsToIDs));
// dlog('Chroms=' + miniJSONify(this.bwg.refsByName));
callback([]);
} else {
this.readWigDataById(chr, min, max, callback);
this.readWigDataById( chr.id, min, max, callback);
}
},

Expand Down

0 comments on commit 461444d

Please sign in to comment.