@gmod/cram 1.5.9 → 1.6.2

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 (258) hide show
  1. package/CHANGELOG.md +90 -0
  2. package/README.md +182 -172
  3. package/dist/craiIndex.d.ts +37 -0
  4. package/dist/craiIndex.js +196 -301
  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 +38 -35
  222. package/src/craiIndex.js +180 -0
  223. package/src/cramFile/codecs/_base.js +49 -0
  224. package/src/cramFile/codecs/beta.js +23 -0
  225. package/src/cramFile/codecs/byteArrayLength.js +55 -0
  226. package/src/cramFile/codecs/byteArrayStop.js +50 -0
  227. package/src/cramFile/codecs/external.js +54 -0
  228. package/src/cramFile/codecs/gamma.js +30 -0
  229. package/src/cramFile/codecs/huffman.js +137 -0
  230. package/src/cramFile/codecs/index.js +38 -0
  231. package/src/cramFile/codecs/subexp.js +32 -0
  232. package/src/cramFile/constants.js +55 -0
  233. package/src/cramFile/container/compressionScheme.js +144 -0
  234. package/src/cramFile/container/index.js +119 -0
  235. package/src/cramFile/file.js +347 -0
  236. package/src/cramFile/index.js +3 -0
  237. package/src/cramFile/record.js +337 -0
  238. package/src/cramFile/sectionParsers.js +379 -0
  239. package/src/cramFile/slice/decodeRecord.js +362 -0
  240. package/src/cramFile/slice/index.js +497 -0
  241. package/src/cramFile/util.js +169 -0
  242. package/src/errors.js +22 -0
  243. package/src/index.js +5 -0
  244. package/src/indexedCramFile.js +191 -0
  245. package/src/io/bufferCache.js +66 -0
  246. package/src/io/index.js +26 -0
  247. package/src/io/localFile.js +35 -0
  248. package/src/io/remoteFile.js +71 -0
  249. package/src/rans/README.md +1 -0
  250. package/src/rans/constants.js +5 -0
  251. package/src/rans/d04.js +83 -0
  252. package/src/rans/d14.js +59 -0
  253. package/src/rans/decoding.js +141 -0
  254. package/src/rans/frequencies.js +121 -0
  255. package/src/rans/index.js +249 -0
  256. package/src/sam.js +15 -0
  257. package/src/unzip-pako.ts +5 -0
  258. package/src/unzip.ts +2 -0
@@ -1,51 +1,64 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
4
-
5
- var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
6
-
7
- var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
8
-
9
- var _assign = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/assign"));
10
-
11
- var _require = require('@gmod/binary-parser'),
12
- Parser = _require.Parser;
13
-
14
- var singleItf8 = new Parser().itf8();
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSectionParsers = exports.cramFileDefinition = void 0;
4
+ var binary_parser_1 = require("@gmod/binary-parser");
5
+ var singleItf8 = new binary_parser_1.Parser().itf8();
15
6
  var cramFileDefinition = {
16
- parser: new Parser().string('magic', {
17
- length: 4
18
- }).uint8('majorVersion').uint8('minorVersion').string('fileId', {
19
- length: 20,
20
- stripNull: true
21
- }),
22
- maxLength: 26
7
+ parser: new binary_parser_1.Parser()
8
+ .string('magic', { length: 4 })
9
+ .uint8('majorVersion')
10
+ .uint8('minorVersion')
11
+ .string('fileId', { length: 20, stripNull: true }),
12
+ maxLength: 26,
23
13
  };
14
+ exports.cramFileDefinition = cramFileDefinition;
24
15
  var cramBlockHeader = {
25
- parser: new Parser().uint8('compressionMethod', {
26
- formatter:
27
- /* istanbul ignore next */
28
- function formatter(b) {
29
- var method = ['raw', 'gzip', 'bzip2', 'lzma', 'rans'][b];
30
- if (!method) throw new Error("compression method number ".concat(b, " not implemented"));
31
- return method;
32
- }
33
- }).uint8('contentType', {
34
- formatter:
35
- /* istanbul ignore next */
36
- function formatter(b) {
37
- var type = ['FILE_HEADER', 'COMPRESSION_HEADER', 'MAPPED_SLICE_HEADER', 'UNMAPPED_SLICE_HEADER', // < only used in cram v1
38
- 'EXTERNAL_DATA', 'CORE_DATA'][b];
39
- if (!type) throw new Error("invalid block content type id ".concat(b));
40
- return type;
41
- }
42
- }).itf8('contentId').itf8('compressedSize').itf8('uncompressedSize'),
43
- maxLength: 17
16
+ parser: new binary_parser_1.Parser()
17
+ .uint8('compressionMethod', {
18
+ formatter: /* istanbul ignore next */ function (/* istanbul ignore next */ b) {
19
+ var method = [
20
+ 'raw',
21
+ 'gzip',
22
+ 'bzip2',
23
+ 'lzma',
24
+ 'rans',
25
+ 'rans4x16',
26
+ 'arith',
27
+ 'fqzcomp',
28
+ 'tok3',
29
+ ][b];
30
+ if (!method) {
31
+ throw new Error("compression method number ".concat(b, " not implemented"));
32
+ }
33
+ return method;
34
+ },
35
+ })
36
+ .uint8('contentType', {
37
+ formatter: /* istanbul ignore next */ function (/* istanbul ignore next */ b) {
38
+ var type = [
39
+ 'FILE_HEADER',
40
+ 'COMPRESSION_HEADER',
41
+ 'MAPPED_SLICE_HEADER',
42
+ 'UNMAPPED_SLICE_HEADER',
43
+ 'EXTERNAL_DATA',
44
+ 'CORE_DATA',
45
+ ][b];
46
+ if (!type) {
47
+ throw new Error("invalid block content type id ".concat(b));
48
+ }
49
+ return type;
50
+ },
51
+ })
52
+ .itf8('contentId')
53
+ .itf8('compressedSize')
54
+ .itf8('uncompressedSize'),
55
+ maxLength: 17,
44
56
  };
45
57
  var cramBlockCrc32 = {
46
- parser: new Parser().uint32('crc32'),
47
- maxLength: 4
48
- }; // const ENCODING_NAMES = [
58
+ parser: new binary_parser_1.Parser().uint32('crc32'),
59
+ maxLength: 4,
60
+ };
61
+ // const ENCODING_NAMES = [
49
62
  // 'NULL', // 0
50
63
  // 'EXTERNAL', // 1
51
64
  // 'GOLOMB', // 2
@@ -57,334 +70,283 @@ var cramBlockCrc32 = {
57
70
  // 'GOLOMB_RICE', // 8
58
71
  // 'GAMMA', // 9
59
72
  // ]
60
-
61
- var cramTagDictionary = new Parser().itf8('size').buffer('ents', {
62
- length: 'size',
63
- formatter:
64
- /* istanbul ignore next */
65
- function formatter(buffer) {
66
- function makeTagSet(stringStart, stringEnd) {
67
- var str = buffer.toString('utf8', stringStart, stringEnd);
68
- var tags = [];
69
-
70
- for (var _i = 0; _i < str.length; _i += 3) {
71
- tags.push(str.substr(_i, 3));
72
- }
73
-
74
- return tags;
75
- }
76
- /* eslint-disable */
77
-
78
-
79
- var tagSets = [];
80
- var stringStart = 0;
81
- var i;
82
- /* eslint-enable */
83
-
84
- for (i = 0; i < buffer.length; i += 1) {
85
- if (!buffer[i]) {
86
- tagSets.push(makeTagSet(stringStart, i));
87
- stringStart = i + 1;
88
- }
89
- }
90
-
91
- if (i > stringStart) tagSets.push(makeTagSet(stringStart, i));
92
- return tagSets;
93
- }
94
- }); // const cramPreservationMapKeys = 'XX RN AP RR SM TD'.split(' ')
95
-
96
- var parseByteAsBool = new Parser().uint8(null, {
97
- formatter:
98
- /* istanbul ignore next */
99
- function formatter(val) {
100
- return !!val;
101
- }
102
- });
103
- var cramPreservationMap = new Parser().itf8('mapSize').itf8('mapCount').array('ents', {
104
- length: 'mapCount',
105
- type: new Parser().string('key', {
106
- length: 2,
107
- stripNull: false // formatter: val => cramPreservationMapKeys[val] || 0,
108
-
109
- }).choice('value', {
110
- tag: 'key',
111
- choices: {
112
- MI: parseByteAsBool,
113
- UI: parseByteAsBool,
114
- PI: parseByteAsBool,
115
- RN: parseByteAsBool,
116
- AP: parseByteAsBool,
117
- RR: parseByteAsBool,
118
- SM: new Parser().array(null, {
119
- type: 'uint8',
120
- length: 5
121
- }),
122
- TD: new Parser().nest(null, {
123
- type: cramTagDictionary,
124
- formatter:
125
- /* istanbul ignore next */
126
- function formatter(data) {
127
- return data.ents;
73
+ var cramTagDictionary = new binary_parser_1.Parser().itf8('size').buffer('ents', {
74
+ length: 'size',
75
+ formatter: /* istanbul ignore next */ function (/* istanbul ignore next */ buffer) {
76
+ function makeTagSet(stringStart, stringEnd) {
77
+ var str = buffer.toString('utf8', stringStart, stringEnd);
78
+ var tags = [];
79
+ for (var i_1 = 0; i_1 < str.length; i_1 += 3) {
80
+ tags.push(str.substr(i_1, 3));
81
+ }
82
+ return tags;
128
83
  }
129
- })
130
- }
131
- })
84
+ /* eslint-disable */
85
+ var tagSets = [];
86
+ var stringStart = 0;
87
+ var i;
88
+ /* eslint-enable */
89
+ for (i = 0; i < buffer.length; i += 1) {
90
+ if (!buffer[i]) {
91
+ tagSets.push(makeTagSet(stringStart, i));
92
+ stringStart = i + 1;
93
+ }
94
+ }
95
+ if (i > stringStart) {
96
+ tagSets.push(makeTagSet(stringStart, i));
97
+ }
98
+ return tagSets;
99
+ },
100
+ });
101
+ // const cramPreservationMapKeys = 'XX RN AP RR SM TD'.split(' ')
102
+ var parseByteAsBool = new binary_parser_1.Parser().uint8(null, {
103
+ formatter: /* istanbul ignore next */ function (/* istanbul ignore next */ val) { return !!val; },
104
+ });
105
+ var cramPreservationMap = new binary_parser_1.Parser()
106
+ .itf8('mapSize')
107
+ .itf8('mapCount')
108
+ .array('ents', {
109
+ length: 'mapCount',
110
+ type: new binary_parser_1.Parser()
111
+ .string('key', {
112
+ length: 2,
113
+ stripNull: false,
114
+ // formatter: val => cramPreservationMapKeys[val] || 0,
115
+ })
116
+ .choice('value', {
117
+ tag: 'key',
118
+ choices: {
119
+ MI: parseByteAsBool,
120
+ UI: parseByteAsBool,
121
+ PI: parseByteAsBool,
122
+ RN: parseByteAsBool,
123
+ AP: parseByteAsBool,
124
+ RR: parseByteAsBool,
125
+ SM: new binary_parser_1.Parser().array(null, { type: 'uint8', length: 5 }),
126
+ TD: new binary_parser_1.Parser().nest(null, {
127
+ type: cramTagDictionary,
128
+ formatter: /* istanbul ignore next */ function (/* istanbul ignore next */ data) { return data.ents; },
129
+ }),
130
+ },
131
+ }),
132
132
  });
133
133
  /* istanbul ignore next */
134
-
135
134
  function formatMap(data) {
136
- var map = {};
137
-
138
- for (var i = 0; i < data.ents.length; i += 1) {
139
- var _data$ents$i = data.ents[i],
140
- key = _data$ents$i.key,
141
- value = _data$ents$i.value;
142
- if (map[key]) console.warn("duplicate key ".concat(key, " in map"));
143
- map[key] = value;
144
- }
145
-
146
- return map;
135
+ var map = {};
136
+ for (var i = 0; i < data.ents.length; i += 1) {
137
+ var _a = data.ents[i], key = _a.key, value = _a.value;
138
+ if (map[key]) {
139
+ console.warn("duplicate key ".concat(key, " in map"));
140
+ }
141
+ map[key] = value;
142
+ }
143
+ return map;
147
144
  }
148
-
149
145
  var unversionedParsers = {
150
- cramFileDefinition: cramFileDefinition,
151
- cramBlockHeader: cramBlockHeader,
152
- cramBlockCrc32: cramBlockCrc32
153
- }; // each of these is a function of the major and minor version
154
-
146
+ cramFileDefinition: cramFileDefinition,
147
+ cramBlockHeader: cramBlockHeader,
148
+ cramBlockCrc32: cramBlockCrc32,
149
+ };
150
+ // each of these is a function of the major and minor version
155
151
  var versionedParsers = {
156
- // assemble a section parser for the unmapped slice header, with slight
157
- // variations depending on the major version of the cram file
158
- cramUnmappedSliceHeader: function cramUnmappedSliceHeader(majorVersion) {
159
- var maxLength = 0;
160
- var parser = new Parser().itf8('numRecords');
161
- maxLength += 5; // recordCounter is itf8 in a CRAM v2 file, absent in CRAM v1
162
-
163
- if (majorVersion >= 3) {
164
- parser = parser.ltf8('recordCounter');
165
- maxLength += 9;
166
- } else if (majorVersion === 2) {
167
- parser = parser.itf8('recordCounter');
168
- maxLength += 5;
169
- }
170
-
171
- parser = parser.itf8('numBlocks').itf8('numContentIds').array('contentIds', {
172
- type: singleItf8,
173
- length: 'numContentIds'
174
- });
175
- maxLength += 5 * 2; // + numContentIds*5
176
- // the md5 sum is missing in cram v1
177
-
178
- if (majorVersion >= 2) {
179
- parser = parser.array('md5', {
180
- type: 'uint8',
181
- length: 16
182
- });
183
- maxLength += 16;
184
- }
185
-
186
- var maxLengthFunc = function maxLengthFunc(numContentIds) {
187
- return maxLength + numContentIds * 5;
188
- };
189
-
190
- return {
191
- parser: parser,
192
- maxLength: maxLengthFunc
193
- }; // : p, maxLength: numContentIds => 5 + 9 + 5 * 2 + 5 * numContentIds + 16 }
194
- },
195
- // assembles a section parser for the unmapped slice header, with slight
196
- // variations depending on the major version of the cram file
197
- cramMappedSliceHeader: function cramMappedSliceHeader(majorVersion) {
198
- var parser = new Parser().itf8('refSeqId').itf8('refSeqStart').itf8('refSeqSpan').itf8('numRecords');
199
- var maxLength = 5 * 4;
200
-
201
- if (majorVersion >= 3) {
202
- parser = parser.ltf8('recordCounter');
203
- maxLength += 9;
204
- } else if (majorVersion === 2) {
205
- parser = parser.itf8('recordCounter');
206
- maxLength += 5;
207
- }
208
-
209
- parser = parser.itf8('numBlocks').itf8('numContentIds').array('contentIds', {
210
- type: singleItf8,
211
- length: 'numContentIds'
212
- }).itf8('refBaseBlockId');
213
- maxLength += 5 * 3; // the md5 sum is missing in cram v1
214
-
215
- if (majorVersion >= 2) {
216
- parser = parser.array('md5', {
217
- type: 'uint8',
218
- length: 16
219
- });
220
- maxLength += 16;
221
- }
222
-
223
- var maxLengthFunc = function maxLengthFunc(numContentIds) {
224
- return maxLength + numContentIds * 5;
225
- };
226
-
227
- return {
228
- parser: parser,
229
- maxLength: maxLengthFunc
230
- };
231
- },
232
- cramEncoding: function cramEncoding(majorVersion) {
233
- var parser = new Parser().namely('cramEncoding').itf8('codecId').itf8('parametersBytes').choice('parameters', {
234
- tag: 'codecId',
235
- choices: {
236
- 0: new Parser(),
237
- // NULL
238
- 1: new Parser().itf8('blockContentId'),
239
- // EXTERNAL
240
- 2: new Parser().itf8('offset').itf8('M'),
241
- // GOLOMB,
242
- // HUFFMAN_INT
243
- 3: Parser.start().itf8('numCodes').array('symbols', {
244
- length: 'numCodes',
245
- type: singleItf8
246
- }).itf8('numLengths').array('bitLengths', {
247
- length: 'numLengths',
248
- type: singleItf8
249
- }),
250
- 4: Parser.start() // BYTE_ARRAY_LEN
251
- .nest('lengthsEncoding', {
252
- type: 'cramEncoding'
253
- }).nest('valuesEncoding', {
254
- type: 'cramEncoding'
255
- }),
256
- // BYTE_ARRAY_STOP is a little different for CRAM v1
257
- 5: new Parser().uint8('stopByte')[majorVersion > 1 ? 'itf8' : 'int']('blockContentId'),
258
- 6: new Parser().itf8('offset').itf8('length'),
259
- // BETA
260
- 7: new Parser().itf8('offset').itf8('K'),
261
- // SUBEXP
262
- 8: new Parser().itf8('offset').itf8('log2m'),
263
- // GOLOMB_RICE
264
- 9: new Parser().itf8('offset') // GAMMA
265
-
266
- }
267
- });
268
- return {
269
- parser: parser
270
- };
271
- },
272
- cramDataSeriesEncodingMap: function cramDataSeriesEncodingMap(majorVersion) {
273
- return new Parser().itf8('mapSize').itf8('mapCount').array('ents', {
274
- length: 'mapCount',
275
- type: new Parser().string('key', {
276
- length: 2,
277
- stripNull: false
278
- }).nest('value', {
279
- type: this.cramEncoding(majorVersion).parser
280
- })
281
- });
282
- },
283
- cramTagEncodingMap: function cramTagEncodingMap(majorVersion) {
284
- return new Parser().itf8('mapSize').itf8('mapCount').array('ents', {
285
- length: 'mapCount',
286
- type: new Parser().itf8('key', {
287
- formatter:
288
- /* istanbul ignore next */
289
- function formatter(integerRepresentation) {
290
- return (
291
- /* istanbul ignore next */
292
- String.fromCharCode(integerRepresentation >> 16 & 0xff) + String.fromCharCode(integerRepresentation >> 8 & 0xff) + String.fromCharCode(integerRepresentation & 0xff)
293
- );
152
+ // assemble a section parser for the unmapped slice header, with slight
153
+ // variations depending on the major version of the cram file
154
+ cramUnmappedSliceHeader: function (majorVersion) {
155
+ var maxLength = 0;
156
+ var parser = new binary_parser_1.Parser().itf8('numRecords');
157
+ maxLength += 5;
158
+ // recordCounter is itf8 in a CRAM v2 file, absent in CRAM v1
159
+ if (majorVersion >= 3) {
160
+ parser = parser.ltf8('recordCounter');
161
+ maxLength += 9;
294
162
  }
295
- }).nest('value', {
296
- type: this.cramEncoding(majorVersion).parser
297
- })
298
- });
299
- },
300
- cramCompressionHeader: function cramCompressionHeader(majorVersion) {
301
- var parser = new Parser(); // TODO: if we want to support CRAM v1, we will need to refactor
302
- // compression header into 2 parts to parse the landmarks,
303
- // like the container header
304
-
305
- parser = parser.nest('preservation', {
306
- type: cramPreservationMap,
307
- formatter: formatMap
308
- }).nest('dataSeriesEncoding', {
309
- type: this.cramDataSeriesEncodingMap(majorVersion),
310
- formatter: formatMap
311
- }).nest('tagEncoding', {
312
- type: this.cramTagEncodingMap(majorVersion),
313
- formatter: formatMap
314
- });
315
- return {
316
- parser: parser
317
- };
318
- },
319
- cramContainerHeader1: function cramContainerHeader1(majorVersion) {
320
- var parser = new Parser().int32('length') // byte size of the container data (blocks)
321
- .itf8('refSeqId') // reference sequence identifier, -1 for unmapped reads, -2 for multiple reference sequences
322
- .itf8('refSeqStart') // the alignment start position or 0 for unmapped reads
323
- .itf8('alignmentSpan') // the length of the alignment or 0 for unmapped reads
324
- .itf8('numRecords'); // number of records in the container
325
-
326
- var maxLength = 4 + 5 * 4;
327
-
328
- if (majorVersion >= 3) {
329
- parser = parser.ltf8('recordCounter'); // 1-based sequential index of records in the file/stream.
330
-
331
- maxLength += 9;
332
- } else if (majorVersion === 2) {
333
- parser = parser.itf8('recordCounter');
334
- maxLength += 5;
335
- }
336
-
337
- if (majorVersion > 1) {
338
- parser = parser.ltf8('numBases'); // number of read bases
339
-
340
- maxLength += 9;
341
- }
342
-
343
- parser = parser.itf8('numBlocks') // the number of blocks
344
- .itf8('numLandmarks'); // the number of landmarks
345
-
346
- maxLength += 5 + 5;
347
- return {
348
- parser: parser,
349
- maxLength: maxLength
350
- };
351
- },
352
- cramContainerHeader2: function cramContainerHeader2(majorVersion) {
353
- var parser = new Parser().itf8('numLandmarks') // the number of blocks
354
- // Each integer value of this array is a byte offset
355
- // into the blocks byte array. Landmarks are used for
356
- // random access indexing.
357
- .array('landmarks', {
358
- type: new Parser().itf8(),
359
- length: 'numLandmarks'
360
- });
361
- var crcLength = 0;
362
-
363
- if (majorVersion >= 3) {
364
- parser = parser.uint32('crc32');
365
- crcLength = 4;
366
- }
367
-
368
- return {
369
- parser: parser,
370
- maxLength: function maxLength(numLandmarks) {
371
- return 5 + numLandmarks * 5 + crcLength;
372
- }
373
- };
374
- }
163
+ else if (majorVersion === 2) {
164
+ parser = parser.itf8('recordCounter');
165
+ maxLength += 5;
166
+ }
167
+ parser = parser
168
+ .itf8('numBlocks')
169
+ .itf8('numContentIds')
170
+ .array('contentIds', {
171
+ type: singleItf8,
172
+ length: 'numContentIds',
173
+ });
174
+ maxLength += 5 * 2; // + numContentIds*5
175
+ // the md5 sum is missing in cram v1
176
+ if (majorVersion >= 2) {
177
+ parser = parser.array('md5', { type: 'uint8', length: 16 });
178
+ maxLength += 16;
179
+ }
180
+ var maxLengthFunc = function (numContentIds) { return maxLength + numContentIds * 5; };
181
+ return { parser: parser, maxLength: maxLengthFunc }; // : p, maxLength: numContentIds => 5 + 9 + 5 * 2 + 5 * numContentIds + 16 }
182
+ },
183
+ // assembles a section parser for the unmapped slice header, with slight
184
+ // variations depending on the major version of the cram file
185
+ cramMappedSliceHeader: function (majorVersion) {
186
+ var parser = new binary_parser_1.Parser()
187
+ .itf8('refSeqId')
188
+ .itf8('refSeqStart')
189
+ .itf8('refSeqSpan')
190
+ .itf8('numRecords');
191
+ var maxLength = 5 * 4;
192
+ if (majorVersion >= 3) {
193
+ parser = parser.ltf8('recordCounter');
194
+ maxLength += 9;
195
+ }
196
+ else if (majorVersion === 2) {
197
+ parser = parser.itf8('recordCounter');
198
+ maxLength += 5;
199
+ }
200
+ parser = parser
201
+ .itf8('numBlocks')
202
+ .itf8('numContentIds')
203
+ .array('contentIds', {
204
+ type: singleItf8,
205
+ length: 'numContentIds',
206
+ })
207
+ .itf8('refBaseBlockId');
208
+ maxLength += 5 * 3;
209
+ // the md5 sum is missing in cram v1
210
+ if (majorVersion >= 2) {
211
+ parser = parser.array('md5', { type: 'uint8', length: 16 });
212
+ maxLength += 16;
213
+ }
214
+ var maxLengthFunc = function (numContentIds) { return maxLength + numContentIds * 5; };
215
+ return { parser: parser, maxLength: maxLengthFunc };
216
+ },
217
+ cramEncoding: function (majorVersion) {
218
+ var parser = new binary_parser_1.Parser()
219
+ .namely('cramEncoding')
220
+ .itf8('codecId')
221
+ .itf8('parametersBytes')
222
+ .choice('parameters', {
223
+ tag: 'codecId',
224
+ choices: {
225
+ 0: new binary_parser_1.Parser(),
226
+ 1: new binary_parser_1.Parser().itf8('blockContentId'),
227
+ 2: new binary_parser_1.Parser().itf8('offset').itf8('M'),
228
+ // HUFFMAN_INT
229
+ 3: binary_parser_1.Parser.start()
230
+ .itf8('numCodes')
231
+ .array('symbols', { length: 'numCodes', type: singleItf8 })
232
+ .itf8('numLengths')
233
+ .array('bitLengths', { length: 'numLengths', type: singleItf8 }),
234
+ 4: binary_parser_1.Parser.start() // BYTE_ARRAY_LEN
235
+ .nest('lengthsEncoding', { type: 'cramEncoding' })
236
+ .nest('valuesEncoding', { type: 'cramEncoding' }),
237
+ // BYTE_ARRAY_STOP is a little different for CRAM v1
238
+ 5: new binary_parser_1.Parser()
239
+ .uint8('stopByte')[majorVersion > 1 ? 'itf8' : 'int']('blockContentId'),
240
+ 6: new binary_parser_1.Parser().itf8('offset').itf8('length'),
241
+ 7: new binary_parser_1.Parser().itf8('offset').itf8('K'),
242
+ 8: new binary_parser_1.Parser().itf8('offset').itf8('log2m'),
243
+ 9: new binary_parser_1.Parser().itf8('offset'), // GAMMA
244
+ },
245
+ });
246
+ return { parser: parser };
247
+ },
248
+ cramDataSeriesEncodingMap: function (majorVersion) {
249
+ return new binary_parser_1.Parser()
250
+ .itf8('mapSize')
251
+ .itf8('mapCount')
252
+ .array('ents', {
253
+ length: 'mapCount',
254
+ type: new binary_parser_1.Parser()
255
+ .string('key', { length: 2, stripNull: false })
256
+ .nest('value', { type: this.cramEncoding(majorVersion).parser }),
257
+ });
258
+ },
259
+ cramTagEncodingMap: function (majorVersion) {
260
+ return new binary_parser_1.Parser()
261
+ .itf8('mapSize')
262
+ .itf8('mapCount')
263
+ .array('ents', {
264
+ length: 'mapCount',
265
+ type: new binary_parser_1.Parser()
266
+ .itf8('key', {
267
+ formatter: /* istanbul ignore next */ function (/* istanbul ignore next */ integerRepresentation) {
268
+ /* istanbul ignore next */
269
+ return String.fromCharCode((integerRepresentation >> 16) & 0xff) +
270
+ String.fromCharCode((integerRepresentation >> 8) & 0xff) +
271
+ String.fromCharCode(integerRepresentation & 0xff);
272
+ },
273
+ })
274
+ .nest('value', { type: this.cramEncoding(majorVersion).parser }),
275
+ });
276
+ },
277
+ cramCompressionHeader: function (majorVersion) {
278
+ var parser = new binary_parser_1.Parser();
279
+ // TODO: if we want to support CRAM v1, we will need to refactor
280
+ // compression header into 2 parts to parse the landmarks,
281
+ // like the container header
282
+ parser = parser
283
+ .nest('preservation', {
284
+ type: cramPreservationMap,
285
+ formatter: formatMap,
286
+ })
287
+ .nest('dataSeriesEncoding', {
288
+ type: this.cramDataSeriesEncodingMap(majorVersion),
289
+ formatter: formatMap,
290
+ })
291
+ .nest('tagEncoding', {
292
+ type: this.cramTagEncodingMap(majorVersion),
293
+ formatter: formatMap,
294
+ });
295
+ return { parser: parser };
296
+ },
297
+ cramContainerHeader1: function (majorVersion) {
298
+ var parser = new binary_parser_1.Parser()
299
+ .int32('length') // byte size of the container data (blocks)
300
+ .itf8('refSeqId') // reference sequence identifier, -1 for unmapped reads, -2 for multiple reference sequences
301
+ .itf8('refSeqStart') // the alignment start position or 0 for unmapped reads
302
+ .itf8('alignmentSpan') // the length of the alignment or 0 for unmapped reads
303
+ .itf8('numRecords'); // number of records in the container
304
+ var maxLength = 4 + 5 * 4;
305
+ if (majorVersion >= 3) {
306
+ parser = parser.ltf8('recordCounter'); // 1-based sequential index of records in the file/stream.
307
+ maxLength += 9;
308
+ }
309
+ else if (majorVersion === 2) {
310
+ parser = parser.itf8('recordCounter');
311
+ maxLength += 5;
312
+ }
313
+ if (majorVersion > 1) {
314
+ parser = parser.ltf8('numBases'); // number of read bases
315
+ maxLength += 9;
316
+ }
317
+ parser = parser
318
+ .itf8('numBlocks') // the number of blocks
319
+ .itf8('numLandmarks'); // the number of landmarks
320
+ maxLength += 5 + 5;
321
+ return { parser: parser, maxLength: maxLength };
322
+ },
323
+ cramContainerHeader2: function (majorVersion) {
324
+ var parser = new binary_parser_1.Parser()
325
+ .itf8('numLandmarks') // the number of blocks
326
+ // Each integer value of this array is a byte offset
327
+ // into the blocks byte array. Landmarks are used for
328
+ // random access indexing.
329
+ .array('landmarks', {
330
+ type: new binary_parser_1.Parser().itf8(),
331
+ length: 'numLandmarks',
332
+ });
333
+ var crcLength = 0;
334
+ if (majorVersion >= 3) {
335
+ parser = parser.uint32('crc32');
336
+ crcLength = 4;
337
+ }
338
+ return {
339
+ parser: parser,
340
+ maxLength: function (numLandmarks) { return 5 + numLandmarks * 5 + crcLength; },
341
+ };
342
+ },
375
343
  };
376
-
377
344
  function getSectionParsers(majorVersion) {
378
- var _context;
379
-
380
- var parsers = (0, _assign.default)({}, unversionedParsers);
381
- (0, _forEach.default)(_context = (0, _keys.default)(versionedParsers)).call(_context, function (parserName) {
382
- parsers[parserName] = versionedParsers[parserName](majorVersion);
383
- });
384
- return parsers;
345
+ var parsers = Object.assign({}, unversionedParsers);
346
+ Object.keys(versionedParsers).forEach(function (parserName) {
347
+ parsers[parserName] = versionedParsers[parserName](majorVersion);
348
+ });
349
+ return parsers;
385
350
  }
386
-
387
- module.exports = {
388
- cramFileDefinition: cramFileDefinition,
389
- getSectionParsers: getSectionParsers
390
- };
351
+ exports.getSectionParsers = getSectionParsers;
352
+ //# sourceMappingURL=sectionParsers.js.map