@gmod/cram 2.0.1 → 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.
Files changed (109) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/craiIndex.d.ts +2 -2
  3. package/dist/craiIndex.js +5 -9
  4. package/dist/craiIndex.js.map +1 -1
  5. package/dist/cram-bundle.js +1 -1
  6. package/dist/cramFile/codecs/_base.d.ts +6 -6
  7. package/dist/cramFile/codecs/external.js +1 -0
  8. package/dist/cramFile/codecs/external.js.map +1 -1
  9. package/dist/cramFile/codecs/huffman.d.ts +0 -1
  10. package/dist/cramFile/codecs/huffman.js +1 -3
  11. package/dist/cramFile/codecs/huffman.js.map +1 -1
  12. package/dist/cramFile/container/compressionScheme.js +1 -1
  13. package/dist/cramFile/container/compressionScheme.js.map +1 -1
  14. package/dist/cramFile/encoding.d.ts +20 -20
  15. package/dist/cramFile/file.d.ts +6 -6
  16. package/dist/cramFile/filehandle.d.ts +1 -2
  17. package/dist/cramFile/index.d.ts +1 -2
  18. package/dist/cramFile/index.js +3 -3
  19. package/dist/cramFile/index.js.map +1 -1
  20. package/dist/cramFile/record.d.ts +6 -6
  21. package/dist/cramFile/record.js +7 -4
  22. package/dist/cramFile/record.js.map +1 -1
  23. package/dist/cramFile/sectionParsers.d.ts +8 -8
  24. package/dist/cramFile/sectionParsers.js +3 -4
  25. package/dist/cramFile/sectionParsers.js.map +1 -1
  26. package/dist/cramFile/slice/decodeRecord.js +6 -10
  27. package/dist/cramFile/slice/decodeRecord.js.map +1 -1
  28. package/dist/cramFile/slice/index.js +24 -22
  29. package/dist/cramFile/slice/index.js.map +1 -1
  30. package/dist/cramFile/util.js +1 -1
  31. package/dist/cramFile/util.js.map +1 -1
  32. package/dist/index.d.ts +3 -4
  33. package/dist/index.js +7 -30
  34. package/dist/index.js.map +1 -1
  35. package/dist/indexedCramFile.d.ts +6 -6
  36. package/dist/indexedCramFile.js +13 -18
  37. package/dist/indexedCramFile.js.map +1 -1
  38. package/dist/io/index.d.ts +2 -1
  39. package/dist/io/index.js +4 -3
  40. package/dist/io/index.js.map +1 -1
  41. package/dist/sam.js +10 -13
  42. package/dist/sam.js.map +1 -1
  43. package/dist/unzip.d.ts +1 -2
  44. package/dist/unzip.js +1 -1
  45. package/dist/unzip.js.map +1 -1
  46. package/esm/craiIndex.d.ts +2 -2
  47. package/esm/craiIndex.js +5 -9
  48. package/esm/craiIndex.js.map +1 -1
  49. package/esm/cramFile/codecs/_base.d.ts +6 -6
  50. package/esm/cramFile/codecs/external.js +1 -0
  51. package/esm/cramFile/codecs/external.js.map +1 -1
  52. package/esm/cramFile/codecs/huffman.d.ts +0 -1
  53. package/esm/cramFile/codecs/huffman.js +1 -3
  54. package/esm/cramFile/codecs/huffman.js.map +1 -1
  55. package/esm/cramFile/container/compressionScheme.js +1 -1
  56. package/esm/cramFile/container/compressionScheme.js.map +1 -1
  57. package/esm/cramFile/encoding.d.ts +20 -20
  58. package/esm/cramFile/file.d.ts +6 -6
  59. package/esm/cramFile/filehandle.d.ts +1 -2
  60. package/esm/cramFile/index.d.ts +1 -2
  61. package/esm/cramFile/index.js +1 -2
  62. package/esm/cramFile/index.js.map +1 -1
  63. package/esm/cramFile/record.d.ts +6 -6
  64. package/esm/cramFile/record.js +7 -4
  65. package/esm/cramFile/record.js.map +1 -1
  66. package/esm/cramFile/sectionParsers.d.ts +8 -8
  67. package/esm/cramFile/sectionParsers.js +3 -4
  68. package/esm/cramFile/sectionParsers.js.map +1 -1
  69. package/esm/cramFile/slice/decodeRecord.js +6 -10
  70. package/esm/cramFile/slice/decodeRecord.js.map +1 -1
  71. package/esm/cramFile/slice/index.js +24 -22
  72. package/esm/cramFile/slice/index.js.map +1 -1
  73. package/esm/cramFile/util.js +1 -1
  74. package/esm/cramFile/util.js.map +1 -1
  75. package/esm/index.d.ts +3 -4
  76. package/esm/index.js +3 -4
  77. package/esm/index.js.map +1 -1
  78. package/esm/indexedCramFile.d.ts +6 -6
  79. package/esm/indexedCramFile.js +13 -18
  80. package/esm/indexedCramFile.js.map +1 -1
  81. package/esm/io/index.d.ts +2 -1
  82. package/esm/io/index.js +2 -1
  83. package/esm/io/index.js.map +1 -1
  84. package/esm/sam.js +10 -13
  85. package/esm/sam.js.map +1 -1
  86. package/esm/unzip.d.ts +1 -2
  87. package/esm/unzip.js +1 -2
  88. package/esm/unzip.js.map +1 -1
  89. package/package.json +11 -11
  90. package/src/craiIndex.ts +8 -13
  91. package/src/cramFile/codecs/_base.ts +3 -3
  92. package/src/cramFile/codecs/external.ts +1 -0
  93. package/src/cramFile/codecs/huffman.ts +7 -8
  94. package/src/cramFile/container/compressionScheme.ts +1 -1
  95. package/src/cramFile/encoding.ts +10 -10
  96. package/src/cramFile/file.ts +5 -5
  97. package/src/cramFile/filehandle.ts +1 -3
  98. package/src/cramFile/index.ts +1 -2
  99. package/src/cramFile/record.ts +13 -10
  100. package/src/cramFile/sectionParsers.ts +8 -9
  101. package/src/cramFile/slice/decodeRecord.ts +15 -17
  102. package/src/cramFile/slice/index.ts +26 -23
  103. package/src/cramFile/util.ts +1 -1
  104. package/src/index.ts +3 -5
  105. package/src/indexedCramFile.ts +19 -23
  106. package/src/io/index.ts +3 -1
  107. package/src/sam.ts +12 -14
  108. package/src/typings/binary-parser.d.ts +1 -1
  109. package/src/unzip.ts +1 -2
@@ -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 type CramFileSource = {
9
+ export interface CramFileSource {
10
10
  cramFilehandle?: Filehandle
11
11
  cramUrl?: string
12
12
  cramPath?: string
13
13
  }
14
14
 
15
- export type CramIndexLike = {
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: SeqFetch
48
- checkSequenceMD5: boolean
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
- if (args.cram) {
55
- this.cram = args.cram
56
- } else {
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 (let i = 0; i < ret.length; i += 1) {
132
- const name = ret[i].readName
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 = ret[i].uniqueId
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 (let i = 0; i < ret.length; i += 1) {
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 (let i = 0; i < mateBlocks.length; i += 1) {
174
- mateChunks.push(...mateBlocks[i])
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: Array<Promise<CramRecord[]>> = []
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 (let i = 0; i < feats.length; i += 1) {
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
@@ -28,4 +28,6 @@ function open(
28
28
  throw new Error('no url, path, or filehandle provided, cannot open')
29
29
  }
30
30
 
31
- export { LocalFile, RemoteFile, fromUrl, open }
31
+ export { fromUrl, open }
32
+
33
+ export { LocalFile, RemoteFile } from 'generic-filehandle'
package/src/sam.ts CHANGED
@@ -14,20 +14,18 @@ export function parseHeaderText(text: string) {
14
14
  tag: tag.slice(1),
15
15
  data: fields.map(f => {
16
16
  const r = f.indexOf(':')
17
- if (r !== -1) {
18
- return {
19
- tag: f.slice(0, r),
20
- value: f.slice(r + 1),
21
- }
22
- } else {
23
- // @CO lines are not comma separated.
24
- // See "samtools view -H c2\#pad.3.0.cram"
25
- // so, just store value tag itself
26
- return {
27
- tag: f,
28
- value: undefined,
29
- }
30
- }
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
+ }
31
29
  }),
32
30
  })
33
31
  }
@@ -1,5 +1,5 @@
1
1
  declare module '@gmod/binary-parser' {
2
- export type Options = {
2
+ export interface Options {
3
3
  stripNull?: boolean
4
4
  formatter?: (item: any) => any
5
5
  length?: number | string | ((this: { $parent: unknown }) => void)
package/src/unzip.ts CHANGED
@@ -1,2 +1 @@
1
- import { gunzipSync } from 'zlib'
2
- export { gunzipSync as unzip }
1
+ export { gunzipSync as unzip } from 'zlib'