@gmod/cram 3.0.0 → 3.0.1
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/dist/cram-bundle.js +1 -1
- package/dist/cramFile/codecs/byteArrayStop.js +1 -1
- package/dist/cramFile/codecs/huffman.js +1 -1
- package/dist/cramFile/codecs/huffman.js.map +1 -1
- package/dist/cramFile/codecs/subexp.js.map +1 -1
- package/dist/cramFile/container/index.d.ts +1 -0
- package/dist/cramFile/container/index.js +8 -5
- package/dist/cramFile/container/index.js.map +1 -1
- package/dist/cramFile/file.d.ts +1 -0
- package/dist/cramFile/file.js +14 -13
- package/dist/cramFile/file.js.map +1 -1
- package/dist/cramFile/record.js +2 -2
- package/dist/cramFile/record.js.map +1 -1
- package/dist/cramFile/sectionParsers.js.map +1 -1
- package/dist/cramFile/slice/decodeRecord.js +5 -4
- package/dist/cramFile/slice/decodeRecord.js.map +1 -1
- package/dist/cramFile/slice/index.js +2 -2
- package/dist/cramFile/slice/index.js.map +1 -1
- package/dist/cramFile/util.js.map +1 -1
- package/dist/rans/d04.js.map +1 -1
- package/dist/rans/decoding.d.ts +4 -4
- package/dist/rans/decoding.js +5 -6
- package/dist/rans/decoding.js.map +1 -1
- package/dist/rans/index.js +4 -3
- package/dist/rans/index.js.map +1 -1
- package/esm/cramFile/codecs/byteArrayStop.js +1 -1
- package/esm/cramFile/codecs/huffman.js +1 -1
- package/esm/cramFile/codecs/huffman.js.map +1 -1
- package/esm/cramFile/codecs/subexp.js.map +1 -1
- package/esm/cramFile/container/index.d.ts +1 -0
- package/esm/cramFile/container/index.js +6 -3
- package/esm/cramFile/container/index.js.map +1 -1
- package/esm/cramFile/file.d.ts +1 -0
- package/esm/cramFile/file.js +6 -5
- package/esm/cramFile/file.js.map +1 -1
- package/esm/cramFile/record.js +2 -2
- package/esm/cramFile/record.js.map +1 -1
- package/esm/cramFile/sectionParsers.js.map +1 -1
- package/esm/cramFile/slice/decodeRecord.js +5 -4
- package/esm/cramFile/slice/decodeRecord.js.map +1 -1
- package/esm/cramFile/slice/index.js +2 -2
- package/esm/cramFile/slice/index.js.map +1 -1
- package/esm/cramFile/util.js +3 -3
- package/esm/cramFile/util.js.map +1 -1
- package/esm/rans/d04.js.map +1 -1
- package/esm/rans/decoding.d.ts +4 -4
- package/esm/rans/decoding.js +5 -6
- package/esm/rans/decoding.js.map +1 -1
- package/esm/rans/index.js +3 -2
- package/esm/rans/index.js.map +1 -1
- package/package.json +1 -1
- package/src/cramFile/codecs/byteArrayStop.ts +1 -1
- package/src/cramFile/codecs/huffman.ts +1 -1
- package/src/cramFile/codecs/subexp.ts +2 -2
- package/src/cramFile/container/index.ts +6 -6
- package/src/cramFile/declare.d.ts +1 -0
- package/src/cramFile/file.ts +10 -11
- package/src/cramFile/record.ts +3 -6
- package/src/cramFile/sectionParsers.ts +4 -4
- package/src/cramFile/slice/decodeRecord.ts +20 -12
- package/src/cramFile/slice/index.ts +2 -2
- package/src/cramFile/util.ts +5 -5
- package/src/rans/d04.ts +1 -1
- package/src/rans/decoding.ts +5 -7
- package/src/rans/index.ts +3 -2
package/src/cramFile/file.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Buffer } from 'buffer'
|
|
2
2
|
import crc32 from 'buffer-crc32'
|
|
3
3
|
import QuickLRU from 'quick-lru'
|
|
4
4
|
import htscodecs from '@jkbonfield/htscodecs'
|
|
5
|
-
// @ts-expect-error
|
|
6
5
|
import bzip2 from 'bzip2'
|
|
7
6
|
import { XzReadableStream } from 'xz-decompress'
|
|
8
7
|
import { CramMalformedError, CramUnimplementedError } from '../errors'
|
|
8
|
+
// locals
|
|
9
|
+
import { unzip } from '../unzip'
|
|
9
10
|
import ransuncompress from '../rans'
|
|
10
11
|
import {
|
|
11
12
|
BlockHeader,
|
|
@@ -13,13 +14,11 @@ import {
|
|
|
13
14
|
cramFileDefinition,
|
|
14
15
|
getSectionParsers,
|
|
15
16
|
} from './sectionParsers'
|
|
16
|
-
|
|
17
17
|
import CramContainer from './container'
|
|
18
|
-
|
|
18
|
+
import CramRecord from './record'
|
|
19
19
|
import { open } from '../io'
|
|
20
20
|
import { parseItem, tinyMemoize } from './util'
|
|
21
21
|
import { parseHeaderText } from '../sam'
|
|
22
|
-
import CramRecord from './record'
|
|
23
22
|
import { Filehandle } from './filehandle'
|
|
24
23
|
|
|
25
24
|
function bufferToStream(buf: Buffer) {
|
|
@@ -31,7 +30,7 @@ function bufferToStream(buf: Buffer) {
|
|
|
31
30
|
})
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
// source:https://abdulapopoola.com/2019/01/20/check-endianness-with-javascript/
|
|
33
|
+
// source: https://abdulapopoola.com/2019/01/20/check-endianness-with-javascript/
|
|
35
34
|
function getEndianness() {
|
|
36
35
|
const uInt32 = new Uint32Array([0x11223344])
|
|
37
36
|
const uInt8 = new Uint8Array(uInt32.buffer)
|
|
@@ -163,7 +162,7 @@ export default class CramFile {
|
|
|
163
162
|
const { cramContainerHeader1 } = sectionParsers
|
|
164
163
|
|
|
165
164
|
// skip with a series of reads to the proper container
|
|
166
|
-
let currentContainer
|
|
165
|
+
let currentContainer: CramContainer | undefined
|
|
167
166
|
for (let i = 0; i <= containerNumber; i++) {
|
|
168
167
|
// if we are about to go off the end of the file
|
|
169
168
|
// and have not found that container, it does not exist
|
|
@@ -282,7 +281,7 @@ export default class CramFile {
|
|
|
282
281
|
size = section.maxLength,
|
|
283
282
|
preReadBuffer = undefined,
|
|
284
283
|
) {
|
|
285
|
-
let buffer
|
|
284
|
+
let buffer: Buffer
|
|
286
285
|
if (preReadBuffer) {
|
|
287
286
|
buffer = preReadBuffer
|
|
288
287
|
} else {
|
|
@@ -314,15 +313,15 @@ export default class CramFile {
|
|
|
314
313
|
const bits = bzip2.array(inputBuffer)
|
|
315
314
|
let size = bzip2.header(bits)
|
|
316
315
|
let j = 0
|
|
317
|
-
let chunk
|
|
316
|
+
let chunk: Uint8Array | -1
|
|
318
317
|
do {
|
|
319
318
|
chunk = bzip2.decompress(bits, size)
|
|
320
|
-
if (chunk
|
|
319
|
+
if (chunk !== -1) {
|
|
321
320
|
Buffer.from(chunk).copy(outputBuffer, j)
|
|
322
321
|
j += chunk.length
|
|
323
322
|
size -= chunk.length
|
|
324
323
|
}
|
|
325
|
-
} while (chunk
|
|
324
|
+
} while (chunk !== -1)
|
|
326
325
|
} else if (compressionMethod === 'lzma') {
|
|
327
326
|
const decompressedResponse = new Response(
|
|
328
327
|
new XzReadableStream(bufferToStream(inputBuffer)),
|
package/src/cramFile/record.ts
CHANGED
|
@@ -18,10 +18,7 @@ export interface ReadFeature {
|
|
|
18
18
|
sub?: string
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
function decodeReadSequence(
|
|
22
|
-
cramRecord: CramRecord,
|
|
23
|
-
refRegion: RefRegion,
|
|
24
|
-
): string | null {
|
|
21
|
+
function decodeReadSequence(cramRecord: CramRecord, refRegion: RefRegion) {
|
|
25
22
|
// if it has no length, it has no sequence
|
|
26
23
|
if (!cramRecord.lengthOnRef && !cramRecord.readLength) {
|
|
27
24
|
return null
|
|
@@ -215,8 +212,8 @@ function makeFlagsHelper<T>(
|
|
|
215
212
|
): FlagsDecoder<T> & FlagsEncoder<T> {
|
|
216
213
|
const r: any = {}
|
|
217
214
|
for (const [code, name] of x) {
|
|
218
|
-
r[
|
|
219
|
-
r[
|
|
215
|
+
r[`is${name}`] = (flags: number) => !!(flags & code)
|
|
216
|
+
r[`set${name}`] = (flags: number) => flags | code
|
|
220
217
|
}
|
|
221
218
|
|
|
222
219
|
return r
|
|
@@ -314,7 +314,7 @@ function cramUnmappedSliceHeader(majorVersion: number) {
|
|
|
314
314
|
}
|
|
315
315
|
|
|
316
316
|
// the md5 sum is missing in cram v1
|
|
317
|
-
let md5
|
|
317
|
+
let md5: TupleOf<number, 16> | undefined
|
|
318
318
|
if (majorVersion >= 2) {
|
|
319
319
|
md5 = [...buffer.subarray(offset, offset + 16)] as TupleOf<number, 16>
|
|
320
320
|
offset += 16
|
|
@@ -391,7 +391,7 @@ function cramMappedSliceHeader(majorVersion: number) {
|
|
|
391
391
|
// EL2
|
|
392
392
|
|
|
393
393
|
// the md5 sum is missing in cram v1
|
|
394
|
-
let md5
|
|
394
|
+
let md5: TupleOf<number, 16> | undefined
|
|
395
395
|
if (majorVersion >= 2) {
|
|
396
396
|
md5 = [...buffer.subarray(offset, offset + 16)] as TupleOf<number, 16>
|
|
397
397
|
offset += 16
|
|
@@ -674,7 +674,7 @@ function cramContainerHeader1(majorVersion: number) {
|
|
|
674
674
|
console.warn('setting recordCounter=0')
|
|
675
675
|
}
|
|
676
676
|
|
|
677
|
-
let numBases
|
|
677
|
+
let numBases: number | undefined
|
|
678
678
|
if (majorVersion > 1) {
|
|
679
679
|
const [n, newOffset5] = parseLtf8(buffer, offset)
|
|
680
680
|
numBases = n
|
|
@@ -716,7 +716,7 @@ function cramContainerHeader2(majorVersion: number) {
|
|
|
716
716
|
landmarks.push(landmark)
|
|
717
717
|
}
|
|
718
718
|
|
|
719
|
-
let crc32
|
|
719
|
+
let crc32: number | undefined
|
|
720
720
|
if (majorVersion >= 3) {
|
|
721
721
|
crc32 = dataView.getUint32(offset, true)
|
|
722
722
|
offset += 4
|
|
@@ -74,7 +74,7 @@ function parseTagValueArray(buffer: Buffer) {
|
|
|
74
74
|
array[i] = arr[i]
|
|
75
75
|
}
|
|
76
76
|
} else {
|
|
77
|
-
throw new Error(
|
|
77
|
+
throw new Error(`unknown type: ${arrayType}`)
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
return array
|
|
@@ -249,20 +249,27 @@ export default function decodeRecord(
|
|
|
249
249
|
cursors.lastAlignmentStart = alignmentStart
|
|
250
250
|
const readGroupId = decodeDataSeries('RG')
|
|
251
251
|
|
|
252
|
-
let readName
|
|
252
|
+
let readName: string | undefined
|
|
253
253
|
if (compressionScheme.readNamesIncluded) {
|
|
254
254
|
readName = readNullTerminatedString(decodeDataSeries('RN'))
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
-
let mateToUse
|
|
258
|
-
|
|
259
|
-
|
|
257
|
+
let mateToUse:
|
|
258
|
+
| {
|
|
259
|
+
mateFlags: number
|
|
260
|
+
mateSequenceId: number
|
|
261
|
+
mateAlignmentStart: number
|
|
262
|
+
mateReadName: string | undefined
|
|
263
|
+
}
|
|
264
|
+
| undefined
|
|
265
|
+
let templateSize: number | undefined
|
|
266
|
+
let mateRecordNumber: number | undefined
|
|
260
267
|
// mate record
|
|
261
268
|
if (CramFlagsDecoder.isDetached(cramFlags)) {
|
|
262
|
-
// note: the MF is a byte in 1.0, int32 in 2+, but once again this doesn't
|
|
263
|
-
//
|
|
269
|
+
// note: the MF is a byte in 1.0, int32 in 2+, but once again this doesn't
|
|
270
|
+
// matter for javascript
|
|
264
271
|
const mateFlags = decodeDataSeries('MF')
|
|
265
|
-
let mateReadName
|
|
272
|
+
let mateReadName: string | undefined
|
|
266
273
|
if (!compressionScheme.readNamesIncluded) {
|
|
267
274
|
mateReadName = readNullTerminatedString(decodeDataSeries('RN'))
|
|
268
275
|
readName = mateReadName
|
|
@@ -327,9 +334,9 @@ export default function decodeRecord(
|
|
|
327
334
|
tags[tagName] = parseTagData(tagType, tagData)
|
|
328
335
|
}
|
|
329
336
|
|
|
330
|
-
let readFeatures
|
|
331
|
-
let lengthOnRef
|
|
332
|
-
let mappingQuality
|
|
337
|
+
let readFeatures: ReadFeature[] | undefined
|
|
338
|
+
let lengthOnRef: number | undefined
|
|
339
|
+
let mappingQuality: number | undefined
|
|
333
340
|
let qualityScores: number[] | undefined | null
|
|
334
341
|
let readBases = undefined
|
|
335
342
|
if (!BamFlagsDecoder.isSegmentUnmapped(flags)) {
|
|
@@ -345,7 +352,8 @@ export default function decodeRecord(
|
|
|
345
352
|
)
|
|
346
353
|
}
|
|
347
354
|
|
|
348
|
-
// compute the read's true span on the reference sequence, and the end
|
|
355
|
+
// compute the read's true span on the reference sequence, and the end
|
|
356
|
+
// coordinate of the alignment on the reference
|
|
349
357
|
lengthOnRef = readLength
|
|
350
358
|
if (readFeatures) {
|
|
351
359
|
for (const { code, data } of readFeatures) {
|
|
@@ -177,7 +177,7 @@ function associateIntraSliceMate(
|
|
|
177
177
|
|
|
178
178
|
// delete this last because it's used by the
|
|
179
179
|
// complicated template length estimation
|
|
180
|
-
|
|
180
|
+
thisRecord.mateRecordNumber = undefined
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
export default class CramSlice {
|
|
@@ -524,7 +524,7 @@ export default class CramSlice {
|
|
|
524
524
|
refRegion = {
|
|
525
525
|
id: seqId,
|
|
526
526
|
start: record.alignmentStart,
|
|
527
|
-
end:
|
|
527
|
+
end: Number.NEGATIVE_INFINITY,
|
|
528
528
|
seq: null,
|
|
529
529
|
}
|
|
530
530
|
refRegions[seqId] = refRegion
|
package/src/cramFile/util.ts
CHANGED
|
@@ -21,7 +21,7 @@ export function itf8Size(v: number) {
|
|
|
21
21
|
export function parseItf8(buffer: Uint8Array, initialOffset: number) {
|
|
22
22
|
let offset = initialOffset
|
|
23
23
|
const countFlags = buffer[offset]
|
|
24
|
-
let result
|
|
24
|
+
let result: number
|
|
25
25
|
if (countFlags < 0x80) {
|
|
26
26
|
result = countFlags
|
|
27
27
|
offset = offset + 1
|
|
@@ -63,7 +63,7 @@ export function parseItf8(buffer: Uint8Array, initialOffset: number) {
|
|
|
63
63
|
export function parseLtf8(buffer: Buffer, initialOffset: number) {
|
|
64
64
|
let offset = initialOffset
|
|
65
65
|
const countFlags = buffer[offset]
|
|
66
|
-
let n
|
|
66
|
+
let n: number | Long
|
|
67
67
|
if (countFlags < 0x80) {
|
|
68
68
|
n = countFlags
|
|
69
69
|
offset += 1
|
|
@@ -88,7 +88,7 @@ export function parseLtf8(buffer: Buffer, initialOffset: number) {
|
|
|
88
88
|
offset += 4
|
|
89
89
|
} else if (countFlags < 0xf8) {
|
|
90
90
|
n =
|
|
91
|
-
((buffer[offset] & 15) *
|
|
91
|
+
((buffer[offset] & 15) * 2 ** 32 + (buffer[offset + 1] << 24)) |
|
|
92
92
|
((buffer[offset + 2] << 16) |
|
|
93
93
|
(buffer[offset + 3] << 8) |
|
|
94
94
|
buffer[offset + 4])
|
|
@@ -96,7 +96,7 @@ export function parseLtf8(buffer: Buffer, initialOffset: number) {
|
|
|
96
96
|
offset += 5
|
|
97
97
|
} else if (countFlags < 0xfc) {
|
|
98
98
|
n =
|
|
99
|
-
((((buffer[offset] & 7) << 8) | buffer[offset + 1]) *
|
|
99
|
+
((((buffer[offset] & 7) << 8) | buffer[offset + 1]) * 2 ** 32 +
|
|
100
100
|
(buffer[offset + 2] << 24)) |
|
|
101
101
|
((buffer[offset + 3] << 16) |
|
|
102
102
|
(buffer[offset + 4] << 8) |
|
|
@@ -107,7 +107,7 @@ export function parseLtf8(buffer: Buffer, initialOffset: number) {
|
|
|
107
107
|
((((buffer[offset] & 3) << 16) |
|
|
108
108
|
(buffer[offset + 1] << 8) |
|
|
109
109
|
buffer[offset + 2]) *
|
|
110
|
-
|
|
110
|
+
2 ** 32 +
|
|
111
111
|
(buffer[offset + 3] << 24)) |
|
|
112
112
|
((buffer[offset + 4] << 16) |
|
|
113
113
|
(buffer[offset + 5] << 8) |
|
package/src/rans/d04.ts
CHANGED
package/src/rans/decoding.ts
CHANGED
|
@@ -24,7 +24,7 @@ class AriDecoder {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
class
|
|
27
|
+
class DecodingSymbol {
|
|
28
28
|
// int start; // Start of range.
|
|
29
29
|
// int freq; // Symbol frequency.
|
|
30
30
|
constructor() {
|
|
@@ -36,10 +36,10 @@ class Symbol {
|
|
|
36
36
|
// Initialize a decoder symbol to start "start" and frequency "freq"
|
|
37
37
|
function symbolInit(sym, start, freq) {
|
|
38
38
|
if (!(start <= 1 << 16)) {
|
|
39
|
-
throw new CramMalformedError(
|
|
39
|
+
throw new CramMalformedError('assertion failed: start <= 1<<16')
|
|
40
40
|
}
|
|
41
41
|
if (!(freq <= (1 << 16) - start)) {
|
|
42
|
-
throw new CramMalformedError(
|
|
42
|
+
throw new CramMalformedError('assertion failed: freq <= 1<<16')
|
|
43
43
|
}
|
|
44
44
|
sym.start = start
|
|
45
45
|
sym.freq = freq
|
|
@@ -127,10 +127,10 @@ function symbolInit(sym, start, freq) {
|
|
|
127
127
|
return r
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
|
|
130
|
+
export default {
|
|
131
131
|
FC,
|
|
132
132
|
AriDecoder,
|
|
133
|
-
|
|
133
|
+
DecodingSymbol,
|
|
134
134
|
symbolInit,
|
|
135
135
|
advanceStep,
|
|
136
136
|
advanceSymbolStep,
|
|
@@ -138,5 +138,3 @@ const Decode = {
|
|
|
138
138
|
advanceSymbol,
|
|
139
139
|
renormalize,
|
|
140
140
|
}
|
|
141
|
-
|
|
142
|
-
export default Decode
|
package/src/rans/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
//@ts-nocheck
|
|
2
|
+
import { Buffer } from 'buffer'
|
|
2
3
|
import { CramMalformedError } from '../errors'
|
|
3
4
|
|
|
4
5
|
import Decoding from './decoding'
|
|
@@ -118,7 +119,7 @@ function /* static ByteBuffer */ uncompressOrder0Way4(
|
|
|
118
119
|
const D = new Decoding.AriDecoder()
|
|
119
120
|
const syms = new Array(256)
|
|
120
121
|
for (let i = 0; i < syms.length; i += 1) {
|
|
121
|
-
syms[i] = new Decoding.
|
|
122
|
+
syms[i] = new Decoding.DecodingSymbol()
|
|
122
123
|
}
|
|
123
124
|
|
|
124
125
|
readStatsO0(input, D, syms)
|
|
@@ -140,7 +141,7 @@ function /* static ByteBuffer */ uncompressOrder1Way4(
|
|
|
140
141
|
for (let i = 0; i < syms.length; i += 1) {
|
|
141
142
|
syms[i] = new Array(256)
|
|
142
143
|
for (let j = 0; j < syms[i].length; j += 1) {
|
|
143
|
-
syms[i][j] = new Decoding.
|
|
144
|
+
syms[i][j] = new Decoding.DecodingSymbol()
|
|
144
145
|
}
|
|
145
146
|
}
|
|
146
147
|
readStatsO1(input, D, syms)
|