@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
package/esm/indexedCramFile.d.ts
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
|
+
import CramFile from './cramFile';
|
|
2
|
+
import CramRecord from './cramFile/record';
|
|
3
|
+
import { SeqFetch } from './cramFile/file';
|
|
4
|
+
import { Filehandle } from './cramFile/filehandle';
|
|
5
|
+
import { Slice } from './craiIndex';
|
|
6
|
+
export declare type CramFileSource = {
|
|
7
|
+
cramFilehandle?: Filehandle;
|
|
8
|
+
cramUrl?: string;
|
|
9
|
+
cramPath?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare type CramIndexLike = {
|
|
12
|
+
getEntriesForRange: (seqId: number, start: number, end: number) => Promise<Slice[]>;
|
|
13
|
+
hasDataForReferenceSequence: (seqId: number) => Promise<boolean>;
|
|
14
|
+
};
|
|
1
15
|
export default class IndexedCramFile {
|
|
16
|
+
cram: CramFile;
|
|
17
|
+
index: CramIndexLike;
|
|
18
|
+
private fetchSizeLimit;
|
|
2
19
|
/**
|
|
3
20
|
*
|
|
4
21
|
* @param {object} args
|
|
@@ -10,11 +27,16 @@ export default class IndexedCramFile {
|
|
|
10
27
|
* checksum of the reference sequence underlying a slice. In some applications, this check can cause an inconvenient amount (many megabases) of sequences to be fetched.
|
|
11
28
|
*/
|
|
12
29
|
constructor(args: {
|
|
30
|
+
index: CramIndexLike;
|
|
31
|
+
fetchSizeLimit?: number;
|
|
32
|
+
} & ({
|
|
13
33
|
cram: CramFile;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
34
|
+
} | ({
|
|
35
|
+
cram?: undefined;
|
|
36
|
+
seqFetch: SeqFetch;
|
|
37
|
+
checkSequenceMD5: boolean;
|
|
38
|
+
cacheSize?: number;
|
|
39
|
+
} & CramFileSource)));
|
|
18
40
|
/**
|
|
19
41
|
*
|
|
20
42
|
* @param {number} seq numeric ID of the reference sequence
|
|
@@ -22,18 +44,21 @@ export default class IndexedCramFile {
|
|
|
22
44
|
* @param {number} end end of the range of interest. 1-based closed coordinates.
|
|
23
45
|
* @returns {Promise[Array[CramRecord]]}
|
|
24
46
|
*/
|
|
25
|
-
getRecordsForRange(seq: number, start: number, end: number, opts?: {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
47
|
+
getRecordsForRange(seq: number, start: number, end: number, opts?: {
|
|
48
|
+
viewAsPairs?: boolean;
|
|
49
|
+
pairAcrossChr?: boolean;
|
|
50
|
+
maxInsertSize?: number;
|
|
51
|
+
}): Promise<CramRecord[]>;
|
|
52
|
+
getRecordsInSlice({ containerStart, sliceStart, sliceBytes, }: {
|
|
53
|
+
containerStart: number;
|
|
54
|
+
sliceStart: number;
|
|
55
|
+
sliceBytes: number;
|
|
56
|
+
}, filterFunction: (r: CramRecord) => boolean): Promise<CramRecord[]>;
|
|
31
57
|
/**
|
|
32
58
|
*
|
|
33
59
|
* @param {number} seqId
|
|
34
60
|
* @returns {Promise} true if the CRAM file contains data for the given
|
|
35
61
|
* reference sequence numerical ID
|
|
36
62
|
*/
|
|
37
|
-
hasDataForReferenceSequence(seqId: number): Promise<
|
|
63
|
+
hasDataForReferenceSequence(seqId: number): Promise<boolean>;
|
|
38
64
|
}
|
|
39
|
-
import CramFile from "./cramFile";
|
package/esm/indexedCramFile.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CramSizeLimitError, CramUnimplementedError } from './errors';
|
|
2
2
|
import CramFile from './cramFile';
|
|
3
3
|
export default class IndexedCramFile {
|
|
4
4
|
/**
|
|
@@ -58,8 +58,9 @@ export default class IndexedCramFile {
|
|
|
58
58
|
}
|
|
59
59
|
// TODO: do we need to merge or de-duplicate the blocks?
|
|
60
60
|
// fetch all the slices and parse the feature data
|
|
61
|
-
const filter = feature => feature.sequenceId === seq &&
|
|
61
|
+
const filter = (feature) => feature.sequenceId === seq &&
|
|
62
62
|
feature.alignmentStart <= end &&
|
|
63
|
+
feature.lengthOnRef !== undefined &&
|
|
63
64
|
feature.alignmentStart + feature.lengthOnRef - 1 >= start;
|
|
64
65
|
const sliceResults = await Promise.all(slices.map(slice => this.getRecordsInSlice(slice, filter)));
|
|
65
66
|
let ret = Array.prototype.concat(...sliceResults);
|
|
@@ -68,6 +69,9 @@ export default class IndexedCramFile {
|
|
|
68
69
|
const readIds = {};
|
|
69
70
|
for (let i = 0; i < ret.length; i += 1) {
|
|
70
71
|
const name = ret[i].readName;
|
|
72
|
+
if (name === undefined) {
|
|
73
|
+
throw new Error();
|
|
74
|
+
}
|
|
71
75
|
const id = ret[i].uniqueId;
|
|
72
76
|
if (!readNames[name]) {
|
|
73
77
|
readNames[name] = 0;
|
|
@@ -83,13 +87,17 @@ export default class IndexedCramFile {
|
|
|
83
87
|
});
|
|
84
88
|
const matePromises = [];
|
|
85
89
|
for (let i = 0; i < ret.length; i += 1) {
|
|
86
|
-
const
|
|
90
|
+
const cramRecord = ret[i];
|
|
91
|
+
const name = cramRecord.readName;
|
|
92
|
+
if (name === undefined) {
|
|
93
|
+
throw new Error();
|
|
94
|
+
}
|
|
87
95
|
if (unmatedPairs[name] &&
|
|
88
|
-
|
|
89
|
-
(
|
|
90
|
-
Math.abs(
|
|
96
|
+
cramRecord.mate &&
|
|
97
|
+
(cramRecord.mate.sequenceId === seqId || opts.pairAcrossChr) &&
|
|
98
|
+
Math.abs(cramRecord.alignmentStart - cramRecord.mate.alignmentStart) <
|
|
91
99
|
opts.maxInsertSize) {
|
|
92
|
-
const mateSlices = this.index.getEntriesForRange(
|
|
100
|
+
const mateSlices = this.index.getEntriesForRange(cramRecord.mate.sequenceId, cramRecord.mate.alignmentStart, cramRecord.mate.alignmentStart + 1);
|
|
93
101
|
matePromises.push(mateSlices);
|
|
94
102
|
}
|
|
95
103
|
}
|
|
@@ -121,6 +129,9 @@ export default class IndexedCramFile {
|
|
|
121
129
|
const mateRecs = [];
|
|
122
130
|
for (let i = 0; i < feats.length; i += 1) {
|
|
123
131
|
const feature = feats[i];
|
|
132
|
+
if (feature.readName === undefined) {
|
|
133
|
+
throw new Error();
|
|
134
|
+
}
|
|
124
135
|
if (unmatedPairs[feature.readName] && !readIds[feature.uniqueId]) {
|
|
125
136
|
mateRecs.push(feature);
|
|
126
137
|
}
|
|
@@ -137,7 +148,7 @@ export default class IndexedCramFile {
|
|
|
137
148
|
}
|
|
138
149
|
return ret;
|
|
139
150
|
}
|
|
140
|
-
getRecordsInSlice({ containerStart, sliceStart, sliceBytes }, filterFunction) {
|
|
151
|
+
getRecordsInSlice({ containerStart, sliceStart, sliceBytes, }, filterFunction) {
|
|
141
152
|
const container = this.cram.getContainerAtPosition(containerStart);
|
|
142
153
|
const slice = container.getSlice(sliceStart, sliceBytes);
|
|
143
154
|
return slice.getRecords(filterFunction);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indexedCramFile.js","sourceRoot":"","sources":["../src/indexedCramFile.
|
|
1
|
+
{"version":3,"file":"indexedCramFile.js","sourceRoot":"","sources":["../src/indexedCramFile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAA;AAErE,OAAO,QAAQ,MAAM,YAAY,CAAA;AAqBjC,MAAM,CAAC,OAAO,OAAO,eAAe;IAKlC;;;;;;;;;OASG;IACH,YACE,IAWC;QAED,uDAAuD;QACvD,IAAI,IAAI,CAAC,IAAI,EAAE;YACb,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;SACtB;aAAM;YACL,IAAI,CAAC,IAAI,GAAG,IAAI,QAAQ,CAAC;gBACvB,GAAG,EAAE,IAAI,CAAC,OA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GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CACvD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CACvB,CAAA;gBACD,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;aAC3B;SACF;QACD,OAAO,GAAG,CAAA;IACZ,CAAC;IAED,iBAAiB,CACf,EACE,cAAc,EACd,UAAU,EACV,UAAU,GACyD,EACrE,cAA0C;QAE1C,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,cAAc,CAAC,CAAA;QAClE,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,CAAA;QACxD,OAAO,KAAK,CAAC,UAAU,CAAC,cAAc,CAAC,CAAA;IACzC,CAAC;IAED;;;;;OAKG;IACH,2BAA2B,CAAC,KAAa;QACvC,OAAO,IAAI,CAAC,KAAK,CAAC,2BAA2B,CAAC,KAAK,CAAC,CAAA;IACtD,CAAC;CACF"}
|
package/esm/io/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import RemoteFile from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export { LocalFile, RemoteFile };
|
|
1
|
+
import { Filehandle } from '../cramFile/filehandle';
|
|
2
|
+
import { LocalFile, RemoteFile } from 'generic-filehandle';
|
|
3
|
+
declare function fromUrl(source: string): LocalFile | RemoteFile;
|
|
4
|
+
declare function open(maybeUrl?: string, maybePath?: string, maybeFilehandle?: Filehandle): Filehandle;
|
|
5
|
+
export { LocalFile, RemoteFile, fromUrl, open };
|
package/esm/io/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import url from 'url';
|
|
2
|
-
import
|
|
3
|
-
import LocalFile from '
|
|
2
|
+
import { ensureNotNullish } from '../typescript';
|
|
3
|
+
import { LocalFile, RemoteFile } from 'generic-filehandle';
|
|
4
4
|
function fromUrl(source) {
|
|
5
5
|
const { protocol, pathname } = url.parse(source);
|
|
6
6
|
if (protocol === 'file:') {
|
|
7
|
-
return new LocalFile(unescape(pathname));
|
|
7
|
+
return new LocalFile(unescape(ensureNotNullish(pathname)));
|
|
8
8
|
}
|
|
9
9
|
return new RemoteFile(source);
|
|
10
10
|
}
|
package/esm/io/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/io/index.
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/io/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AACrB,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAEhD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAE1D,SAAS,OAAO,CAAC,MAAc;IAC7B,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IAChD,IAAI,QAAQ,KAAK,OAAO,EAAE;QACxB,OAAO,IAAI,SAAS,CAAC,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;KAC3D;IACD,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAA;AAC/B,CAAC;AAED,SAAS,IAAI,CACX,QAAiB,EACjB,SAAkB,EAClB,eAA4B;IAE5B,IAAI,eAAe,EAAE;QACnB,OAAO,eAAe,CAAA;KACvB;IACD,IAAI,QAAQ,EAAE;QACZ,OAAO,OAAO,CAAC,QAAQ,CAAC,CAAA;KACzB;IACD,IAAI,SAAS,EAAE;QACb,OAAO,IAAI,SAAS,CAAC,SAAS,CAAC,CAAA;KAChC;IACD,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAA;AACtE,CAAC;AAED,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
package/esm/sam.d.ts
CHANGED
package/esm/sam.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sam.js","sourceRoot":"","sources":["../src/sam.
|
|
1
|
+
{"version":3,"file":"sam.js","sourceRoot":"","sources":["../src/sam.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACjC,MAAM,IAAI,GAAqB,EAAE,CAAA;IACjC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACnB,MAAM,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QACzC,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;YAClC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;YACzC,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAA;QACjC,CAAC,CAAC,CAAA;QACF,IAAI,GAAG,EAAE;YACP,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAA;SACtD;IACH,CAAC,CAAC,CAAA;IACF,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function ensureNotNullish<T>(x: T | null | undefined): T;
|
|
2
|
+
export declare type TupleOf<T, N extends number> = N extends N ? number extends N ? T[] : _TupleOf<T, N, []> : never;
|
|
3
|
+
export declare type _TupleOf<T, N extends number, R extends unknown[]> = R['length'] extends N ? R : _TupleOf<T, N, [T, ...R]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typescript.js","sourceRoot":"","sources":["../src/typescript.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,gBAAgB,CAAI,CAAuB;IACzD,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS,EAAE;QACjC,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;KAC9C;IACD,OAAO,CAAC,CAAA;AACV,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gmod/cram",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "read CRAM files with pure Javascript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "GMOD/cram-js",
|
|
@@ -27,10 +27,11 @@
|
|
|
27
27
|
"prebuild": "npm run clean",
|
|
28
28
|
"clean": "rimraf dist esm",
|
|
29
29
|
"build:esm": "tsc --target es2018 --outDir esm",
|
|
30
|
-
"build:es5": "tsc --target
|
|
30
|
+
"build:es5": "tsc --target es2015 --module commonjs --outDir dist",
|
|
31
31
|
"build": "npm run build:esm && npm run build:es5",
|
|
32
32
|
"postbuild": "webpack",
|
|
33
33
|
"prepublishOnly": "npm test && npm run build && cp dist/errors.js errors.js",
|
|
34
|
+
"prepack": "npm test && npm run build && cp dist/errors.js errors.js",
|
|
34
35
|
"postpublish": "rm errors.js",
|
|
35
36
|
"postversion": "git push --follow-tags"
|
|
36
37
|
},
|
|
@@ -47,32 +48,38 @@
|
|
|
47
48
|
"buffer-crc32": "^0.2.13",
|
|
48
49
|
"bzip2": "^0.1.1",
|
|
49
50
|
"cross-fetch": "^3.0.0",
|
|
50
|
-
"es6-promisify": "^6.0.1",
|
|
51
51
|
"long": "^4.0.0",
|
|
52
52
|
"md5": "^2.2.1",
|
|
53
53
|
"pako": "^1.0.4",
|
|
54
|
-
"quick-lru": "^
|
|
54
|
+
"quick-lru": "^4.0.1"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
+
"@babel/plugin-transform-modules-commonjs": "^7.18.2",
|
|
58
|
+
"@babel/preset-typescript": "^7.17.12",
|
|
57
59
|
"@gmod/indexedfasta": "^2.0.2",
|
|
60
|
+
"@types/buffer-crc32": "^0.2.0",
|
|
58
61
|
"@types/jest": "^27.4.0",
|
|
62
|
+
"@types/long": "^4.0.2",
|
|
63
|
+
"@types/md5": "^2.3.2",
|
|
59
64
|
"@types/pako": "^1.0.3",
|
|
60
65
|
"@typescript-eslint/eslint-plugin": "^5.9.1",
|
|
61
66
|
"@typescript-eslint/parser": "^5.9.1",
|
|
67
|
+
"buffer": "^6.0.3",
|
|
62
68
|
"documentation": "^13.2.5",
|
|
63
|
-
"eslint": "^
|
|
64
|
-
"eslint-config-prettier": "^8.
|
|
69
|
+
"eslint": "^8.15.0",
|
|
70
|
+
"eslint-config-prettier": "^8.5.0",
|
|
65
71
|
"eslint-plugin-import": "^2.25.4",
|
|
66
72
|
"eslint-plugin-prettier": "^4.0.0",
|
|
67
|
-
"glob": "^
|
|
68
|
-
"jest": "^
|
|
73
|
+
"glob": "^8.0.3",
|
|
74
|
+
"jest": "^28.1.0",
|
|
69
75
|
"mock-fs": "^5.1.2",
|
|
70
76
|
"prettier": "^2.5.1",
|
|
71
77
|
"rimraf": "^3.0.2",
|
|
72
|
-
"ts-jest": "^
|
|
78
|
+
"ts-jest": "^28.0.2",
|
|
73
79
|
"typescript": "^4.5.4",
|
|
74
|
-
"
|
|
75
|
-
"webpack
|
|
80
|
+
"url": "^0.11.0",
|
|
81
|
+
"webpack": "5.72.1",
|
|
82
|
+
"webpack-cli": "^4.9.2"
|
|
76
83
|
},
|
|
77
84
|
"publishConfig": {
|
|
78
85
|
"access": "public"
|
|
@@ -3,20 +3,22 @@ import QuickLRU from 'quick-lru'
|
|
|
3
3
|
import { unzip } from './unzip'
|
|
4
4
|
import { open } from './io'
|
|
5
5
|
import { CramMalformedError } from './errors'
|
|
6
|
+
import { CramFileSource } from './cramFile/file'
|
|
7
|
+
import { Filehandle } from './cramFile/filehandle'
|
|
6
8
|
|
|
7
9
|
const BAI_MAGIC = 21578050 // BAI\1
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return `${this.start}:${this.span}:${this.containerStart}:${this.sliceStart}:${this.sliceBytes}`
|
|
16
|
-
}
|
|
11
|
+
export type Slice = {
|
|
12
|
+
start: number
|
|
13
|
+
span: number
|
|
14
|
+
containerStart: number
|
|
15
|
+
sliceStart: number
|
|
16
|
+
sliceBytes: number
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
type ParsedIndex = Record<string, Slice[]>
|
|
20
|
+
|
|
21
|
+
function addRecordToIndex(index: ParsedIndex, record: number[]) {
|
|
20
22
|
if (record.some(el => el === undefined)) {
|
|
21
23
|
throw new CramMalformedError('invalid .crai index file')
|
|
22
24
|
}
|
|
@@ -27,15 +29,13 @@ function addRecordToIndex(index, record) {
|
|
|
27
29
|
index[seqId] = []
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
index[seqId].push(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}),
|
|
38
|
-
)
|
|
32
|
+
index[seqId].push({
|
|
33
|
+
start,
|
|
34
|
+
span,
|
|
35
|
+
containerStart,
|
|
36
|
+
sliceStart,
|
|
37
|
+
sliceBytes,
|
|
38
|
+
})
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
export default class CraiIndex {
|
|
@@ -47,6 +47,8 @@ export default class CraiIndex {
|
|
|
47
47
|
// 5. Slice start byte position in the container data (‘blocks’)
|
|
48
48
|
// 6. Slice size in bytes
|
|
49
49
|
// Each line represents a slice in the CRAM file. Please note that all slices must be listed in index file.
|
|
50
|
+
private _parseCache: AbortablePromiseCache<unknown, ParsedIndex>
|
|
51
|
+
private filehandle: Filehandle
|
|
50
52
|
|
|
51
53
|
/**
|
|
52
54
|
*
|
|
@@ -55,18 +57,18 @@ export default class CraiIndex {
|
|
|
55
57
|
* @param {string} [args.url]
|
|
56
58
|
* @param {FileHandle} [args.filehandle]
|
|
57
59
|
*/
|
|
58
|
-
constructor(args) {
|
|
59
|
-
|
|
60
|
-
this._parseCache = new AbortablePromiseCache({
|
|
60
|
+
constructor(args: CramFileSource) {
|
|
61
|
+
this.filehandle = open(args.url, args.path, args.filehandle)
|
|
62
|
+
this._parseCache = new AbortablePromiseCache<unknown, ParsedIndex>({
|
|
61
63
|
cache: new QuickLRU({ maxSize: 1 }),
|
|
62
|
-
fill: (data, signal) => this.parseIndex(
|
|
64
|
+
fill: (data, signal) => this.parseIndex(),
|
|
63
65
|
})
|
|
64
|
-
this.readFile = filehandle.readFile.bind(filehandle)
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
parseIndex() {
|
|
68
|
-
const index = {}
|
|
69
|
-
return this.
|
|
69
|
+
const index: ParsedIndex = {}
|
|
70
|
+
return this.filehandle
|
|
71
|
+
.readFile()
|
|
70
72
|
.then(data => {
|
|
71
73
|
if (data[0] === 31 && data[1] === 139) {
|
|
72
74
|
return unzip(data)
|
|
@@ -86,7 +88,7 @@ export default class CraiIndex {
|
|
|
86
88
|
// supposed to be only digits and whitespace characters
|
|
87
89
|
// this is written in a deliberately low-level fashion for performance,
|
|
88
90
|
// because some .crai files can be pretty large.
|
|
89
|
-
let currentRecord = []
|
|
91
|
+
let currentRecord: number[] = []
|
|
90
92
|
let currentString = ''
|
|
91
93
|
for (let i = 0; i < uncompressedBuffer.length; i += 1) {
|
|
92
94
|
const charCode = uncompressedBuffer[i]
|
|
@@ -128,7 +130,7 @@ export default class CraiIndex {
|
|
|
128
130
|
})
|
|
129
131
|
}
|
|
130
132
|
|
|
131
|
-
getIndex(opts = {}) {
|
|
133
|
+
getIndex(opts: { signal?: AbortSignal } = {}) {
|
|
132
134
|
return this._parseCache.get('index', null, opts.signal)
|
|
133
135
|
}
|
|
134
136
|
|
|
@@ -137,7 +139,7 @@ export default class CraiIndex {
|
|
|
137
139
|
* @returns {Promise} true if the index contains entries for
|
|
138
140
|
* the given reference sequence ID, false otherwise
|
|
139
141
|
*/
|
|
140
|
-
async hasDataForReferenceSequence(seqId) {
|
|
142
|
+
async hasDataForReferenceSequence(seqId: number) {
|
|
141
143
|
return !!(await this.getIndex())[seqId]
|
|
142
144
|
}
|
|
143
145
|
|
|
@@ -152,16 +154,20 @@ export default class CraiIndex {
|
|
|
152
154
|
* an array of objects of the form
|
|
153
155
|
* `{start, span, containerStart, sliceStart, sliceBytes }`
|
|
154
156
|
*/
|
|
155
|
-
async getEntriesForRange(
|
|
157
|
+
async getEntriesForRange(
|
|
158
|
+
seqId: number,
|
|
159
|
+
queryStart: number,
|
|
160
|
+
queryEnd: number,
|
|
161
|
+
) {
|
|
156
162
|
const seqEntries = (await this.getIndex())[seqId]
|
|
157
163
|
if (!seqEntries) {
|
|
158
164
|
return []
|
|
159
165
|
}
|
|
160
166
|
|
|
161
|
-
const compare = entry => {
|
|
167
|
+
const compare = (entry: Slice) => {
|
|
162
168
|
const entryStart = entry.start
|
|
163
169
|
const entryEnd = entry.start + entry.span
|
|
164
|
-
if (entryStart
|
|
170
|
+
if (entryStart > queryEnd) {
|
|
165
171
|
return -1
|
|
166
172
|
} // entry is ahead of query
|
|
167
173
|
if (entryEnd <= queryStart) {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import CramSlice from '../slice'
|
|
2
|
+
import { CramFileBlock } from '../file'
|
|
3
|
+
import { DataType } from './dataSeriesTypes'
|
|
4
|
+
|
|
5
|
+
export type DataTypeMapping = {
|
|
6
|
+
byte: number
|
|
7
|
+
int: number
|
|
8
|
+
long: number
|
|
9
|
+
byteArray: Uint8Array
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type Cursor = {
|
|
13
|
+
bitPosition: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
|
|
14
|
+
bytePosition: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type Cursors = {
|
|
18
|
+
lastAlignmentStart: number
|
|
19
|
+
coreBlock: Cursor
|
|
20
|
+
externalBlocks: {
|
|
21
|
+
map: Map<any, any>
|
|
22
|
+
getCursor: (contentId: number) => Cursor
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// codec base class
|
|
27
|
+
export default abstract class CramCodec<
|
|
28
|
+
TResult extends DataType = DataType,
|
|
29
|
+
TParameters = unknown,
|
|
30
|
+
> {
|
|
31
|
+
public parameters: TParameters
|
|
32
|
+
public dataType: DataType
|
|
33
|
+
|
|
34
|
+
constructor(parameters: TParameters, dataType: TResult) {
|
|
35
|
+
this.parameters = parameters
|
|
36
|
+
this.dataType = dataType
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
abstract decode(
|
|
40
|
+
slice: CramSlice,
|
|
41
|
+
coreDataBlock: CramFileBlock,
|
|
42
|
+
blocksByContentId: Record<number, CramFileBlock>,
|
|
43
|
+
cursors: Cursors,
|
|
44
|
+
): DataTypeMapping[TResult]
|
|
45
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CramUnimplementedError } from '../../errors'
|
|
2
|
+
import CramCodec, { Cursors } from './_base'
|
|
3
|
+
import { getBits } from './getBits'
|
|
4
|
+
import CramSlice from '../slice'
|
|
5
|
+
import { CramFileBlock } from '../file'
|
|
6
|
+
import { BetaEncoding } from '../encoding'
|
|
7
|
+
|
|
8
|
+
export default class BetaCodec extends CramCodec<
|
|
9
|
+
'int',
|
|
10
|
+
BetaEncoding['parameters']
|
|
11
|
+
> {
|
|
12
|
+
constructor(parameters: BetaEncoding['parameters'], dataType: 'int') {
|
|
13
|
+
super(parameters, dataType)
|
|
14
|
+
if (this.dataType !== 'int') {
|
|
15
|
+
throw new CramUnimplementedError(
|
|
16
|
+
`${this.dataType} decoding not yet implemented by BETA codec`,
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
decode(
|
|
22
|
+
slice: CramSlice,
|
|
23
|
+
coreDataBlock: CramFileBlock,
|
|
24
|
+
blocksByContentId: Record<number, CramFileBlock>,
|
|
25
|
+
cursors: Cursors,
|
|
26
|
+
) {
|
|
27
|
+
const fromBits = getBits(
|
|
28
|
+
coreDataBlock.content,
|
|
29
|
+
cursors.coreBlock,
|
|
30
|
+
this.parameters.length,
|
|
31
|
+
)
|
|
32
|
+
return fromBits - this.parameters.offset
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
import { tinyMemoize } from '../util'
|
|
2
2
|
|
|
3
|
-
import CramCodec from './_base'
|
|
3
|
+
import CramCodec, { Cursors } from './_base'
|
|
4
|
+
import { ByteArrayLengthEncoding, CramEncoding } from '../encoding'
|
|
5
|
+
import CramSlice from '../slice'
|
|
6
|
+
import { CramFileBlock } from '../file'
|
|
7
|
+
import { DataType } from './dataSeriesTypes'
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
|
|
9
|
+
type CramCodecFactory = <TData extends DataType = DataType>(
|
|
10
|
+
encodingData: CramEncoding,
|
|
11
|
+
dataType: TData | 'ignore',
|
|
12
|
+
) => CramCodec<TData>
|
|
13
|
+
|
|
14
|
+
export default class ByteArrayStopCodec extends CramCodec<
|
|
15
|
+
'byteArray',
|
|
16
|
+
ByteArrayLengthEncoding['parameters']
|
|
17
|
+
> {
|
|
18
|
+
private instantiateCodec: CramCodecFactory
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
parameters: ByteArrayLengthEncoding['parameters'],
|
|
22
|
+
dataType: 'byteArray',
|
|
23
|
+
instantiateCodec: CramCodecFactory,
|
|
24
|
+
) {
|
|
7
25
|
super(parameters, dataType)
|
|
8
26
|
this.instantiateCodec = instantiateCodec
|
|
9
27
|
if (dataType !== 'byteArray') {
|
|
@@ -13,7 +31,12 @@ export default class ByteArrayStopCodec extends CramCodec {
|
|
|
13
31
|
}
|
|
14
32
|
}
|
|
15
33
|
|
|
16
|
-
decode(
|
|
34
|
+
decode(
|
|
35
|
+
slice: CramSlice,
|
|
36
|
+
coreDataBlock: CramFileBlock,
|
|
37
|
+
blocksByContentId: Record<number, CramFileBlock>,
|
|
38
|
+
cursors: Cursors,
|
|
39
|
+
) {
|
|
17
40
|
const lengthCodec = this._getLengthCodec()
|
|
18
41
|
const arrayLength = lengthCodec.decode(
|
|
19
42
|
slice,
|
|
@@ -45,7 +68,6 @@ export default class ByteArrayStopCodec extends CramCodec {
|
|
|
45
68
|
// memoize
|
|
46
69
|
_getDataCodec() {
|
|
47
70
|
const encodingParams = this.parameters.valuesEncoding
|
|
48
|
-
|
|
49
71
|
return this.instantiateCodec(encodingParams, 'byte')
|
|
50
72
|
}
|
|
51
73
|
}
|
|
@@ -1,20 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CramMalformedError } from '../../errors'
|
|
2
2
|
|
|
3
|
-
import CramCodec from './_base'
|
|
3
|
+
import CramCodec, { Cursor, Cursors } from './_base'
|
|
4
|
+
import CramSlice from '../slice'
|
|
5
|
+
import { CramFileBlock } from '../file'
|
|
6
|
+
import { ByteArrayStopCramEncoding } from '../encoding'
|
|
7
|
+
import { CramBufferOverrunError } from './getBits'
|
|
4
8
|
|
|
5
|
-
export default class ByteArrayStopCodec extends CramCodec
|
|
6
|
-
|
|
9
|
+
export default class ByteArrayStopCodec extends CramCodec<
|
|
10
|
+
'byteArray',
|
|
11
|
+
ByteArrayStopCramEncoding['parameters']
|
|
12
|
+
> {
|
|
13
|
+
constructor(
|
|
14
|
+
parameters: ByteArrayStopCramEncoding['parameters'],
|
|
15
|
+
dataType: 'byteArray',
|
|
16
|
+
) {
|
|
7
17
|
super(parameters, dataType)
|
|
8
|
-
if (dataType
|
|
9
|
-
this._decode = this._decodeByteArray
|
|
10
|
-
} else {
|
|
18
|
+
if (dataType !== 'byteArray') {
|
|
11
19
|
throw new TypeError(
|
|
12
20
|
`byteArrayStop codec does not support data type ${dataType}`,
|
|
13
21
|
)
|
|
14
22
|
}
|
|
15
23
|
}
|
|
16
24
|
|
|
17
|
-
decode(
|
|
25
|
+
decode(
|
|
26
|
+
slice: CramSlice,
|
|
27
|
+
coreDataBlock: CramFileBlock,
|
|
28
|
+
blocksByContentId: Record<number, CramFileBlock>,
|
|
29
|
+
cursors: Cursors,
|
|
30
|
+
) {
|
|
18
31
|
const { blockContentId } = this.parameters
|
|
19
32
|
const contentBlock = blocksByContentId[blockContentId]
|
|
20
33
|
if (!contentBlock) {
|
|
@@ -23,10 +36,10 @@ export default class ByteArrayStopCodec extends CramCodec {
|
|
|
23
36
|
)
|
|
24
37
|
}
|
|
25
38
|
const cursor = cursors.externalBlocks.getCursor(blockContentId)
|
|
26
|
-
return this.
|
|
39
|
+
return this._decodeByteArray(contentBlock, cursor)
|
|
27
40
|
}
|
|
28
41
|
|
|
29
|
-
_decodeByteArray(contentBlock, cursor) {
|
|
42
|
+
_decodeByteArray(contentBlock: CramFileBlock, cursor: Cursor) {
|
|
30
43
|
const dataBuffer = contentBlock.content
|
|
31
44
|
const { stopByte } = this.parameters
|
|
32
45
|
// scan to the next stop byte
|
|
@@ -41,9 +54,9 @@ export default class ByteArrayStopCodec extends CramCodec {
|
|
|
41
54
|
`byteArrayStop reading beyond length of data buffer?`,
|
|
42
55
|
)
|
|
43
56
|
}
|
|
44
|
-
stopPosition
|
|
57
|
+
stopPosition = stopPosition + 1
|
|
45
58
|
}
|
|
46
59
|
cursor.bytePosition = stopPosition + 1
|
|
47
|
-
return dataBuffer.
|
|
60
|
+
return dataBuffer.subarray(startPosition, stopPosition)
|
|
48
61
|
}
|
|
49
62
|
}
|