@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.
- package/CHANGELOG.md +90 -0
- package/README.md +182 -172
- package/dist/craiIndex.d.ts +37 -0
- package/dist/craiIndex.js +196 -301
- package/dist/craiIndex.js.map +1 -0
- package/dist/cram-bundle.js +6 -15
- package/dist/cramFile/codecs/_base.d.ts +6 -0
- package/dist/cramFile/codecs/_base.js +44 -53
- package/dist/cramFile/codecs/_base.js.map +1 -0
- package/dist/cramFile/codecs/beta.d.ts +4 -0
- package/dist/cramFile/codecs/beta.js +38 -48
- package/dist/cramFile/codecs/beta.js.map +1 -0
- package/dist/cramFile/codecs/byteArrayLength.d.ts +8 -0
- package/dist/cramFile/codecs/byteArrayLength.js +58 -78
- package/dist/cramFile/codecs/byteArrayLength.js.map +1 -0
- package/dist/cramFile/codecs/byteArrayStop.d.ts +6 -0
- package/dist/cramFile/codecs/byteArrayStop.js +62 -76
- package/dist/cramFile/codecs/byteArrayStop.js.map +1 -0
- package/dist/cramFile/codecs/external.d.ts +7 -0
- package/dist/cramFile/codecs/external.js +63 -81
- package/dist/cramFile/codecs/external.js.map +1 -0
- package/dist/cramFile/codecs/gamma.d.ts +4 -0
- package/dist/cramFile/codecs/gamma.js +43 -56
- package/dist/cramFile/codecs/gamma.js.map +1 -0
- package/dist/cramFile/codecs/huffman.d.ts +17 -0
- package/dist/cramFile/codecs/huffman.js +126 -199
- package/dist/cramFile/codecs/huffman.js.map +1 -0
- package/dist/cramFile/codecs/index.d.ts +2 -0
- package/dist/cramFile/codecs/index.js +31 -38
- package/dist/cramFile/codecs/index.js.map +1 -0
- package/dist/cramFile/codecs/subexp.d.ts +4 -0
- package/dist/cramFile/codecs/subexp.js +51 -64
- package/dist/cramFile/codecs/subexp.js.map +1 -0
- package/dist/cramFile/constants.d.ts +36 -0
- package/dist/cramFile/constants.js +52 -50
- package/dist/cramFile/constants.js.map +1 -0
- package/dist/cramFile/container/compressionScheme.d.ts +23 -0
- package/dist/cramFile/container/compressionScheme.js +115 -153
- package/dist/cramFile/container/compressionScheme.js.map +1 -0
- package/dist/cramFile/container/index.d.ts +13 -0
- package/dist/cramFile/container/index.js +169 -283
- package/dist/cramFile/container/index.js.map +1 -0
- package/dist/cramFile/file.d.ts +63 -0
- package/dist/cramFile/file.js +440 -766
- package/dist/cramFile/file.js.map +1 -0
- package/dist/cramFile/index.d.ts +2 -0
- package/dist/cramFile/index.js +7 -4
- package/dist/cramFile/index.js.map +1 -0
- package/dist/cramFile/record.d.ts +79 -0
- package/dist/cramFile/record.js +253 -308
- package/dist/cramFile/record.js.map +1 -0
- package/dist/cramFile/sectionParsers.d.ts +18 -0
- package/dist/cramFile/sectionParsers.js +324 -362
- package/dist/cramFile/sectionParsers.js.map +1 -0
- package/dist/cramFile/slice/decodeRecord.d.ts +2 -0
- package/dist/cramFile/slice/decodeRecord.js +278 -298
- package/dist/cramFile/slice/decodeRecord.js.map +1 -0
- package/dist/cramFile/slice/index.d.ts +20 -0
- package/dist/cramFile/slice/index.js +488 -789
- package/dist/cramFile/slice/index.js.map +1 -0
- package/dist/cramFile/util.d.ts +5 -0
- package/dist/cramFile/util.js +158 -144
- package/dist/cramFile/util.js.map +1 -0
- package/dist/errors.d.ts +23 -0
- package/dist/errors.js +66 -103
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +12 -12
- package/dist/index.js.map +1 -0
- package/dist/indexedCramFile.d.ts +39 -0
- package/dist/indexedCramFile.js +213 -315
- package/dist/indexedCramFile.js.map +1 -0
- package/dist/io/bufferCache.d.ts +12 -0
- package/dist/io/bufferCache.js +108 -128
- package/dist/io/bufferCache.js.map +1 -0
- package/dist/io/index.d.ts +5 -0
- package/dist/io/index.js +29 -27
- package/dist/io/index.js.map +1 -0
- package/dist/io/localFile.d.ts +10 -0
- package/dist/io/localFile.js +105 -162
- package/dist/io/localFile.js.map +1 -0
- package/dist/io/remoteFile.d.ts +16 -0
- package/dist/io/remoteFile.js +137 -206
- package/dist/io/remoteFile.js.map +1 -0
- package/dist/rans/constants.d.ts +3 -0
- package/dist/rans/constants.js +6 -6
- package/dist/rans/constants.js.map +1 -0
- package/dist/rans/d04.d.ts +1 -0
- package/dist/rans/d04.js +70 -99
- package/dist/rans/d04.js.map +1 -0
- package/dist/rans/d14.d.ts +1 -0
- package/dist/rans/d14.js +55 -93
- package/dist/rans/d14.js.map +1 -0
- package/dist/rans/decoding.d.ts +30 -0
- package/dist/rans/decoding.js +112 -159
- package/dist/rans/decoding.js.map +1 -0
- package/dist/rans/frequencies.d.ts +2 -0
- package/dist/rans/frequencies.js +110 -119
- package/dist/rans/frequencies.js.map +1 -0
- package/dist/rans/index.d.ts +1 -0
- package/dist/rans/index.js +111 -174
- package/dist/rans/index.js.map +1 -0
- package/dist/sam.d.ts +1 -0
- package/dist/sam.js +16 -41
- package/dist/sam.js.map +1 -0
- package/dist/unzip-pako.d.ts +2 -0
- package/dist/unzip-pako.js +9 -0
- package/dist/unzip-pako.js.map +1 -0
- package/dist/unzip.d.ts +2 -0
- package/dist/unzip.js +6 -0
- package/dist/unzip.js.map +1 -0
- package/errors.js +66 -103
- package/esm/craiIndex.d.ts +37 -0
- package/esm/craiIndex.js +158 -0
- package/esm/craiIndex.js.map +1 -0
- package/esm/cramFile/codecs/_base.d.ts +6 -0
- package/esm/cramFile/codecs/_base.js +42 -0
- package/esm/cramFile/codecs/_base.js.map +1 -0
- package/esm/cramFile/codecs/beta.d.ts +4 -0
- package/esm/cramFile/codecs/beta.js +15 -0
- package/esm/cramFile/codecs/beta.js.map +1 -0
- package/esm/cramFile/codecs/byteArrayLength.d.ts +8 -0
- package/esm/cramFile/codecs/byteArrayLength.js +35 -0
- package/esm/cramFile/codecs/byteArrayLength.js.map +1 -0
- package/esm/cramFile/codecs/byteArrayStop.d.ts +6 -0
- package/esm/cramFile/codecs/byteArrayStop.js +40 -0
- package/esm/cramFile/codecs/byteArrayStop.js.map +1 -0
- package/esm/cramFile/codecs/external.d.ts +7 -0
- package/esm/cramFile/codecs/external.js +40 -0
- package/esm/cramFile/codecs/external.js.map +1 -0
- package/esm/cramFile/codecs/gamma.d.ts +4 -0
- package/esm/cramFile/codecs/gamma.js +20 -0
- package/esm/cramFile/codecs/gamma.js.map +1 -0
- package/esm/cramFile/codecs/huffman.d.ts +17 -0
- package/esm/cramFile/codecs/huffman.js +107 -0
- package/esm/cramFile/codecs/huffman.js.map +1 -0
- package/esm/cramFile/codecs/index.d.ts +2 -0
- package/esm/cramFile/codecs/index.js +30 -0
- package/esm/cramFile/codecs/index.js.map +1 -0
- package/esm/cramFile/codecs/subexp.d.ts +4 -0
- package/esm/cramFile/codecs/subexp.js +28 -0
- package/esm/cramFile/codecs/subexp.js.map +1 -0
- package/esm/cramFile/constants.d.ts +36 -0
- package/esm/cramFile/constants.js +51 -0
- package/esm/cramFile/constants.js.map +1 -0
- package/esm/cramFile/container/compressionScheme.d.ts +23 -0
- package/esm/cramFile/container/compressionScheme.js +123 -0
- package/esm/cramFile/container/compressionScheme.js.map +1 -0
- package/esm/cramFile/container/index.d.ts +13 -0
- package/esm/cramFile/container/index.js +84 -0
- package/esm/cramFile/container/index.js.map +1 -0
- package/esm/cramFile/file.d.ts +63 -0
- package/esm/cramFile/file.js +281 -0
- package/esm/cramFile/file.js.map +1 -0
- package/esm/cramFile/index.d.ts +2 -0
- package/esm/cramFile/index.js +3 -0
- package/esm/cramFile/index.js.map +1 -0
- package/esm/cramFile/record.d.ts +79 -0
- package/esm/cramFile/record.js +297 -0
- package/esm/cramFile/record.js.map +1 -0
- package/esm/cramFile/sectionParsers.d.ts +18 -0
- package/esm/cramFile/sectionParsers.js +347 -0
- package/esm/cramFile/sectionParsers.js.map +1 -0
- package/esm/cramFile/slice/decodeRecord.d.ts +2 -0
- package/esm/cramFile/slice/decodeRecord.js +299 -0
- package/esm/cramFile/slice/decodeRecord.js.map +1 -0
- package/esm/cramFile/slice/index.d.ts +20 -0
- package/esm/cramFile/slice/index.js +364 -0
- package/esm/cramFile/slice/index.js.map +1 -0
- package/esm/cramFile/util.d.ts +5 -0
- package/esm/cramFile/util.js +161 -0
- package/esm/cramFile/util.js.map +1 -0
- package/esm/errors.d.ts +23 -0
- package/esm/errors.js +24 -0
- package/esm/errors.js.map +1 -0
- package/esm/index.d.ts +4 -0
- package/esm/index.js +5 -0
- package/esm/index.js.map +1 -0
- package/esm/indexedCramFile.d.ts +39 -0
- package/esm/indexedCramFile.js +155 -0
- package/esm/indexedCramFile.js.map +1 -0
- package/esm/io/bufferCache.d.ts +12 -0
- package/esm/io/bufferCache.js +54 -0
- package/esm/io/bufferCache.js.map +1 -0
- package/esm/io/index.d.ts +5 -0
- package/esm/io/index.js +24 -0
- package/esm/io/index.js.map +1 -0
- package/esm/io/localFile.d.ts +10 -0
- package/esm/io/localFile.js +31 -0
- package/esm/io/localFile.js.map +1 -0
- package/esm/io/remoteFile.d.ts +16 -0
- package/esm/io/remoteFile.js +64 -0
- package/esm/io/remoteFile.js.map +1 -0
- package/esm/rans/constants.d.ts +3 -0
- package/esm/rans/constants.js +5 -0
- package/esm/rans/constants.js.map +1 -0
- package/esm/rans/d04.d.ts +1 -0
- package/esm/rans/d04.js +67 -0
- package/esm/rans/d04.js.map +1 -0
- package/esm/rans/d14.d.ts +1 -0
- package/esm/rans/d14.js +52 -0
- package/esm/rans/d14.js.map +1 -0
- package/esm/rans/decoding.d.ts +30 -0
- package/esm/rans/decoding.js +118 -0
- package/esm/rans/decoding.js.map +1 -0
- package/esm/rans/frequencies.d.ts +2 -0
- package/esm/rans/frequencies.js +110 -0
- package/esm/rans/frequencies.js.map +1 -0
- package/esm/rans/index.d.ts +1 -0
- package/esm/rans/index.js +195 -0
- package/esm/rans/index.js.map +1 -0
- package/esm/sam.d.ts +1 -0
- package/esm/sam.js +16 -0
- package/esm/sam.js.map +1 -0
- package/esm/unzip-pako.d.ts +2 -0
- package/esm/unzip-pako.js +5 -0
- package/esm/unzip-pako.js.map +1 -0
- package/esm/unzip.d.ts +2 -0
- package/esm/unzip.js +3 -0
- package/esm/unzip.js.map +1 -0
- package/package.json +38 -35
- package/src/craiIndex.js +180 -0
- package/src/cramFile/codecs/_base.js +49 -0
- package/src/cramFile/codecs/beta.js +23 -0
- package/src/cramFile/codecs/byteArrayLength.js +55 -0
- package/src/cramFile/codecs/byteArrayStop.js +50 -0
- package/src/cramFile/codecs/external.js +54 -0
- package/src/cramFile/codecs/gamma.js +30 -0
- package/src/cramFile/codecs/huffman.js +137 -0
- package/src/cramFile/codecs/index.js +38 -0
- package/src/cramFile/codecs/subexp.js +32 -0
- package/src/cramFile/constants.js +55 -0
- package/src/cramFile/container/compressionScheme.js +144 -0
- package/src/cramFile/container/index.js +119 -0
- package/src/cramFile/file.js +347 -0
- package/src/cramFile/index.js +3 -0
- package/src/cramFile/record.js +337 -0
- package/src/cramFile/sectionParsers.js +379 -0
- package/src/cramFile/slice/decodeRecord.js +362 -0
- package/src/cramFile/slice/index.js +497 -0
- package/src/cramFile/util.js +169 -0
- package/src/errors.js +22 -0
- package/src/index.js +5 -0
- package/src/indexedCramFile.js +191 -0
- package/src/io/bufferCache.js +66 -0
- package/src/io/index.js +26 -0
- package/src/io/localFile.js +35 -0
- package/src/io/remoteFile.js +71 -0
- package/src/rans/README.md +1 -0
- package/src/rans/constants.js +5 -0
- package/src/rans/d04.js +83 -0
- package/src/rans/d14.js +59 -0
- package/src/rans/decoding.js +141 -0
- package/src/rans/frequencies.js +121 -0
- package/src/rans/index.js +249 -0
- package/src/sam.js +15 -0
- package/src/unzip-pako.ts +5 -0
- package/src/unzip.ts +2 -0
|
@@ -1,51 +1,64 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
};
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
};
|
|
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
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
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
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
parsers
|
|
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
|
-
|
|
388
|
-
cramFileDefinition: cramFileDefinition,
|
|
389
|
-
getSectionParsers: getSectionParsers
|
|
390
|
-
};
|
|
351
|
+
exports.getSectionParsers = getSectionParsers;
|
|
352
|
+
//# sourceMappingURL=sectionParsers.js.map
|