Skip to content

Commit

Permalink
Show BAI fetch notification w/o index chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
danvk committed Jul 8, 2015
1 parent f3d0da5 commit b0c6936
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
37 changes: 23 additions & 14 deletions src/main/BamDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,31 @@ function createFromBamFile(remoteSource: BamFile): BamDataSource {
}
}

function saveContigMapping(header: Object) {
header.references.forEach(ref => {
var name = ref.name;
contigNames[name] = name;
contigNames['chr' + name] = name;
if (name.slice(0, 3) == 'chr') {
contigNames[name.slice(3)] = name;
}
});
}

function fetch(range: GenomeRange) {
var refsPromise;
if (!_.isEmpty(contigNames)) {
refsPromise = Q.when();
} else {
refsPromise = remoteSource.header.then(header => {
header.references.forEach(ref => {
var name = ref.name;
contigNames[name] = name;
contigNames['chr' + name] = name;
if (name.slice(0, 3) == 'chr') {
contigNames[name.slice(3)] = name;
}
var refsPromise = !_.isEmpty(contigNames) ? Q.when() :
remoteSource.header.then(saveContigMapping);

// For BAMs without index chunks, we need to fetch the entire BAI file
// before we can know how large the BAM header is. If the header is
// pending, it's almost certainly because the BAI file is in flight.
Q.when().then(() => {
if (refsPromise.isPending() && !remoteSource.hasIndexChunks) {
o.trigger('networkprogress', {
status: 'Fetching BAM index -- use index chunks to speed this up'
});
});
}
}
}).done();

return refsPromise.then(() => {
var contigName = contigNames[range.contig];
Expand Down
2 changes: 1 addition & 1 deletion src/main/Root.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var Root = React.createClass({
this.props.tracks.forEach(track => {
track.source.rangeChanged(range);
});
});
}).done();
},
makeDivForTrack(key: string, track: VisualizedTrack): React.Element {
var trackEl = React.createElement(track.visualization, {
Expand Down
2 changes: 2 additions & 0 deletions src/main/bam.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,14 @@ class Bam {
index: ?BaiFile;
header: Q.Promise<Object>;
remoteFile: RemoteFile;
hasIndexChunks: boolean;

constructor(remoteFile: RemoteFile,
remoteIndexFile?: RemoteFile,
indexChunks?: Object) {
this.remoteFile = remoteFile;
this.index = remoteIndexFile ? new BaiFile(remoteIndexFile, indexChunks) : null;
this.hasIndexChunks = !!indexChunks;

var sizePromise = this.index ? this.index.getHeaderSize() : Q.when(2 * 65535);
this.header = sizePromise.then(size => {
Expand Down

0 comments on commit b0c6936

Please sign in to comment.