@gmod/bam 1.1.18 → 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 (79) hide show
  1. package/CHANGELOG.md +61 -25
  2. package/README.md +95 -57
  3. package/dist/bai.d.ts +34 -15
  4. package/dist/bai.js +87 -91
  5. package/dist/bai.js.map +1 -1
  6. package/dist/bamFile.d.ts +33 -27
  7. package/dist/bamFile.js +127 -121
  8. package/dist/bamFile.js.map +1 -1
  9. package/dist/chunk.d.ts +4 -8
  10. package/dist/chunk.js +2 -8
  11. package/dist/chunk.js.map +1 -1
  12. package/dist/csi.d.ts +74 -10
  13. package/dist/csi.js +78 -90
  14. package/dist/csi.js.map +1 -1
  15. package/dist/htsget.d.ts +5 -8
  16. package/dist/htsget.js +72 -47
  17. package/dist/htsget.js.map +1 -1
  18. package/dist/index.d.ts +5 -6
  19. package/dist/index.js +11 -11
  20. package/dist/index.js.map +1 -1
  21. package/dist/indexFile.d.ts +0 -6
  22. package/dist/indexFile.js +0 -35
  23. package/dist/indexFile.js.map +1 -1
  24. package/dist/nullIndex.d.ts +7 -0
  25. package/dist/nullIndex.js +33 -0
  26. package/dist/nullIndex.js.map +1 -0
  27. package/dist/record.d.ts +2 -2
  28. package/dist/record.js +34 -24
  29. package/dist/record.js.map +1 -1
  30. package/dist/sam.js +9 -7
  31. package/dist/sam.js.map +1 -1
  32. package/dist/util.d.ts +13 -1
  33. package/dist/util.js +47 -15
  34. package/dist/util.js.map +1 -1
  35. package/esm/bai.d.ts +34 -15
  36. package/esm/bai.js +86 -91
  37. package/esm/bai.js.map +1 -1
  38. package/esm/bamFile.d.ts +33 -27
  39. package/esm/bamFile.js +124 -120
  40. package/esm/bamFile.js.map +1 -1
  41. package/esm/chunk.d.ts +4 -8
  42. package/esm/chunk.js +2 -8
  43. package/esm/chunk.js.map +1 -1
  44. package/esm/csi.d.ts +74 -10
  45. package/esm/csi.js +85 -93
  46. package/esm/csi.js.map +1 -1
  47. package/esm/htsget.d.ts +5 -8
  48. package/esm/htsget.js +68 -43
  49. package/esm/htsget.js.map +1 -1
  50. package/esm/index.d.ts +5 -6
  51. package/esm/index.js +5 -6
  52. package/esm/index.js.map +1 -1
  53. package/esm/indexFile.d.ts +0 -6
  54. package/esm/indexFile.js +0 -22
  55. package/esm/indexFile.js.map +1 -1
  56. package/esm/nullIndex.d.ts +7 -0
  57. package/esm/nullIndex.js +16 -0
  58. package/esm/nullIndex.js.map +1 -0
  59. package/esm/record.d.ts +2 -2
  60. package/esm/record.js +34 -24
  61. package/esm/record.js.map +1 -1
  62. package/esm/sam.js +9 -7
  63. package/esm/sam.js.map +1 -1
  64. package/esm/util.d.ts +13 -1
  65. package/esm/util.js +40 -14
  66. package/esm/util.js.map +1 -1
  67. package/package.json +16 -17
  68. package/src/bai.ts +99 -102
  69. package/src/bamFile.ts +174 -198
  70. package/src/chunk.ts +6 -20
  71. package/src/csi.ts +102 -111
  72. package/src/htsget.ts +81 -61
  73. package/src/index.ts +5 -7
  74. package/src/indexFile.ts +0 -27
  75. package/src/nullIndex.ts +18 -0
  76. package/src/record.ts +34 -24
  77. package/src/sam.ts +9 -7
  78. package/src/util.ts +54 -13
  79. package/src/declare.d.ts +0 -2
package/CHANGELOG.md CHANGED
@@ -1,7 +1,19 @@
1
- ## [1.1.18](https://github.com/GMOD/bam-js/compare/v1.1.17...v1.1.18) (2022-12-17)
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))
2
7
 
3
8
 
4
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
+
5
17
  - Use es2015 for nodejs build
6
18
 
7
19
  ## [1.1.17](https://github.com/GMOD/bam-js/compare/v1.1.16...v1.1.17) (2022-07-18)
@@ -14,7 +26,8 @@
14
26
 
15
27
  ## [1.1.15](https://github.com/GMOD/bam-js/compare/v1.1.14...v1.1.15) (2022-03-18)
16
28
 
17
- - 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'
18
31
  - Speed improvement by caching chunks of features
19
32
 
20
33
  ## [1.1.14](https://github.com/GMOD/bam-js/compare/v1.1.13...v1.1.14) (2022-03-14)
@@ -29,7 +42,8 @@
29
42
 
30
43
  ## [1.1.12](https://github.com/GMOD/bam-js/compare/v1.1.11...v1.1.12) (2022-02-17)
31
44
 
32
- - 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
33
47
 
34
48
  <a name="1.1.11"></a>
35
49
 
@@ -49,7 +63,8 @@
49
63
  ## [1.1.9](https://github.com/GMOD/bam-js/compare/v1.1.8...v1.1.9) (2021-12-14)
50
64
 
51
65
  - Add ESM module export in package.json (smaller bundle size for consumers)
52
- - 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)
53
68
 
54
69
  <a name="1.1.8"></a>
55
70
 
@@ -67,7 +82,8 @@
67
82
 
68
83
  ## [1.1.6](https://github.com/GMOD/bam-js/compare/v1.1.5...v1.1.6) (2021-02-20)
69
84
 
70
- - 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
71
87
 
72
88
  <a name="1.1.5"></a>
73
89
 
@@ -80,7 +96,8 @@
80
96
  ## [1.1.4](https://github.com/GMOD/bam-js/compare/v1.1.3...v1.1.4) (2020-12-11)
81
97
 
82
98
  - Add canMergeBlocks to CSI code (already existed in BAI)
83
- - Add suggestion from @jrobinso about reg2bins modification for memory saving (Thanks!)
99
+ - Add suggestion from @jrobinso about reg2bins modification for memory saving
100
+ (Thanks!)
84
101
  - Add getHeaderText() method for getting a text string of the header data
85
102
 
86
103
  <a name="1.1.3"></a>
@@ -119,7 +136,8 @@
119
136
  ## [1.0.41](https://github.com/GMOD/bam-js/compare/v1.0.40...v1.0.41) (2020-08-19)
120
137
 
121
138
  - Add htsget example
122
- - 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
123
141
 
124
142
  <a name="1.0.40"></a>
125
143
 
@@ -129,14 +147,16 @@
129
147
 
130
148
  ## [1.0.39](https://github.com/GMOD/bam-js/compare/v1.0.38...v1.0.39) (2020-07-30)
131
149
 
132
- - 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
133
152
 
134
153
  <a name="1.0.38"></a>
135
154
 
136
155
  ## [1.0.38](https://github.com/GMOD/bam-js/compare/v1.0.37...v1.0.38) (2020-07-30)
137
156
 
138
157
  - Direct construction of qual/seq toString
139
- - 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
140
160
 
141
161
  <a name="1.0.37"></a>
142
162
 
@@ -148,31 +168,36 @@
148
168
 
149
169
  ## [1.0.36](https://github.com/GMOD/bam-js/compare/v1.0.35...v1.0.36) (2020-03-05)
150
170
 
151
- - 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
152
173
 
153
174
  <a name="1.0.35"></a>
154
175
 
155
176
  ## [1.0.35](https://github.com/GMOD/bam-js/compare/v1.0.34...v1.0.35) (2020-02-04)
156
177
 
157
- - 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
158
180
 
159
181
  <a name="1.0.34"></a>
160
182
 
161
183
  ## [1.0.34](https://github.com/GMOD/bam-js/compare/v1.0.33...v1.0.34) (2020-01-24)
162
184
 
163
- - 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
164
187
 
165
188
  <a name="1.0.33"></a>
166
189
 
167
190
  ## [1.0.33](https://github.com/GMOD/bam-js/compare/v1.0.32...v1.0.33) (2020-01-24)
168
191
 
169
- - 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
170
194
 
171
195
  <a name="1.0.32"></a>
172
196
 
173
197
  ## [1.0.32](https://github.com/GMOD/bam-js/compare/v1.0.31...v1.0.32) (2019-11-16)
174
198
 
175
- - 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
176
201
 
177
202
  <a name="1.0.31"></a>
178
203
 
@@ -190,7 +215,8 @@
190
215
 
191
216
  ## [1.0.29](https://github.com/GMOD/bam-js/compare/v1.0.28...v1.0.29) (2019-10-31)
192
217
 
193
- - 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
194
220
  - Alternate chunk merging strategy inspired by igv.js code
195
221
 
196
222
  <a name="1.0.28"></a>
@@ -243,32 +269,40 @@
243
269
 
244
270
  ## [1.0.21](https://github.com/GMOD/bam-js/compare/v1.0.20...v1.0.21) (2019-08-06)
245
271
 
246
- - 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)
247
274
 
248
275
  <a name="1.0.20"></a>
249
276
 
250
277
  ## [1.0.20](https://github.com/GMOD/bam-js/compare/v1.0.19...v1.0.20) (2019-06-06)
251
278
 
252
- - 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)
253
- - 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
254
283
 
255
284
  ## [1.0.19](https://github.com/GMOD/bam-js/compare/v1.0.18...v1.0.19) (2019-05-30)
256
285
 
257
- - 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
258
288
  - Fixed aborting on index retrieval code
259
289
 
260
290
  ## [1.0.18](https://github.com/GMOD/bam-js/compare/v1.0.17...v1.0.18) (2019-05-01)
261
291
 
262
- - Bump generic-filehandle to 1.0.9 to fix error with using native fetch (global fetch needed to be bound)
263
- - 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
264
296
 
265
297
  ## [1.0.17](https://github.com/GMOD/bam-js/compare/v1.0.16...v1.0.17) (2019-04-28)
266
298
 
267
- - 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
268
301
 
269
302
  ## [1.0.16](https://github.com/GMOD/bam-js/compare/v1.0.15...v1.0.16) (2019-04-28)
270
303
 
271
- - 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
272
306
  - Fixed abortSignal on read() calls
273
307
  - Updated API to allow bamUrl/baiUrl/csiUrl
274
308
 
@@ -314,7 +348,8 @@
314
348
  ## [1.0.9](https://github.com/GMOD/bam-js/compare/v1.0.8...v1.0.9) (2018-11-16)
315
349
 
316
350
  - Allow bases other than ACGT to be decoded
317
- - 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
318
353
 
319
354
  <a name="1.0.8"></a>
320
355
 
@@ -332,7 +367,8 @@
332
367
 
333
368
  ## [1.0.6](https://github.com/GMOD/bam-js/compare/v1.0.5...v1.0.6) (2018-10-19)
334
369
 
335
- - 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
336
372
 
337
373
  <a name="1.0.5"></a>
338
374
 
package/README.md CHANGED
@@ -4,12 +4,15 @@
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',
@@ -22,9 +25,10 @@ var header = await t.getHeader()
22
25
  var records = await t.getRecordsForRange('ctgA', 0, 50000)
23
26
  ```
24
27
 
25
- The `bamPath` argument only works on nodejs, in the browser, you should pass `bamFilehandle` with a generic-filehandle e.g. RemoteFile
28
+ The `bamPath` argument only works on nodejs. In the browser, you should pass
29
+ `bamFilehandle` with a generic-filehandle e.g. `RemoteFile`
26
30
 
27
- ```js
31
+ ```typescript
28
32
  const { RemoteFile } = require('generic-filehandle')
29
33
  const bam = new BamFile({
30
34
  bamFilehandle: new RemoteFile('yourfile.bam'), // or a full http url
@@ -32,15 +36,16 @@ const bam = new BamFile({
32
36
  })
33
37
  ```
34
38
 
35
- 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!)
36
41
 
37
42
  ## Usage with htsget
38
43
 
39
- Since 1.0.41 we support htsget!
44
+ Since 1.0.41 we support usage of the htsget protocol
40
45
 
41
46
  Here is a small code snippet for this
42
47
 
43
- ```js
48
+ ```typescript
44
49
  const { HtsgetFile } = require('@gmod/bam')
45
50
 
46
51
  const ti = new HtsgetFile({
@@ -51,64 +56,87 @@ await ti.getHeader()
51
56
  const records = await ti.getRecordsForRange(1, 2000000, 2000001)
52
57
  ```
53
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
+
54
62
  ## Documentation
55
63
 
56
64
  ### BAM constructor
57
65
 
58
66
  The BAM class constructor accepts arguments
59
67
 
60
- - bamPath/bamUrl/bamFilehandle - a string file path to a local file or a class object with a read method
61
- - csiPath/csiUrl/csiFilehandle - a CSI index for the BAM file, required for long chromosomes greater than 2^29 in length
62
- - baiPath/baiUrl/baiFilehandle - a BAI index for the BAM file
63
- - fetchSizeLimit - total size of the number of chunks being fetched at once. default: ~50MB
64
- - chunkSizeLimit - size limit on any individual chunk. default: ~10MB
65
- - cacheSize - limit on number of chunks to cache. default: 50
66
- - 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
67
-
68
- 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
69
82
 
70
83
  ### async getRecordsForRange(refName, start, end, opts)
71
84
 
72
85
  Note: you must run getHeader before running getRecordsForRange
73
86
 
74
- - refName - a string for the chrom to fetch from
75
- - start - a 0 based half open start coordinate
76
- - end - a 0 based half open end coordinate
77
- - opts.signal - an AbortSignal to indicate stop processing
78
- - opts.viewAsPairs - re-dispatches requests to find mate pairs. default: false
79
- - opts.pairAcrossChr - control the viewAsPairs option behavior to pair across chromosomes. default: false
80
- - opts.maxInsertSize - control the viewAsPairs option behavior to limit distance within a chromosome to fetch. default: 200kb
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
81
96
 
82
97
  ### async \*streamRecordsForRange(refName, start, end, opts)
83
98
 
84
- This is a async generator function that takes the same signature as getRecordsForRange but results can be processed using
85
-
86
- for await(const chunk of file.streamRecordsForRange(refName, start, end, opts)) {
87
- }
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
+ ```
88
111
 
89
- 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
90
114
 
91
115
  ### async getHeader(opts: {....anything to pass to generic-filehandle opts})
92
116
 
93
- 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
94
119
 
95
120
  ### async indexCov(refName, start, end)
96
121
 
97
- - refName - a string for the chrom to fetch from
98
- - start - a 0 based half open start coordinate (optional)
99
- - 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)
100
125
 
101
- 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
102
128
 
103
- ### async lineCount(refName)
129
+ ### async lineCount(refName: string)
104
130
 
105
- - refName - a string for the chrom to fetch from
131
+ - `refName` - a string for the chrom to fetch from
106
132
 
107
- 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
108
136
 
109
- ### async hasRefSeq(refName)
137
+ ### async hasRefSeq(refName: string)
110
138
 
111
- - refName - a string for the chrom to check
139
+ - `refName` - a string for the chrom to check
112
140
 
113
141
  Returns whether we have this refName in the sample
114
142
 
@@ -121,41 +149,51 @@ You can access data feature.get('field') to get the value of a feature attribute
121
149
 
122
150
  Example
123
151
 
124
- feature.get('seq_id') // numerical sequence id corresponding to position in the sam header
125
- feature.get('start') // 0 based half open start coordinate
126
- 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
+ ```
127
157
 
128
158
  #### Fields
129
159
 
130
- feature.get('name') // QNAME
131
- feature.get('seq') // feature sequence
132
- feature.get('qual') // qualities
133
- feature.get('cigar') // cigar string
134
- feature.get('MD') // MD string
135
- feature.get('SA') // supplementary alignments
136
- feature.get('template_length') // TLEN
137
- 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
+ ```
138
170
 
139
171
  #### Flags
140
172
 
141
- 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
+ ```
142
176
 
143
177
  #### Tags
144
178
 
145
179
  BAM tags such as MD can be obtained via
146
180
 
147
- feature.get('MD')
181
+ ```typescript
182
+ feature.get('MD')
183
+ ```
148
184
 
149
185
  A full list of tags that can be obtained can be obtained via
150
186
 
151
187
  feature._tags()
152
188
 
153
- 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
154
191
 
155
- ## License
192
+ #### Note
156
193
 
157
- 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.
158
196
 
159
- ```
197
+ ## License
160
198
 
161
- ```
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
  }