@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,46 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
var errors_1 = require("../../errors");
|
|
43
|
+
var util_1 = require("../util");
|
|
44
|
+
var constants_1 = __importDefault(require("../constants"));
|
|
45
|
+
var decodeRecord_1 = __importDefault(require("./decodeRecord"));
|
|
44
46
|
/**
|
|
45
47
|
* @private
|
|
46
48
|
* Try to estimate the template length from a bunch of interrelated multi-segment reads.
|
|
@@ -48,33 +50,30 @@ var decodeRecord = require('./decodeRecord');
|
|
|
48
50
|
* @param {number} currentRecordNumber
|
|
49
51
|
* @param {CramRecord} thisRecord
|
|
50
52
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
53
|
function calculateMultiSegmentMatedTemplateLength(allRecords, currentRecordNumber, thisRecord) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
function getAllMatedRecords(startRecord) {
|
|
55
|
+
var records = [startRecord];
|
|
56
|
+
if (startRecord.mateRecordNumber >= 0) {
|
|
57
|
+
var mateRecord = allRecords[startRecord.mateRecordNumber];
|
|
58
|
+
if (!mateRecord) {
|
|
59
|
+
throw new errors_1.CramMalformedError('intra-slice mate record not found, this file seems malformed');
|
|
60
|
+
}
|
|
61
|
+
records.push.apply(records, getAllMatedRecords(mateRecord));
|
|
62
|
+
}
|
|
63
|
+
return records;
|
|
64
|
+
}
|
|
65
|
+
var matedRecords = getAllMatedRecords(thisRecord);
|
|
66
|
+
var starts = matedRecords.map(function (r) { return r.alignmentStart; });
|
|
67
|
+
var ends = matedRecords.map(function (r) { return r.alignmentStart + r.readLength - 1; });
|
|
68
|
+
var estimatedTemplateLength = Math.max.apply(Math, ends) - Math.min.apply(Math, starts) + 1;
|
|
69
|
+
if (estimatedTemplateLength >= 0) {
|
|
70
|
+
matedRecords.forEach(function (r) {
|
|
71
|
+
if (r.templateLength !== undefined) {
|
|
72
|
+
throw new errors_1.CramMalformedError('mate pair group has some members that have template lengths already, this file seems malformed');
|
|
73
|
+
}
|
|
74
|
+
r.templateLength = estimatedTemplateLength;
|
|
75
|
+
});
|
|
61
76
|
}
|
|
62
|
-
|
|
63
|
-
return records;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
var matedRecords = getAllMatedRecords(thisRecord);
|
|
67
|
-
var starts = (0, _map.default)(matedRecords).call(matedRecords, function (r) {
|
|
68
|
-
return r.alignmentStart;
|
|
69
|
-
});
|
|
70
|
-
var ends = (0, _map.default)(matedRecords).call(matedRecords, function (r) {
|
|
71
|
-
return r.alignmentStart + r.readLength - 1;
|
|
72
|
-
});
|
|
73
|
-
var estimatedTemplateLength = Math.max.apply(Math, (0, _toConsumableArray2.default)(ends)) - Math.min.apply(Math, (0, _toConsumableArray2.default)(starts)) + 1;
|
|
74
|
-
if (estimatedTemplateLength >= 0) (0, _forEach.default)(matedRecords).call(matedRecords, function (r) {
|
|
75
|
-
if (r.templateLength !== undefined) throw new CramMalformedError('mate pair group has some members that have template lengths already, this file seems malformed');
|
|
76
|
-
r.templateLength = estimatedTemplateLength;
|
|
77
|
-
});
|
|
78
77
|
}
|
|
79
78
|
/**
|
|
80
79
|
* @private
|
|
@@ -83,746 +82,446 @@ function calculateMultiSegmentMatedTemplateLength(allRecords, currentRecordNumbe
|
|
|
83
82
|
* @param {CramRecord} thisRecord
|
|
84
83
|
* @param {CramRecord} mateRecord
|
|
85
84
|
*/
|
|
86
|
-
|
|
87
|
-
|
|
88
85
|
function calculateIntraSliceMatePairTemplateLength(thisRecord, mateRecord) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
86
|
+
// this just estimates the template length by using the simple (non-gapped) end coordinate of each
|
|
87
|
+
// read, because gapping in the alignment doesn't mean the template is longer or shorter
|
|
88
|
+
var start = Math.min(thisRecord.alignmentStart, mateRecord.alignmentStart);
|
|
89
|
+
var end = Math.max(thisRecord.alignmentStart + thisRecord.readLength - 1, mateRecord.alignmentStart + mateRecord.readLength - 1);
|
|
90
|
+
var lengthEstimate = end - start + 1;
|
|
91
|
+
thisRecord.templateLength = lengthEstimate;
|
|
92
|
+
mateRecord.templateLength = lengthEstimate;
|
|
96
93
|
}
|
|
97
94
|
/**
|
|
98
95
|
* @private establishes a mate-pair relationship between two records in the same slice.
|
|
99
96
|
* CRAM compresses mate-pair relationships between records in the same slice down into
|
|
100
97
|
* just one record having the index in the slice of its mate
|
|
101
98
|
*/
|
|
102
|
-
|
|
103
|
-
|
|
104
99
|
function associateIntraSliceMate(allRecords, currentRecordNumber, thisRecord, mateRecord) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
// if it does not have any other relationship
|
|
121
|
-
|
|
122
|
-
if (!mateRecord.mate && mateRecord.mateRecordNumber === undefined) {
|
|
123
|
-
mateRecord.mate = {
|
|
124
|
-
sequenceId: thisRecord.sequenceId,
|
|
125
|
-
alignmentStart: thisRecord.alignmentStart,
|
|
126
|
-
uniqueId: thisRecord.uniqueId
|
|
100
|
+
if (!mateRecord) {
|
|
101
|
+
throw new errors_1.CramMalformedError('could not resolve intra-slice mate pairs, file seems truncated or malformed');
|
|
102
|
+
}
|
|
103
|
+
var complicatedMultiSegment = !!(mateRecord.mate ||
|
|
104
|
+
(mateRecord.mateRecordNumber !== undefined &&
|
|
105
|
+
mateRecord.mateRecordNumber !== currentRecordNumber));
|
|
106
|
+
// Deal with lossy read names
|
|
107
|
+
if (!thisRecord.readName) {
|
|
108
|
+
thisRecord.readName = String(thisRecord.uniqueId);
|
|
109
|
+
mateRecord.readName = thisRecord.readName;
|
|
110
|
+
}
|
|
111
|
+
thisRecord.mate = {
|
|
112
|
+
sequenceId: mateRecord.sequenceId,
|
|
113
|
+
alignmentStart: mateRecord.alignmentStart,
|
|
114
|
+
uniqueId: mateRecord.uniqueId,
|
|
127
115
|
};
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
thisRecord.flags |=
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
116
|
+
if (mateRecord.readName) {
|
|
117
|
+
thisRecord.mate.readName = mateRecord.readName;
|
|
118
|
+
}
|
|
119
|
+
// the mate record might have its own mate pointer, if this is some kind of
|
|
120
|
+
// multi-segment (more than paired) scheme, so only relate that one back to this one
|
|
121
|
+
// if it does not have any other relationship
|
|
122
|
+
if (!mateRecord.mate && mateRecord.mateRecordNumber === undefined) {
|
|
123
|
+
mateRecord.mate = {
|
|
124
|
+
sequenceId: thisRecord.sequenceId,
|
|
125
|
+
alignmentStart: thisRecord.alignmentStart,
|
|
126
|
+
uniqueId: thisRecord.uniqueId,
|
|
127
|
+
};
|
|
128
|
+
if (thisRecord.readName) {
|
|
129
|
+
mateRecord.mate.readName = thisRecord.readName;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// make sure the proper flags and cramFlags are set on both records
|
|
133
|
+
// paired
|
|
134
|
+
thisRecord.flags |= constants_1.default.BAM_FPAIRED;
|
|
135
|
+
// set mate unmapped if needed
|
|
136
|
+
if (mateRecord.flags & constants_1.default.BAM_FUNMAP) {
|
|
137
|
+
thisRecord.flags |= constants_1.default.BAM_FMUNMAP;
|
|
138
|
+
// thisRecord.templateLength = 0
|
|
139
|
+
}
|
|
140
|
+
if (thisRecord.flags & constants_1.default.BAM_FUNMAP) {
|
|
141
|
+
// thisRecord.templateLength = 0
|
|
142
|
+
mateRecord.flags |= constants_1.default.BAM_FMUNMAP;
|
|
143
|
+
}
|
|
144
|
+
// set mate reversed if needed
|
|
145
|
+
if (mateRecord.flags & constants_1.default.BAM_FREVERSE) {
|
|
146
|
+
thisRecord.flags |= constants_1.default.BAM_FMREVERSE;
|
|
147
|
+
}
|
|
148
|
+
if (thisRecord.flags & constants_1.default.BAM_FREVERSE) {
|
|
149
|
+
mateRecord.flags |= constants_1.default.BAM_FMREVERSE;
|
|
150
|
+
}
|
|
151
|
+
if (thisRecord.templateLength === undefined) {
|
|
152
|
+
if (complicatedMultiSegment) {
|
|
153
|
+
calculateMultiSegmentMatedTemplateLength(allRecords, currentRecordNumber, thisRecord);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
calculateIntraSliceMatePairTemplateLength(thisRecord, mateRecord);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// delete this last because it's used by the
|
|
160
|
+
// complicated template length estimation
|
|
161
|
+
delete thisRecord.mateRecordNumber;
|
|
160
162
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
(0, _classCallCheck2.default)(this, CramSlice);
|
|
167
|
-
this.container = container;
|
|
168
|
-
this.file = container.file;
|
|
169
|
-
this.containerPosition = position;
|
|
170
|
-
} // memoize
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
(0, _createClass2.default)(CramSlice, [{
|
|
174
|
-
key: "getHeader",
|
|
175
|
-
value: function () {
|
|
176
|
-
var _getHeader = (0, _asyncToGenerator2.default)(
|
|
177
|
-
/*#__PURE__*/
|
|
178
|
-
_regenerator.default.mark(function _callee() {
|
|
179
|
-
var sectionParsers, containerHeader, header;
|
|
180
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
181
|
-
while (1) {
|
|
182
|
-
switch (_context.prev = _context.next) {
|
|
183
|
-
case 0:
|
|
184
|
-
_context.next = 2;
|
|
185
|
-
return this.file.getSectionParsers();
|
|
186
|
-
|
|
187
|
-
case 2:
|
|
188
|
-
sectionParsers = _context.sent;
|
|
189
|
-
_context.next = 5;
|
|
190
|
-
return this.container.getHeader();
|
|
191
|
-
|
|
192
|
-
case 5:
|
|
193
|
-
containerHeader = _context.sent;
|
|
194
|
-
_context.next = 8;
|
|
195
|
-
return this.file.readBlock(containerHeader._endPosition + this.containerPosition);
|
|
196
|
-
|
|
197
|
-
case 8:
|
|
198
|
-
header = _context.sent;
|
|
199
|
-
|
|
200
|
-
if (!(header.contentType === 'MAPPED_SLICE_HEADER')) {
|
|
201
|
-
_context.next = 13;
|
|
202
|
-
break;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
header.content = parseItem(header.content, sectionParsers.cramMappedSliceHeader.parser, 0, containerHeader._endPosition);
|
|
206
|
-
_context.next = 18;
|
|
207
|
-
break;
|
|
208
|
-
|
|
209
|
-
case 13:
|
|
210
|
-
if (!(header.contentType === 'UNMAPPED_SLICE_HEADER')) {
|
|
211
|
-
_context.next = 17;
|
|
212
|
-
break;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
header.content = parseItem(header.content, sectionParsers.cramUnmappedSliceHeader.parser, 0, containerHeader._endPosition);
|
|
216
|
-
_context.next = 18;
|
|
217
|
-
break;
|
|
218
|
-
|
|
219
|
-
case 17:
|
|
220
|
-
throw new CramMalformedError("error reading slice header block, invalid content type ".concat(header._contentType));
|
|
221
|
-
|
|
222
|
-
case 18:
|
|
223
|
-
return _context.abrupt("return", header);
|
|
224
|
-
|
|
225
|
-
case 19:
|
|
226
|
-
case "end":
|
|
227
|
-
return _context.stop();
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}, _callee, this);
|
|
231
|
-
}));
|
|
232
|
-
|
|
233
|
-
function getHeader() {
|
|
234
|
-
return _getHeader.apply(this, arguments);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return getHeader;
|
|
238
|
-
}() // memoize
|
|
239
|
-
|
|
240
|
-
}, {
|
|
241
|
-
key: "getBlocks",
|
|
242
|
-
value: function () {
|
|
243
|
-
var _getBlocks = (0, _asyncToGenerator2.default)(
|
|
244
|
-
/*#__PURE__*/
|
|
245
|
-
_regenerator.default.mark(function _callee2() {
|
|
246
|
-
var header, blockPosition, blocks, i;
|
|
247
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
248
|
-
while (1) {
|
|
249
|
-
switch (_context2.prev = _context2.next) {
|
|
250
|
-
case 0:
|
|
251
|
-
_context2.next = 2;
|
|
252
|
-
return this.getHeader();
|
|
253
|
-
|
|
254
|
-
case 2:
|
|
255
|
-
header = _context2.sent;
|
|
256
|
-
// read all the blocks into memory and store them
|
|
257
|
-
blockPosition = header._endPosition;
|
|
258
|
-
blocks = new Array(header.content.numBlocks);
|
|
259
|
-
i = 0;
|
|
260
|
-
|
|
261
|
-
case 6:
|
|
262
|
-
if (!(i < blocks.length)) {
|
|
263
|
-
_context2.next = 14;
|
|
264
|
-
break;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
_context2.next = 9;
|
|
268
|
-
return this.file.readBlock(blockPosition);
|
|
269
|
-
|
|
270
|
-
case 9:
|
|
271
|
-
blocks[i] = _context2.sent;
|
|
272
|
-
blockPosition = blocks[i]._endPosition;
|
|
273
|
-
|
|
274
|
-
case 11:
|
|
275
|
-
i += 1;
|
|
276
|
-
_context2.next = 6;
|
|
277
|
-
break;
|
|
278
|
-
|
|
279
|
-
case 14:
|
|
280
|
-
return _context2.abrupt("return", blocks);
|
|
281
|
-
|
|
282
|
-
case 15:
|
|
283
|
-
case "end":
|
|
284
|
-
return _context2.stop();
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}, _callee2, this);
|
|
288
|
-
}));
|
|
289
|
-
|
|
290
|
-
function getBlocks() {
|
|
291
|
-
return _getBlocks.apply(this, arguments);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
return getBlocks;
|
|
295
|
-
}() // no memoize
|
|
296
|
-
|
|
297
|
-
}, {
|
|
298
|
-
key: "getCoreDataBlock",
|
|
299
|
-
value: function () {
|
|
300
|
-
var _getCoreDataBlock = (0, _asyncToGenerator2.default)(
|
|
301
|
-
/*#__PURE__*/
|
|
302
|
-
_regenerator.default.mark(function _callee3() {
|
|
303
|
-
var blocks;
|
|
304
|
-
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
305
|
-
while (1) {
|
|
306
|
-
switch (_context3.prev = _context3.next) {
|
|
307
|
-
case 0:
|
|
308
|
-
_context3.next = 2;
|
|
309
|
-
return this.getBlocks();
|
|
310
|
-
|
|
311
|
-
case 2:
|
|
312
|
-
blocks = _context3.sent;
|
|
313
|
-
return _context3.abrupt("return", blocks[0]);
|
|
314
|
-
|
|
315
|
-
case 4:
|
|
316
|
-
case "end":
|
|
317
|
-
return _context3.stop();
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}, _callee3, this);
|
|
321
|
-
}));
|
|
322
|
-
|
|
323
|
-
function getCoreDataBlock() {
|
|
324
|
-
return _getCoreDataBlock.apply(this, arguments);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
return getCoreDataBlock;
|
|
328
|
-
}() // memoize
|
|
329
|
-
|
|
330
|
-
}, {
|
|
331
|
-
key: "_getBlocksContentIdIndex",
|
|
332
|
-
value: function () {
|
|
333
|
-
var _getBlocksContentIdIndex2 = (0, _asyncToGenerator2.default)(
|
|
334
|
-
/*#__PURE__*/
|
|
335
|
-
_regenerator.default.mark(function _callee4() {
|
|
336
|
-
var blocks, blocksByContentId;
|
|
337
|
-
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
338
|
-
while (1) {
|
|
339
|
-
switch (_context4.prev = _context4.next) {
|
|
340
|
-
case 0:
|
|
341
|
-
_context4.next = 2;
|
|
342
|
-
return this.getBlocks();
|
|
343
|
-
|
|
344
|
-
case 2:
|
|
345
|
-
blocks = _context4.sent;
|
|
346
|
-
blocksByContentId = {};
|
|
347
|
-
(0, _forEach.default)(blocks).call(blocks, function (block) {
|
|
348
|
-
if (block.contentType === 'EXTERNAL_DATA') {
|
|
349
|
-
blocksByContentId[block.contentId] = block;
|
|
350
|
-
}
|
|
351
|
-
});
|
|
352
|
-
return _context4.abrupt("return", blocksByContentId);
|
|
353
|
-
|
|
354
|
-
case 6:
|
|
355
|
-
case "end":
|
|
356
|
-
return _context4.stop();
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}, _callee4, this);
|
|
360
|
-
}));
|
|
361
|
-
|
|
362
|
-
function _getBlocksContentIdIndex() {
|
|
363
|
-
return _getBlocksContentIdIndex2.apply(this, arguments);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
return _getBlocksContentIdIndex;
|
|
367
|
-
}()
|
|
368
|
-
}, {
|
|
369
|
-
key: "getBlockByContentId",
|
|
370
|
-
value: function () {
|
|
371
|
-
var _getBlockByContentId = (0, _asyncToGenerator2.default)(
|
|
372
|
-
/*#__PURE__*/
|
|
373
|
-
_regenerator.default.mark(function _callee5(id) {
|
|
374
|
-
var blocksByContentId;
|
|
375
|
-
return _regenerator.default.wrap(function _callee5$(_context5) {
|
|
376
|
-
while (1) {
|
|
377
|
-
switch (_context5.prev = _context5.next) {
|
|
378
|
-
case 0:
|
|
379
|
-
_context5.next = 2;
|
|
380
|
-
return this._getBlocksContentIdIndex();
|
|
381
|
-
|
|
382
|
-
case 2:
|
|
383
|
-
blocksByContentId = _context5.sent;
|
|
384
|
-
return _context5.abrupt("return", blocksByContentId[id]);
|
|
385
|
-
|
|
386
|
-
case 4:
|
|
387
|
-
case "end":
|
|
388
|
-
return _context5.stop();
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
}, _callee5, this);
|
|
392
|
-
}));
|
|
393
|
-
|
|
394
|
-
function getBlockByContentId(_x) {
|
|
395
|
-
return _getBlockByContentId.apply(this, arguments);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
return getBlockByContentId;
|
|
399
|
-
}()
|
|
400
|
-
}, {
|
|
401
|
-
key: "getReferenceRegion",
|
|
402
|
-
value: function () {
|
|
403
|
-
var _getReferenceRegion = (0, _asyncToGenerator2.default)(
|
|
404
|
-
/*#__PURE__*/
|
|
405
|
-
_regenerator.default.mark(function _callee6() {
|
|
406
|
-
var sliceHeader, compressionScheme, refBlock, seq;
|
|
407
|
-
return _regenerator.default.wrap(function _callee6$(_context6) {
|
|
408
|
-
while (1) {
|
|
409
|
-
switch (_context6.prev = _context6.next) {
|
|
410
|
-
case 0:
|
|
411
|
-
_context6.next = 2;
|
|
412
|
-
return this.getHeader();
|
|
413
|
-
|
|
414
|
-
case 2:
|
|
415
|
-
sliceHeader = _context6.sent.content;
|
|
416
|
-
|
|
417
|
-
if (!(sliceHeader.refSeqId < 0)) {
|
|
418
|
-
_context6.next = 5;
|
|
419
|
-
break;
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
return _context6.abrupt("return", undefined);
|
|
423
|
-
|
|
424
|
-
case 5:
|
|
425
|
-
_context6.next = 7;
|
|
426
|
-
return this.container.getCompressionScheme();
|
|
427
|
-
|
|
428
|
-
case 7:
|
|
429
|
-
compressionScheme = _context6.sent;
|
|
430
|
-
|
|
431
|
-
if (!(sliceHeader.refBaseBlockId >= 0)) {
|
|
432
|
-
_context6.next = 15;
|
|
433
|
-
break;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
refBlock = this.getBlockByContentId(sliceHeader.refBaseBlockId);
|
|
437
|
-
|
|
438
|
-
if (refBlock) {
|
|
439
|
-
_context6.next = 12;
|
|
440
|
-
break;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
throw new CramMalformedError('embedded reference specified, but reference block does not exist');
|
|
444
|
-
|
|
445
|
-
case 12:
|
|
446
|
-
if (!(sliceHeader.span > refBlock.uncompressedSize)) {
|
|
447
|
-
_context6.next = 14;
|
|
448
|
-
break;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
throw new CramMalformedError('Embedded reference is too small');
|
|
452
|
-
|
|
453
|
-
case 14:
|
|
454
|
-
return _context6.abrupt("return", {
|
|
455
|
-
seq: refBlock.data.toString('utf8'),
|
|
456
|
-
start: sliceHeader.refSeqStart,
|
|
457
|
-
end: sliceHeader.refSeqStart + sliceHeader.refSeqSpan - 1,
|
|
458
|
-
span: sliceHeader.refSeqSpan
|
|
459
|
-
});
|
|
460
|
-
|
|
461
|
-
case 15:
|
|
462
|
-
if (!(compressionScheme.referenceRequired || this.file.fetchReferenceSequenceCallback)) {
|
|
463
|
-
_context6.next = 24;
|
|
464
|
-
break;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
if (this.file.fetchReferenceSequenceCallback) {
|
|
468
|
-
_context6.next = 18;
|
|
469
|
-
break;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
throw new Error('reference sequence not embedded, and seqFetch callback not provided, cannot fetch reference sequence');
|
|
473
|
-
|
|
474
|
-
case 18:
|
|
475
|
-
_context6.next = 20;
|
|
476
|
-
return this.file.fetchReferenceSequenceCallback(sliceHeader.refSeqId, sliceHeader.refSeqStart, sliceHeader.refSeqStart + sliceHeader.refSeqSpan - 1);
|
|
477
|
-
|
|
478
|
-
case 20:
|
|
479
|
-
seq = _context6.sent;
|
|
480
|
-
|
|
481
|
-
if (!(seq.length !== sliceHeader.refSeqSpan)) {
|
|
482
|
-
_context6.next = 23;
|
|
483
|
-
break;
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
throw new CramArgumentError('seqFetch callback returned a reference sequence of the wrong length');
|
|
487
|
-
|
|
488
|
-
case 23:
|
|
489
|
-
return _context6.abrupt("return", {
|
|
490
|
-
seq: seq,
|
|
491
|
-
start: sliceHeader.refSeqStart,
|
|
492
|
-
end: sliceHeader.refSeqStart + sliceHeader.refSeqSpan - 1,
|
|
493
|
-
span: sliceHeader.refSeqSpan
|
|
494
|
-
});
|
|
495
|
-
|
|
496
|
-
case 24:
|
|
497
|
-
return _context6.abrupt("return", undefined);
|
|
498
|
-
|
|
499
|
-
case 25:
|
|
500
|
-
case "end":
|
|
501
|
-
return _context6.stop();
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
}, _callee6, this);
|
|
505
|
-
}));
|
|
506
|
-
|
|
507
|
-
function getReferenceRegion() {
|
|
508
|
-
return _getReferenceRegion.apply(this, arguments);
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
return getReferenceRegion;
|
|
512
|
-
}()
|
|
513
|
-
}, {
|
|
514
|
-
key: "getAllRecords",
|
|
515
|
-
value: function getAllRecords() {
|
|
516
|
-
return this.getRecords(function () {
|
|
517
|
-
return true;
|
|
518
|
-
});
|
|
163
|
+
var CramSlice = /** @class */ (function () {
|
|
164
|
+
function CramSlice(container, position) {
|
|
165
|
+
this.container = container;
|
|
166
|
+
this.file = container.file;
|
|
167
|
+
this.containerPosition = position;
|
|
519
168
|
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
_context12.next = 9;
|
|
546
|
-
return this.getHeader();
|
|
547
|
-
|
|
548
|
-
case 9:
|
|
549
|
-
sliceHeader = _context12.sent;
|
|
550
|
-
_context12.next = 12;
|
|
551
|
-
return this._getBlocksContentIdIndex();
|
|
552
|
-
|
|
553
|
-
case 12:
|
|
554
|
-
blocksByContentId = _context12.sent;
|
|
555
|
-
|
|
556
|
-
if (!(majorVersion > 1 && this.file.options.checkSequenceMD5 && sliceHeader.content.refSeqId >= 0 && sliceHeader.content.md5.join('') !== '0000000000000000')) {
|
|
557
|
-
_context12.next = 23;
|
|
558
|
-
break;
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
_context12.next = 16;
|
|
562
|
-
return this.getReferenceRegion();
|
|
563
|
-
|
|
564
|
-
case 16:
|
|
565
|
-
refRegion = _context12.sent;
|
|
566
|
-
|
|
567
|
-
if (!refRegion) {
|
|
568
|
-
_context12.next = 23;
|
|
569
|
-
break;
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
seq = refRegion.seq, start = refRegion.start, end = refRegion.end;
|
|
573
|
-
seqMd5 = sequenceMD5(seq);
|
|
574
|
-
storedMd5 = (0, _map.default)(_context7 = sliceHeader.content.md5).call(_context7, function (byte) {
|
|
575
|
-
return (byte < 16 ? '0' : '') + byte.toString(16);
|
|
576
|
-
}).join('');
|
|
577
|
-
|
|
578
|
-
if (!(seqMd5 !== storedMd5)) {
|
|
579
|
-
_context12.next = 23;
|
|
580
|
-
break;
|
|
169
|
+
// memoize
|
|
170
|
+
CramSlice.prototype.getHeader = function () {
|
|
171
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
172
|
+
var sectionParsers, containerHeader, header;
|
|
173
|
+
return __generator(this, function (_a) {
|
|
174
|
+
switch (_a.label) {
|
|
175
|
+
case 0: return [4 /*yield*/, this.file.getSectionParsers()];
|
|
176
|
+
case 1:
|
|
177
|
+
sectionParsers = _a.sent();
|
|
178
|
+
return [4 /*yield*/, this.container.getHeader()];
|
|
179
|
+
case 2:
|
|
180
|
+
containerHeader = _a.sent();
|
|
181
|
+
return [4 /*yield*/, this.file.readBlock(containerHeader._endPosition + this.containerPosition)];
|
|
182
|
+
case 3:
|
|
183
|
+
header = _a.sent();
|
|
184
|
+
if (header.contentType === 'MAPPED_SLICE_HEADER') {
|
|
185
|
+
header.content = (0, util_1.parseItem)(header.content, sectionParsers.cramMappedSliceHeader.parser, 0, containerHeader._endPosition);
|
|
186
|
+
}
|
|
187
|
+
else if (header.contentType === 'UNMAPPED_SLICE_HEADER') {
|
|
188
|
+
header.content = (0, util_1.parseItem)(header.content, sectionParsers.cramUnmappedSliceHeader.parser, 0, containerHeader._endPosition);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
throw new errors_1.CramMalformedError("error reading slice header block, invalid content type ".concat(header._contentType));
|
|
192
|
+
}
|
|
193
|
+
return [2 /*return*/, header];
|
|
581
194
|
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
};
|
|
614
|
-
|
|
615
|
-
records = new Array(sliceHeader.content.numRecords);
|
|
616
|
-
i = 0;
|
|
617
|
-
|
|
618
|
-
case 30:
|
|
619
|
-
if (!(i < records.length)) {
|
|
620
|
-
_context12.next = 48;
|
|
621
|
-
break;
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
// memoize
|
|
199
|
+
CramSlice.prototype.getBlocks = function () {
|
|
200
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
201
|
+
var header, blockPosition, blocks, i, _a, _b;
|
|
202
|
+
return __generator(this, function (_c) {
|
|
203
|
+
switch (_c.label) {
|
|
204
|
+
case 0: return [4 /*yield*/, this.getHeader()
|
|
205
|
+
// read all the blocks into memory and store them
|
|
206
|
+
];
|
|
207
|
+
case 1:
|
|
208
|
+
header = _c.sent();
|
|
209
|
+
blockPosition = header._endPosition;
|
|
210
|
+
blocks = new Array(header.content.numBlocks);
|
|
211
|
+
i = 0;
|
|
212
|
+
_c.label = 2;
|
|
213
|
+
case 2:
|
|
214
|
+
if (!(i < blocks.length)) return [3 /*break*/, 5];
|
|
215
|
+
_a = blocks;
|
|
216
|
+
_b = i;
|
|
217
|
+
return [4 /*yield*/, this.file.readBlock(blockPosition)];
|
|
218
|
+
case 3:
|
|
219
|
+
_a[_b] = _c.sent();
|
|
220
|
+
blockPosition = blocks[i]._endPosition;
|
|
221
|
+
_c.label = 4;
|
|
222
|
+
case 4:
|
|
223
|
+
i += 1;
|
|
224
|
+
return [3 /*break*/, 2];
|
|
225
|
+
case 5: return [2 /*return*/, blocks];
|
|
622
226
|
}
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
// no memoize
|
|
231
|
+
CramSlice.prototype.getCoreDataBlock = function () {
|
|
232
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
233
|
+
var blocks;
|
|
234
|
+
return __generator(this, function (_a) {
|
|
235
|
+
switch (_a.label) {
|
|
236
|
+
case 0: return [4 /*yield*/, this.getBlocks()
|
|
237
|
+
// the core data block is always the first block in the slice
|
|
238
|
+
];
|
|
239
|
+
case 1:
|
|
240
|
+
blocks = _a.sent();
|
|
241
|
+
// the core data block is always the first block in the slice
|
|
242
|
+
return [2 /*return*/, blocks[0]];
|
|
637
243
|
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
mateRecordNumber = records[_i].mateRecordNumber;
|
|
658
|
-
if (mateRecordNumber >= 0) associateIntraSliceMate(records, _i, records[_i], records[mateRecordNumber]);
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
};
|
|
247
|
+
// memoize
|
|
248
|
+
CramSlice.prototype._getBlocksContentIdIndex = function () {
|
|
249
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
250
|
+
var blocks, blocksByContentId;
|
|
251
|
+
return __generator(this, function (_a) {
|
|
252
|
+
switch (_a.label) {
|
|
253
|
+
case 0: return [4 /*yield*/, this.getBlocks()];
|
|
254
|
+
case 1:
|
|
255
|
+
blocks = _a.sent();
|
|
256
|
+
blocksByContentId = {};
|
|
257
|
+
blocks.forEach(function (block) {
|
|
258
|
+
if (block.contentType === 'EXTERNAL_DATA') {
|
|
259
|
+
blocksByContentId[block.contentId] = block;
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
return [2 /*return*/, blocksByContentId];
|
|
659
263
|
}
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
return _fetchRecords2.apply(this, arguments);
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
return _fetchRecords;
|
|
676
|
-
}()
|
|
677
|
-
}, {
|
|
678
|
-
key: "getRecords",
|
|
679
|
-
value: function () {
|
|
680
|
-
var _getRecords = (0, _asyncToGenerator2.default)(
|
|
681
|
-
/*#__PURE__*/
|
|
682
|
-
_regenerator.default.mark(function _callee9(filterFunction) {
|
|
683
|
-
var _context13,
|
|
684
|
-
_this2 = this;
|
|
685
|
-
|
|
686
|
-
var cacheKey, recordsPromise, records, sliceHeader, _context14, singleRefId, _compressionScheme, refRegions, i, seqId, refRegion, end, _i2, _seqId, _refRegion;
|
|
687
|
-
|
|
688
|
-
return _regenerator.default.wrap(function _callee9$(_context16) {
|
|
689
|
-
while (1) {
|
|
690
|
-
switch (_context16.prev = _context16.next) {
|
|
691
|
-
case 0:
|
|
692
|
-
// fetch the features if necessary, using the file-level feature cache
|
|
693
|
-
cacheKey = this.container.filePosition + this.containerPosition;
|
|
694
|
-
recordsPromise = this.file.featureCache.get(cacheKey);
|
|
695
|
-
|
|
696
|
-
if (!recordsPromise) {
|
|
697
|
-
recordsPromise = this._fetchRecords();
|
|
698
|
-
this.file.featureCache.set(cacheKey, recordsPromise);
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
};
|
|
267
|
+
CramSlice.prototype.getBlockByContentId = function (id) {
|
|
268
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
269
|
+
var blocksByContentId;
|
|
270
|
+
return __generator(this, function (_a) {
|
|
271
|
+
switch (_a.label) {
|
|
272
|
+
case 0: return [4 /*yield*/, this._getBlocksContentIdIndex()];
|
|
273
|
+
case 1:
|
|
274
|
+
blocksByContentId = _a.sent();
|
|
275
|
+
return [2 /*return*/, blocksByContentId[id]];
|
|
699
276
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
};
|
|
280
|
+
CramSlice.prototype.getReferenceRegion = function () {
|
|
281
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
282
|
+
var sliceHeader, compressionScheme, refBlock, seq;
|
|
283
|
+
return __generator(this, function (_a) {
|
|
284
|
+
switch (_a.label) {
|
|
285
|
+
case 0: return [4 /*yield*/, this.getHeader()];
|
|
286
|
+
case 1:
|
|
287
|
+
sliceHeader = (_a.sent()).content;
|
|
288
|
+
if (sliceHeader.refSeqId < 0) {
|
|
289
|
+
return [2 /*return*/, undefined];
|
|
290
|
+
}
|
|
291
|
+
return [4 /*yield*/, this.container.getCompressionScheme()
|
|
292
|
+
// console.log(JSON.stringify(sliceHeader, null, ' '))
|
|
293
|
+
];
|
|
294
|
+
case 2:
|
|
295
|
+
compressionScheme = _a.sent();
|
|
296
|
+
// console.log(JSON.stringify(sliceHeader, null, ' '))
|
|
297
|
+
if (sliceHeader.refBaseBlockId >= 0) {
|
|
298
|
+
refBlock = this.getBlockByContentId(sliceHeader.refBaseBlockId);
|
|
299
|
+
if (!refBlock) {
|
|
300
|
+
throw new errors_1.CramMalformedError('embedded reference specified, but reference block does not exist');
|
|
301
|
+
}
|
|
302
|
+
if (sliceHeader.span > refBlock.uncompressedSize) {
|
|
303
|
+
throw new errors_1.CramMalformedError('Embedded reference is too small');
|
|
304
|
+
}
|
|
305
|
+
return [2 /*return*/, {
|
|
306
|
+
seq: refBlock.data.toString('utf8'),
|
|
307
|
+
start: sliceHeader.refSeqStart,
|
|
308
|
+
end: sliceHeader.refSeqStart + sliceHeader.refSeqSpan - 1,
|
|
309
|
+
span: sliceHeader.refSeqSpan,
|
|
310
|
+
}];
|
|
311
|
+
}
|
|
312
|
+
if (!(compressionScheme.referenceRequired ||
|
|
313
|
+
this.file.fetchReferenceSequenceCallback)) return [3 /*break*/, 4];
|
|
314
|
+
if (!this.file.fetchReferenceSequenceCallback) {
|
|
315
|
+
throw new Error('reference sequence not embedded, and seqFetch callback not provided, cannot fetch reference sequence');
|
|
316
|
+
}
|
|
317
|
+
return [4 /*yield*/, this.file.fetchReferenceSequenceCallback(sliceHeader.refSeqId, sliceHeader.refSeqStart, sliceHeader.refSeqStart + sliceHeader.refSeqSpan - 1)];
|
|
318
|
+
case 3:
|
|
319
|
+
seq = _a.sent();
|
|
320
|
+
if (seq.length !== sliceHeader.refSeqSpan) {
|
|
321
|
+
throw new errors_1.CramArgumentError('seqFetch callback returned a reference sequence of the wrong length');
|
|
322
|
+
}
|
|
323
|
+
return [2 /*return*/, {
|
|
324
|
+
seq: seq,
|
|
325
|
+
start: sliceHeader.refSeqStart,
|
|
326
|
+
end: sliceHeader.refSeqStart + sliceHeader.refSeqSpan - 1,
|
|
327
|
+
span: sliceHeader.refSeqSpan,
|
|
328
|
+
}];
|
|
329
|
+
case 4: return [2 /*return*/, undefined];
|
|
714
330
|
}
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
};
|
|
334
|
+
CramSlice.prototype.getAllRecords = function () {
|
|
335
|
+
return this.getRecords(function () { return true; });
|
|
336
|
+
};
|
|
337
|
+
CramSlice.prototype._fetchRecords = function () {
|
|
338
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
339
|
+
var majorVersion, compressionScheme, sliceHeader, blocksByContentId, refRegion, seq, start, end, seqMd5, storedMd5, coreDataBlock, cursors, decodeDataSeries, records, i, i, mateRecordNumber;
|
|
340
|
+
var _this = this;
|
|
341
|
+
return __generator(this, function (_a) {
|
|
342
|
+
switch (_a.label) {
|
|
343
|
+
case 0: return [4 /*yield*/, this.file.getDefinition()];
|
|
344
|
+
case 1:
|
|
345
|
+
majorVersion = (_a.sent()).majorVersion;
|
|
346
|
+
return [4 /*yield*/, this.container.getCompressionScheme()];
|
|
347
|
+
case 2:
|
|
348
|
+
compressionScheme = _a.sent();
|
|
349
|
+
return [4 /*yield*/, this.getHeader()];
|
|
350
|
+
case 3:
|
|
351
|
+
sliceHeader = _a.sent();
|
|
352
|
+
return [4 /*yield*/, this._getBlocksContentIdIndex()
|
|
353
|
+
// check MD5 of reference if available
|
|
354
|
+
];
|
|
355
|
+
case 4:
|
|
356
|
+
blocksByContentId = _a.sent();
|
|
357
|
+
if (!(majorVersion > 1 &&
|
|
358
|
+
this.file.options.checkSequenceMD5 &&
|
|
359
|
+
sliceHeader.content.refSeqId >= 0 &&
|
|
360
|
+
sliceHeader.content.md5.join('') !== '0000000000000000')) return [3 /*break*/, 6];
|
|
361
|
+
return [4 /*yield*/, this.getReferenceRegion()];
|
|
362
|
+
case 5:
|
|
363
|
+
refRegion = _a.sent();
|
|
364
|
+
if (refRegion) {
|
|
365
|
+
seq = refRegion.seq, start = refRegion.start, end = refRegion.end;
|
|
366
|
+
seqMd5 = (0, util_1.sequenceMD5)(seq);
|
|
367
|
+
storedMd5 = sliceHeader.content.md5
|
|
368
|
+
.map(function (byte) { return (byte < 16 ? '0' : '') + byte.toString(16); })
|
|
369
|
+
.join('');
|
|
370
|
+
if (seqMd5 !== storedMd5) {
|
|
371
|
+
throw new errors_1.CramMalformedError("MD5 checksum reference mismatch for ref ".concat(sliceHeader.content.refSeqId, " pos ").concat(start, "..").concat(end, ". recorded MD5: ").concat(storedMd5, ", calculated MD5: ").concat(seqMd5));
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
_a.label = 6;
|
|
375
|
+
case 6: return [4 /*yield*/, this.getCoreDataBlock()];
|
|
376
|
+
case 7:
|
|
377
|
+
coreDataBlock = _a.sent();
|
|
378
|
+
cursors = {
|
|
379
|
+
lastAlignmentStart: sliceHeader.content.refSeqStart || 0,
|
|
380
|
+
coreBlock: { bitPosition: 7, bytePosition: 0 },
|
|
381
|
+
externalBlocks: {
|
|
382
|
+
getCursor: function (contentId) {
|
|
383
|
+
if (!this[contentId]) {
|
|
384
|
+
this[contentId] = { bitPosition: 7, bytePosition: 0 };
|
|
385
|
+
}
|
|
386
|
+
return this[contentId];
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
};
|
|
390
|
+
decodeDataSeries = function (dataSeriesName) {
|
|
391
|
+
var codec = compressionScheme.getCodecForDataSeries(dataSeriesName);
|
|
392
|
+
if (!codec) {
|
|
393
|
+
throw new errors_1.CramMalformedError("no codec defined for ".concat(dataSeriesName, " data series"));
|
|
394
|
+
}
|
|
395
|
+
// console.log(dataSeriesName, Object.getPrototypeOf(codec))
|
|
396
|
+
return codec.decode(_this, coreDataBlock, blocksByContentId, cursors);
|
|
397
|
+
};
|
|
398
|
+
records = new Array(sliceHeader.content.numRecords);
|
|
399
|
+
for (i = 0; i < records.length; i += 1) {
|
|
400
|
+
try {
|
|
401
|
+
records[i] = (0, decodeRecord_1.default)(this, decodeDataSeries, compressionScheme, sliceHeader, coreDataBlock, blocksByContentId, cursors, majorVersion, i);
|
|
402
|
+
records[i].uniqueId =
|
|
403
|
+
sliceHeader.contentPosition +
|
|
404
|
+
sliceHeader.content.recordCounter +
|
|
405
|
+
i +
|
|
406
|
+
1;
|
|
407
|
+
}
|
|
408
|
+
catch (e) {
|
|
409
|
+
if (e instanceof errors_1.CramBufferOverrunError) {
|
|
410
|
+
console.warn('read attempted beyond end of buffer, file seems truncated.');
|
|
411
|
+
records = records.filter(function (r) { return !!r; });
|
|
412
|
+
break;
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
throw e;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
// interpret `recordsToNextFragment` attributes to make standard `mate` objects
|
|
420
|
+
// Resolve mate pair cross-references between records in this slice
|
|
421
|
+
for (i = 0; i < records.length; i += 1) {
|
|
422
|
+
mateRecordNumber = records[i].mateRecordNumber;
|
|
423
|
+
if (mateRecordNumber >= 0) {
|
|
424
|
+
associateIntraSliceMate(records, i, records[i], records[mateRecordNumber]);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return [2 /*return*/, records];
|
|
727
428
|
}
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
};
|
|
432
|
+
CramSlice.prototype.getRecords = function (filterFunction) {
|
|
433
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
434
|
+
var cacheKey, recordsPromise, records, sliceHeader, singleRefId, compressionScheme, refRegions, i, seqId, refRegion, end, i, seqId, refRegion;
|
|
435
|
+
var _this = this;
|
|
436
|
+
return __generator(this, function (_a) {
|
|
437
|
+
switch (_a.label) {
|
|
438
|
+
case 0:
|
|
439
|
+
cacheKey = this.container.filePosition + this.containerPosition;
|
|
440
|
+
recordsPromise = this.file.featureCache.get(cacheKey);
|
|
441
|
+
if (!recordsPromise) {
|
|
442
|
+
recordsPromise = this._fetchRecords();
|
|
443
|
+
this.file.featureCache.set(cacheKey, recordsPromise);
|
|
444
|
+
}
|
|
445
|
+
return [4 /*yield*/, recordsPromise];
|
|
446
|
+
case 1:
|
|
447
|
+
records = (_a.sent()).filter(filterFunction);
|
|
448
|
+
if (!(records.length && this.file.fetchReferenceSequenceCallback)) return [3 /*break*/, 5];
|
|
449
|
+
return [4 /*yield*/, this.getHeader()];
|
|
450
|
+
case 2:
|
|
451
|
+
sliceHeader = _a.sent();
|
|
452
|
+
if (!(sliceHeader.content.refSeqId >= 0 || // single-ref slice
|
|
453
|
+
sliceHeader.content.refSeqId === -2) // multi-ref slice
|
|
454
|
+
) return [3 /*break*/, 5]; // multi-ref slice
|
|
455
|
+
singleRefId = sliceHeader.content.refSeqId >= 0
|
|
456
|
+
? sliceHeader.content.refSeqId
|
|
457
|
+
: undefined;
|
|
458
|
+
return [4 /*yield*/, this.container.getCompressionScheme()];
|
|
459
|
+
case 3:
|
|
460
|
+
compressionScheme = _a.sent();
|
|
461
|
+
refRegions = {} // seqId => { start, end, seq }
|
|
462
|
+
;
|
|
463
|
+
// iterate over the records to find the spans of the reference sequences we need to fetch
|
|
464
|
+
for (i = 0; i < records.length; i += 1) {
|
|
465
|
+
seqId = singleRefId !== undefined ? singleRefId : records[i].sequenceId;
|
|
466
|
+
refRegion = refRegions[seqId];
|
|
467
|
+
if (!refRegion) {
|
|
468
|
+
refRegion = {
|
|
469
|
+
id: seqId,
|
|
470
|
+
start: records[i].alignmentStart,
|
|
471
|
+
end: -Infinity,
|
|
472
|
+
};
|
|
473
|
+
refRegions[seqId] = refRegion;
|
|
474
|
+
}
|
|
475
|
+
end = records[i].alignmentStart +
|
|
476
|
+
(records[i].lengthOnRef || records[i].readLength) -
|
|
477
|
+
1;
|
|
478
|
+
if (end > refRegion.end) {
|
|
479
|
+
refRegion.end = end;
|
|
480
|
+
}
|
|
481
|
+
if (records[i].alignmentStart < refRegion.start) {
|
|
482
|
+
refRegion.start = records[i].alignmentStart;
|
|
771
483
|
}
|
|
772
|
-
|
|
773
|
-
_context15.next = 3;
|
|
774
|
-
return _this2.file.fetchReferenceSequenceCallback(refRegion.id, refRegion.start, refRegion.end);
|
|
775
|
-
|
|
776
|
-
case 3:
|
|
777
|
-
refRegion.seq = _context15.sent;
|
|
778
|
-
|
|
779
|
-
case 4:
|
|
780
|
-
case "end":
|
|
781
|
-
return _context15.stop();
|
|
782
484
|
}
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
485
|
+
// fetch the `seq` for all of the ref regions
|
|
486
|
+
return [4 /*yield*/, Promise.all(Object.values(refRegions).map(function (refRegion) { return __awaiter(_this, void 0, void 0, function () {
|
|
487
|
+
var _a;
|
|
488
|
+
return __generator(this, function (_b) {
|
|
489
|
+
switch (_b.label) {
|
|
490
|
+
case 0:
|
|
491
|
+
if (!(refRegion.id !== -1 && refRegion.start <= refRegion.end)) return [3 /*break*/, 2];
|
|
492
|
+
_a = refRegion;
|
|
493
|
+
return [4 /*yield*/, this.file.fetchReferenceSequenceCallback(refRegion.id, refRegion.start, refRegion.end)];
|
|
494
|
+
case 1:
|
|
495
|
+
_a.seq = _b.sent();
|
|
496
|
+
_b.label = 2;
|
|
497
|
+
case 2: return [2 /*return*/];
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
}); }))
|
|
501
|
+
// now decorate all the records with them
|
|
502
|
+
];
|
|
503
|
+
case 4:
|
|
504
|
+
// fetch the `seq` for all of the ref regions
|
|
505
|
+
_a.sent();
|
|
506
|
+
// now decorate all the records with them
|
|
507
|
+
for (i = 0; i < records.length; i += 1) {
|
|
508
|
+
seqId = singleRefId !== undefined ? singleRefId : records[i].sequenceId;
|
|
509
|
+
refRegion = refRegions[seqId];
|
|
510
|
+
if (refRegion && refRegion.seq) {
|
|
511
|
+
records[i].addReferenceSequence(refRegion, compressionScheme);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
_a.label = 5;
|
|
515
|
+
case 5: return [2 /*return*/, records];
|
|
801
516
|
}
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
function getRecords(_x2) {
|
|
815
|
-
return _getRecords.apply(this, arguments);
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
return getRecords;
|
|
819
|
-
}()
|
|
820
|
-
}]);
|
|
821
|
-
return CramSlice;
|
|
822
|
-
}(); // memoize several methods in the class for performance
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
(0, _forEach.default)(_context17 = 'getHeader getBlocks _getBlocksContentIdIndex'.split(' ')).call(_context17, function (method) {
|
|
826
|
-
return tinyMemoize(CramSlice, method);
|
|
827
|
-
});
|
|
828
|
-
module.exports = CramSlice;
|
|
517
|
+
});
|
|
518
|
+
});
|
|
519
|
+
};
|
|
520
|
+
return CramSlice;
|
|
521
|
+
}());
|
|
522
|
+
exports.default = CramSlice;
|
|
523
|
+
// memoize several methods in the class for performance
|
|
524
|
+
'getHeader getBlocks _getBlocksContentIdIndex'
|
|
525
|
+
.split(' ')
|
|
526
|
+
.forEach(function (method) { return (0, util_1.tinyMemoize)(CramSlice, method); });
|
|
527
|
+
//# sourceMappingURL=index.js.map
|