@gmod/bam 1.1.17 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/CHANGELOG.md +65 -25
  2. package/README.md +108 -57
  3. package/dist/bai.d.ts +34 -15
  4. package/dist/bai.js +180 -273
  5. package/dist/bai.js.map +1 -1
  6. package/dist/bamFile.d.ts +33 -27
  7. package/dist/bamFile.js +353 -572
  8. package/dist/bamFile.js.map +1 -1
  9. package/dist/chunk.d.ts +4 -8
  10. package/dist/chunk.js +13 -21
  11. package/dist/chunk.js.map +1 -1
  12. package/dist/csi.d.ts +74 -10
  13. package/dist/csi.js +157 -256
  14. package/dist/csi.js.map +1 -1
  15. package/dist/errors.js +12 -57
  16. package/dist/errors.js.map +1 -1
  17. package/dist/htsget.d.ts +5 -8
  18. package/dist/htsget.js +120 -209
  19. package/dist/htsget.js.map +1 -1
  20. package/dist/index.d.ts +5 -6
  21. package/dist/index.js +11 -11
  22. package/dist/index.js.map +1 -1
  23. package/dist/indexFile.d.ts +0 -6
  24. package/dist/indexFile.js +3 -77
  25. package/dist/indexFile.js.map +1 -1
  26. package/dist/nullIndex.d.ts +7 -0
  27. package/dist/nullIndex.js +33 -0
  28. package/dist/nullIndex.js.map +1 -0
  29. package/dist/record.d.ts +2 -2
  30. package/dist/record.js +200 -193
  31. package/dist/record.js.map +1 -1
  32. package/dist/sam.js +12 -10
  33. package/dist/sam.js.map +1 -1
  34. package/dist/util.d.ts +13 -1
  35. package/dist/util.js +55 -58
  36. package/dist/util.js.map +1 -1
  37. package/dist/virtualOffset.js +13 -20
  38. package/dist/virtualOffset.js.map +1 -1
  39. package/esm/bai.d.ts +34 -15
  40. package/esm/bai.js +86 -91
  41. package/esm/bai.js.map +1 -1
  42. package/esm/bamFile.d.ts +33 -27
  43. package/esm/bamFile.js +124 -120
  44. package/esm/bamFile.js.map +1 -1
  45. package/esm/chunk.d.ts +4 -8
  46. package/esm/chunk.js +2 -8
  47. package/esm/chunk.js.map +1 -1
  48. package/esm/csi.d.ts +74 -10
  49. package/esm/csi.js +85 -93
  50. package/esm/csi.js.map +1 -1
  51. package/esm/htsget.d.ts +5 -8
  52. package/esm/htsget.js +68 -43
  53. package/esm/htsget.js.map +1 -1
  54. package/esm/index.d.ts +5 -6
  55. package/esm/index.js +5 -6
  56. package/esm/index.js.map +1 -1
  57. package/esm/indexFile.d.ts +0 -6
  58. package/esm/indexFile.js +0 -22
  59. package/esm/indexFile.js.map +1 -1
  60. package/esm/nullIndex.d.ts +7 -0
  61. package/esm/nullIndex.js +16 -0
  62. package/esm/nullIndex.js.map +1 -0
  63. package/esm/record.d.ts +2 -2
  64. package/esm/record.js +34 -24
  65. package/esm/record.js.map +1 -1
  66. package/esm/sam.js +9 -7
  67. package/esm/sam.js.map +1 -1
  68. package/esm/util.d.ts +13 -1
  69. package/esm/util.js +40 -14
  70. package/esm/util.js.map +1 -1
  71. package/package.json +19 -20
  72. package/src/bai.ts +99 -102
  73. package/src/bamFile.ts +174 -198
  74. package/src/chunk.ts +6 -20
  75. package/src/csi.ts +102 -111
  76. package/src/htsget.ts +81 -61
  77. package/src/index.ts +5 -7
  78. package/src/indexFile.ts +0 -27
  79. package/src/nullIndex.ts +18 -0
  80. package/src/record.ts +34 -24
  81. package/src/sam.ts +9 -7
  82. package/src/util.ts +54 -13
  83. package/src/declare.d.ts +0 -2
package/CHANGELOG.md CHANGED
@@ -1,6 +1,22 @@
1
- ## [1.1.17](https://github.com/GMOD/bam-js/compare/v1.1.16...v1.1.17) (2022-07-18)
1
+ # [2.0.0](https://github.com/GMOD/bam-js/compare/v1.1.18...v2.0.0) (2023-06-08)
2
+
3
+
4
+ ### Features
5
+
6
+ * explicit buffer import ([#98](https://github.com/GMOD/bam-js/issues/98)) ([66de9f4](https://github.com/GMOD/bam-js/commit/66de9f4ce30e3ff647d5297f093695e92ec9227c))
7
+
2
8
 
3
9
 
10
+ - Add explicit buffer import
11
+ - Remove cross-fetch and object.entries polyfills
12
+ - Improve typescripting
13
+ - Remove chunkSizeLimit and fetchSizeLimit
14
+
15
+ ## [1.1.18](https://github.com/GMOD/bam-js/compare/v1.1.17...v1.1.18) (2022-12-17)
16
+
17
+ - Use es2015 for nodejs build
18
+
19
+ ## [1.1.17](https://github.com/GMOD/bam-js/compare/v1.1.16...v1.1.17) (2022-07-18)
4
20
 
5
21
  - Bump devDeps and generic-filehandle to 3.0.0
6
22
 
@@ -10,7 +26,8 @@
10
26
 
11
27
  ## [1.1.15](https://github.com/GMOD/bam-js/compare/v1.1.14...v1.1.15) (2022-03-18)
12
28
 
13
- - Fix for htsget failing with message 'input must be buffer, number, or string, received object'
29
+ - Fix for htsget failing with message 'input must be buffer, number, or string,
30
+ received object'
14
31
  - Speed improvement by caching chunks of features
15
32
 
16
33
  ## [1.1.14](https://github.com/GMOD/bam-js/compare/v1.1.13...v1.1.14) (2022-03-14)
@@ -25,7 +42,8 @@
25
42
 
26
43
  ## [1.1.12](https://github.com/GMOD/bam-js/compare/v1.1.11...v1.1.12) (2022-02-17)
27
44
 
28
- - Add blocksForRange method to BamFile class to help stats estimation in JBrowse 2
45
+ - Add blocksForRange method to BamFile class to help stats estimation in JBrowse
46
+ 2
29
47
 
30
48
  <a name="1.1.11"></a>
31
49
 
@@ -45,7 +63,8 @@
45
63
  ## [1.1.9](https://github.com/GMOD/bam-js/compare/v1.1.8...v1.1.9) (2021-12-14)
46
64
 
47
65
  - Add ESM module export in package.json (smaller bundle size for consumers)
48
- - Cache BAI readFile result for compatibility with node.js native filehandles (which otherwise fail if re-reading the filehandle twice)
66
+ - Cache BAI readFile result for compatibility with node.js native filehandles
67
+ (which otherwise fail if re-reading the filehandle twice)
49
68
 
50
69
  <a name="1.1.8"></a>
51
70
 
@@ -63,7 +82,8 @@
63
82
 
64
83
  ## [1.1.6](https://github.com/GMOD/bam-js/compare/v1.1.5...v1.1.6) (2021-02-20)
65
84
 
66
- - Add qualRaw function on records for getting raw qual score array instead of string
85
+ - Add qualRaw function on records for getting raw qual score array instead of
86
+ string
67
87
 
68
88
  <a name="1.1.5"></a>
69
89
 
@@ -76,7 +96,8 @@
76
96
  ## [1.1.4](https://github.com/GMOD/bam-js/compare/v1.1.3...v1.1.4) (2020-12-11)
77
97
 
78
98
  - Add canMergeBlocks to CSI code (already existed in BAI)
79
- - Add suggestion from @jrobinso about reg2bins modification for memory saving (Thanks!)
99
+ - Add suggestion from @jrobinso about reg2bins modification for memory saving
100
+ (Thanks!)
80
101
  - Add getHeaderText() method for getting a text string of the header data
81
102
 
82
103
  <a name="1.1.3"></a>
@@ -115,7 +136,8 @@
115
136
  ## [1.0.41](https://github.com/GMOD/bam-js/compare/v1.0.40...v1.0.41) (2020-08-19)
116
137
 
117
138
  - Add htsget example
118
- - Support opts object to getHeader allowing things like auth headers to be passed right off the bat
139
+ - Support opts object to getHeader allowing things like auth headers to be
140
+ passed right off the bat
119
141
 
120
142
  <a name="1.0.40"></a>
121
143
 
@@ -125,14 +147,16 @@
125
147
 
126
148
  ## [1.0.39](https://github.com/GMOD/bam-js/compare/v1.0.38...v1.0.39) (2020-07-30)
127
149
 
128
- - Don't use origin master in the follow-tags postpublish command for cleaner version publishing
150
+ - Don't use origin master in the follow-tags postpublish command for cleaner
151
+ version publishing
129
152
 
130
153
  <a name="1.0.38"></a>
131
154
 
132
155
  ## [1.0.38](https://github.com/GMOD/bam-js/compare/v1.0.37...v1.0.38) (2020-07-30)
133
156
 
134
157
  - Direct construction of qual/seq toString
135
- - Improve performance of the uniqueID calculation for pathological cases where there are tons of bins
158
+ - Improve performance of the uniqueID calculation for pathological cases where
159
+ there are tons of bins
136
160
 
137
161
  <a name="1.0.37"></a>
138
162
 
@@ -144,31 +168,36 @@
144
168
 
145
169
  ## [1.0.36](https://github.com/GMOD/bam-js/compare/v1.0.35...v1.0.36) (2020-03-05)
146
170
 
147
- - Adds a shortcut to stop parsing chunks after a record is detected to be outside the requested range while decoding
171
+ - Adds a shortcut to stop parsing chunks after a record is detected to be
172
+ outside the requested range while decoding
148
173
 
149
174
  <a name="1.0.35"></a>
150
175
 
151
176
  ## [1.0.35](https://github.com/GMOD/bam-js/compare/v1.0.34...v1.0.35) (2020-02-04)
152
177
 
153
- - Update scheme used to calculate unique fileOffset based IDs using @gmod/bgzf-filehandle updates
178
+ - Update scheme used to calculate unique fileOffset based IDs using
179
+ @gmod/bgzf-filehandle updates
154
180
 
155
181
  <a name="1.0.34"></a>
156
182
 
157
183
  ## [1.0.34](https://github.com/GMOD/bam-js/compare/v1.0.33...v1.0.34) (2020-01-24)
158
184
 
159
- - Small fix for using id() instead of .get('id') for weird SAM records containing ID field
185
+ - Small fix for using id() instead of .get('id') for weird SAM records
186
+ containing ID field
160
187
 
161
188
  <a name="1.0.33"></a>
162
189
 
163
190
  ## [1.0.33](https://github.com/GMOD/bam-js/compare/v1.0.32...v1.0.33) (2020-01-24)
164
191
 
165
- - Perform decoding of entire chunk up front to aid caching, reverts change in 1.0.29
192
+ - Perform decoding of entire chunk up front to aid caching, reverts change in
193
+ 1.0.29
166
194
 
167
195
  <a name="1.0.32"></a>
168
196
 
169
197
  ## [1.0.32](https://github.com/GMOD/bam-js/compare/v1.0.31...v1.0.32) (2019-11-16)
170
198
 
171
- - Add a speed improvement for long reads by pre-allocating sequence/quality scores array
199
+ - Add a speed improvement for long reads by pre-allocating sequence/quality
200
+ scores array
172
201
 
173
202
  <a name="1.0.31"></a>
174
203
 
@@ -186,7 +215,8 @@
186
215
 
187
216
  ## [1.0.29](https://github.com/GMOD/bam-js/compare/v1.0.28...v1.0.29) (2019-10-31)
188
217
 
189
- - Decoding of the BAM records at time of use instead of entire chunk decoded up front
218
+ - Decoding of the BAM records at time of use instead of entire chunk decoded up
219
+ front
190
220
  - Alternate chunk merging strategy inspired by igv.js code
191
221
 
192
222
  <a name="1.0.28"></a>
@@ -239,32 +269,40 @@
239
269
 
240
270
  ## [1.0.21](https://github.com/GMOD/bam-js/compare/v1.0.20...v1.0.21) (2019-08-06)
241
271
 
242
- - Add a fix for the small chunk unpacking re-seeking in the same bgzf block repeatedly (#35)
272
+ - Add a fix for the small chunk unpacking re-seeking in the same bgzf block
273
+ repeatedly (#35)
243
274
 
244
275
  <a name="1.0.20"></a>
245
276
 
246
277
  ## [1.0.20](https://github.com/GMOD/bam-js/compare/v1.0.19...v1.0.20) (2019-06-06)
247
278
 
248
- - Added a method for smaller chunk unpacking, by modifying the header parsing to return smaller chunks and the bgzf unzipping to respect chunk boundaries (#30)
249
- - Use fileOffset as bam feature ID which previously was crc32 of the BAM buffer which consequently speeds up processing and allows exact duplicate features
279
+ - Added a method for smaller chunk unpacking, by modifying the header parsing to
280
+ return smaller chunks and the bgzf unzipping to respect chunk boundaries (#30)
281
+ - Use fileOffset as bam feature ID which previously was crc32 of the BAM buffer
282
+ which consequently speeds up processing and allows exact duplicate features
250
283
 
251
284
  ## [1.0.19](https://github.com/GMOD/bam-js/compare/v1.0.18...v1.0.19) (2019-05-30)
252
285
 
253
- - Added lineCount and hasRefSeq functions to BamFile, each accepting a string seqName
286
+ - Added lineCount and hasRefSeq functions to BamFile, each accepting a string
287
+ seqName
254
288
  - Fixed aborting on index retrieval code
255
289
 
256
290
  ## [1.0.18](https://github.com/GMOD/bam-js/compare/v1.0.17...v1.0.18) (2019-05-01)
257
291
 
258
- - Bump generic-filehandle to 1.0.9 to fix error with using native fetch (global fetch needed to be bound)
259
- - Bump abortable-promise-cache to 1.0.1 version to fix error with using native fetch and abort signals
292
+ - Bump generic-filehandle to 1.0.9 to fix error with using native fetch (global
293
+ fetch needed to be bound)
294
+ - Bump abortable-promise-cache to 1.0.1 version to fix error with using native
295
+ fetch and abort signals
260
296
 
261
297
  ## [1.0.17](https://github.com/GMOD/bam-js/compare/v1.0.16...v1.0.17) (2019-04-28)
262
298
 
263
- - Fix wrong number of arguments being passed to the readRefSeqs file read() invocation resulting in bad range requests
299
+ - Fix wrong number of arguments being passed to the readRefSeqs file read()
300
+ invocation resulting in bad range requests
264
301
 
265
302
  ## [1.0.16](https://github.com/GMOD/bam-js/compare/v1.0.15...v1.0.16) (2019-04-28)
266
303
 
267
- - Added indexCov algorithm to retrieve approximate coverage of the BAM inferred from the size of the BAI linear index bins
304
+ - Added indexCov algorithm to retrieve approximate coverage of the BAM inferred
305
+ from the size of the BAI linear index bins
268
306
  - Fixed abortSignal on read() calls
269
307
  - Updated API to allow bamUrl/baiUrl/csiUrl
270
308
 
@@ -310,7 +348,8 @@
310
348
  ## [1.0.9](https://github.com/GMOD/bam-js/compare/v1.0.8...v1.0.9) (2018-11-16)
311
349
 
312
350
  - Allow bases other than ACGT to be decoded
313
- - Make viewAsPairs only resolve pairs on given refSeq unless pairAcrossChr is enabled for query
351
+ - Make viewAsPairs only resolve pairs on given refSeq unless pairAcrossChr is
352
+ enabled for query
314
353
 
315
354
  <a name="1.0.8"></a>
316
355
 
@@ -328,7 +367,8 @@
328
367
 
329
368
  ## [1.0.6](https://github.com/GMOD/bam-js/compare/v1.0.5...v1.0.6) (2018-10-19)
330
369
 
331
- - Add bugfix for where bytes for an invalid request returns 0 resulting in pako unzip errors
370
+ - Add bugfix for where bytes for an invalid request returns 0 resulting in pako
371
+ unzip errors
332
372
 
333
373
  <a name="1.0.5"></a>
334
374
 
package/README.md CHANGED
@@ -1,35 +1,51 @@
1
1
  [![NPM version](https://img.shields.io/npm/v/@gmod/bam.svg?style=flat-square)](https://npmjs.org/package/@gmod/bam)
2
2
  [![Coverage Status](https://img.shields.io/codecov/c/github/GMOD/bam-js/master.svg?style=flat-square)](https://codecov.io/gh/GMOD/bam-js/branch/master)
3
- [![Build Status](https://img.shields.io/github/workflow/status/GMOD/bam-js/Push/master?logo=github&style=flat-query)](https://github.com/GMOD/bam-js/actions?query=branch%3Amaster+workflow%3APush+)
3
+ [![Build Status](https://img.shields.io/github/actions/workflow/status/GMOD/bam-js/push.yml?branch=master)](https://github.com/GMOD/bam-js/actions?query=branch%3Amaster+workflow%3APush+)
4
4
 
5
5
  ## Install
6
6
 
7
- $ npm install --save @gmod/bam
7
+ ```bash
8
+ $ npm install --save @gmod/bam
9
+ ```
8
10
 
9
11
  ## Usage
10
12
 
11
- ```js
12
- const { BamFile } = require('@gmod/bam') // or import {BamFile} from '@gmod/bam'
13
+ ```typescript
14
+ const { BamFile } = require('@gmod/bam')
15
+ // or import {BamFile} from '@gmod/bam'
13
16
 
14
17
  const t = new BamFile({
15
18
  bamPath: 'test.bam',
16
19
  })
17
20
 
21
+ // note: it's required to first run getHeader before any getRecordsForRange
18
22
  var header = await t.getHeader()
19
23
 
20
24
  // this would get same records as samtools view ctgA:1-50000
21
- var records = await t.getRecordsForRange('ctgA', 0, 49999)
25
+ var records = await t.getRecordsForRange('ctgA', 0, 50000)
26
+ ```
27
+
28
+ The `bamPath` argument only works on nodejs. In the browser, you should pass
29
+ `bamFilehandle` with a generic-filehandle e.g. `RemoteFile`
30
+
31
+ ```typescript
32
+ const { RemoteFile } = require('generic-filehandle')
33
+ const bam = new BamFile({
34
+ bamFilehandle: new RemoteFile('yourfile.bam'), // or a full http url
35
+ baiFilehandle: new RemoteFile('yourfile.bam.bai'), // or a full http url
36
+ })
22
37
  ```
23
38
 
24
- Input are 0-based half-open coordinates (note: not the same as samtools view coordinate inputs!)
39
+ Input are 0-based half-open coordinates (note: not the same as samtools view
40
+ coordinate inputs!)
25
41
 
26
42
  ## Usage with htsget
27
43
 
28
- Since 1.0.41 we support htsget!
44
+ Since 1.0.41 we support usage of the htsget protocol
29
45
 
30
46
  Here is a small code snippet for this
31
47
 
32
- ```js
48
+ ```typescript
33
49
  const { HtsgetFile } = require('@gmod/bam')
34
50
 
35
51
  const ti = new HtsgetFile({
@@ -40,62 +56,87 @@ await ti.getHeader()
40
56
  const records = await ti.getRecordsForRange(1, 2000000, 2000001)
41
57
  ```
42
58
 
59
+ Our implementation makes some assumptions about how the protocol is implemented,
60
+ so let us know if it doesn't work for your use case
61
+
43
62
  ## Documentation
44
63
 
45
64
  ### BAM constructor
46
65
 
47
66
  The BAM class constructor accepts arguments
48
67
 
49
- - bamPath/bamUrl/bamFilehandle - a string file path to a local file or a class object with a read method
50
- - csiPath/csiUrl/csiFilehandle - a CSI index for the BAM file, required for long chromosomes greater than 2^29 in length
51
- - baiPath/baiUrl/baiFilehandle - a BAI index for the BAM file
52
- - fetchSizeLimit - total size of the number of chunks being fetched at once. default: ~50MB
53
- - chunkSizeLimit - size limit on any individual chunk. default: ~10MB
54
- - cacheSize - limit on number of chunks to cache. default: 50
55
- - yieldThreadTime - the interval at which the code yields to the main thread when it is parsing a lot of data. default: 100ms. Set to 0 to performed no yielding
56
-
57
- Note: filehandles implement the Filehandle interface from https://www.npmjs.com/package/generic-filehandle. This module offers the path and url arguments as convenience methods for supplying the LocalFile and RemoteFile
68
+ - `bamPath`/`bamUrl`/`bamFilehandle` - a string file path to a local file or a
69
+ class object with a read method
70
+ - `csiPath`/`csiUrl`/`csiFilehandle` - a CSI index for the BAM file, required
71
+ for long chromosomes greater than 2^29 in length
72
+ - `baiPath`/`baiUrl`/`baiFilehandle` - a BAI index for the BAM file
73
+ - `cacheSize` - limit on number of chunks to cache. default: 50
74
+ - `yieldThreadTime` - the interval at which the code yields to the main thread
75
+ when it is parsing a lot of data. default: 100ms. Set to 0 to performed no
76
+ yielding
77
+
78
+ Note: filehandles implement the Filehandle interface from
79
+ https://www.npmjs.com/package/generic-filehandle. This module offers the path
80
+ and url arguments as convenience methods for supplying the LocalFile and
81
+ RemoteFile
58
82
 
59
83
  ### async getRecordsForRange(refName, start, end, opts)
60
84
 
61
- - refName - a string for the chrom to fetch from
62
- - start - a 0 based half open start coordinate
63
- - end - a 0 based half open end coordinate
64
- - opts.signal - an AbortSignal to indicate stop processing
65
- - opts.viewAsPairs - re-dispatches requests to find mate pairs. default: false
66
- - opts.pairAcrossChr - control the viewAsPairs option behavior to pair across chromosomes. default: false
67
- - opts.maxInsertSize - control the viewAsPairs option behavior to limit distance within a chromosome to fetch. default: 200kb
85
+ Note: you must run getHeader before running getRecordsForRange
68
86
 
69
- ### async \*streamRecordsForRange(refName, start, end, opts)
87
+ - `refName` - a string for the chrom to fetch from
88
+ - `start` - a 0-based half open start coordinate
89
+ - `end` - a 0-based half open end coordinate
90
+ - `opts.signal` - an AbortSignal to indicate stop processing
91
+ - `opts.viewAsPairs` - re-dispatches requests to find mate pairs. default: false
92
+ - `opts.pairAcrossChr` - control the viewAsPairs option behavior to pair across
93
+ chromosomes. default: false
94
+ - `opts.maxInsertSize` - control the viewAsPairs option behavior to limit
95
+ distance within a chromosome to fetch. default: 200kb
70
96
 
71
- This is a async generator function that takes the same signature as getRecordsForRange but results can be processed using
97
+ ### async \*streamRecordsForRange(refName, start, end, opts)
72
98
 
73
- for await(const chunk of file.streamRecordsForRange(refName, start, end, opts)) {
74
- }
99
+ This is a async generator function that takes the same signature as
100
+ `getRecordsForRange` but results can be processed using
101
+
102
+ ```typescript
103
+ for await (const chunk of file.streamRecordsForRange(
104
+ refName,
105
+ start,
106
+ end,
107
+ opts,
108
+ )) {
109
+ }
110
+ ```
75
111
 
76
- The getRecordsForRange simply wraps this process by concatenating chunks into an array
112
+ The `getRecordsForRange` simply wraps this process by concatenating chunks into
113
+ an array
77
114
 
78
115
  ### async getHeader(opts: {....anything to pass to generic-filehandle opts})
79
116
 
80
- This obtains the header from HtsgetFile or BamFile. Retrieves BAM file and BAI/CSI header if applicable, or API request for refnames from htsget
117
+ This obtains the header from `HtsgetFile` or `BamFile`. Retrieves BAM file and
118
+ BAI/CSI header if applicable, or API request for refnames from htsget
81
119
 
82
120
  ### async indexCov(refName, start, end)
83
121
 
84
- - refName - a string for the chrom to fetch from
85
- - start - a 0 based half open start coordinate (optional)
86
- - end - a 0 based half open end coordinate (optional)
122
+ - `refName` - a string for the chrom to fetch from
123
+ - `start` - a 0-based half open start coordinate (optional)
124
+ - `end` - a 0-based half open end coordinate (optional)
87
125
 
88
- Returns features of the form {start, end, score} containing estimated feature density across 16kb windows in the genome
126
+ Returns features of the form {start, end, score} containing estimated feature
127
+ density across 16kb windows in the genome
89
128
 
90
- ### async lineCount(refName)
129
+ ### async lineCount(refName: string)
91
130
 
92
- - refName - a string for the chrom to fetch from
131
+ - `refName` - a string for the chrom to fetch from
93
132
 
94
- Returns number of features on refName, uses special pseudo-bin from the BAI/CSI index (e.g. bin 37450 from bai, returning n_mapped from SAM spec pdf) or -1 if refName not exist in sample
133
+ Returns number of features on refName, uses special pseudo-bin from the BAI/CSI
134
+ index (e.g. bin 37450 from bai, returning n_mapped from SAM spec pdf) or -1 if
135
+ refName not exist in sample
95
136
 
96
- ### async hasRefSeq(refName)
137
+ ### async hasRefSeq(refName: string)
97
138
 
98
- - refName - a string for the chrom to check
139
+ - `refName` - a string for the chrom to check
99
140
 
100
141
  Returns whether we have this refName in the sample
101
142
 
@@ -108,41 +149,51 @@ You can access data feature.get('field') to get the value of a feature attribute
108
149
 
109
150
  Example
110
151
 
111
- feature.get('seq_id') // numerical sequence id corresponding to position in the sam header
112
- feature.get('start') // 0 based half open start coordinate
113
- feature.get('end') // 0 based half open end coordinate
152
+ ```typescript
153
+ feature.get('seq_id') // numerical sequence id corresponding to position in the sam header
154
+ feature.get('start') // 0-based half open start coordinate
155
+ feature.get('end') // 0-based half open end coordinate
156
+ ```
114
157
 
115
158
  #### Fields
116
159
 
117
- feature.get('name') // QNAME
118
- feature.get('seq') // feature sequence
119
- feature.get('qual') // qualities
120
- feature.get('cigar') // cigar string
121
- feature.get('MD') // MD string
122
- feature.get('SA') // supplementary alignments
123
- feature.get('template_length') // TLEN
124
- feature.get('length_on_ref') // derived from CIGAR using standard algorithm
160
+ ```typescript
161
+ feature.get('name') // QNAME
162
+ feature.get('seq') // feature sequence
163
+ feature.get('qual') // qualities
164
+ feature.get('cigar') // cigar string
165
+ feature.get('MD') // MD string
166
+ feature.get('SA') // supplementary alignments
167
+ feature.get('template_length') // TLEN
168
+ feature.get('length_on_ref') // derived from CIGAR using standard algorithm
169
+ ```
125
170
 
126
171
  #### Flags
127
172
 
128
- feature.get('flags') // see https://broadinstitute.github.io/picard/explain-flags.html
173
+ ```typescript
174
+ feature.get('flags') // see https://broadinstitute.github.io/picard/explain-flags.html
175
+ ```
129
176
 
130
177
  #### Tags
131
178
 
132
179
  BAM tags such as MD can be obtained via
133
180
 
134
- feature.get('MD')
181
+ ```typescript
182
+ feature.get('MD')
183
+ ```
135
184
 
136
185
  A full list of tags that can be obtained can be obtained via
137
186
 
138
187
  feature._tags()
139
188
 
140
- The feature format may change in future versions to be more raw data records, but this will be a major version bump
189
+ The feature format may change in future versions to be more raw data records,
190
+ but this will be a major version bump
141
191
 
142
- ## License
192
+ #### Note
143
193
 
144
- MIT © [Colin Diesh](https://github.com/cmdcolin)
194
+ The reason that we hide the data behind this ".get" function is that we lazily
195
+ decode records on demand, which can reduce memory consumption.
145
196
 
146
- ```
197
+ ## License
147
198
 
148
- ```
199
+ MIT © [Colin Diesh](https://github.com/cmdcolin)
package/dist/bai.d.ts CHANGED
@@ -1,26 +1,45 @@
1
- /// <reference types="node" />
1
+ import VirtualOffset from './virtualOffset';
2
2
  import Chunk from './chunk';
3
- import IndexFile from './indexFile';
4
3
  import { BaseOpts } from './util';
4
+ import IndexFile from './indexFile';
5
5
  export default class BAI extends IndexFile {
6
- baiP?: Promise<Buffer>;
7
- parsePseudoBin(bytes: Buffer, offset: number): {
8
- lineCount: number;
9
- };
10
- lineCount(refId: number, opts?: BaseOpts): Promise<any>;
11
- fetchBai(opts?: BaseOpts): Promise<Buffer>;
12
- _parse(): Promise<{
13
- [key: string]: any;
6
+ setupP?: ReturnType<BAI['_parse']>;
7
+ lineCount(refId: number, opts?: BaseOpts): Promise<number>;
8
+ _parse(opts?: BaseOpts): Promise<{
9
+ bai: boolean;
10
+ firstDataLine: VirtualOffset | undefined;
11
+ maxBlockSize: number;
12
+ indices: {
13
+ binIndex: {
14
+ [key: string]: Chunk[];
15
+ };
16
+ linearIndex: VirtualOffset[];
17
+ stats?: {
18
+ lineCount: number;
19
+ } | undefined;
20
+ }[];
21
+ refCount: number;
14
22
  }>;
15
23
  indexCov(seqId: number, start?: number, end?: number, opts?: BaseOpts): Promise<{
16
24
  start: number;
17
25
  end: number;
18
26
  score: number;
19
27
  }[]>;
20
- /**
21
- * calculate the list of bins that may overlap with region [beg,end) (zero-based half-open)
22
- * @returns {Array[number]}
23
- */
24
- reg2bins(beg: number, end: number): number[][];
25
28
  blocksForRange(refId: number, min: number, max: number, opts?: BaseOpts): Promise<Chunk[]>;
29
+ parse(opts?: BaseOpts): Promise<{
30
+ bai: boolean;
31
+ firstDataLine: VirtualOffset | undefined;
32
+ maxBlockSize: number;
33
+ indices: {
34
+ binIndex: {
35
+ [key: string]: Chunk[];
36
+ };
37
+ linearIndex: VirtualOffset[];
38
+ stats?: {
39
+ lineCount: number;
40
+ } | undefined;
41
+ }[];
42
+ refCount: number;
43
+ }>;
44
+ hasRefSeq(seqId: number, opts?: BaseOpts): Promise<boolean>;
26
45
  }