@gmod/cram 1.6.3 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/dist/craiIndex.d.ts +19 -12
- package/dist/craiIndex.js +63 -123
- package/dist/craiIndex.js.map +1 -1
- package/dist/cram-bundle.js +2 -17
- package/dist/cram-bundle.js.LICENSE.txt +17 -0
- package/dist/cramFile/codecs/_base.d.ts +26 -5
- package/dist/cramFile/codecs/_base.js +3 -39
- package/dist/cramFile/codecs/_base.js.map +1 -1
- package/dist/cramFile/codecs/beta.d.ts +7 -3
- package/dist/cramFile/codecs/beta.js +13 -31
- package/dist/cramFile/codecs/beta.js.map +1 -1
- package/dist/cramFile/codecs/byteArrayLength.d.ts +13 -7
- package/dist/cramFile/codecs/byteArrayLength.js +22 -41
- package/dist/cramFile/codecs/byteArrayLength.js.map +1 -1
- package/dist/cramFile/codecs/byteArrayStop.d.ts +9 -5
- package/dist/cramFile/codecs/byteArrayStop.js +25 -46
- package/dist/cramFile/codecs/byteArrayStop.js.map +1 -1
- package/dist/cramFile/codecs/dataSeriesTypes.d.ts +4 -0
- package/dist/cramFile/codecs/dataSeriesTypes.js +3 -0
- package/dist/cramFile/codecs/dataSeriesTypes.js.map +1 -0
- package/dist/cramFile/codecs/external.d.ts +10 -6
- package/dist/cramFile/codecs/external.js +26 -44
- package/dist/cramFile/codecs/external.js.map +1 -1
- package/dist/cramFile/codecs/gamma.d.ts +7 -3
- package/dist/cramFile/codecs/gamma.js +16 -34
- package/dist/cramFile/codecs/gamma.js.map +1 -1
- package/dist/cramFile/codecs/getBits.d.ts +7 -0
- package/dist/cramFile/codecs/getBits.js +26 -0
- package/dist/cramFile/codecs/getBits.js.map +1 -0
- package/dist/cramFile/codecs/huffman.d.ts +17 -13
- package/dist/cramFile/codecs/huffman.js +76 -85
- package/dist/cramFile/codecs/huffman.js.map +1 -1
- package/dist/cramFile/codecs/index.d.ts +4 -2
- package/dist/cramFile/codecs/index.js +12 -13
- package/dist/cramFile/codecs/index.js.map +1 -1
- package/dist/cramFile/codecs/subexp.d.ts +7 -3
- package/dist/cramFile/codecs/subexp.js +19 -36
- package/dist/cramFile/codecs/subexp.js.map +1 -1
- package/dist/cramFile/constants.d.ts +35 -35
- package/dist/cramFile/constants.js +1 -1
- package/dist/cramFile/constants.js.map +1 -1
- package/dist/cramFile/container/compressionScheme.d.ts +57 -11
- package/dist/cramFile/container/compressionScheme.js +37 -32
- package/dist/cramFile/container/compressionScheme.js.map +1 -1
- package/dist/cramFile/container/index.d.ts +23 -9
- package/dist/cramFile/container/index.js +74 -144
- package/dist/cramFile/container/index.js.map +1 -1
- package/dist/cramFile/encoding.d.ts +78 -0
- package/dist/cramFile/encoding.js +3 -0
- package/dist/cramFile/encoding.js.map +1 -0
- package/dist/cramFile/file.d.ts +91 -41
- package/dist/cramFile/file.js +234 -368
- package/dist/cramFile/file.js.map +1 -1
- package/dist/cramFile/filehandle.d.ts +2 -0
- package/dist/cramFile/filehandle.js +3 -0
- package/dist/cramFile/filehandle.js.map +1 -0
- package/dist/cramFile/index.d.ts +1 -1
- package/dist/cramFile/index.js +1 -1
- package/dist/cramFile/index.js.map +1 -1
- package/dist/cramFile/record.d.ts +61 -17
- package/dist/cramFile/record.js +153 -77
- package/dist/cramFile/record.js.map +1 -1
- package/dist/cramFile/sectionParsers.d.ts +99 -8
- package/dist/cramFile/sectionParsers.js +70 -80
- package/dist/cramFile/sectionParsers.js.map +1 -1
- package/dist/cramFile/slice/decodeRecord.d.ts +30 -2
- package/dist/cramFile/slice/decodeRecord.js +148 -118
- package/dist/cramFile/slice/decodeRecord.js.map +1 -1
- package/dist/cramFile/slice/index.d.ts +21 -14
- package/dist/cramFile/slice/index.js +286 -381
- package/dist/cramFile/slice/index.js.map +1 -1
- package/dist/cramFile/util.d.ts +11 -5
- package/dist/cramFile/util.js +19 -97
- package/dist/cramFile/util.js.map +1 -1
- package/dist/errors.d.ts +5 -10
- package/dist/errors.js +11 -62
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/indexedCramFile.d.ts +37 -12
- package/dist/indexedCramFile.js +114 -154
- package/dist/indexedCramFile.js.map +1 -1
- package/dist/io/index.d.ts +5 -5
- package/dist/io/index.js +9 -9
- package/dist/io/index.js.map +1 -1
- package/dist/rans/constants.js +3 -3
- package/dist/rans/constants.js.map +1 -1
- package/dist/rans/d04.js +15 -15
- package/dist/rans/d04.js.map +1 -1
- package/dist/rans/d14.js +21 -21
- package/dist/rans/d14.js.map +1 -1
- package/dist/rans/decoding.js +27 -30
- package/dist/rans/decoding.js.map +1 -1
- package/dist/rans/frequencies.js +11 -11
- package/dist/rans/frequencies.js.map +1 -1
- package/dist/rans/index.js +46 -49
- package/dist/rans/index.js.map +1 -1
- package/dist/sam.d.ts +8 -1
- package/dist/sam.js +7 -7
- package/dist/sam.js.map +1 -1
- package/dist/typescript.d.ts +3 -0
- package/dist/typescript.js +11 -0
- package/dist/typescript.js.map +1 -0
- package/dist/unzip-pako.js +1 -1
- package/dist/unzip-pako.js.map +1 -1
- package/dist/unzip.js +1 -1
- package/dist/unzip.js.map +1 -1
- package/errors.js +11 -62
- package/esm/craiIndex.d.ts +19 -12
- package/esm/craiIndex.js +8 -24
- package/esm/craiIndex.js.map +1 -1
- package/esm/cramFile/codecs/_base.d.ts +26 -5
- package/esm/cramFile/codecs/_base.js +1 -35
- package/esm/cramFile/codecs/_base.js.map +1 -1
- package/esm/cramFile/codecs/beta.d.ts +7 -3
- package/esm/cramFile/codecs/beta.js +4 -3
- package/esm/cramFile/codecs/beta.js.map +1 -1
- package/esm/cramFile/codecs/byteArrayLength.d.ts +13 -7
- package/esm/cramFile/codecs/byteArrayLength.js +1 -1
- package/esm/cramFile/codecs/byteArrayLength.js.map +1 -1
- package/esm/cramFile/codecs/byteArrayStop.d.ts +9 -5
- package/esm/cramFile/codecs/byteArrayStop.js +7 -9
- package/esm/cramFile/codecs/byteArrayStop.js.map +1 -1
- package/esm/cramFile/codecs/dataSeriesTypes.d.ts +4 -0
- package/esm/cramFile/codecs/dataSeriesTypes.js +2 -0
- package/esm/cramFile/codecs/dataSeriesTypes.js.map +1 -0
- package/esm/cramFile/codecs/external.d.ts +10 -6
- package/esm/cramFile/codecs/external.js +4 -3
- package/esm/cramFile/codecs/external.js.map +1 -1
- package/esm/cramFile/codecs/gamma.d.ts +7 -3
- package/esm/cramFile/codecs/gamma.js +5 -4
- package/esm/cramFile/codecs/gamma.js.map +1 -1
- package/esm/cramFile/codecs/getBits.d.ts +7 -0
- package/esm/cramFile/codecs/getBits.js +21 -0
- package/esm/cramFile/codecs/getBits.js.map +1 -0
- package/esm/cramFile/codecs/huffman.d.ts +17 -13
- package/esm/cramFile/codecs/huffman.js +22 -9
- package/esm/cramFile/codecs/huffman.js.map +1 -1
- package/esm/cramFile/codecs/index.d.ts +4 -2
- package/esm/cramFile/codecs/index.js +1 -1
- package/esm/cramFile/codecs/index.js.map +1 -1
- package/esm/cramFile/codecs/subexp.d.ts +7 -3
- package/esm/cramFile/codecs/subexp.js +7 -5
- package/esm/cramFile/codecs/subexp.js.map +1 -1
- package/esm/cramFile/constants.d.ts +35 -35
- package/esm/cramFile/constants.js.map +1 -1
- package/esm/cramFile/container/compressionScheme.d.ts +57 -11
- package/esm/cramFile/container/compressionScheme.js +15 -8
- package/esm/cramFile/container/compressionScheme.js.map +1 -1
- package/esm/cramFile/container/index.d.ts +23 -9
- package/esm/cramFile/container/index.js +11 -9
- package/esm/cramFile/container/index.js.map +1 -1
- package/esm/cramFile/encoding.d.ts +78 -0
- package/esm/cramFile/encoding.js +2 -0
- package/esm/cramFile/encoding.js.map +1 -0
- package/esm/cramFile/file.d.ts +91 -41
- package/esm/cramFile/file.js +59 -47
- package/esm/cramFile/file.js.map +1 -1
- package/esm/cramFile/filehandle.d.ts +2 -0
- package/esm/cramFile/filehandle.js +2 -0
- package/esm/cramFile/filehandle.js.map +1 -0
- package/esm/cramFile/index.d.ts +1 -1
- package/esm/cramFile/index.js.map +1 -1
- package/esm/cramFile/record.d.ts +61 -17
- package/esm/cramFile/record.js +83 -5
- package/esm/cramFile/record.js.map +1 -1
- package/esm/cramFile/sectionParsers.d.ts +99 -8
- package/esm/cramFile/sectionParsers.js +7 -17
- package/esm/cramFile/sectionParsers.js.map +1 -1
- package/esm/cramFile/slice/decodeRecord.d.ts +30 -2
- package/esm/cramFile/slice/decodeRecord.js +102 -70
- package/esm/cramFile/slice/decodeRecord.js.map +1 -1
- package/esm/cramFile/slice/index.d.ts +21 -14
- package/esm/cramFile/slice/index.js +77 -38
- package/esm/cramFile/slice/index.js.map +1 -1
- package/esm/cramFile/util.d.ts +11 -5
- package/esm/cramFile/util.js +11 -82
- package/esm/cramFile/util.js.map +1 -1
- package/esm/errors.d.ts +5 -10
- package/esm/errors.js +0 -5
- package/esm/errors.js.map +1 -1
- package/esm/index.d.ts +3 -3
- package/esm/index.js.map +1 -1
- package/esm/indexedCramFile.d.ts +37 -12
- package/esm/indexedCramFile.js +19 -8
- package/esm/indexedCramFile.js.map +1 -1
- package/esm/io/index.d.ts +5 -5
- package/esm/io/index.js +3 -3
- package/esm/io/index.js.map +1 -1
- package/esm/sam.d.ts +8 -1
- package/esm/sam.js.map +1 -1
- package/esm/typescript.d.ts +3 -0
- package/esm/typescript.js +7 -0
- package/esm/typescript.js.map +1 -0
- package/package.json +18 -11
- package/src/{craiIndex.js → craiIndex.ts} +37 -31
- package/src/cramFile/codecs/_base.ts +45 -0
- package/src/cramFile/codecs/beta.ts +34 -0
- package/src/cramFile/codecs/{byteArrayLength.js → byteArrayLength.ts} +27 -5
- package/src/cramFile/codecs/{byteArrayStop.js → byteArrayStop.ts} +25 -12
- package/src/cramFile/codecs/dataSeriesTypes.ts +39 -0
- package/src/cramFile/codecs/{external.js → external.ts} +28 -12
- package/src/cramFile/codecs/gamma.ts +42 -0
- package/src/cramFile/codecs/getBits.ts +28 -0
- package/src/cramFile/codecs/{huffman.js → huffman.ts} +48 -15
- package/src/cramFile/codecs/{index.js → index.ts} +9 -3
- package/src/cramFile/codecs/subexp.ts +45 -0
- package/src/cramFile/{constants.js → constants.ts} +0 -0
- package/src/cramFile/container/{compressionScheme.js → compressionScheme.ts} +50 -18
- package/src/cramFile/container/{index.js → index.ts} +13 -13
- package/src/cramFile/encoding.ts +98 -0
- package/src/cramFile/{file.js → file.ts} +136 -62
- package/src/cramFile/filehandle.ts +3 -0
- package/src/cramFile/{index.js → index.ts} +0 -0
- package/src/cramFile/{record.js → record.ts} +185 -14
- package/src/cramFile/{sectionParsers.js → sectionParsers.ts} +148 -20
- package/src/cramFile/slice/{decodeRecord.js → decodeRecord.ts} +158 -105
- package/src/cramFile/slice/{index.js → index.ts} +138 -63
- package/src/cramFile/{util.js → util.ts} +28 -17
- package/src/{errors.js → errors.ts} +0 -5
- package/src/{index.js → index.ts} +0 -0
- package/src/{indexedCramFile.js → indexedCramFile.ts} +79 -19
- package/src/io/{index.js → index.ts} +10 -5
- package/src/{sam.js → sam.ts} +7 -2
- package/src/typescript.ts +17 -0
- package/src/typings/binary-parser.d.ts +44 -0
- package/src/typings/bzip2.d.ts +7 -0
- package/src/typings/htscodecs.d.ts +6 -0
- package/dist/io/bufferCache.d.ts +0 -12
- package/dist/io/bufferCache.js +0 -112
- package/dist/io/bufferCache.js.map +0 -1
- package/dist/io/localFile.d.ts +0 -10
- package/dist/io/localFile.js +0 -108
- package/dist/io/localFile.js.map +0 -1
- package/dist/io/remoteFile.d.ts +0 -16
- package/dist/io/remoteFile.js +0 -143
- package/dist/io/remoteFile.js.map +0 -1
- package/esm/io/bufferCache.d.ts +0 -12
- package/esm/io/bufferCache.js +0 -54
- package/esm/io/bufferCache.js.map +0 -1
- package/esm/io/localFile.d.ts +0 -10
- package/esm/io/localFile.js +0 -31
- package/esm/io/localFile.js.map +0 -1
- package/esm/io/remoteFile.d.ts +0 -16
- package/esm/io/remoteFile.js +0 -64
- package/esm/io/remoteFile.js.map +0 -1
- package/src/cramFile/codecs/_base.js +0 -49
- package/src/cramFile/codecs/beta.js +0 -23
- package/src/cramFile/codecs/gamma.js +0 -30
- package/src/cramFile/codecs/subexp.js +0 -32
- package/src/io/bufferCache.js +0 -66
- package/src/io/localFile.js +0 -35
- package/src/io/remoteFile.js +0 -71
|
@@ -8,41 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
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
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
13
|
};
|
|
41
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
15
|
+
const errors_1 = require("../../errors");
|
|
16
|
+
const util_1 = require("../util");
|
|
17
|
+
const constants_1 = __importDefault(require("../constants"));
|
|
18
|
+
const decodeRecord_1 = __importDefault(require("./decodeRecord"));
|
|
19
|
+
const record_1 = __importDefault(require("../record"));
|
|
20
|
+
const sectionParsers_1 = require("../sectionParsers");
|
|
21
|
+
const getBits_1 = require("../codecs/getBits");
|
|
46
22
|
/**
|
|
47
23
|
* @private
|
|
48
24
|
* Try to estimate the template length from a bunch of interrelated multi-segment reads.
|
|
@@ -52,22 +28,23 @@ var decodeRecord_1 = __importDefault(require("./decodeRecord"));
|
|
|
52
28
|
*/
|
|
53
29
|
function calculateMultiSegmentMatedTemplateLength(allRecords, currentRecordNumber, thisRecord) {
|
|
54
30
|
function getAllMatedRecords(startRecord) {
|
|
55
|
-
|
|
56
|
-
if (startRecord.mateRecordNumber
|
|
57
|
-
|
|
31
|
+
const records = [startRecord];
|
|
32
|
+
if (startRecord.mateRecordNumber !== undefined &&
|
|
33
|
+
startRecord.mateRecordNumber >= 0) {
|
|
34
|
+
const mateRecord = allRecords[startRecord.mateRecordNumber];
|
|
58
35
|
if (!mateRecord) {
|
|
59
36
|
throw new errors_1.CramMalformedError('intra-slice mate record not found, this file seems malformed');
|
|
60
37
|
}
|
|
61
|
-
records.push
|
|
38
|
+
records.push(...getAllMatedRecords(mateRecord));
|
|
62
39
|
}
|
|
63
40
|
return records;
|
|
64
41
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
42
|
+
const matedRecords = getAllMatedRecords(thisRecord);
|
|
43
|
+
const starts = matedRecords.map(r => r.alignmentStart);
|
|
44
|
+
const ends = matedRecords.map(r => r.alignmentStart + r.readLength - 1);
|
|
45
|
+
const estimatedTemplateLength = Math.max(...ends) - Math.min(...starts) + 1;
|
|
69
46
|
if (estimatedTemplateLength >= 0) {
|
|
70
|
-
matedRecords.forEach(
|
|
47
|
+
matedRecords.forEach(r => {
|
|
71
48
|
if (r.templateLength !== undefined) {
|
|
72
49
|
throw new errors_1.CramMalformedError('mate pair group has some members that have template lengths already, this file seems malformed');
|
|
73
50
|
}
|
|
@@ -85,9 +62,9 @@ function calculateMultiSegmentMatedTemplateLength(allRecords, currentRecordNumbe
|
|
|
85
62
|
function calculateIntraSliceMatePairTemplateLength(thisRecord, mateRecord) {
|
|
86
63
|
// this just estimates the template length by using the simple (non-gapped) end coordinate of each
|
|
87
64
|
// read, because gapping in the alignment doesn't mean the template is longer or shorter
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
65
|
+
const start = Math.min(thisRecord.alignmentStart, mateRecord.alignmentStart);
|
|
66
|
+
const end = Math.max(thisRecord.alignmentStart + thisRecord.readLength - 1, mateRecord.alignmentStart + mateRecord.readLength - 1);
|
|
67
|
+
const lengthEstimate = end - start + 1;
|
|
91
68
|
thisRecord.templateLength = lengthEstimate;
|
|
92
69
|
mateRecord.templateLength = lengthEstimate;
|
|
93
70
|
}
|
|
@@ -100,7 +77,7 @@ function associateIntraSliceMate(allRecords, currentRecordNumber, thisRecord, ma
|
|
|
100
77
|
if (!mateRecord) {
|
|
101
78
|
throw new errors_1.CramMalformedError('could not resolve intra-slice mate pairs, file seems truncated or malformed');
|
|
102
79
|
}
|
|
103
|
-
|
|
80
|
+
const complicatedMultiSegment = !!(mateRecord.mate ||
|
|
104
81
|
(mateRecord.mateRecordNumber !== undefined &&
|
|
105
82
|
mateRecord.mateRecordNumber !== currentRecordNumber));
|
|
106
83
|
// Deal with lossy read names
|
|
@@ -160,371 +137,299 @@ function associateIntraSliceMate(allRecords, currentRecordNumber, thisRecord, ma
|
|
|
160
137
|
// complicated template length estimation
|
|
161
138
|
delete thisRecord.mateRecordNumber;
|
|
162
139
|
}
|
|
163
|
-
|
|
164
|
-
|
|
140
|
+
class CramSlice {
|
|
141
|
+
constructor(container, containerPosition, _unused) {
|
|
165
142
|
this.container = container;
|
|
143
|
+
this.containerPosition = containerPosition;
|
|
166
144
|
this.file = container.file;
|
|
167
|
-
this.containerPosition = position;
|
|
168
145
|
}
|
|
169
146
|
// memoize
|
|
170
|
-
|
|
171
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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];
|
|
194
|
-
}
|
|
195
|
-
});
|
|
147
|
+
getHeader() {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
// fetch and parse the slice header
|
|
150
|
+
const sectionParsers = yield this.file.getSectionParsers();
|
|
151
|
+
const containerHeader = yield this.container.getHeader();
|
|
152
|
+
const header = yield this.file.readBlock(containerHeader._endPosition + this.containerPosition);
|
|
153
|
+
if (header === undefined) {
|
|
154
|
+
throw new Error();
|
|
155
|
+
}
|
|
156
|
+
if (header.contentType === 'MAPPED_SLICE_HEADER') {
|
|
157
|
+
const content = (0, util_1.parseItem)(header.content, sectionParsers.cramMappedSliceHeader.parser, 0, containerHeader._endPosition);
|
|
158
|
+
return Object.assign(Object.assign({}, header), { parsedContent: content });
|
|
159
|
+
}
|
|
160
|
+
else if (header.contentType === 'UNMAPPED_SLICE_HEADER') {
|
|
161
|
+
const content = (0, util_1.parseItem)(header.content, sectionParsers.cramUnmappedSliceHeader.parser, 0, containerHeader._endPosition);
|
|
162
|
+
return Object.assign(Object.assign({}, header), { parsedContent: content });
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
throw new errors_1.CramMalformedError(`error reading slice header block, invalid content type ${header.contentType}`);
|
|
166
|
+
}
|
|
196
167
|
});
|
|
197
|
-
}
|
|
168
|
+
}
|
|
198
169
|
// memoize
|
|
199
|
-
|
|
200
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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];
|
|
170
|
+
getBlocks() {
|
|
171
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
+
const header = yield this.getHeader();
|
|
173
|
+
// read all the blocks into memory and store them
|
|
174
|
+
let blockPosition = header._endPosition;
|
|
175
|
+
const blocks = new Array(header.parsedContent.numBlocks);
|
|
176
|
+
for (let i = 0; i < blocks.length; i += 1) {
|
|
177
|
+
const block = yield this.file.readBlock(blockPosition);
|
|
178
|
+
if (block === undefined) {
|
|
179
|
+
throw new Error();
|
|
226
180
|
}
|
|
227
|
-
|
|
181
|
+
blocks[i] = block;
|
|
182
|
+
blockPosition = blocks[i]._endPosition;
|
|
183
|
+
}
|
|
184
|
+
return blocks;
|
|
228
185
|
});
|
|
229
|
-
}
|
|
186
|
+
}
|
|
230
187
|
// no memoize
|
|
231
|
-
|
|
232
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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]];
|
|
243
|
-
}
|
|
244
|
-
});
|
|
188
|
+
getCoreDataBlock() {
|
|
189
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
+
const blocks = yield this.getBlocks();
|
|
191
|
+
// the core data block is always the first block in the slice
|
|
192
|
+
return blocks[0];
|
|
245
193
|
});
|
|
246
|
-
}
|
|
194
|
+
}
|
|
247
195
|
// memoize
|
|
248
|
-
|
|
249
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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];
|
|
196
|
+
_getBlocksContentIdIndex() {
|
|
197
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
198
|
+
const blocks = yield this.getBlocks();
|
|
199
|
+
const blocksByContentId = {};
|
|
200
|
+
blocks.forEach(block => {
|
|
201
|
+
if (block.contentType === 'EXTERNAL_DATA') {
|
|
202
|
+
blocksByContentId[block.contentId] = block;
|
|
263
203
|
}
|
|
264
204
|
});
|
|
205
|
+
return blocksByContentId;
|
|
265
206
|
});
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
269
|
-
|
|
270
|
-
return
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
207
|
+
}
|
|
208
|
+
getBlockByContentId(id) {
|
|
209
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
210
|
+
const blocksByContentId = yield this._getBlocksContentIdIndex();
|
|
211
|
+
return blocksByContentId[id];
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
getReferenceRegion() {
|
|
215
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
216
|
+
// read the slice header
|
|
217
|
+
const sliceHeader = (yield this.getHeader()).parsedContent;
|
|
218
|
+
if (!(0, sectionParsers_1.isMappedSliceHeader)(sliceHeader)) {
|
|
219
|
+
throw new Error();
|
|
220
|
+
}
|
|
221
|
+
if (sliceHeader.refSeqId < 0) {
|
|
222
|
+
return undefined;
|
|
223
|
+
}
|
|
224
|
+
const compressionScheme = yield this.container.getCompressionScheme();
|
|
225
|
+
if (compressionScheme === undefined) {
|
|
226
|
+
throw new Error();
|
|
227
|
+
}
|
|
228
|
+
// console.log(JSON.stringify(sliceHeader, null, ' '))
|
|
229
|
+
if (sliceHeader.refBaseBlockId >= 0) {
|
|
230
|
+
const refBlock = yield this.getBlockByContentId(sliceHeader.refBaseBlockId);
|
|
231
|
+
if (!refBlock) {
|
|
232
|
+
throw new errors_1.CramMalformedError('embedded reference specified, but reference block does not exist');
|
|
276
233
|
}
|
|
277
|
-
|
|
234
|
+
// TODO: we do not read anything named 'span'
|
|
235
|
+
// if (sliceHeader.span > refBlock.uncompressedSize) {
|
|
236
|
+
// throw new CramMalformedError('Embedded reference is too small')
|
|
237
|
+
// }
|
|
238
|
+
// TODO verify
|
|
239
|
+
return {
|
|
240
|
+
seq: refBlock.data.toString('utf8'),
|
|
241
|
+
start: sliceHeader.refSeqStart,
|
|
242
|
+
end: sliceHeader.refSeqStart + sliceHeader.refSeqSpan - 1,
|
|
243
|
+
span: sliceHeader.refSeqSpan,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
if (compressionScheme.referenceRequired ||
|
|
247
|
+
this.file.fetchReferenceSequenceCallback) {
|
|
248
|
+
if (!this.file.fetchReferenceSequenceCallback) {
|
|
249
|
+
throw new Error('reference sequence not embedded, and seqFetch callback not provided, cannot fetch reference sequence');
|
|
250
|
+
}
|
|
251
|
+
const seq = yield this.file.fetchReferenceSequenceCallback(sliceHeader.refSeqId, sliceHeader.refSeqStart, sliceHeader.refSeqStart + sliceHeader.refSeqSpan - 1);
|
|
252
|
+
if (seq.length !== sliceHeader.refSeqSpan) {
|
|
253
|
+
throw new errors_1.CramArgumentError('seqFetch callback returned a reference sequence of the wrong length');
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
seq,
|
|
257
|
+
start: sliceHeader.refSeqStart,
|
|
258
|
+
end: sliceHeader.refSeqStart + sliceHeader.refSeqSpan - 1,
|
|
259
|
+
span: sliceHeader.refSeqSpan,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
return undefined;
|
|
278
263
|
});
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
return
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
-
|
|
264
|
+
}
|
|
265
|
+
getAllRecords() {
|
|
266
|
+
return this.getRecords(() => true);
|
|
267
|
+
}
|
|
268
|
+
_fetchRecords() {
|
|
269
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
270
|
+
const { majorVersion } = yield this.file.getDefinition();
|
|
271
|
+
const compressionScheme = yield this.container.getCompressionScheme();
|
|
272
|
+
if (compressionScheme === undefined) {
|
|
273
|
+
throw new Error();
|
|
274
|
+
}
|
|
275
|
+
const sliceHeader = yield this.getHeader();
|
|
276
|
+
if (sliceHeader === undefined) {
|
|
277
|
+
throw new Error();
|
|
278
|
+
}
|
|
279
|
+
const blocksByContentId = yield this._getBlocksContentIdIndex();
|
|
280
|
+
// check MD5 of reference if available
|
|
281
|
+
if (majorVersion > 1 &&
|
|
282
|
+
this.file.options.checkSequenceMD5 &&
|
|
283
|
+
(0, sectionParsers_1.isMappedSliceHeader)(sliceHeader.parsedContent) &&
|
|
284
|
+
sliceHeader.parsedContent.refSeqId >= 0 &&
|
|
285
|
+
sliceHeader.parsedContent.md5.join('') !== '0000000000000000') {
|
|
286
|
+
const refRegion = yield this.getReferenceRegion();
|
|
287
|
+
if (refRegion) {
|
|
288
|
+
const { seq, start, end } = refRegion;
|
|
289
|
+
const seqMd5 = (0, util_1.sequenceMD5)(seq);
|
|
290
|
+
const storedMd5 = sliceHeader.parsedContent.md5
|
|
291
|
+
.map(byte => (byte < 16 ? '0' : '') + byte.toString(16))
|
|
292
|
+
.join('');
|
|
293
|
+
if (seqMd5 !== storedMd5) {
|
|
294
|
+
throw new errors_1.CramMalformedError(`MD5 checksum reference mismatch for ref ${sliceHeader.parsedContent.refSeqId} pos ${start}..${end}. recorded MD5: ${storedMd5}, calculated MD5: ${seqMd5}`);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
// tracks the read position within the block. codec.decode() methods
|
|
299
|
+
// advance the byte and bit positions in the cursor as they decode
|
|
300
|
+
// data note that we are only decoding a single block here, the core
|
|
301
|
+
// data block
|
|
302
|
+
const coreDataBlock = yield this.getCoreDataBlock();
|
|
303
|
+
const cursors = {
|
|
304
|
+
lastAlignmentStart: (0, sectionParsers_1.isMappedSliceHeader)(sliceHeader.parsedContent)
|
|
305
|
+
? sliceHeader.parsedContent.refSeqStart
|
|
306
|
+
: 0,
|
|
307
|
+
coreBlock: { bitPosition: 7, bytePosition: 0 },
|
|
308
|
+
externalBlocks: {
|
|
309
|
+
map: new Map(),
|
|
310
|
+
getCursor(contentId) {
|
|
311
|
+
let r = this.map.get(contentId);
|
|
312
|
+
if (r === undefined) {
|
|
313
|
+
r = { bitPosition: 7, bytePosition: 0 };
|
|
314
|
+
this.map.set(contentId, r);
|
|
322
315
|
}
|
|
323
|
-
return
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
316
|
+
return r;
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
};
|
|
320
|
+
const decodeDataSeries = (dataSeriesName) => {
|
|
321
|
+
const codec = compressionScheme.getCodecForDataSeries(dataSeriesName);
|
|
322
|
+
if (!codec) {
|
|
323
|
+
throw new errors_1.CramMalformedError(`no codec defined for ${dataSeriesName} data series`);
|
|
330
324
|
}
|
|
331
|
-
|
|
325
|
+
// console.log(dataSeriesName, Object.getPrototypeOf(codec))
|
|
326
|
+
const decoded = codec.decode(this, coreDataBlock, blocksByContentId, cursors);
|
|
327
|
+
return decoded;
|
|
328
|
+
};
|
|
329
|
+
let records = new Array(sliceHeader.parsedContent.numRecords);
|
|
330
|
+
for (let i = 0; i < records.length; i += 1) {
|
|
331
|
+
try {
|
|
332
|
+
const init = (0, decodeRecord_1.default)(this, decodeDataSeries, compressionScheme, sliceHeader, coreDataBlock, blocksByContentId, cursors, majorVersion, i);
|
|
333
|
+
records[i] = new record_1.default(Object.assign(Object.assign({}, init), { uniqueId: sliceHeader.contentPosition +
|
|
334
|
+
sliceHeader.parsedContent.recordCounter +
|
|
335
|
+
i +
|
|
336
|
+
1 }));
|
|
337
|
+
}
|
|
338
|
+
catch (e) {
|
|
339
|
+
if (e instanceof getBits_1.CramBufferOverrunError) {
|
|
340
|
+
console.warn('read attempted beyond end of buffer, file seems truncated.');
|
|
341
|
+
records = records.filter(r => !!r);
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
throw e;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
// interpret `recordsToNextFragment` attributes to make standard `mate`
|
|
350
|
+
// objects Resolve mate pair cross-references between records in this slice
|
|
351
|
+
for (let i = 0; i < records.length; i += 1) {
|
|
352
|
+
const { mateRecordNumber } = records[i];
|
|
353
|
+
if (mateRecordNumber !== undefined && mateRecordNumber >= 0) {
|
|
354
|
+
associateIntraSliceMate(records, i, records[i], records[mateRecordNumber]);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return records;
|
|
332
358
|
});
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
return this
|
|
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
|
-
refRegion =
|
|
364
|
-
if (refRegion) {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
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
|
-
map: new Map(),
|
|
383
|
-
getCursor: function (contentId) {
|
|
384
|
-
var r = this.map.get(contentId);
|
|
385
|
-
if (r === undefined) {
|
|
386
|
-
r = { bitPosition: 7, bytePosition: 0 };
|
|
387
|
-
this.map.set(contentId, r);
|
|
388
|
-
}
|
|
389
|
-
return r;
|
|
390
|
-
},
|
|
391
|
-
},
|
|
392
|
-
};
|
|
393
|
-
decodeDataSeries = function (dataSeriesName) {
|
|
394
|
-
var codec = compressionScheme.getCodecForDataSeries(dataSeriesName);
|
|
395
|
-
if (!codec) {
|
|
396
|
-
throw new errors_1.CramMalformedError("no codec defined for ".concat(dataSeriesName, " data series"));
|
|
397
|
-
}
|
|
398
|
-
// console.log(dataSeriesName, Object.getPrototypeOf(codec))
|
|
399
|
-
return codec.decode(_this, coreDataBlock, blocksByContentId, cursors);
|
|
400
|
-
};
|
|
401
|
-
records = new Array(sliceHeader.content.numRecords);
|
|
402
|
-
for (i = 0; i < records.length; i += 1) {
|
|
403
|
-
try {
|
|
404
|
-
records[i] = (0, decodeRecord_1.default)(this, decodeDataSeries, compressionScheme, sliceHeader, coreDataBlock, blocksByContentId, cursors, majorVersion, i);
|
|
405
|
-
records[i].uniqueId =
|
|
406
|
-
sliceHeader.contentPosition +
|
|
407
|
-
sliceHeader.content.recordCounter +
|
|
408
|
-
i +
|
|
409
|
-
1;
|
|
410
|
-
}
|
|
411
|
-
catch (e) {
|
|
412
|
-
if (e instanceof errors_1.CramBufferOverrunError) {
|
|
413
|
-
console.warn('read attempted beyond end of buffer, file seems truncated.');
|
|
414
|
-
records = records.filter(function (r) { return !!r; });
|
|
415
|
-
break;
|
|
416
|
-
}
|
|
417
|
-
else {
|
|
418
|
-
throw e;
|
|
419
|
-
}
|
|
420
|
-
}
|
|
359
|
+
}
|
|
360
|
+
getRecords(filterFunction) {
|
|
361
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
362
|
+
// fetch the features if necessary, using the file-level feature cache
|
|
363
|
+
const cacheKey = this.container.filePosition + this.containerPosition;
|
|
364
|
+
let recordsPromise = this.file.featureCache.get(cacheKey.toString());
|
|
365
|
+
if (!recordsPromise) {
|
|
366
|
+
recordsPromise = this._fetchRecords();
|
|
367
|
+
this.file.featureCache.set(cacheKey.toString(), recordsPromise);
|
|
368
|
+
}
|
|
369
|
+
const unfiltered = yield recordsPromise;
|
|
370
|
+
const records = unfiltered.filter(filterFunction);
|
|
371
|
+
// if we can fetch reference sequence, add the reference sequence to the records
|
|
372
|
+
if (records.length && this.file.fetchReferenceSequenceCallback) {
|
|
373
|
+
const sliceHeader = yield this.getHeader();
|
|
374
|
+
if ((0, sectionParsers_1.isMappedSliceHeader)(sliceHeader.parsedContent) &&
|
|
375
|
+
(sliceHeader.parsedContent.refSeqId >= 0 || // single-ref slice
|
|
376
|
+
sliceHeader.parsedContent.refSeqId === -2) // multi-ref slice
|
|
377
|
+
) {
|
|
378
|
+
const singleRefId = sliceHeader.parsedContent.refSeqId >= 0
|
|
379
|
+
? sliceHeader.parsedContent.refSeqId
|
|
380
|
+
: undefined;
|
|
381
|
+
const compressionScheme = yield this.container.getCompressionScheme();
|
|
382
|
+
if (compressionScheme === undefined) {
|
|
383
|
+
throw new Error();
|
|
384
|
+
}
|
|
385
|
+
const refRegions = {}; // seqId => { start, end, seq }
|
|
386
|
+
// iterate over the records to find the spans of the reference sequences we need to fetch
|
|
387
|
+
for (let i = 0; i < records.length; i += 1) {
|
|
388
|
+
const seqId = singleRefId !== undefined ? singleRefId : records[i].sequenceId;
|
|
389
|
+
let refRegion = refRegions[seqId];
|
|
390
|
+
if (!refRegion) {
|
|
391
|
+
refRegion = {
|
|
392
|
+
id: seqId,
|
|
393
|
+
start: records[i].alignmentStart,
|
|
394
|
+
end: -Infinity,
|
|
395
|
+
seq: null,
|
|
396
|
+
};
|
|
397
|
+
refRegions[seqId] = refRegion;
|
|
421
398
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
associateIntraSliceMate(records, i, records[i], records[mateRecordNumber]);
|
|
428
|
-
}
|
|
399
|
+
const end = records[i].alignmentStart +
|
|
400
|
+
(records[i].lengthOnRef || records[i].readLength) -
|
|
401
|
+
1;
|
|
402
|
+
if (end > refRegion.end) {
|
|
403
|
+
refRegion.end = end;
|
|
429
404
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
});
|
|
433
|
-
});
|
|
434
|
-
};
|
|
435
|
-
CramSlice.prototype.getRecords = function (filterFunction) {
|
|
436
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
437
|
-
var cacheKey, recordsPromise, records, sliceHeader, singleRefId, compressionScheme, refRegions, i, seqId, refRegion, end, i, seqId, refRegion;
|
|
438
|
-
var _this = this;
|
|
439
|
-
return __generator(this, function (_a) {
|
|
440
|
-
switch (_a.label) {
|
|
441
|
-
case 0:
|
|
442
|
-
cacheKey = this.container.filePosition + this.containerPosition;
|
|
443
|
-
recordsPromise = this.file.featureCache.get(cacheKey);
|
|
444
|
-
if (!recordsPromise) {
|
|
445
|
-
recordsPromise = this._fetchRecords();
|
|
446
|
-
this.file.featureCache.set(cacheKey, recordsPromise);
|
|
405
|
+
if (records[i].alignmentStart < refRegion.start) {
|
|
406
|
+
refRegion.start = records[i].alignmentStart;
|
|
447
407
|
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
if (
|
|
452
|
-
|
|
453
|
-
case 2:
|
|
454
|
-
sliceHeader = _a.sent();
|
|
455
|
-
if (!(sliceHeader.content.refSeqId >= 0 || // single-ref slice
|
|
456
|
-
sliceHeader.content.refSeqId === -2) // multi-ref slice
|
|
457
|
-
) return [3 /*break*/, 5]; // multi-ref slice
|
|
458
|
-
singleRefId = sliceHeader.content.refSeqId >= 0
|
|
459
|
-
? sliceHeader.content.refSeqId
|
|
460
|
-
: undefined;
|
|
461
|
-
return [4 /*yield*/, this.container.getCompressionScheme()];
|
|
462
|
-
case 3:
|
|
463
|
-
compressionScheme = _a.sent();
|
|
464
|
-
refRegions = {} // seqId => { start, end, seq }
|
|
465
|
-
;
|
|
466
|
-
// iterate over the records to find the spans of the reference sequences we need to fetch
|
|
467
|
-
for (i = 0; i < records.length; i += 1) {
|
|
468
|
-
seqId = singleRefId !== undefined ? singleRefId : records[i].sequenceId;
|
|
469
|
-
refRegion = refRegions[seqId];
|
|
470
|
-
if (!refRegion) {
|
|
471
|
-
refRegion = {
|
|
472
|
-
id: seqId,
|
|
473
|
-
start: records[i].alignmentStart,
|
|
474
|
-
end: -Infinity,
|
|
475
|
-
};
|
|
476
|
-
refRegions[seqId] = refRegion;
|
|
477
|
-
}
|
|
478
|
-
end = records[i].alignmentStart +
|
|
479
|
-
(records[i].lengthOnRef || records[i].readLength) -
|
|
480
|
-
1;
|
|
481
|
-
if (end > refRegion.end) {
|
|
482
|
-
refRegion.end = end;
|
|
483
|
-
}
|
|
484
|
-
if (records[i].alignmentStart < refRegion.start) {
|
|
485
|
-
refRegion.start = records[i].alignmentStart;
|
|
486
|
-
}
|
|
408
|
+
}
|
|
409
|
+
// fetch the `seq` for all of the ref regions
|
|
410
|
+
yield Promise.all(Object.values(refRegions).map((refRegion) => __awaiter(this, void 0, void 0, function* () {
|
|
411
|
+
if (refRegion.id !== -1 && refRegion.start <= refRegion.end) {
|
|
412
|
+
refRegion.seq = yield this.file.fetchReferenceSequenceCallback(refRegion.id, refRegion.start, refRegion.end);
|
|
487
413
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
return [4 /*yield*/, this.file.fetchReferenceSequenceCallback(refRegion.id, refRegion.start, refRegion.end)];
|
|
497
|
-
case 1:
|
|
498
|
-
_a.seq = _b.sent();
|
|
499
|
-
_b.label = 2;
|
|
500
|
-
case 2: return [2 /*return*/];
|
|
501
|
-
}
|
|
502
|
-
});
|
|
503
|
-
}); }))
|
|
504
|
-
// now decorate all the records with them
|
|
505
|
-
];
|
|
506
|
-
case 4:
|
|
507
|
-
// fetch the `seq` for all of the ref regions
|
|
508
|
-
_a.sent();
|
|
509
|
-
// now decorate all the records with them
|
|
510
|
-
for (i = 0; i < records.length; i += 1) {
|
|
511
|
-
seqId = singleRefId !== undefined ? singleRefId : records[i].sequenceId;
|
|
512
|
-
refRegion = refRegions[seqId];
|
|
513
|
-
if (refRegion && refRegion.seq) {
|
|
514
|
-
records[i].addReferenceSequence(refRegion, compressionScheme);
|
|
515
|
-
}
|
|
414
|
+
})));
|
|
415
|
+
// now decorate all the records with them
|
|
416
|
+
for (let i = 0; i < records.length; i += 1) {
|
|
417
|
+
const seqId = singleRefId !== undefined ? singleRefId : records[i].sequenceId;
|
|
418
|
+
const refRegion = refRegions[seqId];
|
|
419
|
+
if (refRegion && refRegion.seq) {
|
|
420
|
+
const seq = refRegion.seq;
|
|
421
|
+
records[i].addReferenceSequence(Object.assign(Object.assign({}, refRegion), { seq }), compressionScheme);
|
|
516
422
|
}
|
|
517
|
-
|
|
518
|
-
case 5: return [2 /*return*/, records];
|
|
423
|
+
}
|
|
519
424
|
}
|
|
520
|
-
}
|
|
425
|
+
}
|
|
426
|
+
return records;
|
|
521
427
|
});
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
}());
|
|
428
|
+
}
|
|
429
|
+
}
|
|
525
430
|
exports.default = CramSlice;
|
|
526
431
|
// memoize several methods in the class for performance
|
|
527
432
|
'getHeader getBlocks _getBlocksContentIdIndex'
|
|
528
433
|
.split(' ')
|
|
529
|
-
.forEach(
|
|
434
|
+
.forEach(method => (0, util_1.tinyMemoize)(CramSlice, method));
|
|
530
435
|
//# sourceMappingURL=index.js.map
|