@gmod/cram 1.5.9 → 1.6.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 (258) hide show
  1. package/CHANGELOG.md +90 -0
  2. package/README.md +182 -172
  3. package/dist/craiIndex.d.ts +37 -0
  4. package/dist/craiIndex.js +196 -301
  5. package/dist/craiIndex.js.map +1 -0
  6. package/dist/cram-bundle.js +6 -15
  7. package/dist/cramFile/codecs/_base.d.ts +6 -0
  8. package/dist/cramFile/codecs/_base.js +44 -53
  9. package/dist/cramFile/codecs/_base.js.map +1 -0
  10. package/dist/cramFile/codecs/beta.d.ts +4 -0
  11. package/dist/cramFile/codecs/beta.js +38 -48
  12. package/dist/cramFile/codecs/beta.js.map +1 -0
  13. package/dist/cramFile/codecs/byteArrayLength.d.ts +8 -0
  14. package/dist/cramFile/codecs/byteArrayLength.js +58 -78
  15. package/dist/cramFile/codecs/byteArrayLength.js.map +1 -0
  16. package/dist/cramFile/codecs/byteArrayStop.d.ts +6 -0
  17. package/dist/cramFile/codecs/byteArrayStop.js +62 -76
  18. package/dist/cramFile/codecs/byteArrayStop.js.map +1 -0
  19. package/dist/cramFile/codecs/external.d.ts +7 -0
  20. package/dist/cramFile/codecs/external.js +63 -81
  21. package/dist/cramFile/codecs/external.js.map +1 -0
  22. package/dist/cramFile/codecs/gamma.d.ts +4 -0
  23. package/dist/cramFile/codecs/gamma.js +43 -56
  24. package/dist/cramFile/codecs/gamma.js.map +1 -0
  25. package/dist/cramFile/codecs/huffman.d.ts +17 -0
  26. package/dist/cramFile/codecs/huffman.js +126 -199
  27. package/dist/cramFile/codecs/huffman.js.map +1 -0
  28. package/dist/cramFile/codecs/index.d.ts +2 -0
  29. package/dist/cramFile/codecs/index.js +31 -38
  30. package/dist/cramFile/codecs/index.js.map +1 -0
  31. package/dist/cramFile/codecs/subexp.d.ts +4 -0
  32. package/dist/cramFile/codecs/subexp.js +51 -64
  33. package/dist/cramFile/codecs/subexp.js.map +1 -0
  34. package/dist/cramFile/constants.d.ts +36 -0
  35. package/dist/cramFile/constants.js +52 -50
  36. package/dist/cramFile/constants.js.map +1 -0
  37. package/dist/cramFile/container/compressionScheme.d.ts +23 -0
  38. package/dist/cramFile/container/compressionScheme.js +115 -153
  39. package/dist/cramFile/container/compressionScheme.js.map +1 -0
  40. package/dist/cramFile/container/index.d.ts +13 -0
  41. package/dist/cramFile/container/index.js +169 -283
  42. package/dist/cramFile/container/index.js.map +1 -0
  43. package/dist/cramFile/file.d.ts +63 -0
  44. package/dist/cramFile/file.js +440 -766
  45. package/dist/cramFile/file.js.map +1 -0
  46. package/dist/cramFile/index.d.ts +2 -0
  47. package/dist/cramFile/index.js +7 -4
  48. package/dist/cramFile/index.js.map +1 -0
  49. package/dist/cramFile/record.d.ts +79 -0
  50. package/dist/cramFile/record.js +253 -308
  51. package/dist/cramFile/record.js.map +1 -0
  52. package/dist/cramFile/sectionParsers.d.ts +18 -0
  53. package/dist/cramFile/sectionParsers.js +324 -362
  54. package/dist/cramFile/sectionParsers.js.map +1 -0
  55. package/dist/cramFile/slice/decodeRecord.d.ts +2 -0
  56. package/dist/cramFile/slice/decodeRecord.js +278 -298
  57. package/dist/cramFile/slice/decodeRecord.js.map +1 -0
  58. package/dist/cramFile/slice/index.d.ts +20 -0
  59. package/dist/cramFile/slice/index.js +488 -789
  60. package/dist/cramFile/slice/index.js.map +1 -0
  61. package/dist/cramFile/util.d.ts +5 -0
  62. package/dist/cramFile/util.js +158 -144
  63. package/dist/cramFile/util.js.map +1 -0
  64. package/dist/errors.d.ts +23 -0
  65. package/dist/errors.js +66 -103
  66. package/dist/errors.js.map +1 -0
  67. package/dist/index.d.ts +4 -0
  68. package/dist/index.js +12 -12
  69. package/dist/index.js.map +1 -0
  70. package/dist/indexedCramFile.d.ts +39 -0
  71. package/dist/indexedCramFile.js +213 -315
  72. package/dist/indexedCramFile.js.map +1 -0
  73. package/dist/io/bufferCache.d.ts +12 -0
  74. package/dist/io/bufferCache.js +108 -128
  75. package/dist/io/bufferCache.js.map +1 -0
  76. package/dist/io/index.d.ts +5 -0
  77. package/dist/io/index.js +29 -27
  78. package/dist/io/index.js.map +1 -0
  79. package/dist/io/localFile.d.ts +10 -0
  80. package/dist/io/localFile.js +105 -162
  81. package/dist/io/localFile.js.map +1 -0
  82. package/dist/io/remoteFile.d.ts +16 -0
  83. package/dist/io/remoteFile.js +137 -206
  84. package/dist/io/remoteFile.js.map +1 -0
  85. package/dist/rans/constants.d.ts +3 -0
  86. package/dist/rans/constants.js +6 -6
  87. package/dist/rans/constants.js.map +1 -0
  88. package/dist/rans/d04.d.ts +1 -0
  89. package/dist/rans/d04.js +70 -99
  90. package/dist/rans/d04.js.map +1 -0
  91. package/dist/rans/d14.d.ts +1 -0
  92. package/dist/rans/d14.js +55 -93
  93. package/dist/rans/d14.js.map +1 -0
  94. package/dist/rans/decoding.d.ts +30 -0
  95. package/dist/rans/decoding.js +112 -159
  96. package/dist/rans/decoding.js.map +1 -0
  97. package/dist/rans/frequencies.d.ts +2 -0
  98. package/dist/rans/frequencies.js +110 -119
  99. package/dist/rans/frequencies.js.map +1 -0
  100. package/dist/rans/index.d.ts +1 -0
  101. package/dist/rans/index.js +111 -174
  102. package/dist/rans/index.js.map +1 -0
  103. package/dist/sam.d.ts +1 -0
  104. package/dist/sam.js +16 -41
  105. package/dist/sam.js.map +1 -0
  106. package/dist/unzip-pako.d.ts +2 -0
  107. package/dist/unzip-pako.js +9 -0
  108. package/dist/unzip-pako.js.map +1 -0
  109. package/dist/unzip.d.ts +2 -0
  110. package/dist/unzip.js +6 -0
  111. package/dist/unzip.js.map +1 -0
  112. package/errors.js +66 -103
  113. package/esm/craiIndex.d.ts +37 -0
  114. package/esm/craiIndex.js +158 -0
  115. package/esm/craiIndex.js.map +1 -0
  116. package/esm/cramFile/codecs/_base.d.ts +6 -0
  117. package/esm/cramFile/codecs/_base.js +42 -0
  118. package/esm/cramFile/codecs/_base.js.map +1 -0
  119. package/esm/cramFile/codecs/beta.d.ts +4 -0
  120. package/esm/cramFile/codecs/beta.js +15 -0
  121. package/esm/cramFile/codecs/beta.js.map +1 -0
  122. package/esm/cramFile/codecs/byteArrayLength.d.ts +8 -0
  123. package/esm/cramFile/codecs/byteArrayLength.js +35 -0
  124. package/esm/cramFile/codecs/byteArrayLength.js.map +1 -0
  125. package/esm/cramFile/codecs/byteArrayStop.d.ts +6 -0
  126. package/esm/cramFile/codecs/byteArrayStop.js +40 -0
  127. package/esm/cramFile/codecs/byteArrayStop.js.map +1 -0
  128. package/esm/cramFile/codecs/external.d.ts +7 -0
  129. package/esm/cramFile/codecs/external.js +40 -0
  130. package/esm/cramFile/codecs/external.js.map +1 -0
  131. package/esm/cramFile/codecs/gamma.d.ts +4 -0
  132. package/esm/cramFile/codecs/gamma.js +20 -0
  133. package/esm/cramFile/codecs/gamma.js.map +1 -0
  134. package/esm/cramFile/codecs/huffman.d.ts +17 -0
  135. package/esm/cramFile/codecs/huffman.js +107 -0
  136. package/esm/cramFile/codecs/huffman.js.map +1 -0
  137. package/esm/cramFile/codecs/index.d.ts +2 -0
  138. package/esm/cramFile/codecs/index.js +30 -0
  139. package/esm/cramFile/codecs/index.js.map +1 -0
  140. package/esm/cramFile/codecs/subexp.d.ts +4 -0
  141. package/esm/cramFile/codecs/subexp.js +28 -0
  142. package/esm/cramFile/codecs/subexp.js.map +1 -0
  143. package/esm/cramFile/constants.d.ts +36 -0
  144. package/esm/cramFile/constants.js +51 -0
  145. package/esm/cramFile/constants.js.map +1 -0
  146. package/esm/cramFile/container/compressionScheme.d.ts +23 -0
  147. package/esm/cramFile/container/compressionScheme.js +123 -0
  148. package/esm/cramFile/container/compressionScheme.js.map +1 -0
  149. package/esm/cramFile/container/index.d.ts +13 -0
  150. package/esm/cramFile/container/index.js +84 -0
  151. package/esm/cramFile/container/index.js.map +1 -0
  152. package/esm/cramFile/file.d.ts +63 -0
  153. package/esm/cramFile/file.js +281 -0
  154. package/esm/cramFile/file.js.map +1 -0
  155. package/esm/cramFile/index.d.ts +2 -0
  156. package/esm/cramFile/index.js +3 -0
  157. package/esm/cramFile/index.js.map +1 -0
  158. package/esm/cramFile/record.d.ts +79 -0
  159. package/esm/cramFile/record.js +297 -0
  160. package/esm/cramFile/record.js.map +1 -0
  161. package/esm/cramFile/sectionParsers.d.ts +18 -0
  162. package/esm/cramFile/sectionParsers.js +347 -0
  163. package/esm/cramFile/sectionParsers.js.map +1 -0
  164. package/esm/cramFile/slice/decodeRecord.d.ts +2 -0
  165. package/esm/cramFile/slice/decodeRecord.js +299 -0
  166. package/esm/cramFile/slice/decodeRecord.js.map +1 -0
  167. package/esm/cramFile/slice/index.d.ts +20 -0
  168. package/esm/cramFile/slice/index.js +364 -0
  169. package/esm/cramFile/slice/index.js.map +1 -0
  170. package/esm/cramFile/util.d.ts +5 -0
  171. package/esm/cramFile/util.js +161 -0
  172. package/esm/cramFile/util.js.map +1 -0
  173. package/esm/errors.d.ts +23 -0
  174. package/esm/errors.js +24 -0
  175. package/esm/errors.js.map +1 -0
  176. package/esm/index.d.ts +4 -0
  177. package/esm/index.js +5 -0
  178. package/esm/index.js.map +1 -0
  179. package/esm/indexedCramFile.d.ts +39 -0
  180. package/esm/indexedCramFile.js +155 -0
  181. package/esm/indexedCramFile.js.map +1 -0
  182. package/esm/io/bufferCache.d.ts +12 -0
  183. package/esm/io/bufferCache.js +54 -0
  184. package/esm/io/bufferCache.js.map +1 -0
  185. package/esm/io/index.d.ts +5 -0
  186. package/esm/io/index.js +24 -0
  187. package/esm/io/index.js.map +1 -0
  188. package/esm/io/localFile.d.ts +10 -0
  189. package/esm/io/localFile.js +31 -0
  190. package/esm/io/localFile.js.map +1 -0
  191. package/esm/io/remoteFile.d.ts +16 -0
  192. package/esm/io/remoteFile.js +64 -0
  193. package/esm/io/remoteFile.js.map +1 -0
  194. package/esm/rans/constants.d.ts +3 -0
  195. package/esm/rans/constants.js +5 -0
  196. package/esm/rans/constants.js.map +1 -0
  197. package/esm/rans/d04.d.ts +1 -0
  198. package/esm/rans/d04.js +67 -0
  199. package/esm/rans/d04.js.map +1 -0
  200. package/esm/rans/d14.d.ts +1 -0
  201. package/esm/rans/d14.js +52 -0
  202. package/esm/rans/d14.js.map +1 -0
  203. package/esm/rans/decoding.d.ts +30 -0
  204. package/esm/rans/decoding.js +118 -0
  205. package/esm/rans/decoding.js.map +1 -0
  206. package/esm/rans/frequencies.d.ts +2 -0
  207. package/esm/rans/frequencies.js +110 -0
  208. package/esm/rans/frequencies.js.map +1 -0
  209. package/esm/rans/index.d.ts +1 -0
  210. package/esm/rans/index.js +195 -0
  211. package/esm/rans/index.js.map +1 -0
  212. package/esm/sam.d.ts +1 -0
  213. package/esm/sam.js +16 -0
  214. package/esm/sam.js.map +1 -0
  215. package/esm/unzip-pako.d.ts +2 -0
  216. package/esm/unzip-pako.js +5 -0
  217. package/esm/unzip-pako.js.map +1 -0
  218. package/esm/unzip.d.ts +2 -0
  219. package/esm/unzip.js +3 -0
  220. package/esm/unzip.js.map +1 -0
  221. package/package.json +38 -35
  222. package/src/craiIndex.js +180 -0
  223. package/src/cramFile/codecs/_base.js +49 -0
  224. package/src/cramFile/codecs/beta.js +23 -0
  225. package/src/cramFile/codecs/byteArrayLength.js +55 -0
  226. package/src/cramFile/codecs/byteArrayStop.js +50 -0
  227. package/src/cramFile/codecs/external.js +54 -0
  228. package/src/cramFile/codecs/gamma.js +30 -0
  229. package/src/cramFile/codecs/huffman.js +137 -0
  230. package/src/cramFile/codecs/index.js +38 -0
  231. package/src/cramFile/codecs/subexp.js +32 -0
  232. package/src/cramFile/constants.js +55 -0
  233. package/src/cramFile/container/compressionScheme.js +144 -0
  234. package/src/cramFile/container/index.js +119 -0
  235. package/src/cramFile/file.js +347 -0
  236. package/src/cramFile/index.js +3 -0
  237. package/src/cramFile/record.js +337 -0
  238. package/src/cramFile/sectionParsers.js +379 -0
  239. package/src/cramFile/slice/decodeRecord.js +362 -0
  240. package/src/cramFile/slice/index.js +497 -0
  241. package/src/cramFile/util.js +169 -0
  242. package/src/errors.js +22 -0
  243. package/src/index.js +5 -0
  244. package/src/indexedCramFile.js +191 -0
  245. package/src/io/bufferCache.js +66 -0
  246. package/src/io/index.js +26 -0
  247. package/src/io/localFile.js +35 -0
  248. package/src/io/remoteFile.js +71 -0
  249. package/src/rans/README.md +1 -0
  250. package/src/rans/constants.js +5 -0
  251. package/src/rans/d04.js +83 -0
  252. package/src/rans/d14.js +59 -0
  253. package/src/rans/decoding.js +141 -0
  254. package/src/rans/frequencies.js +121 -0
  255. package/src/rans/index.js +249 -0
  256. package/src/sam.js +15 -0
  257. package/src/unzip-pako.ts +5 -0
  258. package/src/unzip.ts +2 -0
@@ -0,0 +1,364 @@
1
+ import { CramMalformedError, CramBufferOverrunError, CramArgumentError, } from '../../errors';
2
+ import { parseItem, tinyMemoize, sequenceMD5 } from '../util';
3
+ import Constants from '../constants';
4
+ import decodeRecord from './decodeRecord';
5
+ /**
6
+ * @private
7
+ * Try to estimate the template length from a bunch of interrelated multi-segment reads.
8
+ * @param {Array[CramRecord]} allRecords
9
+ * @param {number} currentRecordNumber
10
+ * @param {CramRecord} thisRecord
11
+ */
12
+ function calculateMultiSegmentMatedTemplateLength(allRecords, currentRecordNumber, thisRecord) {
13
+ function getAllMatedRecords(startRecord) {
14
+ const records = [startRecord];
15
+ if (startRecord.mateRecordNumber >= 0) {
16
+ const mateRecord = allRecords[startRecord.mateRecordNumber];
17
+ if (!mateRecord) {
18
+ throw new CramMalformedError('intra-slice mate record not found, this file seems malformed');
19
+ }
20
+ records.push(...getAllMatedRecords(mateRecord));
21
+ }
22
+ return records;
23
+ }
24
+ const matedRecords = getAllMatedRecords(thisRecord);
25
+ const starts = matedRecords.map(r => r.alignmentStart);
26
+ const ends = matedRecords.map(r => r.alignmentStart + r.readLength - 1);
27
+ const estimatedTemplateLength = Math.max(...ends) - Math.min(...starts) + 1;
28
+ if (estimatedTemplateLength >= 0) {
29
+ matedRecords.forEach(r => {
30
+ if (r.templateLength !== undefined) {
31
+ throw new CramMalformedError('mate pair group has some members that have template lengths already, this file seems malformed');
32
+ }
33
+ r.templateLength = estimatedTemplateLength;
34
+ });
35
+ }
36
+ }
37
+ /**
38
+ * @private
39
+ * Attempt to calculate the `templateLength` for a pair of intra-slice paired reads.
40
+ * Ported from htslib. Algorithm is imperfect.
41
+ * @param {CramRecord} thisRecord
42
+ * @param {CramRecord} mateRecord
43
+ */
44
+ function calculateIntraSliceMatePairTemplateLength(thisRecord, mateRecord) {
45
+ // this just estimates the template length by using the simple (non-gapped) end coordinate of each
46
+ // read, because gapping in the alignment doesn't mean the template is longer or shorter
47
+ const start = Math.min(thisRecord.alignmentStart, mateRecord.alignmentStart);
48
+ const end = Math.max(thisRecord.alignmentStart + thisRecord.readLength - 1, mateRecord.alignmentStart + mateRecord.readLength - 1);
49
+ const lengthEstimate = end - start + 1;
50
+ thisRecord.templateLength = lengthEstimate;
51
+ mateRecord.templateLength = lengthEstimate;
52
+ }
53
+ /**
54
+ * @private establishes a mate-pair relationship between two records in the same slice.
55
+ * CRAM compresses mate-pair relationships between records in the same slice down into
56
+ * just one record having the index in the slice of its mate
57
+ */
58
+ function associateIntraSliceMate(allRecords, currentRecordNumber, thisRecord, mateRecord) {
59
+ if (!mateRecord) {
60
+ throw new CramMalformedError('could not resolve intra-slice mate pairs, file seems truncated or malformed');
61
+ }
62
+ const complicatedMultiSegment = !!(mateRecord.mate ||
63
+ (mateRecord.mateRecordNumber !== undefined &&
64
+ mateRecord.mateRecordNumber !== currentRecordNumber));
65
+ // Deal with lossy read names
66
+ if (!thisRecord.readName) {
67
+ thisRecord.readName = String(thisRecord.uniqueId);
68
+ mateRecord.readName = thisRecord.readName;
69
+ }
70
+ thisRecord.mate = {
71
+ sequenceId: mateRecord.sequenceId,
72
+ alignmentStart: mateRecord.alignmentStart,
73
+ uniqueId: mateRecord.uniqueId,
74
+ };
75
+ if (mateRecord.readName) {
76
+ thisRecord.mate.readName = mateRecord.readName;
77
+ }
78
+ // the mate record might have its own mate pointer, if this is some kind of
79
+ // multi-segment (more than paired) scheme, so only relate that one back to this one
80
+ // if it does not have any other relationship
81
+ if (!mateRecord.mate && mateRecord.mateRecordNumber === undefined) {
82
+ mateRecord.mate = {
83
+ sequenceId: thisRecord.sequenceId,
84
+ alignmentStart: thisRecord.alignmentStart,
85
+ uniqueId: thisRecord.uniqueId,
86
+ };
87
+ if (thisRecord.readName) {
88
+ mateRecord.mate.readName = thisRecord.readName;
89
+ }
90
+ }
91
+ // make sure the proper flags and cramFlags are set on both records
92
+ // paired
93
+ thisRecord.flags |= Constants.BAM_FPAIRED;
94
+ // set mate unmapped if needed
95
+ if (mateRecord.flags & Constants.BAM_FUNMAP) {
96
+ thisRecord.flags |= Constants.BAM_FMUNMAP;
97
+ // thisRecord.templateLength = 0
98
+ }
99
+ if (thisRecord.flags & Constants.BAM_FUNMAP) {
100
+ // thisRecord.templateLength = 0
101
+ mateRecord.flags |= Constants.BAM_FMUNMAP;
102
+ }
103
+ // set mate reversed if needed
104
+ if (mateRecord.flags & Constants.BAM_FREVERSE) {
105
+ thisRecord.flags |= Constants.BAM_FMREVERSE;
106
+ }
107
+ if (thisRecord.flags & Constants.BAM_FREVERSE) {
108
+ mateRecord.flags |= Constants.BAM_FMREVERSE;
109
+ }
110
+ if (thisRecord.templateLength === undefined) {
111
+ if (complicatedMultiSegment) {
112
+ calculateMultiSegmentMatedTemplateLength(allRecords, currentRecordNumber, thisRecord);
113
+ }
114
+ else {
115
+ calculateIntraSliceMatePairTemplateLength(thisRecord, mateRecord);
116
+ }
117
+ }
118
+ // delete this last because it's used by the
119
+ // complicated template length estimation
120
+ delete thisRecord.mateRecordNumber;
121
+ }
122
+ export default class CramSlice {
123
+ constructor(container, position) {
124
+ this.container = container;
125
+ this.file = container.file;
126
+ this.containerPosition = position;
127
+ }
128
+ // memoize
129
+ async getHeader() {
130
+ // fetch and parse the slice header
131
+ const sectionParsers = await this.file.getSectionParsers();
132
+ const containerHeader = await this.container.getHeader();
133
+ const header = await this.file.readBlock(containerHeader._endPosition + this.containerPosition);
134
+ if (header.contentType === 'MAPPED_SLICE_HEADER') {
135
+ header.content = parseItem(header.content, sectionParsers.cramMappedSliceHeader.parser, 0, containerHeader._endPosition);
136
+ }
137
+ else if (header.contentType === 'UNMAPPED_SLICE_HEADER') {
138
+ header.content = parseItem(header.content, sectionParsers.cramUnmappedSliceHeader.parser, 0, containerHeader._endPosition);
139
+ }
140
+ else {
141
+ throw new CramMalformedError(`error reading slice header block, invalid content type ${header._contentType}`);
142
+ }
143
+ return header;
144
+ }
145
+ // memoize
146
+ async getBlocks() {
147
+ const header = await this.getHeader();
148
+ // read all the blocks into memory and store them
149
+ let blockPosition = header._endPosition;
150
+ const blocks = new Array(header.content.numBlocks);
151
+ for (let i = 0; i < blocks.length; i += 1) {
152
+ blocks[i] = await this.file.readBlock(blockPosition);
153
+ blockPosition = blocks[i]._endPosition;
154
+ }
155
+ return blocks;
156
+ }
157
+ // no memoize
158
+ async getCoreDataBlock() {
159
+ const blocks = await this.getBlocks();
160
+ // the core data block is always the first block in the slice
161
+ return blocks[0];
162
+ }
163
+ // memoize
164
+ async _getBlocksContentIdIndex() {
165
+ const blocks = await this.getBlocks();
166
+ const blocksByContentId = {};
167
+ blocks.forEach(block => {
168
+ if (block.contentType === 'EXTERNAL_DATA') {
169
+ blocksByContentId[block.contentId] = block;
170
+ }
171
+ });
172
+ return blocksByContentId;
173
+ }
174
+ async getBlockByContentId(id) {
175
+ const blocksByContentId = await this._getBlocksContentIdIndex();
176
+ return blocksByContentId[id];
177
+ }
178
+ async getReferenceRegion() {
179
+ // read the slice header
180
+ const sliceHeader = (await this.getHeader()).content;
181
+ if (sliceHeader.refSeqId < 0) {
182
+ return undefined;
183
+ }
184
+ const compressionScheme = await this.container.getCompressionScheme();
185
+ // console.log(JSON.stringify(sliceHeader, null, ' '))
186
+ if (sliceHeader.refBaseBlockId >= 0) {
187
+ const refBlock = this.getBlockByContentId(sliceHeader.refBaseBlockId);
188
+ if (!refBlock) {
189
+ throw new CramMalformedError('embedded reference specified, but reference block does not exist');
190
+ }
191
+ if (sliceHeader.span > refBlock.uncompressedSize) {
192
+ throw new CramMalformedError('Embedded reference is too small');
193
+ }
194
+ return {
195
+ seq: refBlock.data.toString('utf8'),
196
+ start: sliceHeader.refSeqStart,
197
+ end: sliceHeader.refSeqStart + sliceHeader.refSeqSpan - 1,
198
+ span: sliceHeader.refSeqSpan,
199
+ };
200
+ }
201
+ if (compressionScheme.referenceRequired ||
202
+ this.file.fetchReferenceSequenceCallback) {
203
+ if (!this.file.fetchReferenceSequenceCallback) {
204
+ throw new Error('reference sequence not embedded, and seqFetch callback not provided, cannot fetch reference sequence');
205
+ }
206
+ const seq = await this.file.fetchReferenceSequenceCallback(sliceHeader.refSeqId, sliceHeader.refSeqStart, sliceHeader.refSeqStart + sliceHeader.refSeqSpan - 1);
207
+ if (seq.length !== sliceHeader.refSeqSpan) {
208
+ throw new CramArgumentError('seqFetch callback returned a reference sequence of the wrong length');
209
+ }
210
+ return {
211
+ seq,
212
+ start: sliceHeader.refSeqStart,
213
+ end: sliceHeader.refSeqStart + sliceHeader.refSeqSpan - 1,
214
+ span: sliceHeader.refSeqSpan,
215
+ };
216
+ }
217
+ return undefined;
218
+ }
219
+ getAllRecords() {
220
+ return this.getRecords(() => true);
221
+ }
222
+ async _fetchRecords() {
223
+ const { majorVersion } = await this.file.getDefinition();
224
+ const compressionScheme = await this.container.getCompressionScheme();
225
+ const sliceHeader = await this.getHeader();
226
+ const blocksByContentId = await this._getBlocksContentIdIndex();
227
+ // check MD5 of reference if available
228
+ if (majorVersion > 1 &&
229
+ this.file.options.checkSequenceMD5 &&
230
+ sliceHeader.content.refSeqId >= 0 &&
231
+ sliceHeader.content.md5.join('') !== '0000000000000000') {
232
+ const refRegion = await this.getReferenceRegion();
233
+ if (refRegion) {
234
+ const { seq, start, end } = refRegion;
235
+ const seqMd5 = sequenceMD5(seq);
236
+ const storedMd5 = sliceHeader.content.md5
237
+ .map(byte => (byte < 16 ? '0' : '') + byte.toString(16))
238
+ .join('');
239
+ if (seqMd5 !== storedMd5) {
240
+ throw new CramMalformedError(`MD5 checksum reference mismatch for ref ${sliceHeader.content.refSeqId} pos ${start}..${end}. recorded MD5: ${storedMd5}, calculated MD5: ${seqMd5}`);
241
+ }
242
+ }
243
+ }
244
+ // tracks the read position within the block. codec.decode() methods
245
+ // advance the byte and bit positions in the cursor as they decode data
246
+ // note that we are only decoding a single block here, the core data block
247
+ const coreDataBlock = await this.getCoreDataBlock();
248
+ const cursors = {
249
+ lastAlignmentStart: sliceHeader.content.refSeqStart || 0,
250
+ coreBlock: { bitPosition: 7, bytePosition: 0 },
251
+ externalBlocks: {
252
+ getCursor(contentId) {
253
+ if (!this[contentId]) {
254
+ this[contentId] = { bitPosition: 7, bytePosition: 0 };
255
+ }
256
+ return this[contentId];
257
+ },
258
+ },
259
+ };
260
+ const decodeDataSeries = dataSeriesName => {
261
+ const codec = compressionScheme.getCodecForDataSeries(dataSeriesName);
262
+ if (!codec) {
263
+ throw new CramMalformedError(`no codec defined for ${dataSeriesName} data series`);
264
+ }
265
+ // console.log(dataSeriesName, Object.getPrototypeOf(codec))
266
+ return codec.decode(this, coreDataBlock, blocksByContentId, cursors);
267
+ };
268
+ let records = new Array(sliceHeader.content.numRecords);
269
+ for (let i = 0; i < records.length; i += 1) {
270
+ try {
271
+ records[i] = decodeRecord(this, decodeDataSeries, compressionScheme, sliceHeader, coreDataBlock, blocksByContentId, cursors, majorVersion, i);
272
+ records[i].uniqueId =
273
+ sliceHeader.contentPosition +
274
+ sliceHeader.content.recordCounter +
275
+ i +
276
+ 1;
277
+ }
278
+ catch (e) {
279
+ if (e instanceof CramBufferOverrunError) {
280
+ console.warn('read attempted beyond end of buffer, file seems truncated.');
281
+ records = records.filter(r => !!r);
282
+ break;
283
+ }
284
+ else {
285
+ throw e;
286
+ }
287
+ }
288
+ }
289
+ // interpret `recordsToNextFragment` attributes to make standard `mate` objects
290
+ // Resolve mate pair cross-references between records in this slice
291
+ for (let i = 0; i < records.length; i += 1) {
292
+ const { mateRecordNumber } = records[i];
293
+ if (mateRecordNumber >= 0) {
294
+ associateIntraSliceMate(records, i, records[i], records[mateRecordNumber]);
295
+ }
296
+ }
297
+ return records;
298
+ }
299
+ async getRecords(filterFunction) {
300
+ // fetch the features if necessary, using the file-level feature cache
301
+ const cacheKey = this.container.filePosition + this.containerPosition;
302
+ let recordsPromise = this.file.featureCache.get(cacheKey);
303
+ if (!recordsPromise) {
304
+ recordsPromise = this._fetchRecords();
305
+ this.file.featureCache.set(cacheKey, recordsPromise);
306
+ }
307
+ const records = (await recordsPromise).filter(filterFunction);
308
+ // if we can fetch reference sequence, add the reference sequence to the records
309
+ if (records.length && this.file.fetchReferenceSequenceCallback) {
310
+ const sliceHeader = await this.getHeader();
311
+ if (sliceHeader.content.refSeqId >= 0 || // single-ref slice
312
+ sliceHeader.content.refSeqId === -2 // multi-ref slice
313
+ ) {
314
+ const singleRefId = sliceHeader.content.refSeqId >= 0
315
+ ? sliceHeader.content.refSeqId
316
+ : undefined;
317
+ const compressionScheme = await this.container.getCompressionScheme();
318
+ const refRegions = {}; // seqId => { start, end, seq }
319
+ // iterate over the records to find the spans of the reference sequences we need to fetch
320
+ for (let i = 0; i < records.length; i += 1) {
321
+ const seqId = singleRefId !== undefined ? singleRefId : records[i].sequenceId;
322
+ let refRegion = refRegions[seqId];
323
+ if (!refRegion) {
324
+ refRegion = {
325
+ id: seqId,
326
+ start: records[i].alignmentStart,
327
+ end: -Infinity,
328
+ };
329
+ refRegions[seqId] = refRegion;
330
+ }
331
+ const end = records[i].alignmentStart +
332
+ (records[i].lengthOnRef || records[i].readLength) -
333
+ 1;
334
+ if (end > refRegion.end) {
335
+ refRegion.end = end;
336
+ }
337
+ if (records[i].alignmentStart < refRegion.start) {
338
+ refRegion.start = records[i].alignmentStart;
339
+ }
340
+ }
341
+ // fetch the `seq` for all of the ref regions
342
+ await Promise.all(Object.values(refRegions).map(async (refRegion) => {
343
+ if (refRegion.id !== -1 && refRegion.start <= refRegion.end) {
344
+ refRegion.seq = await this.file.fetchReferenceSequenceCallback(refRegion.id, refRegion.start, refRegion.end);
345
+ }
346
+ }));
347
+ // now decorate all the records with them
348
+ for (let i = 0; i < records.length; i += 1) {
349
+ const seqId = singleRefId !== undefined ? singleRefId : records[i].sequenceId;
350
+ const refRegion = refRegions[seqId];
351
+ if (refRegion && refRegion.seq) {
352
+ records[i].addReferenceSequence(refRegion, compressionScheme);
353
+ }
354
+ }
355
+ }
356
+ }
357
+ return records;
358
+ }
359
+ }
360
+ // memoize several methods in the class for performance
361
+ 'getHeader getBlocks _getBlocksContentIdIndex'
362
+ .split(' ')
363
+ .forEach(method => tinyMemoize(CramSlice, method));
364
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cramFile/slice/index.js"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE7D,OAAO,SAAS,MAAM,cAAc,CAAA;AACpC,OAAO,YAAY,MAAM,gBAAgB,CAAA;AAEzC;;;;;;GAMG;AACH,SAAS,wCAAwC,CAC/C,UAAU,EACV,mBAAmB,EACnB,UAAU;IAEV,SAAS,kBAAkB,CAAC,WAAW;QACrC,MAAM,OAAO,GAAG,CAAC,WAAW,CAAC,CAAA;QAC7B,IAAI,WAAW,CAAC,gBAAgB,IAAI,CAAC,EAAE;YACrC,MAAM,UAAU,GAAG,UAAU,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAA;YAC3D,IAAI,CAAC,UAAU,EAAE;gBACf,MAAM,IAAI,kBAAkB,CAC1B,8DAA8D,CAC/D,CAAA;aACF;YACD,OAAO,CAAC,IAAI,CAAC,GAAG,kBAAkB,CAAC,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AiB,CAAC,CAAA;qBAC9D;iBACF;aACF;SACF;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;CACF;AAED,uDAAuD;AACvD,8CAA8C;KAC3C,KAAK,CAAC,GAAG,CAAC;KACV,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,WAAW,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ export function itf8Size(v: any): 1 | 2 | 3 | 4 | 5;
2
+ export function parseItf8(buffer: any, initialOffset: any): any[];
3
+ export function parseItem(buffer: any, parser: any, startBufferPosition?: number, startFilePosition?: number): any;
4
+ export function tinyMemoize(_class: any, methodName: any): void;
5
+ export function sequenceMD5(seq: any): any;
@@ -0,0 +1,161 @@
1
+ import md5 from 'md5';
2
+ import { CramBufferOverrunError } from '../errors';
3
+ export function itf8Size(v) {
4
+ if (!(v & ~0x7f)) {
5
+ return 1;
6
+ }
7
+ if (!(v & ~0x3fff)) {
8
+ return 2;
9
+ }
10
+ if (!(v & ~0x1fffff)) {
11
+ return 3;
12
+ }
13
+ if (!(v & ~0xfffffff)) {
14
+ return 4;
15
+ }
16
+ return 5;
17
+ }
18
+ export function parseItf8(buffer, initialOffset) {
19
+ let offset = initialOffset;
20
+ const countFlags = buffer[offset];
21
+ let result;
22
+ if (countFlags < 0x80) {
23
+ result = countFlags;
24
+ offset += 1;
25
+ }
26
+ else if (countFlags < 0xc0) {
27
+ result = ((countFlags << 8) | buffer[offset + 1]) & 0x3fff;
28
+ offset += 2;
29
+ }
30
+ else if (countFlags < 0xe0) {
31
+ result =
32
+ ((countFlags << 16) | (buffer[offset + 1] << 8) | buffer[offset + 2]) &
33
+ 0x1fffff;
34
+ offset += 3;
35
+ }
36
+ else if (countFlags < 0xf0) {
37
+ result =
38
+ ((countFlags << 24) |
39
+ (buffer[offset + 1] << 16) |
40
+ (buffer[offset + 2] << 8) |
41
+ buffer[offset + 3]) &
42
+ 0x0fffffff;
43
+ offset += 4;
44
+ }
45
+ else {
46
+ result =
47
+ ((countFlags & 0x0f) << 28) |
48
+ (buffer[offset + 1] << 20) |
49
+ (buffer[offset + 2] << 12) |
50
+ (buffer[offset + 3] << 4) |
51
+ (buffer[offset + 4] & 0x0f);
52
+ // x=((0xff & 0x0f)<<28) | (0xff<<20) | (0xff<<12) | (0xff<<4) | (0x0f & 0x0f);
53
+ // TODO *val_p = uv < 0x80000000UL ? uv : -((int32_t) (0xffffffffUL - uv)) - 1;
54
+ offset += 5;
55
+ }
56
+ if (offset > buffer.length) {
57
+ throw new CramBufferOverrunError('Attempted to read beyond end of buffer; this file seems truncated.');
58
+ }
59
+ return [result, offset - initialOffset];
60
+ }
61
+ // parseLtf8(buffer, initialOffset) {
62
+ // let offset = initialOffset
63
+ // const countFlags = buffer[offset]
64
+ // let result
65
+ // if (countFlags < 0x80) {
66
+ // result = countFlags
67
+ // offset += 1
68
+ // } else if (countFlags < 0xc0) {
69
+ // result = ((buffer[offset] << 8) | buffer[offset + 1]) & 0x3fff
70
+ // offset += 2
71
+ // } else if (countFlags < 0xe0) {
72
+ // result =
73
+ // ((buffer[offset] << 16) |
74
+ // (buffer[offset + 1] << 8) |
75
+ // buffer[offset + 2]) &
76
+ // 0x1fffff
77
+ // offset += 3
78
+ // } else if (countFlags < 0xf0) {
79
+ // result =
80
+ // ((buffer[offset] << 24) |
81
+ // (buffer[offset + 1] << 16) |
82
+ // (buffer[offset + 2] << 8) |
83
+ // buffer[offset + 3]) &
84
+ // 0x0fffffff
85
+ // offset += 4
86
+ // } else if (countFlags < 0xf8) {
87
+ // result =
88
+ // ((buffer[offset] & 15) * Math.pow(2,32) + (buffer[offset + 1] << 24)) |
89
+ // ((buffer[offset + 2] << 16) |
90
+ // (buffer[offset + 3] << 8) |
91
+ // buffer[offset + 4])
92
+ // // TODO *val_p = uv < 0x80000000UL ? uv : -((int32_t) (0xffffffffUL - uv)) - 1;
93
+ // offset += 5
94
+ // } else if (countFlags < 0xfc) {
95
+ // result =
96
+ // ((((buffer[offset] & 7) << 8) | buffer[offset + 1]) * Math.pow(2,32) +
97
+ // (buffer[offset + 2] << 24)) |
98
+ // ((buffer[offset + 3] << 16) |
99
+ // (buffer[offset + 4] << 8) |
100
+ // buffer[offset + 5])
101
+ // offset += 6
102
+ // } else if (countFlags < 0xfe) {
103
+ // result =
104
+ // ((((buffer[offset] & 3) << 16) |
105
+ // (buffer[offset + 1] << 8) |
106
+ // buffer[offset + 2]) *
107
+ // Math.pow(2,32) +
108
+ // (buffer[offset + 3] << 24)) |
109
+ // ((buffer[offset + 4] << 16) |
110
+ // (buffer[offset + 5] << 8) |
111
+ // buffer[offset + 6])
112
+ // offset += 7
113
+ // } else if (countFlags < 0xff) {
114
+ // result = Long.fromBytesBE(buffer.slice(offset + 1, offset + 8))
115
+ // if (
116
+ // result.greaterThan(Number.MAX_SAFE_INTEGER) ||
117
+ // result.lessThan(Number.MIN_SAFE_INTEGER)
118
+ // )
119
+ // throw new CramUnimplementedError('integer overflow')
120
+ // result = result.toNumber()
121
+ // offset += 8
122
+ // } else {
123
+ // result = Long.fromBytesBE(buffer.slice(offset + 1, offset + 9))
124
+ // if (
125
+ // result.greaterThan(Number.MAX_SAFE_INTEGER) ||
126
+ // result.lessThan(Number.MIN_SAFE_INTEGER)
127
+ // )
128
+ // throw new CramUnimplementedError('integer overflow')
129
+ // result = result.toNumber()
130
+ // offset += 9
131
+ // }
132
+ // return [result, offset - initialOffset]
133
+ // },
134
+ export function parseItem(buffer, parser, startBufferPosition = 0, startFilePosition = 0) {
135
+ const { offset, result } = parser.parse(buffer);
136
+ result._endPosition = offset + startFilePosition;
137
+ result._size = offset - startBufferPosition;
138
+ return result;
139
+ }
140
+ // this would be nice as a decorator, but i'm a little worried about
141
+ // babel support for it going away or changing.
142
+ // memoizes a method in the stupidest possible way, with no regard for the
143
+ // arguments. actually, this only works on methods that take no arguments
144
+ export function tinyMemoize(_class, methodName) {
145
+ const method = _class.prototype[methodName];
146
+ const memoAttrName = `_memo_${methodName}`;
147
+ _class.prototype[methodName] = function _tinyMemoized() {
148
+ if (!(memoAttrName in this)) {
149
+ const res = method.call(this);
150
+ this[memoAttrName] = res;
151
+ Promise.resolve(res).catch(() => {
152
+ delete this[memoAttrName];
153
+ });
154
+ }
155
+ return this[memoAttrName];
156
+ };
157
+ }
158
+ export function sequenceMD5(seq) {
159
+ return md5(seq.toUpperCase().replace(/[^\x21-\x7e]/g, ''));
160
+ }
161
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/cramFile/util.js"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AACrB,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAA;AAElD,MAAM,UAAU,QAAQ,CAAC,CAAC;IACxB,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;QAChB,OAAO,CAAC,CAAA;KACT;IACD,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;QAClB,OAAO,CAAC,CAAA;KACT;IACD,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;QACpB,OAAO,CAAC,CAAA;KACT;IACD,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;QACrB,OAAO,CAAC,CAAA;KACT;IACD,OAAO,CAAC,CAAA;AACV,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,MAAM,EAAE,aAAa;IAC7C,IAAI,MAAM,GAAG,aAAa,CAAA;IAC1B,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;IACjC,IAAI,MAAM,CAAA;IACV,IAAI,UAAU,GAAG,IAAI,EAAE;QACrB,MAAM,GAAG,UAAU,CAAA;QACnB,MAAM,IAAI,CAAC,CAAA;KACZ;SAAM,IAAI,UAAU,GAAG,IAAI,EAAE;QAC5B,MAAM,GAAG,CAAC,CAAC,UAAU,IAAI,CAA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,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IAC/C,MAAM,CAAC,YAAY,GAAG,MAAM,GAAG,iBAAiB,CAAA;IAChD,MAAM,CAAC,KAAK,GAAG,MAAM,GAAG,mBAAmB,CAAA;IAC3C,OAAO,MAAM,CAAA;AACf,CAAC;AAED,oEAAoE;AACpE,+CAA+C;AAC/C,0EAA0E;AAC1E,0EAA0E;AAC1E,MAAM,UAAU,WAAW,CAAC,MAAM,EAAE,UAAU;IAC5C,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,CAAA;IAC3C,MAAM,YAAY,GAAG,SAAS,UAAU,EAAE,CAAA;IAC1C,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,SAAS,aAAa;QACnD,IAAI,CAAC,CAAC,YAAY,IAAI,IAAI,CAAC,EAAE;YAC3B,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YAC7B,IAAI,CAAC,YAAY,CAAC,GAAG,GAAG,CAAA;YACxB,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;gBAC9B,OAAO,IAAI,CAAC,YAAY,CAAC,CAAA;YAC3B,CAAC,CAAC,CAAA;SACH;QACD,OAAO,IAAI,CAAC,YAAY,CAAC,CAAA;IAC3B,CAAC,CAAA;AACH,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,GAAG;IAC7B,OAAO,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,CAAA;AAC5D,CAAC"}
@@ -0,0 +1,23 @@
1
+ export class CramError extends Error {
2
+ }
3
+ /** Error caused by encountering a part of the CRAM spec that has not yet been implemented */
4
+ export class CramUnimplementedError extends Error {
5
+ }
6
+ /** An error caused by malformed data. */
7
+ export class CramMalformedError extends CramError {
8
+ }
9
+ /**
10
+ * An error caused by attempting to read beyond the end of the defined data.
11
+ */
12
+ export class CramBufferOverrunError extends CramMalformedError {
13
+ }
14
+ /**
15
+ * An error caused by data being too big, exceeding a size limit.
16
+ */
17
+ export class CramSizeLimitError extends CramError {
18
+ }
19
+ /**
20
+ * An invalid argument was supplied to a cram-js method or object.
21
+ */
22
+ export class CramArgumentError extends CramError {
23
+ }
package/esm/errors.js ADDED
@@ -0,0 +1,24 @@
1
+ export class CramError extends Error {
2
+ }
3
+ /** Error caused by encountering a part of the CRAM spec that has not yet been implemented */
4
+ export class CramUnimplementedError extends Error {
5
+ }
6
+ /** An error caused by malformed data. */
7
+ export class CramMalformedError extends CramError {
8
+ }
9
+ /**
10
+ * An error caused by attempting to read beyond the end of the defined data.
11
+ */
12
+ export class CramBufferOverrunError extends CramMalformedError {
13
+ }
14
+ /**
15
+ * An error caused by data being too big, exceeding a size limit.
16
+ */
17
+ export class CramSizeLimitError extends CramError {
18
+ }
19
+ /**
20
+ * An invalid argument was supplied to a cram-js method or object.
21
+ */
22
+ export class CramArgumentError extends CramError {
23
+ }
24
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.js"],"names":[],"mappings":"AAAA,MAAM,OAAO,SAAU,SAAQ,KAAK;CAAG;AAEvC,6FAA6F;AAC7F,MAAM,OAAO,sBAAuB,SAAQ,KAAK;CAAG;AAEpD,0CAA0C;AAC1C,MAAM,OAAO,kBAAmB,SAAQ,SAAS;CAAG;AAEpD;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,kBAAkB;CAAG;AAEjE;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,SAAS;CAAG;AAEpD;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,SAAS;CAAG"}
package/esm/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import CramFile from "./cramFile";
2
+ import IndexedCramFile from "./indexedCramFile";
3
+ import CraiIndex from "./craiIndex";
4
+ export { CramFile, IndexedCramFile, CraiIndex };
package/esm/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import CramFile from './cramFile';
2
+ import IndexedCramFile from './indexedCramFile';
3
+ import CraiIndex from './craiIndex';
4
+ export { CramFile, IndexedCramFile, CraiIndex };
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAC/C,OAAO,SAAS,MAAM,aAAa,CAAA;AAEnC,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,SAAS,EAAE,CAAA"}