/
bam-fetcher.js
46 lines (37 loc) · 1.07 KB
/
bam-fetcher.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import slugid from 'slugid';
import { BamFile } from '@gmod/bam';
import ChromosomeInfo from '../ChromosomeInfo';
import { spawn, Thread, Worker } from 'threads';
class BAMDataFetcher {
constructor(dataConfig) {
this.dataConfig = dataConfig;
this.uid = slugid.nice();
this.worker = spawn(
new Worker('./bam-fetcher-worker.js')
);
this.initPromise = this.worker.then((tileFunctions) => {
console.log('tileFunctions:', tileFunctions);
return tileFunctions.init(
this.uid, dataConfig.url, dataConfig.chromSizesUrl
).then(() => this.worker);
});
console.log('constructor');
}
tilesetInfo(callback) {
console.log('tsi');
this.worker.then((tileFunctions) => {
tileFunctions.tilesetInfo(this.uid).then(
callback
);
});
}
fetchTilesDebounced(receivedTiles, tileIds) {
console.log('ftd', tileIds);
this.worker.then((tileFunctions) => {
tileFunctions.fetchTilesDebounced(
this.uid, tileIds
).then(receivedTiles);
});
}
}
export default BAMDataFetcher;