@gmod/cram 1.5.7 → 1.6.1

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 (221) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/README.md +184 -174
  3. package/dist/craiIndex.d.ts +37 -0
  4. package/dist/craiIndex.js +196 -365
  5. package/dist/craiIndex.js.map +1 -0
  6. package/dist/cram-bundle.js +6 -15
  7. package/dist/cramFile/codecs/_base.d.ts +6 -0
  8. package/dist/cramFile/codecs/_base.js +44 -53
  9. package/dist/cramFile/codecs/_base.js.map +1 -0
  10. package/dist/cramFile/codecs/beta.d.ts +4 -0
  11. package/dist/cramFile/codecs/beta.js +38 -48
  12. package/dist/cramFile/codecs/beta.js.map +1 -0
  13. package/dist/cramFile/codecs/byteArrayLength.d.ts +8 -0
  14. package/dist/cramFile/codecs/byteArrayLength.js +58 -78
  15. package/dist/cramFile/codecs/byteArrayLength.js.map +1 -0
  16. package/dist/cramFile/codecs/byteArrayStop.d.ts +6 -0
  17. package/dist/cramFile/codecs/byteArrayStop.js +62 -76
  18. package/dist/cramFile/codecs/byteArrayStop.js.map +1 -0
  19. package/dist/cramFile/codecs/external.d.ts +7 -0
  20. package/dist/cramFile/codecs/external.js +63 -81
  21. package/dist/cramFile/codecs/external.js.map +1 -0
  22. package/dist/cramFile/codecs/gamma.d.ts +4 -0
  23. package/dist/cramFile/codecs/gamma.js +43 -56
  24. package/dist/cramFile/codecs/gamma.js.map +1 -0
  25. package/dist/cramFile/codecs/huffman.d.ts +17 -0
  26. package/dist/cramFile/codecs/huffman.js +126 -199
  27. package/dist/cramFile/codecs/huffman.js.map +1 -0
  28. package/dist/cramFile/codecs/index.d.ts +2 -0
  29. package/dist/cramFile/codecs/index.js +31 -38
  30. package/dist/cramFile/codecs/index.js.map +1 -0
  31. package/dist/cramFile/codecs/subexp.d.ts +4 -0
  32. package/dist/cramFile/codecs/subexp.js +51 -64
  33. package/dist/cramFile/codecs/subexp.js.map +1 -0
  34. package/dist/cramFile/constants.d.ts +36 -0
  35. package/dist/cramFile/constants.js +52 -50
  36. package/dist/cramFile/constants.js.map +1 -0
  37. package/dist/cramFile/container/compressionScheme.d.ts +23 -0
  38. package/dist/cramFile/container/compressionScheme.js +115 -153
  39. package/dist/cramFile/container/compressionScheme.js.map +1 -0
  40. package/dist/cramFile/container/index.d.ts +13 -0
  41. package/dist/cramFile/container/index.js +169 -283
  42. package/dist/cramFile/container/index.js.map +1 -0
  43. package/dist/cramFile/file.d.ts +63 -0
  44. package/dist/cramFile/file.js +440 -766
  45. package/dist/cramFile/file.js.map +1 -0
  46. package/dist/cramFile/index.d.ts +2 -0
  47. package/dist/cramFile/index.js +7 -4
  48. package/dist/cramFile/index.js.map +1 -0
  49. package/dist/cramFile/record.d.ts +79 -0
  50. package/dist/cramFile/record.js +253 -308
  51. package/dist/cramFile/record.js.map +1 -0
  52. package/dist/cramFile/sectionParsers.d.ts +18 -0
  53. package/dist/cramFile/sectionParsers.js +324 -362
  54. package/dist/cramFile/sectionParsers.js.map +1 -0
  55. package/dist/cramFile/slice/decodeRecord.d.ts +2 -0
  56. package/dist/cramFile/slice/decodeRecord.js +278 -298
  57. package/dist/cramFile/slice/decodeRecord.js.map +1 -0
  58. package/dist/cramFile/slice/index.d.ts +20 -0
  59. package/dist/cramFile/slice/index.js +488 -789
  60. package/dist/cramFile/slice/index.js.map +1 -0
  61. package/dist/cramFile/util.d.ts +5 -0
  62. package/dist/cramFile/util.js +158 -144
  63. package/dist/cramFile/util.js.map +1 -0
  64. package/dist/errors.d.ts +23 -0
  65. package/dist/errors.js +66 -103
  66. package/dist/errors.js.map +1 -0
  67. package/dist/index.d.ts +4 -0
  68. package/dist/index.js +12 -12
  69. package/dist/index.js.map +1 -0
  70. package/dist/indexedCramFile.d.ts +39 -0
  71. package/dist/indexedCramFile.js +213 -315
  72. package/dist/indexedCramFile.js.map +1 -0
  73. package/dist/io/bufferCache.d.ts +12 -0
  74. package/dist/io/bufferCache.js +108 -128
  75. package/dist/io/bufferCache.js.map +1 -0
  76. package/dist/io/index.d.ts +5 -0
  77. package/dist/io/index.js +29 -27
  78. package/dist/io/index.js.map +1 -0
  79. package/dist/io/localFile.d.ts +10 -0
  80. package/dist/io/localFile.js +105 -162
  81. package/dist/io/localFile.js.map +1 -0
  82. package/dist/io/remoteFile.d.ts +16 -0
  83. package/dist/io/remoteFile.js +137 -206
  84. package/dist/io/remoteFile.js.map +1 -0
  85. package/dist/rans/constants.d.ts +3 -0
  86. package/dist/rans/constants.js +6 -6
  87. package/dist/rans/constants.js.map +1 -0
  88. package/dist/rans/d04.d.ts +1 -0
  89. package/dist/rans/d04.js +70 -99
  90. package/dist/rans/d04.js.map +1 -0
  91. package/dist/rans/d14.d.ts +1 -0
  92. package/dist/rans/d14.js +55 -93
  93. package/dist/rans/d14.js.map +1 -0
  94. package/dist/rans/decoding.d.ts +30 -0
  95. package/dist/rans/decoding.js +112 -159
  96. package/dist/rans/decoding.js.map +1 -0
  97. package/dist/rans/frequencies.d.ts +2 -0
  98. package/dist/rans/frequencies.js +110 -119
  99. package/dist/rans/frequencies.js.map +1 -0
  100. package/dist/rans/index.d.ts +1 -0
  101. package/dist/rans/index.js +111 -174
  102. package/dist/rans/index.js.map +1 -0
  103. package/dist/sam.d.ts +1 -0
  104. package/dist/sam.js +16 -41
  105. package/dist/sam.js.map +1 -0
  106. package/dist/unzip-pako.d.ts +2 -0
  107. package/dist/unzip-pako.js +9 -0
  108. package/dist/unzip-pako.js.map +1 -0
  109. package/dist/unzip.d.ts +2 -0
  110. package/dist/unzip.js +6 -0
  111. package/dist/unzip.js.map +1 -0
  112. package/errors.js +66 -103
  113. package/esm/craiIndex.d.ts +37 -0
  114. package/esm/craiIndex.js +158 -0
  115. package/esm/craiIndex.js.map +1 -0
  116. package/esm/cramFile/codecs/_base.d.ts +6 -0
  117. package/esm/cramFile/codecs/_base.js +42 -0
  118. package/esm/cramFile/codecs/_base.js.map +1 -0
  119. package/esm/cramFile/codecs/beta.d.ts +4 -0
  120. package/esm/cramFile/codecs/beta.js +15 -0
  121. package/esm/cramFile/codecs/beta.js.map +1 -0
  122. package/esm/cramFile/codecs/byteArrayLength.d.ts +8 -0
  123. package/esm/cramFile/codecs/byteArrayLength.js +35 -0
  124. package/esm/cramFile/codecs/byteArrayLength.js.map +1 -0
  125. package/esm/cramFile/codecs/byteArrayStop.d.ts +6 -0
  126. package/esm/cramFile/codecs/byteArrayStop.js +40 -0
  127. package/esm/cramFile/codecs/byteArrayStop.js.map +1 -0
  128. package/esm/cramFile/codecs/external.d.ts +7 -0
  129. package/esm/cramFile/codecs/external.js +40 -0
  130. package/esm/cramFile/codecs/external.js.map +1 -0
  131. package/esm/cramFile/codecs/gamma.d.ts +4 -0
  132. package/esm/cramFile/codecs/gamma.js +20 -0
  133. package/esm/cramFile/codecs/gamma.js.map +1 -0
  134. package/esm/cramFile/codecs/huffman.d.ts +17 -0
  135. package/esm/cramFile/codecs/huffman.js +107 -0
  136. package/esm/cramFile/codecs/huffman.js.map +1 -0
  137. package/esm/cramFile/codecs/index.d.ts +2 -0
  138. package/esm/cramFile/codecs/index.js +30 -0
  139. package/esm/cramFile/codecs/index.js.map +1 -0
  140. package/esm/cramFile/codecs/subexp.d.ts +4 -0
  141. package/esm/cramFile/codecs/subexp.js +28 -0
  142. package/esm/cramFile/codecs/subexp.js.map +1 -0
  143. package/esm/cramFile/constants.d.ts +36 -0
  144. package/esm/cramFile/constants.js +51 -0
  145. package/esm/cramFile/constants.js.map +1 -0
  146. package/esm/cramFile/container/compressionScheme.d.ts +23 -0
  147. package/esm/cramFile/container/compressionScheme.js +123 -0
  148. package/esm/cramFile/container/compressionScheme.js.map +1 -0
  149. package/esm/cramFile/container/index.d.ts +13 -0
  150. package/esm/cramFile/container/index.js +84 -0
  151. package/esm/cramFile/container/index.js.map +1 -0
  152. package/esm/cramFile/file.d.ts +63 -0
  153. package/esm/cramFile/file.js +281 -0
  154. package/esm/cramFile/file.js.map +1 -0
  155. package/esm/cramFile/index.d.ts +2 -0
  156. package/esm/cramFile/index.js +3 -0
  157. package/esm/cramFile/index.js.map +1 -0
  158. package/esm/cramFile/record.d.ts +79 -0
  159. package/esm/cramFile/record.js +297 -0
  160. package/esm/cramFile/record.js.map +1 -0
  161. package/esm/cramFile/sectionParsers.d.ts +18 -0
  162. package/esm/cramFile/sectionParsers.js +347 -0
  163. package/esm/cramFile/sectionParsers.js.map +1 -0
  164. package/esm/cramFile/slice/decodeRecord.d.ts +2 -0
  165. package/esm/cramFile/slice/decodeRecord.js +299 -0
  166. package/esm/cramFile/slice/decodeRecord.js.map +1 -0
  167. package/esm/cramFile/slice/index.d.ts +20 -0
  168. package/esm/cramFile/slice/index.js +364 -0
  169. package/esm/cramFile/slice/index.js.map +1 -0
  170. package/esm/cramFile/util.d.ts +5 -0
  171. package/esm/cramFile/util.js +161 -0
  172. package/esm/cramFile/util.js.map +1 -0
  173. package/esm/errors.d.ts +23 -0
  174. package/esm/errors.js +24 -0
  175. package/esm/errors.js.map +1 -0
  176. package/esm/index.d.ts +4 -0
  177. package/esm/index.js +5 -0
  178. package/esm/index.js.map +1 -0
  179. package/esm/indexedCramFile.d.ts +39 -0
  180. package/esm/indexedCramFile.js +155 -0
  181. package/esm/indexedCramFile.js.map +1 -0
  182. package/esm/io/bufferCache.d.ts +12 -0
  183. package/esm/io/bufferCache.js +54 -0
  184. package/esm/io/bufferCache.js.map +1 -0
  185. package/esm/io/index.d.ts +5 -0
  186. package/esm/io/index.js +24 -0
  187. package/esm/io/index.js.map +1 -0
  188. package/esm/io/localFile.d.ts +10 -0
  189. package/esm/io/localFile.js +31 -0
  190. package/esm/io/localFile.js.map +1 -0
  191. package/esm/io/remoteFile.d.ts +16 -0
  192. package/esm/io/remoteFile.js +64 -0
  193. package/esm/io/remoteFile.js.map +1 -0
  194. package/esm/rans/constants.d.ts +3 -0
  195. package/esm/rans/constants.js +5 -0
  196. package/esm/rans/constants.js.map +1 -0
  197. package/esm/rans/d04.d.ts +1 -0
  198. package/esm/rans/d04.js +67 -0
  199. package/esm/rans/d04.js.map +1 -0
  200. package/esm/rans/d14.d.ts +1 -0
  201. package/esm/rans/d14.js +52 -0
  202. package/esm/rans/d14.js.map +1 -0
  203. package/esm/rans/decoding.d.ts +30 -0
  204. package/esm/rans/decoding.js +118 -0
  205. package/esm/rans/decoding.js.map +1 -0
  206. package/esm/rans/frequencies.d.ts +2 -0
  207. package/esm/rans/frequencies.js +110 -0
  208. package/esm/rans/frequencies.js.map +1 -0
  209. package/esm/rans/index.d.ts +1 -0
  210. package/esm/rans/index.js +195 -0
  211. package/esm/rans/index.js.map +1 -0
  212. package/esm/sam.d.ts +1 -0
  213. package/esm/sam.js +16 -0
  214. package/esm/sam.js.map +1 -0
  215. package/esm/unzip-pako.d.ts +2 -0
  216. package/esm/unzip-pako.js +5 -0
  217. package/esm/unzip-pako.js.map +1 -0
  218. package/esm/unzip.d.ts +2 -0
  219. package/esm/unzip.js +3 -0
  220. package/esm/unzip.js.map +1 -0
  221. package/package.json +37 -35
package/CHANGELOG.md ADDED
@@ -0,0 +1,86 @@
1
+ # v1.6.1
2
+
3
+ - Explicitly use pako for browser bundle to help avoid buggy zlib polyfills
4
+
5
+ # v1.6.0
6
+
7
+ - Support CRAMv3.1 (thanks to @jkbonfield for contributing!)
8
+ - Support bzip codec
9
+ - Remove localFile from the browser bundle using "browser" package.json field
10
+ - Add esm module field in package.json
11
+
12
+ # v1.5.9
13
+
14
+ - Fix CRAM not downloading proper records for long reads (pt2, PR #84)
15
+
16
+ # v1.5.8
17
+
18
+ - Fix CRAM not downloading proper records for long reads (pt1, PR #85)
19
+
20
+ # v1.5.7
21
+
22
+ - Add getHeaderText to CRAM to get SAM header
23
+
24
+ # v1.5.6
25
+
26
+ - Remove unnecessary rethor win tinyMemoize error handler
27
+ - Avoid uncaught promise from constructor
28
+
29
+ # v1.5.5
30
+
31
+ - Fix ability to reload CRAM file after failure
32
+ - Check if BAI file incorrectly submitted as index for CRAM
33
+
34
+ # v1.5.4
35
+
36
+ - Fix handling of hard clipping
37
+
38
+ # v1.5.3
39
+
40
+ - Improved README
41
+ - Upgrade to babel 7
42
+ - Upgrade @gmod/binary-parser
43
+ - Add fix for 'b', 'q', and 'Q' readFeatures
44
+
45
+ # v1.5.2
46
+
47
+ - Fix off-by-one error in range query
48
+ - Add webpack cram-bundle.js
49
+
50
+ # v1.5.1
51
+
52
+ - Add fix for when mate is unmapped
53
+
54
+ # v1.5.0
55
+
56
+ - Add lossy-names support
57
+ - Fix for mate strand
58
+
59
+ # v1.4.3
60
+
61
+ - Make sure mate exists for unmated pair, can exist when coordinate slices of cram file are made via samtools view
62
+
63
+ # v1.4.2
64
+
65
+ - Switch to es6-promisify for ie11
66
+ - Switch to quick-lru instead of lru-cache for ie11
67
+
68
+ # v1.4.1
69
+
70
+ - Add maxInsertSize for viewAsPairs
71
+
72
+ # v1.4.0
73
+
74
+ - Add viewAsPairs implementation
75
+
76
+ # v1.3.0
77
+
78
+ - Fix tests in node 6
79
+ - Make cram record unique IDs start at 1 instead of 0 to always be truthy
80
+ - Implement gamma and subexp codecs
81
+
82
+ # v1.2.0
83
+
84
+ - Add `getReadBases` docs
85
+ - Rewrite seq calculation to be much faster
86
+ - Implement ref fetching for multi-ref slices
package/README.md CHANGED
@@ -1,15 +1,15 @@
1
1
  # @gmod/cram
2
2
 
3
- [![Generated with nod](https://img.shields.io/badge/generator-nod-2196F3.svg?style=flat-square)](https://github.com/diegohaz/nod)
4
3
  [![NPM version](https://img.shields.io/npm/v/@gmod/cram.svg?style=flat-square)](https://npmjs.org/package/@gmod/cram)
5
- [![Build Status](https://img.shields.io/travis/GMOD/cram-js/master.svg?style=flat-square)](https://travis-ci.org/GMOD/cram-js) [![Coverage Status](https://img.shields.io/codecov/c/github/GMOD/cram-js/master.svg?style=flat-square)](https://codecov.io/gh/GMOD/cram-js/branch/master) [![Greenkeeper badge](https://badges.greenkeeper.io/GMOD/cram-js.svg)](https://greenkeeper.io/)
4
+ [![Coverage Status](https://img.shields.io/codecov/c/github/GMOD/cram-js/master.svg?style=flat-square)](https://codecov.io/gh/GMOD/cram-js/branch/master)
5
+ [![Build Status](https://img.shields.io/github/workflow/status/GMOD/cram-js/Push/master?logo=github&style=flat-query)](https://github.com/GMOD/cram-js/actions?query=branch%3Amaster+workflow%3APush+)
6
6
 
7
7
  Read CRAM files (indexed or unindexed) with pure JS, works in node or in the browser.
8
8
 
9
- - Reads CRAM 3.x and 2.x
10
- - Does not read CRAM 1.x
11
- - Can use .crai indexes out of the box, for efficient sequence fetching, but also has an [index API](#craiindex) that would allow use with other index types
12
- - Does not implement bzip2 or lzma codecs (yet), as these are rarely used in-the-wild; if this is important to your use case, please file an issue
9
+ - Reads CRAM 3.x and 2.x (3.1 added in v1.6.0)
10
+ - Does not read CRAM 1.x
11
+ - Can use .crai indexes out of the box, for efficient sequence fetching, but also has an [index API](#craiindex) that would allow use with other index types
12
+ - Does implement bzip2 but not lzma codecs (yet); if this is important to your use case, please file an issue
13
13
 
14
14
  ## Install
15
15
 
@@ -24,101 +24,142 @@ $ yarn add @gmod/cram
24
24
  ```js
25
25
  const { IndexedCramFile, CramFile, CraiIndex } = require('@gmod/cram')
26
26
 
27
- //Use indexedfasta library for seqFetch, if using local file (see below)
28
- const { IndexedFasta, BgzipIndexedFasta } = require('@gmod/indexedfasta')
29
-
27
+ // Use indexedfasta library for seqFetch, if using local file (see below)
28
+ const { IndexedFasta, BgzipIndexedFasta } = require('@gmod/indexedfasta')
30
29
 
30
+ // this uses local file paths for node.js for IndexedFasta, for usages using
31
+ // remote URLs see indexedfasta docs for filehandles and
32
+ // https://github.com/gmod/generic-filehandle
31
33
  const t = new IndexedFasta({
32
34
  path: '/filesystem/yourfile.fa',
33
35
  faiPath: '/filesystem/yourfile.fa.fai',
34
- });
35
-
36
-
37
- // open local files
38
- const indexedFile = new IndexedCramFile({
39
- cramPath: '/filesystem/yourfile.cram',
40
- index: new CraiIndex({
41
- path: '/filesystem/yourfile.cram.crai'),
42
- }),
43
- seqFetch: async (seqId, start, end) => {
44
- // note:
45
- // * seqFetch should return a promise for a string, in this instance retrieved from IndexedFasta
46
- // * we use start-1 because cram-js uses 1-based but IndexedFasta uses 0-based coordinates
47
- // * the seqId is a numeric identifier
48
- return seq = await t.getSequence(seqId, start-1, end)
49
- }
50
- },
51
- checkSequenceMD5: false,
52
36
  })
53
37
 
54
38
  // example of fetching records from an indexed CRAM file.
55
- // NOTE: only numeric IDs for the reference sequence are accepted.
56
- // For indexedfasta the numeric ID is the order in which the sequence names appear in the header
39
+ // NOTE: only numeric IDs for the reference sequence are accepted.
40
+ // For indexedfasta the numeric ID is the order in which the sequence names
41
+ // appear in the header
57
42
 
58
43
  // Wrap in an async and then run
59
- run = async() => {
60
- const records = await indexedFile.getRecordsForRange(0, 10000, 20000)
44
+ run = async () => {
45
+ const idToName = []
46
+ const nameToId = {}
47
+
48
+ // example opening local files on node.js
49
+ // can also pass `cramUrl` (for the IndexedCramFile class), and `url` (for
50
+ // the CraiIndex) params to open remote URLs
51
+ //
52
+ // alternatively `cramFilehandle` (for the IndexedCramFile class) and
53
+ // `filehandle` (for the CraiIndex) can be used, see for examples
54
+ // https://github.com/gmod/generic-filehandle
55
+
56
+ const indexedFile = new IndexedCramFile({
57
+ cramPath: '/filesystem/yourfile.cram',
58
+ //or
59
+ //cramUrl: 'url/to/file.cram'
60
+ //cramFilehandle: a generic-filehandle or similar filehandle
61
+ index: new CraiIndex({
62
+ path: '/filesystem/yourfile.cram.crai',
63
+ // or
64
+ // url: 'url/to/file.cram.crai'
65
+ // filehandle: a generic-filehandle or similar filehandle
66
+ }),
67
+ seqFetch: async (seqId, start, end) => {
68
+ // note:
69
+ // * seqFetch should return a promise for a string, in this instance retrieved from IndexedFasta
70
+ // * we use start-1 because cram-js uses 1-based but IndexedFasta uses 0-based coordinates
71
+ // * the seqId is a numeric identifier, so we convert it back to a name with idToName
72
+ // * you can return an empty string from this function for testing if you want, but you may not get proper interpretation of record.readFeatures
73
+ return t.getSequence(idToName[seqId], start - 1, end)
74
+ },
75
+ checkSequenceMD5: false,
76
+ })
77
+ const samHeader = await indexedFile.cram.getSamHeader()
78
+
79
+ // use the @SQ lines in the header to figure out the
80
+ // mapping between ref ref ID numbers and names
81
+
82
+ const sqLines = samHeader.filter(l => l.tag === 'SQ')
83
+ sqLines.forEach((sqLine, refId) => {
84
+ sqLine.data.forEach(item => {
85
+ if (item.tag === 'SN') {
86
+ // this is the ref name
87
+ const refName = item.value
88
+ nameToId[refName] = refId
89
+ idToName[refId] = refName
90
+ }
91
+ })
92
+ })
93
+
94
+ const records = await indexedFile.getRecordsForRange(
95
+ nameToId['chr1'],
96
+ 10000,
97
+ 20000,
98
+ )
61
99
  records.forEach(record => {
62
100
  console.log(`got a record named ${record.readName}`)
63
- record.readFeatures.forEach(({ code, pos, refPos, ref, sub }) => {
64
- // process the "read features". this can be used similar to
65
- // CIGAR/MD strings in SAM. see CRAM specs for more details.
66
- if (code === 'X')
67
- console.log(
68
- `${
69
- record.readName
70
- } shows a base substitution of ${ref}->${sub} at ${refPos}`,
71
- )
72
- })
101
+ if (record.readFeatures != undefined) {
102
+ record.readFeatures.forEach(({ code, pos, refPos, ref, sub }) => {
103
+ // process the read features. this can be used similar to
104
+ // CIGAR/MD strings in SAM. see CRAM specs for more details.
105
+ if (code === 'X') {
106
+ console.log(
107
+ `${record.readName} shows a base substitution of ${ref}->${sub} at ${refPos}`,
108
+ )
109
+ }
110
+ })
111
+ }
73
112
  })
74
113
  }
75
114
 
76
115
  run()
77
116
 
78
-
79
117
  // can also pass `cramUrl` (for the IndexedCramFile class), and `url` (for the CraiIndex) params to open remote URLs
80
118
  // alternatively `cramFilehandle` (for the IndexedCramFile class) and `filehandle` (for the CraiIndex) can be used, see for examples https://github.com/gmod/generic-filehandle
81
119
  ```
82
120
 
121
+ You can use cram-js without NPM also with the cram-bundle.js. See the example directory for usage with script tag
122
+
83
123
  ## API (auto-generated)
84
124
 
85
- - [CramRecord](#cramrecord) - format of CRAM records returned by this API
86
- - [ReadFeatures](#readfeatures) - format of read features on records
87
- - [IndexedCramFile](#indexedcramfile) - indexed access into a CRAM file
88
- - [CramFile](#cramfile) - .cram API
89
- - [CraiIndex](#craiindex) - .crai index API
90
- - [Error Classes](#error-classes) - special error classes thrown by this API
125
+ - [CramRecord](#cramrecord) - format of CRAM records returned by this API
126
+ - [ReadFeatures](#readfeatures) - format of read features on records
127
+ - [IndexedCramFile](#indexedcramfile) - indexed access into a CRAM file
128
+ - [CramFile](#cramfile) - .cram API
129
+ - [CraiIndex](#craiindex) - .crai index API
130
+ - [Error Classes](#error-classes) - special error classes thrown by this API
91
131
 
92
132
  ### CramRecord
93
133
 
94
- These are the record objects returned by this API. Much of the data
95
- is stored in them as simple object entries, but there are some accessor
96
- methods used for conveniently getting the values of each of the flags in
97
- the `flags` and `cramFlags` fields.
98
-
99
- #### Static fields
100
-
101
- - **flags** (`number`): the SAM bit-flags field, see the SAM spec for interpretation. Some of the `is*` methods below interpret this field.
102
- - **cramFlags** (`number`): the CRAM-specific bit-flags field, see the CRAM spec for interpretation. Some of the `is*` methods below interpret this field.
103
- - **sequenceId** (`number`): the ID number of the record's reference sequence
104
- - **readLength** (`number`): length of the read in bases
105
- - **alignmentStart** (`number`): start coordinate of the alignment on the reference in 1-based closed coordinates
106
- - **readGroupId** (`number`): ID number of the read group, or -1 if none
107
- - **readName** (`number`): name of the read (string)
108
- - **templateSize** (`number`): for paired sequencing, the total size of the template
109
- - **readFeatures** (`array[ReadFeature]`): array of read features showing insertions, deletions, mismatches, etc. See [ReadFeatures](#readfeatures) for their format.
110
- - **lengthOnRef** (`number`): span of the alignment along the reference sequence
111
- - **mappingQuality** (`number`): SAM mapping quality
112
- - **qualityScores** (`array[number]`): array of numeric quality scores
113
- - **uniqueId** (`number`): unique ID number of the record within the file
114
- - **mate** (`object`)
115
- - **flags** (`number`): CRAM mapping flags for the mate. See CRAM spec for interpretation. Some of the `is*` methods below interpret this field.
116
- - **sequenceId** (`number`): reference sequence ID for the mate mapping
117
- - **alignmentStart** (`number`): start coordinate of the mate mapping. 1-based coordinates.
118
-
119
134
  <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
120
135
 
121
- #### Methods
136
+ ##### Table of Contents
137
+
138
+ - [CramRecord](#cramrecord)
139
+ - [isPaired](#ispaired)
140
+ - [isProperlyPaired](#isproperlypaired)
141
+ - [isSegmentUnmapped](#issegmentunmapped)
142
+ - [isMateUnmapped](#ismateunmapped)
143
+ - [isReverseComplemented](#isreversecomplemented)
144
+ - [isMateReverseComplemented](#ismatereversecomplemented)
145
+ - [isRead1](#isread1)
146
+ - [isRead2](#isread2)
147
+ - [isSecondary](#issecondary)
148
+ - [isFailedQc](#isfailedqc)
149
+ - [isDuplicate](#isduplicate)
150
+ - [isSupplementary](#issupplementary)
151
+ - [isDetached](#isdetached)
152
+ - [hasMateDownStream](#hasmatedownstream)
153
+ - [isPreservingQualityScores](#ispreservingqualityscores)
154
+ - [isUnknownBases](#isunknownbases)
155
+ - [getReadBases](#getreadbases)
156
+ - [getPairOrientation](#getpairorientation)
157
+ - [addReferenceSequence](#addreferencesequence)
158
+ - [Parameters](#parameters)
159
+
160
+ #### CramRecord
161
+
162
+ Class of each CRAM record returned by this API.
122
163
 
123
164
  ##### isPaired
124
165
 
@@ -190,6 +231,12 @@ Get the original sequence of this read.
190
231
 
191
232
  Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** sequence basepairs
192
233
 
234
+ ##### getPairOrientation
235
+
236
+ Get the pair orientation of a paired read. Adapted from igv.js
237
+
238
+ Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** of paired orientatin
239
+
193
240
  ##### addReferenceSequence
194
241
 
195
242
  Annotates this feature with the given reference sequence basepair
@@ -197,13 +244,15 @@ information. This will add a `sub` and a `ref` item to base
197
244
  subsitution read features given the actual substituted and reference
198
245
  base pairs, and will make the `getReadSequence()` method work.
199
246
 
200
- **Parameters**
247
+ ###### Parameters
201
248
 
202
- - `refRegion` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
203
- - `refRegion.start` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
204
- - `refRegion.end` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
205
- - `refRegion.seq` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
206
- - `compressionScheme` **CramContainerCompressionScheme**
249
+ - `refRegion` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
250
+
251
+ - `refRegion.start` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
252
+ - `refRegion.end` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
253
+ - `refRegion.seq` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
254
+
255
+ - `compressionScheme` **CramContainerCompressionScheme**
207
256
 
208
257
  Returns **[undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined)** nothing
209
258
 
@@ -220,41 +269,44 @@ The feature objects appearing in the `readFeatures` member of CramRecord objects
220
269
 
221
270
  ### IndexedCramFile
222
271
 
223
- The pairing of an index and a CramFile. Supports efficient fetching of records for sections of reference sequences.
224
-
225
272
  <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
226
273
 
227
274
  ##### Table of Contents
228
275
 
229
- - [constructor](#constructor)
230
- - [getRecordsForRange](#getrecordsforrange)
231
- - [hasDataForReferenceSequence](#hasdataforreferencesequence)
276
+ - [constructor](#constructor)
277
+ - [Parameters](#parameters)
278
+ - [getRecordsForRange](#getrecordsforrange)
279
+ - [Parameters](#parameters-1)
280
+ - [hasDataForReferenceSequence](#hasdataforreferencesequence)
281
+ - [Parameters](#parameters-2)
232
282
 
233
283
  #### constructor
234
284
 
235
- **Parameters**
285
+ ##### Parameters
236
286
 
237
- - `args` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
238
- - `args.cram` **CramFile**
239
- - `args.index` **Index-like** object that supports getEntriesForRange(seqId,start,end) -> Promise\[Array[index entries]]
240
- - `args.cacheSize` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** optional maximum number of CRAM records to cache. default 20,000
241
- - `args.fetchSizeLimit` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** optional maximum number of bytes to fetch in a single getRecordsForRange call. Default 3 MiB.
242
- - `args.checkSequenceMD5` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** default true. if false, disables verifying the MD5
243
- checksum of the reference sequence underlying a slice. In some applications, this check can cause an inconvenient amount (many megabases) of sequences to be fetched.
287
+ - `args` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
288
+
289
+ - `args.cram` **CramFile**
290
+ - `args.index` **Index-like** object that supports getEntriesForRange(seqId,start,end) -> Promise\[Array\[index entries]]
291
+ - `args.cacheSize` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** optional maximum number of CRAM records to cache. default 20,000
292
+ - `args.fetchSizeLimit` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** optional maximum number of bytes to fetch in a single getRecordsForRange call. Default 3 MiB.
293
+ - `args.checkSequenceMD5` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** default true. if false, disables verifying the MD5
294
+ checksum of the reference sequence underlying a slice. In some applications, this check can cause an inconvenient amount (many megabases) of sequences to be fetched.
244
295
 
245
296
  #### getRecordsForRange
246
297
 
247
- **Parameters**
298
+ ##### Parameters
248
299
 
249
- - `seq` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** numeric ID of the reference sequence
250
- - `start` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** start of the range of interest. 1-based closed coordinates.
251
- - `end` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** end of the range of interest. 1-based closed coordinates.
300
+ - `seq` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** numeric ID of the reference sequence
301
+ - `start` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** start of the range of interest. 1-based closed coordinates.
302
+ - `end` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** end of the range of interest. 1-based closed coordinates.
303
+ - `opts` (optional, default `{}`)
252
304
 
253
305
  #### hasDataForReferenceSequence
254
306
 
255
- **Parameters**
307
+ ##### Parameters
256
308
 
257
- - `seqId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
309
+ - `seqId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
258
310
 
259
311
  Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** true if the CRAM file contains data for the given
260
312
  reference sequence numerical ID
@@ -265,54 +317,56 @@ reference sequence numerical ID
265
317
 
266
318
  ##### Table of Contents
267
319
 
268
- - [constructor](#constructor)
269
- - [containerCount](#containercount)
320
+ - [constructor](#constructor)
321
+ - [Parameters](#parameters)
322
+ - [containerCount](#containercount)
270
323
 
271
324
  #### constructor
272
325
 
273
- **Parameters**
326
+ ##### Parameters
274
327
 
275
- - `args` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
276
- - `args.filehandle` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** a filehandle that implements the stat() and
277
- read() methods of the Node filehandle API <https://nodejs.org/api/fs.html#fs_class_filehandle>
278
- - `args.path` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** path to the cram file
279
- - `args.url` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** url for the cram file. also supports file:// urls for local files
280
- - `args.seqFetch` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** a function with signature
281
- `(seqId, startCoordinate, endCoordinate)` that returns a promise for a string of sequence bases
282
- - `args.cacheSize` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** optional maximum number of CRAM records to cache. default 20,000
283
- - `args.checkSequenceMD5` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** default true. if false, disables verifying the MD5
284
- checksum of the reference sequence underlying a slice. In some applications, this check can cause an inconvenient amount (many megabases) of sequences to be fetched.
328
+ - `args` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
285
329
 
286
- #### containerCount
330
+ - `args.filehandle` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** a filehandle that implements the stat() and
331
+ read() methods of the Node filehandle API <https://nodejs.org/api/fs.html#fs_class_filehandle>
332
+ - `args.path` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** path to the cram file
333
+ - `args.url` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** url for the cram file. also supports file:// urls for local files
334
+ - `args.seqFetch` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** a function with signature
335
+ `(seqId, startCoordinate, endCoordinate)` that returns a promise for a string of sequence bases
336
+ - `args.cacheSize` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** optional maximum number of CRAM records to cache. default 20,000
337
+ - `args.checkSequenceMD5` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** default true. if false, disables verifying the MD5
338
+ checksum of the reference sequence underlying a slice. In some applications, this check can cause an inconvenient amount (many megabases) of sequences to be fetched.
287
339
 
288
- Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the number of containers in the file
340
+ #### containerCount
289
341
 
290
342
  ### CraiIndex
291
343
 
292
- Represents a .crai index.
293
-
294
344
  <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
295
345
 
296
346
  ##### Table of Contents
297
347
 
298
- - [constructor](#constructor)
299
- - [hasDataForReferenceSequence](#hasdataforreferencesequence)
300
- - [getEntriesForRange](#getentriesforrange)
348
+ - [constructor](#constructor)
349
+ - [Parameters](#parameters)
350
+ - [hasDataForReferenceSequence](#hasdataforreferencesequence)
351
+ - [Parameters](#parameters-1)
352
+ - [getEntriesForRange](#getentriesforrange)
353
+ - [Parameters](#parameters-2)
301
354
 
302
355
  #### constructor
303
356
 
304
- **Parameters**
357
+ ##### Parameters
305
358
 
306
- - `args` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
307
- - `args.path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?**
308
- - `args.url` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?**
309
- - `args.filehandle` **FileHandle?**
359
+ - `args` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
360
+
361
+ - `args.path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?**
362
+ - `args.url` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?**
363
+ - `args.filehandle` **FileHandle?**
310
364
 
311
365
  #### hasDataForReferenceSequence
312
366
 
313
- **Parameters**
367
+ ##### Parameters
314
368
 
315
- - `seqId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
369
+ - `seqId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
316
370
 
317
371
  Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** true if the index contains entries for
318
372
  the given reference sequence ID, false otherwise
@@ -321,60 +375,16 @@ the given reference sequence ID, false otherwise
321
375
 
322
376
  fetch index entries for the given range
323
377
 
324
- **Parameters**
378
+ ##### Parameters
325
379
 
326
- - `seqId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
327
- - `queryStart` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
328
- - `queryEnd` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
380
+ - `seqId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
381
+ - `queryStart` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
382
+ - `queryEnd` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
329
383
 
330
384
  Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** promise for
331
385
  an array of objects of the form
332
386
  `{start, span, containerStart, sliceStart, sliceBytes }`
333
387
 
334
- #### Error Classes
335
-
336
- `@gmod/cram/errors` contains some special error classes thrown by cram-js. A list of the error classes is below.
337
-
338
- <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
339
-
340
- ##### Table of Contents
341
-
342
- - [CramUnimplementedError](#cramunimplementederror)
343
- - [CramMalformedError](#crammalformederror)
344
- - [CramBufferOverrunError](#crambufferoverrunerror)
345
- - [CramSizeLimitError](#cramsizelimiterror)
346
- - [CramArgumentError](#cramargumenterror)
347
-
348
- #### CramUnimplementedError
349
-
350
- **Extends Error**
351
-
352
- Error caused by encountering a part of the CRAM spec that has not yet been implemented
353
-
354
- #### CramMalformedError
355
-
356
- **Extends CramError**
357
-
358
- An error caused by malformed data.
359
-
360
- #### CramBufferOverrunError
361
-
362
- **Extends CramMalformedError**
363
-
364
- An error caused by attempting to read beyond the end of the defined data.
365
-
366
- #### CramSizeLimitError
367
-
368
- **Extends CramError**
369
-
370
- An error caused by data being too big, exceeding a size limit.
371
-
372
- #### CramArgumentError
373
-
374
- **Extends CramError**
375
-
376
- An invalid argument was supplied to a cram-js method or object.
377
-
378
388
  ### CramUnimplementedError
379
389
 
380
390
  **Extends Error**
@@ -0,0 +1,37 @@
1
+ export default class CraiIndex {
2
+ /**
3
+ *
4
+ * @param {object} args
5
+ * @param {string} [args.path]
6
+ * @param {string} [args.url]
7
+ * @param {FileHandle} [args.filehandle]
8
+ */
9
+ constructor(args: {
10
+ path?: string | undefined;
11
+ url?: string | undefined;
12
+ filehandle?: any;
13
+ });
14
+ _parseCache: AbortablePromiseCache<any, any>;
15
+ readFile: any;
16
+ parseIndex(): any;
17
+ getIndex(opts?: {}): Promise<any>;
18
+ /**
19
+ * @param {number} seqId
20
+ * @returns {Promise} true if the index contains entries for
21
+ * the given reference sequence ID, false otherwise
22
+ */
23
+ hasDataForReferenceSequence(seqId: number): Promise<any>;
24
+ /**
25
+ * fetch index entries for the given range
26
+ *
27
+ * @param {number} seqId
28
+ * @param {number} queryStart
29
+ * @param {number} queryEnd
30
+ *
31
+ * @returns {Promise} promise for
32
+ * an array of objects of the form
33
+ * `{start, span, containerStart, sliceStart, sliceBytes }`
34
+ */
35
+ getEntriesForRange(seqId: number, queryStart: number, queryEnd: number): Promise<any>;
36
+ }
37
+ import AbortablePromiseCache from "abortable-promise-cache";