@gmod/cram 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/craiIndex.d.ts +2 -2
- package/dist/craiIndex.js +5 -9
- package/dist/craiIndex.js.map +1 -1
- package/dist/cram-bundle.js +1 -1
- package/dist/cramFile/codecs/_base.d.ts +6 -6
- package/dist/cramFile/codecs/beta.js.map +1 -1
- package/dist/cramFile/codecs/byteArrayLength.js.map +1 -1
- package/dist/cramFile/codecs/byteArrayStop.js.map +1 -1
- package/dist/cramFile/codecs/external.js +1 -0
- package/dist/cramFile/codecs/external.js.map +1 -1
- package/dist/cramFile/codecs/gamma.js.map +1 -1
- package/dist/cramFile/codecs/getBits.js.map +1 -1
- package/dist/cramFile/codecs/huffman.d.ts +0 -1
- package/dist/cramFile/codecs/huffman.js +1 -3
- package/dist/cramFile/codecs/huffman.js.map +1 -1
- package/dist/cramFile/codecs/index.js.map +1 -1
- package/dist/cramFile/codecs/subexp.js.map +1 -1
- package/dist/cramFile/container/compressionScheme.js +1 -1
- package/dist/cramFile/container/compressionScheme.js.map +1 -1
- package/dist/cramFile/container/index.js.map +1 -1
- package/dist/cramFile/encoding.d.ts +20 -20
- package/dist/cramFile/file.d.ts +14 -7
- package/dist/cramFile/file.js.map +1 -1
- package/dist/cramFile/filehandle.d.ts +1 -2
- package/dist/cramFile/index.d.ts +1 -2
- package/dist/cramFile/index.js +3 -3
- package/dist/cramFile/index.js.map +1 -1
- package/dist/cramFile/record.d.ts +6 -6
- package/dist/cramFile/record.js +7 -4
- package/dist/cramFile/record.js.map +1 -1
- package/dist/cramFile/sectionParsers.d.ts +9 -8
- package/dist/cramFile/sectionParsers.js +10 -11
- package/dist/cramFile/sectionParsers.js.map +1 -1
- package/dist/cramFile/slice/decodeRecord.js +7 -11
- package/dist/cramFile/slice/decodeRecord.js.map +1 -1
- package/dist/cramFile/slice/index.js +24 -22
- package/dist/cramFile/slice/index.js.map +1 -1
- package/dist/cramFile/util.d.ts +1 -0
- package/dist/cramFile/util.js +1 -1
- package/dist/cramFile/util.js.map +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.js +7 -30
- package/dist/index.js.map +1 -1
- package/dist/indexedCramFile.d.ts +6 -6
- package/dist/indexedCramFile.js +13 -18
- package/dist/indexedCramFile.js.map +1 -1
- package/dist/io/index.d.ts +2 -1
- package/dist/io/index.js +4 -3
- package/dist/io/index.js.map +1 -1
- package/dist/rans/d04.js.map +1 -1
- package/dist/rans/d14.js.map +1 -1
- package/dist/rans/decoding.js.map +1 -1
- package/dist/rans/frequencies.js.map +1 -1
- package/dist/rans/index.js.map +1 -1
- package/dist/sam.d.ts +5 -6
- package/dist/sam.js +20 -7
- package/dist/sam.js.map +1 -1
- package/dist/typescript.js.map +1 -1
- package/dist/unzip.d.ts +2 -2
- package/dist/unzip.js +1 -1
- package/dist/unzip.js.map +1 -1
- package/esm/craiIndex.d.ts +2 -2
- package/esm/craiIndex.js +5 -9
- package/esm/craiIndex.js.map +1 -1
- package/esm/cramFile/codecs/_base.d.ts +6 -6
- package/esm/cramFile/codecs/beta.js.map +1 -1
- package/esm/cramFile/codecs/byteArrayLength.js.map +1 -1
- package/esm/cramFile/codecs/byteArrayStop.js.map +1 -1
- package/esm/cramFile/codecs/external.js +1 -0
- package/esm/cramFile/codecs/external.js.map +1 -1
- package/esm/cramFile/codecs/gamma.js.map +1 -1
- package/esm/cramFile/codecs/getBits.js.map +1 -1
- package/esm/cramFile/codecs/huffman.d.ts +0 -1
- package/esm/cramFile/codecs/huffman.js +1 -3
- package/esm/cramFile/codecs/huffman.js.map +1 -1
- package/esm/cramFile/codecs/index.js.map +1 -1
- package/esm/cramFile/codecs/subexp.js.map +1 -1
- package/esm/cramFile/container/compressionScheme.js +1 -1
- package/esm/cramFile/container/compressionScheme.js.map +1 -1
- package/esm/cramFile/container/index.js.map +1 -1
- package/esm/cramFile/encoding.d.ts +20 -20
- package/esm/cramFile/file.d.ts +14 -7
- package/esm/cramFile/file.js.map +1 -1
- package/esm/cramFile/filehandle.d.ts +1 -2
- package/esm/cramFile/index.d.ts +1 -2
- package/esm/cramFile/index.js +1 -2
- package/esm/cramFile/index.js.map +1 -1
- package/esm/cramFile/record.d.ts +6 -6
- package/esm/cramFile/record.js +7 -4
- package/esm/cramFile/record.js.map +1 -1
- package/esm/cramFile/sectionParsers.d.ts +9 -8
- package/esm/cramFile/sectionParsers.js +10 -11
- package/esm/cramFile/sectionParsers.js.map +1 -1
- package/esm/cramFile/slice/decodeRecord.js +7 -11
- package/esm/cramFile/slice/decodeRecord.js.map +1 -1
- package/esm/cramFile/slice/index.js +24 -22
- package/esm/cramFile/slice/index.js.map +1 -1
- package/esm/cramFile/util.d.ts +1 -0
- package/esm/cramFile/util.js +1 -1
- package/esm/cramFile/util.js.map +1 -1
- package/esm/index.d.ts +3 -4
- package/esm/index.js +3 -4
- package/esm/index.js.map +1 -1
- package/esm/indexedCramFile.d.ts +6 -6
- package/esm/indexedCramFile.js +13 -18
- package/esm/indexedCramFile.js.map +1 -1
- package/esm/io/index.d.ts +2 -1
- package/esm/io/index.js +2 -1
- package/esm/io/index.js.map +1 -1
- package/esm/rans/d04.js.map +1 -1
- package/esm/rans/d14.js.map +1 -1
- package/esm/rans/decoding.js.map +1 -1
- package/esm/rans/frequencies.js.map +1 -1
- package/esm/rans/index.js.map +1 -1
- package/esm/sam.d.ts +5 -6
- package/esm/sam.js +20 -7
- package/esm/sam.js.map +1 -1
- package/esm/typescript.js.map +1 -1
- package/esm/unzip.d.ts +2 -2
- package/esm/unzip.js +1 -2
- package/esm/unzip.js.map +1 -1
- package/package.json +11 -11
- package/src/craiIndex.ts +8 -13
- package/src/cramFile/codecs/_base.ts +3 -3
- package/src/cramFile/codecs/external.ts +1 -0
- package/src/cramFile/codecs/huffman.ts +7 -8
- package/src/cramFile/container/compressionScheme.ts +1 -1
- package/src/cramFile/encoding.ts +10 -10
- package/src/cramFile/file.ts +5 -5
- package/src/cramFile/filehandle.ts +1 -3
- package/src/cramFile/index.ts +1 -2
- package/src/cramFile/record.ts +13 -10
- package/src/cramFile/sectionParsers.ts +8 -9
- package/src/cramFile/slice/decodeRecord.ts +15 -17
- package/src/cramFile/slice/index.ts +26 -23
- package/src/cramFile/util.ts +1 -1
- package/src/index.ts +3 -5
- package/src/indexedCramFile.ts +19 -23
- package/src/io/index.ts +3 -1
- package/src/sam.ts +28 -14
- package/src/typings/binary-parser.d.ts +1 -1
- package/src/unzip.ts +1 -2
|
@@ -199,7 +199,7 @@ export default class CramSlice {
|
|
|
199
199
|
containerHeader._endPosition + this.containerPosition,
|
|
200
200
|
)
|
|
201
201
|
if (header === undefined) {
|
|
202
|
-
throw new Error()
|
|
202
|
+
throw new Error('block header undefined')
|
|
203
203
|
}
|
|
204
204
|
if (header.contentType === 'MAPPED_SLICE_HEADER') {
|
|
205
205
|
const content = parseItem(
|
|
@@ -233,7 +233,7 @@ export default class CramSlice {
|
|
|
233
233
|
for (let i = 0; i < blocks.length; i += 1) {
|
|
234
234
|
const block = await this.file.readBlock(blockPosition)
|
|
235
235
|
if (block === undefined) {
|
|
236
|
-
throw new Error()
|
|
236
|
+
throw new Error('block undefined')
|
|
237
237
|
}
|
|
238
238
|
blocks[i] = block
|
|
239
239
|
blockPosition = blocks[i]._endPosition
|
|
@@ -270,7 +270,7 @@ export default class CramSlice {
|
|
|
270
270
|
// read the slice header
|
|
271
271
|
const sliceHeader = (await this.getHeader()).parsedContent
|
|
272
272
|
if (!isMappedSliceHeader(sliceHeader)) {
|
|
273
|
-
throw new Error()
|
|
273
|
+
throw new Error('slice header not mapped')
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
if (sliceHeader.refSeqId < 0) {
|
|
@@ -279,11 +279,9 @@ export default class CramSlice {
|
|
|
279
279
|
|
|
280
280
|
const compressionScheme = await this.container.getCompressionScheme()
|
|
281
281
|
if (compressionScheme === undefined) {
|
|
282
|
-
throw new Error()
|
|
282
|
+
throw new Error('compression scheme undefined')
|
|
283
283
|
}
|
|
284
284
|
|
|
285
|
-
// console.log(JSON.stringify(sliceHeader, null, ' '))
|
|
286
|
-
|
|
287
285
|
if (sliceHeader.refBaseBlockId >= 0) {
|
|
288
286
|
const refBlock = await this.getBlockByContentId(
|
|
289
287
|
sliceHeader.refBaseBlockId,
|
|
@@ -349,12 +347,12 @@ export default class CramSlice {
|
|
|
349
347
|
|
|
350
348
|
const compressionScheme = await this.container.getCompressionScheme()
|
|
351
349
|
if (compressionScheme === undefined) {
|
|
352
|
-
throw new Error()
|
|
350
|
+
throw new Error('compression scheme undefined')
|
|
353
351
|
}
|
|
354
352
|
|
|
355
353
|
const sliceHeader = await this.getHeader()
|
|
356
354
|
if (sliceHeader === undefined) {
|
|
357
|
-
throw new Error()
|
|
355
|
+
throw new Error('slice header undefined')
|
|
358
356
|
}
|
|
359
357
|
|
|
360
358
|
const blocksByContentId = await this._getBlocksContentIdIndex()
|
|
@@ -503,22 +501,23 @@ export default class CramSlice {
|
|
|
503
501
|
: undefined
|
|
504
502
|
const compressionScheme = await this.container.getCompressionScheme()
|
|
505
503
|
if (compressionScheme === undefined) {
|
|
506
|
-
throw new Error()
|
|
504
|
+
throw new Error('compression scheme undefined')
|
|
507
505
|
}
|
|
508
506
|
const refRegions: Record<
|
|
509
507
|
string,
|
|
510
508
|
{ id: number; start: number; end: number; seq: string | null }
|
|
511
|
-
> = {}
|
|
509
|
+
> = {}
|
|
512
510
|
|
|
513
|
-
// iterate over the records to find the spans of the reference
|
|
514
|
-
|
|
511
|
+
// iterate over the records to find the spans of the reference
|
|
512
|
+
// sequences we need to fetch
|
|
513
|
+
for (const record of records) {
|
|
515
514
|
const seqId =
|
|
516
|
-
singleRefId !== undefined ? singleRefId :
|
|
515
|
+
singleRefId !== undefined ? singleRefId : record.sequenceId
|
|
517
516
|
let refRegion = refRegions[seqId]
|
|
518
517
|
if (!refRegion) {
|
|
519
518
|
refRegion = {
|
|
520
519
|
id: seqId,
|
|
521
|
-
start:
|
|
520
|
+
start: record.alignmentStart,
|
|
522
521
|
end: -Infinity,
|
|
523
522
|
seq: null,
|
|
524
523
|
}
|
|
@@ -526,21 +525,25 @@ export default class CramSlice {
|
|
|
526
525
|
}
|
|
527
526
|
|
|
528
527
|
const end =
|
|
529
|
-
|
|
530
|
-
(
|
|
528
|
+
record.alignmentStart +
|
|
529
|
+
(record.lengthOnRef || record.readLength) -
|
|
531
530
|
1
|
|
532
531
|
if (end > refRegion.end) {
|
|
533
532
|
refRegion.end = end
|
|
534
533
|
}
|
|
535
|
-
if (
|
|
536
|
-
refRegion.start =
|
|
534
|
+
if (record.alignmentStart < refRegion.start) {
|
|
535
|
+
refRegion.start = record.alignmentStart
|
|
537
536
|
}
|
|
538
537
|
}
|
|
539
538
|
|
|
540
539
|
// fetch the `seq` for all of the ref regions
|
|
541
540
|
await Promise.all(
|
|
542
541
|
Object.values(refRegions).map(async refRegion => {
|
|
543
|
-
if (
|
|
542
|
+
if (
|
|
543
|
+
refRegion.id !== -1 &&
|
|
544
|
+
refRegion.start <= refRegion.end &&
|
|
545
|
+
this.file.fetchReferenceSequenceCallback
|
|
546
|
+
) {
|
|
544
547
|
refRegion.seq = await this.file.fetchReferenceSequenceCallback(
|
|
545
548
|
refRegion.id,
|
|
546
549
|
refRegion.start,
|
|
@@ -551,13 +554,13 @@ export default class CramSlice {
|
|
|
551
554
|
)
|
|
552
555
|
|
|
553
556
|
// now decorate all the records with them
|
|
554
|
-
for (
|
|
557
|
+
for (const record of records) {
|
|
555
558
|
const seqId =
|
|
556
|
-
singleRefId !== undefined ? singleRefId :
|
|
559
|
+
singleRefId !== undefined ? singleRefId : record.sequenceId
|
|
557
560
|
const refRegion = refRegions[seqId]
|
|
558
|
-
if (refRegion
|
|
561
|
+
if (refRegion?.seq) {
|
|
559
562
|
const seq = refRegion.seq
|
|
560
|
-
|
|
563
|
+
record.addReferenceSequence(
|
|
561
564
|
{ ...refRegion, seq },
|
|
562
565
|
compressionScheme,
|
|
563
566
|
)
|
package/src/cramFile/util.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export { CramFile, IndexedCramFile, CraiIndex, CramRecord }
|
|
1
|
+
export { default as CramFile, CramRecord } from './cramFile'
|
|
2
|
+
export { default as CraiIndex } from './craiIndex'
|
|
3
|
+
export { default as IndexedCramFile } from './indexedCramFile'
|
package/src/indexedCramFile.ts
CHANGED
|
@@ -6,13 +6,13 @@ import { SeqFetch } from './cramFile/file'
|
|
|
6
6
|
import { Filehandle } from './cramFile/filehandle'
|
|
7
7
|
import { Slice } from './craiIndex'
|
|
8
8
|
|
|
9
|
-
export
|
|
9
|
+
export interface CramFileSource {
|
|
10
10
|
cramFilehandle?: Filehandle
|
|
11
11
|
cramUrl?: string
|
|
12
12
|
cramPath?: string
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export
|
|
15
|
+
export interface CramIndexLike {
|
|
16
16
|
getEntriesForRange: (
|
|
17
17
|
seqId: number,
|
|
18
18
|
start: number,
|
|
@@ -44,17 +44,16 @@ export default class IndexedCramFile {
|
|
|
44
44
|
| { cram: CramFile }
|
|
45
45
|
| ({
|
|
46
46
|
cram?: undefined
|
|
47
|
-
seqFetch
|
|
48
|
-
checkSequenceMD5
|
|
47
|
+
seqFetch?: SeqFetch
|
|
48
|
+
checkSequenceMD5?: boolean
|
|
49
49
|
cacheSize?: number
|
|
50
50
|
} & CramFileSource)
|
|
51
51
|
),
|
|
52
52
|
) {
|
|
53
53
|
// { cram, index, seqFetch /* fasta, fastaIndex */ }) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
this.cram = new CramFile({
|
|
54
|
+
this.cram =
|
|
55
|
+
args.cram ??
|
|
56
|
+
new CramFile({
|
|
58
57
|
url: args.cramUrl,
|
|
59
58
|
path: args.cramPath,
|
|
60
59
|
filehandle: args.cramFilehandle,
|
|
@@ -62,7 +61,6 @@ export default class IndexedCramFile {
|
|
|
62
61
|
checkSequenceMD5: args.checkSequenceMD5,
|
|
63
62
|
cacheSize: args.cacheSize,
|
|
64
63
|
})
|
|
65
|
-
}
|
|
66
64
|
|
|
67
65
|
if (!(this.cram instanceof CramFile)) {
|
|
68
66
|
throw new Error('invalid arguments: no cramfile')
|
|
@@ -128,12 +126,12 @@ export default class IndexedCramFile {
|
|
|
128
126
|
if (opts.viewAsPairs) {
|
|
129
127
|
const readNames: Record<string, number> = {}
|
|
130
128
|
const readIds: Record<string, number> = {}
|
|
131
|
-
for (
|
|
132
|
-
const name =
|
|
129
|
+
for (const read of ret) {
|
|
130
|
+
const name = read.readName
|
|
133
131
|
if (name === undefined) {
|
|
134
|
-
throw new Error()
|
|
132
|
+
throw new Error('readName undefined')
|
|
135
133
|
}
|
|
136
|
-
const id =
|
|
134
|
+
const id = read.uniqueId
|
|
137
135
|
if (!readNames[name]) {
|
|
138
136
|
readNames[name] = 0
|
|
139
137
|
}
|
|
@@ -147,11 +145,10 @@ export default class IndexedCramFile {
|
|
|
147
145
|
}
|
|
148
146
|
})
|
|
149
147
|
const matePromises = []
|
|
150
|
-
for (
|
|
151
|
-
const cramRecord = ret[i]
|
|
148
|
+
for (const cramRecord of ret) {
|
|
152
149
|
const name = cramRecord.readName
|
|
153
150
|
if (name === undefined) {
|
|
154
|
-
throw new Error()
|
|
151
|
+
throw new Error('readName undefined')
|
|
155
152
|
}
|
|
156
153
|
if (
|
|
157
154
|
unmatedPairs[name] &&
|
|
@@ -169,9 +166,9 @@ export default class IndexedCramFile {
|
|
|
169
166
|
}
|
|
170
167
|
}
|
|
171
168
|
const mateBlocks = await Promise.all(matePromises)
|
|
172
|
-
let mateChunks = []
|
|
173
|
-
for (
|
|
174
|
-
mateChunks.push(...
|
|
169
|
+
let mateChunks = [] as Slice[]
|
|
170
|
+
for (const block of mateBlocks) {
|
|
171
|
+
mateChunks.push(...block)
|
|
175
172
|
}
|
|
176
173
|
// filter out duplicates
|
|
177
174
|
mateChunks = mateChunks
|
|
@@ -182,7 +179,7 @@ export default class IndexedCramFile {
|
|
|
182
179
|
)
|
|
183
180
|
|
|
184
181
|
const mateRecordPromises = []
|
|
185
|
-
const mateFeatPromises:
|
|
182
|
+
const mateFeatPromises: Promise<CramRecord[]>[] = []
|
|
186
183
|
|
|
187
184
|
const mateTotalSize = mateChunks
|
|
188
185
|
.map(s => s.sliceBytes)
|
|
@@ -202,10 +199,9 @@ export default class IndexedCramFile {
|
|
|
202
199
|
mateRecordPromises.push(recordPromise)
|
|
203
200
|
const featPromise = recordPromise.then(feats => {
|
|
204
201
|
const mateRecs = []
|
|
205
|
-
for (
|
|
206
|
-
const feature = feats[i]
|
|
202
|
+
for (const feature of feats) {
|
|
207
203
|
if (feature.readName === undefined) {
|
|
208
|
-
throw new Error()
|
|
204
|
+
throw new Error('readName undefined')
|
|
209
205
|
}
|
|
210
206
|
if (unmatedPairs[feature.readName] && !readIds[feature.uniqueId]) {
|
|
211
207
|
mateRecs.push(feature)
|
package/src/io/index.ts
CHANGED
package/src/sam.ts
CHANGED
|
@@ -1,20 +1,34 @@
|
|
|
1
|
-
export
|
|
2
|
-
tag: string
|
|
3
|
-
data: Array<{ tag: string; value: string }>
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export function parseHeaderText(text: string): HeaderDataItem[] {
|
|
1
|
+
export function parseHeaderText(text: string) {
|
|
7
2
|
const lines = text.split(/\r?\n/)
|
|
8
|
-
const data:
|
|
9
|
-
|
|
3
|
+
const data: {
|
|
4
|
+
tag: string
|
|
5
|
+
data: {
|
|
6
|
+
tag: string
|
|
7
|
+
value: string | undefined
|
|
8
|
+
}[]
|
|
9
|
+
}[] = []
|
|
10
|
+
for (const line of lines) {
|
|
10
11
|
const [tag, ...fields] = line.split(/\t/)
|
|
11
|
-
const parsedFields = fields.map(f => {
|
|
12
|
-
const [fieldTag, value] = f.split(':', 2)
|
|
13
|
-
return { tag: fieldTag, value }
|
|
14
|
-
})
|
|
15
12
|
if (tag) {
|
|
16
|
-
data.push({
|
|
13
|
+
data.push({
|
|
14
|
+
tag: tag.slice(1),
|
|
15
|
+
data: fields.map(f => {
|
|
16
|
+
const r = f.indexOf(':')
|
|
17
|
+
return r !== -1
|
|
18
|
+
? {
|
|
19
|
+
tag: f.slice(0, r),
|
|
20
|
+
value: f.slice(r + 1),
|
|
21
|
+
}
|
|
22
|
+
: // @CO lines are not comma separated.
|
|
23
|
+
// See "samtools view -H c2\#pad.3.0.cram"
|
|
24
|
+
// so, just store value tag itself
|
|
25
|
+
{
|
|
26
|
+
tag: f,
|
|
27
|
+
value: undefined,
|
|
28
|
+
}
|
|
29
|
+
}),
|
|
30
|
+
})
|
|
17
31
|
}
|
|
18
|
-
}
|
|
32
|
+
}
|
|
19
33
|
return data
|
|
20
34
|
}
|
package/src/unzip.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { gunzipSync as unzip }
|
|
1
|
+
export { gunzipSync as unzip } from 'zlib'
|