Comparing version 1.0.15 to 1.0.16
@@ -0,1 +1,9 @@ | ||
## [1.0.16](https://github.com/GMOD/bam-js/compare/v1.0.15...v1.0.16) (2019-04-28) | ||
- Added indexCov algorithm to retrieve approximate coverage of the BAM inferred from the size of the BAI linear index bins | ||
- Fixed abortSignal on read() calls | ||
- Updated API to allow bamUrl/baiUrl/csiUrl | ||
## [1.0.15](https://github.com/GMOD/bam-js/compare/v1.0.14...v1.0.15) (2019-04-04) | ||
@@ -2,0 +10,0 @@ |
147
dist/bai.js
@@ -1,9 +0,17 @@ | ||
"use strict";var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/possibleConstructorReturn"));var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/getPrototypeOf"));var _inherits2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/inherits"));var Long = require('long'); | ||
var VirtualOffset = require('./virtualOffset'); | ||
var Chunk = require('./chunk'); | ||
"use strict";var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports, "__esModule", { value: true });exports.default = void 0;var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));var Long = _interopRequireWildcard(require("long")); | ||
var _virtualOffset = require("./virtualOffset"); | ||
var _chunk = _interopRequireDefault(require("./chunk")); | ||
var IndexFile = require('./indexFile'); | ||
var BAI_MAGIC = 21578050; // BAI\1 | ||
var _require = require('./util'),longToNumber = _require.longToNumber,abortBreakPoint = _require.abortBreakPoint;var | ||
var _require = require('./util'),longToNumber = _require.longToNumber,abortBreakPoint = _require.abortBreakPoint; | ||
function roundDown(n, multiple) { | ||
return n - n % multiple; | ||
} | ||
function roundUp(n, multiple) { | ||
return n - n % multiple + multiple; | ||
}var | ||
BAI = /*#__PURE__*/function (_IndexFile) {(0, _inherits2.default)(BAI, _IndexFile);function BAI() {(0, _classCallCheck2.default)(this, BAI);return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(BAI).apply(this, arguments));}(0, _createClass2.default)(BAI, [{ key: "parsePseudoBin", value: function parsePseudoBin( | ||
@@ -27,5 +35,5 @@ bytes, offset) { | ||
// fetch and parse the index | ||
}, { key: "_parse", value: function () {var _parse2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(abortSignal) {var data, bytes, depth, binLimit, currOffset, i, binCount, stats, binIndex, j, bin, chunkCount, chunks, k, u, v, nintv;return _regenerator.default.wrap(function _callee2$(_context2) {while (1) {switch (_context2.prev = _context2.next) {case 0: | ||
}, { key: "_parse", value: function () {var _parse2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(abortSignal) {var data, bytes, depth, binLimit, currOffset, i, binCount, stats, binIndex, j, bin, chunkCount, chunks, k, u, v, linearCount, linearIndex, _k;return _regenerator.default.wrap(function _callee2$(_context2) {while (1) {switch (_context2.prev = _context2.next) {case 0: | ||
data = { bai: true, maxBlockSize: 1 << 16 };_context2.next = 3;return ( | ||
this.filehandle.readFile(abortSignal));case 3:bytes = _context2.sent;if (!( | ||
this.filehandle.readFile({ signal: abortSignal }));case 3:bytes = _context2.sent;if (!( | ||
@@ -67,7 +75,7 @@ | ||
for (k = 0; k < chunkCount; k += 1) { | ||
u = VirtualOffset.fromBytes(bytes, currOffset); | ||
v = VirtualOffset.fromBytes(bytes, currOffset + 8); | ||
u = (0, _virtualOffset.fromBytes)(bytes, currOffset); | ||
v = (0, _virtualOffset.fromBytes)(bytes, currOffset + 8); | ||
currOffset += 16; | ||
this._findFirstData(data, u); | ||
chunks[k] = new Chunk(u, v, bin); | ||
chunks[k] = new _chunk.default(u, v, bin); | ||
} | ||
@@ -78,3 +86,3 @@ binIndex[bin] = chunks;case 38:j += 1;_context2.next = 20;break;case 41: | ||
nintv = bytes.readInt32LE(currOffset); | ||
linearCount = bytes.readInt32LE(currOffset); | ||
currOffset += 4; | ||
@@ -84,21 +92,79 @@ // as we're going through the linear index, figure out | ||
// tells us where the BAM header ends | ||
if (nintv) { | ||
this._findFirstData(bytes, VirtualOffset.fromBytes(bytes, currOffset)); | ||
linearIndex = new Array(linearCount); | ||
for (_k = 0; _k < linearCount; _k += 1) { | ||
linearIndex[_k] = (0, _virtualOffset.fromBytes)(bytes, currOffset); | ||
currOffset += 8; | ||
this._findFirstData(data, linearIndex[_k]); | ||
} | ||
currOffset += nintv * 8; | ||
data.indices[i] = { binIndex: binIndex, linearIndex: linearIndex, stats: stats };case 46:i += 1;_context2.next = 12;break;case 49:return _context2.abrupt("return", | ||
data.indices[i] = { binIndex: binIndex, stats: stats };case 46:i += 1;_context2.next = 12;break;case 49:return _context2.abrupt("return", | ||
data);case 50:case "end":return _context2.stop();}}}, _callee2, this);}));function _parse(_x2) {return _parse2.apply(this, arguments);}return _parse;}() }, { key: "indexCov", value: function () {var _indexCov = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3( | ||
data);case 50:case "end":return _context2.stop();}}}, _callee2, this);}));function _parse(_x2) {return _parse2.apply(this, arguments);}return _parse;}() }, { key: "blocksForRange", value: function () {var _blocksForRange = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3( | ||
seqId, start, end) {var v, range, indexData, seqIdx, _seqIdx$linearIndex, linearIndex, stats, e, s, depths, totalSize, currentPos, i, j;return _regenerator.default.wrap(function _callee3$(_context3) {while (1) {switch (_context3.prev = _context3.next) {case 0: | ||
v = 16384; | ||
range = start !== undefined;_context3.next = 4;return ( | ||
this.parse());case 4:indexData = _context3.sent; | ||
seqIdx = indexData.indices[seqId];if ( | ||
seqIdx) {_context3.next = 8;break;}return _context3.abrupt("return", []);case 8:_seqIdx$linearIndex = | ||
seqIdx.linearIndex, linearIndex = _seqIdx$linearIndex === void 0 ? [] : _seqIdx$linearIndex, stats = seqIdx.stats;if ( | ||
linearIndex.length) {_context3.next = 11;break;}return _context3.abrupt("return", []);case 11: | ||
e = range ? roundUp(end, v) : (linearIndex.length - 1) * v; | ||
s = range ? roundDown(start, v) : 0; | ||
refId, beg, end) {var indexData, indexes, binIndex, bins, l, numOffsets, i, off, _i, chunks, j, _i2, _i3, _i4;return _regenerator.default.wrap(function _callee3$(_context3) {while (1) {switch (_context3.prev = _context3.next) {case 0: | ||
if (beg < 0) beg = 0;_context3.next = 3;return ( | ||
if (range) { | ||
depths = new Array(Math.floor((e - s) / v)); | ||
} else { | ||
depths = new Array(linearIndex.length - 1); | ||
} | ||
totalSize = linearIndex[linearIndex.length - 1].blockPosition;if (!( | ||
e > (linearIndex.length - 1) * v)) {_context3.next = 17;break;}throw ( | ||
new Error('query outside of range of linear index'));case 17: | ||
this.parse());case 3:indexData = _context3.sent;if ( | ||
indexData) {_context3.next = 6;break;}return _context3.abrupt("return", []);case 6: | ||
currentPos = linearIndex[s / v].blockPosition; | ||
for (i = s / v, j = 0; i + 1 < e / v; i++, j++) { | ||
depths[j] = { | ||
score: linearIndex[i + 1].blockPosition - currentPos, | ||
start: i * v, | ||
end: i * v + v }; | ||
currentPos = linearIndex[i + 1].blockPosition; | ||
}return _context3.abrupt("return", | ||
depths.map(function (d) { | ||
return (0, _objectSpread2.default)({}, d, { score: d.score * stats.lineCount / totalSize }); | ||
}));case 20:case "end":return _context3.stop();}}}, _callee3, this);}));function indexCov(_x3, _x4, _x5) {return _indexCov.apply(this, arguments);}return indexCov;}() }, { key: "indexCovTotal", value: function () {var _indexCovTotal = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4( | ||
seqId) {var v, indexData, seqIdx, _seqIdx$linearIndex2, linearIndex, stats, currentPos, depths, totalSize, i, j;return _regenerator.default.wrap(function _callee4$(_context4) {while (1) {switch (_context4.prev = _context4.next) {case 0: | ||
v = 16384;_context4.next = 3;return ( | ||
this.parse());case 3:indexData = _context4.sent; | ||
seqIdx = indexData.indices[seqId];if ( | ||
seqIdx) {_context4.next = 7;break;}return _context4.abrupt("return", []);case 7:_seqIdx$linearIndex2 = | ||
seqIdx.linearIndex, linearIndex = _seqIdx$linearIndex2 === void 0 ? [] : _seqIdx$linearIndex2, stats = seqIdx.stats;if ( | ||
linearIndex.length) {_context4.next = 10;break;}return _context4.abrupt("return", []);case 10: | ||
currentPos = linearIndex[0].blockPosition; | ||
depths = new Array(linearIndex.length - 1); | ||
totalSize = linearIndex.slice(-1)[0].blockPosition; | ||
for (i = 1, j = 0; i < linearIndex.length; i++, j++) { | ||
depths[j] = linearIndex[i].blockPosition - currentPos; | ||
currentPos = linearIndex[i].blockPosition; | ||
}return _context4.abrupt("return", | ||
depths.map(function (d, i) { | ||
return { | ||
score: d * stats.lineCount / totalSize, | ||
start: i * v, | ||
end: i * v + v }; | ||
}));case 15:case "end":return _context4.stop();}}}, _callee4, this);}));function indexCovTotal(_x6) {return _indexCovTotal.apply(this, arguments);}return indexCovTotal;}() }, { key: "blocksForRange", value: function () {var _blocksForRange = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5( | ||
refId, beg, end) {var indexData, indexes, binIndex, bins, l, numOffsets, i, off, _i, chunks, j, _i2, _i3, _i4;return _regenerator.default.wrap(function _callee5$(_context5) {while (1) {switch (_context5.prev = _context5.next) {case 0: | ||
if (beg < 0) beg = 0;_context5.next = 3;return ( | ||
this.parse());case 3:indexData = _context5.sent;if ( | ||
indexData) {_context5.next = 6;break;}return _context5.abrupt("return", []);case 6: | ||
indexes = indexData.indices[refId];if ( | ||
indexes) {_context3.next = 9;break;}return _context3.abrupt("return", []);case 9: | ||
indexes) {_context5.next = 9;break;}return _context5.abrupt("return", []);case 9: | ||
@@ -117,3 +183,3 @@ binIndex = indexes.binIndex; | ||
numOffsets === 0)) {_context3.next = 15;break;}return _context3.abrupt("return", []);case 15: | ||
numOffsets === 0)) {_context5.next = 15;break;}return _context5.abrupt("return", []);case 15: | ||
@@ -126,3 +192,3 @@ off = []; | ||
for (j = 0; j < chunks.length; j += 1) { | ||
off[numOffsets] = new Chunk( | ||
off[numOffsets] = new _chunk.default( | ||
chunks[j].minv, | ||
@@ -136,3 +202,3 @@ chunks[j].maxv, | ||
off.length) {_context3.next = 20;break;}return _context3.abrupt("return", []);case 20: | ||
off.length) {_context5.next = 20;break;}return _context5.abrupt("return", []);case 20: | ||
@@ -167,11 +233,21 @@ off = off.sort(function (a, b) {return a.compareTo(b);}); | ||
} | ||
numOffsets = l + 1;return _context3.abrupt("return", | ||
numOffsets = l + 1;return _context5.abrupt("return", | ||
off.slice(0, numOffsets));case 29:case "end":return _context3.stop();}}}, _callee3, this);}));function blocksForRange(_x3, _x4, _x5) {return _blocksForRange.apply(this, arguments);}return blocksForRange;}() | ||
off.slice(0, numOffsets));case 29:case "end":return _context5.stop();}}}, _callee5, this);}));function blocksForRange(_x7, _x8, _x9) {return _blocksForRange.apply(this, arguments);}return blocksForRange;}() | ||
/** | ||
* calculate the list of bins that may overlap with region [beg,end) (zero-based half-open) | ||
* @returns {Array[number]} | ||
*/ }, { key: "reg2bins", value: function reg2bins( | ||
* @param {number} seqId | ||
* @param {AbortSignal} [abortSignal] | ||
* @returns {Promise} true if the index contains entries for | ||
* the given reference sequence ID, false otherwise | ||
*/ }, { key: "hasRefSeq", value: function () {var _hasRefSeq = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6( | ||
seqId, abortSignal) {return _regenerator.default.wrap(function _callee6$(_context6) {while (1) {switch (_context6.prev = _context6.next) {case 0:_context6.next = 2;return ( | ||
this.parse(abortSignal));case 2:_context6.t1 = seqId;_context6.t0 = _context6.sent.indices[_context6.t1];if (_context6.t0) {_context6.next = 6;break;}_context6.t0 = {};case 6:return _context6.abrupt("return", !!_context6.t0.binIndex);case 7:case "end":return _context6.stop();}}}, _callee6, this);}));function hasRefSeq(_x10, _x11) {return _hasRefSeq.apply(this, arguments);}return hasRefSeq;}() | ||
/** | ||
* calculate the list of bins that may overlap with region [beg,end) (zero-based half-open) | ||
* @returns {Array[number]} | ||
*/ }, { key: "reg2bins", value: function reg2bins( | ||
beg, end) { | ||
@@ -181,11 +257,8 @@ var list = [0]; | ||
for (var k = 1 + (beg >> 26); k <= 1 + (end >> 26); k += 1) {list.push(k);} | ||
for (var _k = 9 + (beg >> 23); _k <= 9 + (end >> 23); _k += 1) {list.push(_k);} | ||
for (var _k2 = 73 + (beg >> 20); _k2 <= 73 + (end >> 20); _k2 += 1) {list.push(_k2);} | ||
for (var _k3 = 585 + (beg >> 17); _k3 <= 585 + (end >> 17); _k3 += 1) {list.push(_k3);} | ||
for (var _k4 = 4681 + (beg >> 14); _k4 <= 4681 + (end >> 14); _k4 += 1) { | ||
list.push(_k4);} | ||
for (var _k2 = 9 + (beg >> 23); _k2 <= 9 + (end >> 23); _k2 += 1) {list.push(_k2);} | ||
for (var _k3 = 73 + (beg >> 20); _k3 <= 73 + (end >> 20); _k3 += 1) {list.push(_k3);} | ||
for (var _k4 = 585 + (beg >> 17); _k4 <= 585 + (end >> 17); _k4 += 1) {list.push(_k4);} | ||
for (var _k5 = 4681 + (beg >> 14); _k5 <= 4681 + (end >> 14); _k5 += 1) { | ||
list.push(_k5);} | ||
return list; | ||
} }]);return BAI;}(IndexFile); | ||
module.exports = BAI; | ||
} }]);return BAI;}(IndexFile);exports.default = BAI; |
@@ -1,11 +0,13 @@ | ||
"use strict";var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/slicedToArray"));var _entries = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/entries"));var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/toConsumableArray"));var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));var _abortablePromiseCache = _interopRequireDefault(require("abortable-promise-cache"));var _require = | ||
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports, "__esModule", { value: true });exports.default = void 0;var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _abortablePromiseCache = _interopRequireDefault(require("abortable-promise-cache")); | ||
var _bai = _interopRequireDefault(require("./bai")); | ||
var _csi = _interopRequireDefault(require("./csi")); | ||
var entries = require('object.entries-ponyfill');var _require = | ||
require('@gmod/bgzf-filehandle'),unzip = _require.unzip; | ||
var LRU = require('quick-lru'); | ||
var BAI = require('./bai'); | ||
var CSI = require('./csi'); | ||
var LocalFile = require('./localFile'); | ||
var BAMFeature = require('./record');var _require2 = | ||
require('./sam'),parseHeaderText = _require2.parseHeaderText;var _require3 = | ||
require('./util'),abortBreakPoint = _require3.abortBreakPoint,checkAbortSignal = _require3.checkAbortSignal; | ||
var LRU = require('quick-lru');var _require2 = | ||
require('generic-filehandle'),LocalFile = _require2.LocalFile,RemoteFile = _require2.RemoteFile; | ||
var BAMFeature = require('./record');var _require3 = | ||
require('./sam'),parseHeaderText = _require3.parseHeaderText;var _require4 = | ||
require('./util'),abortBreakPoint = _require4.abortBreakPoint,checkAbortSignal = _require4.checkAbortSignal; | ||
@@ -35,3 +37,6 @@ var BAM_MAGIC = 21840194; | ||
{var bamFilehandle = _ref.bamFilehandle,bamPath = _ref.bamPath,baiPath = _ref.baiPath,baiFilehandle = _ref.baiFilehandle,csiPath = _ref.csiPath,csiFilehandle = _ref.csiFilehandle,cacheSize = _ref.cacheSize,fetchSizeLimit = _ref.fetchSizeLimit,chunkSizeLimit = _ref.chunkSizeLimit,_ref$renameRefSeqs = _ref.renameRefSeqs,renameRefSeqs = _ref$renameRefSeqs === void 0 ? function (n) {return n;} : _ref$renameRefSeqs;(0, _classCallCheck2.default)(this, BamFile); | ||
{var bamFilehandle = _ref.bamFilehandle,bamPath = _ref.bamPath,bamUrl = _ref.bamUrl,baiPath = _ref.baiPath,baiFilehandle = _ref.baiFilehandle,baiUrl = _ref.baiUrl,csiPath = _ref.csiPath,csiFilehandle = _ref.csiFilehandle,csiUrl = _ref.csiUrl,cacheSize = _ref.cacheSize,fetchSizeLimit = _ref.fetchSizeLimit,chunkSizeLimit = _ref.chunkSizeLimit,_ref$renameRefSeqs = _ref.renameRefSeqs,renameRefSeqs = _ref$renameRefSeqs === void 0 ? function (n) {return n;} : _ref$renameRefSeqs;(0, _classCallCheck2.default)(this, BamFile); | ||
this.renameRefSeq = renameRefSeqs; | ||
@@ -43,18 +48,24 @@ | ||
this.bam = new LocalFile(bamPath); | ||
} else if (bamUrl) { | ||
this.bam = new RemoteFile(bamUrl); | ||
} | ||
if (csiFilehandle) { | ||
this.index = new CSI({ filehandle: csiFilehandle }); | ||
this.index = new _csi.default({ filehandle: csiFilehandle }); | ||
} else if (csiPath) { | ||
this.index = new CSI({ | ||
filehandle: new LocalFile(csiPath) }); | ||
this.index = new _csi.default({ filehandle: new LocalFile(csiPath) }); | ||
} else if (csiUrl) { | ||
this.index = new _csi.default({ filehandle: new RemoteFile(csiUrl) }); | ||
} else if (baiFilehandle) { | ||
this.index = new BAI({ filehandle: baiFilehandle }); | ||
this.index = new _bai.default({ filehandle: baiFilehandle }); | ||
} else if (baiPath) { | ||
this.index = new BAI({ filehandle: new LocalFile(baiPath) }); | ||
this.index = new _bai.default({ filehandle: new LocalFile(baiPath) }); | ||
} else if (baiUrl) { | ||
this.index = new _bai.default({ filehandle: new RemoteFile(baiUrl) }); | ||
} else if (bamPath) { | ||
this.index = new _bai.default({ filehandle: new LocalFile("".concat(bamPath, ".bai")) }); | ||
} else if (bamUrl) { | ||
this.index = new _bai.default({ filehandle: new RemoteFile("".concat(bamUrl, ".bai")) }); | ||
} else { | ||
this.index = new BAI({ filehandle: new LocalFile("".concat(bamPath, ".bai")) }); | ||
throw new Error('unable to infer index format'); | ||
} | ||
this.featureCache = new _abortablePromiseCache.default({ | ||
@@ -79,8 +90,4 @@ cache: new LRU({ | ||
buf = Buffer.alloc(ret + blockLen);_context.next = 8;return ( | ||
this.bam.read( | ||
buf, | ||
0, | ||
ret + blockLen, | ||
0, | ||
abortSignal));case 8:bytesRead = _context.sent;if ( | ||
this.bam.read(buf, 0, ret + blockLen, 0, { | ||
signal: abortSignal }));case 8:bytesRead = _context.sent;if ( | ||
@@ -96,3 +103,3 @@ bytesRead) {_context.next = 11;break;}throw ( | ||
this.bam.readFile(abortSignal));case 16:buf = _context.sent;case 17:_context.next = 19;return ( | ||
this.bam.readFile({ signal: abortSignal }));case 16:buf = _context.sent;case 17:_context.next = 19;return ( | ||
@@ -124,7 +131,4 @@ | ||
this.bam.read( | ||
buf, | ||
0, | ||
refSeqBytes + blockLen, | ||
abortSignal));case 5:bytesRead = _context2.sent;if ( | ||
this.bam.read(buf, 0, refSeqBytes + blockLen, { | ||
signal: abortSignal }));case 5:bytesRead = _context2.sent;if ( | ||
@@ -231,3 +235,3 @@ bytesRead) {_context2.next = 8;break;}return _context2.abrupt("return", | ||
});_context4.next = 6;return ( | ||
_promise.default.all(featPromises));case 6:recs = _context4.sent; | ||
Promise.all(featPromises));case 6:recs = _context4.sent; | ||
checkAbortSignal(opts.signal); | ||
@@ -246,3 +250,3 @@ ret = (_ref3 = []).concat.apply(_ref3, (0, _toConsumableArray2.default)(recs));if (! | ||
unmatedPairs = {}; | ||
(0, _entries.default)(readNames).forEach(function (_ref4) {var _ref5 = (0, _slicedToArray2.default)(_ref4, 2),k = _ref5[0],v = _ref5[1]; | ||
entries(readNames).forEach(function (_ref4) {var _ref5 = (0, _slicedToArray2.default)(_ref4, 2),k = _ref5[0],v = _ref5[1]; | ||
if (v === 1) unmatedPairs[k] = true; | ||
@@ -269,3 +273,3 @@ }); | ||
}_context4.next = 19;return ( | ||
_promise.default.all(matePromises));case 19:mateBlocks = _context4.sent; | ||
Promise.all(matePromises));case 19:mateBlocks = _context4.sent; | ||
mateChunks = []; | ||
@@ -316,3 +320,3 @@ for (_i2 = 0; _i2 < mateBlocks.length; _i2++) { | ||
});_context4.next = 31;return ( | ||
_promise.default.all(mateFeatPromises));case 31:newMateFeats = _context4.sent; | ||
Promise.all(mateFeatPromises));case 31:newMateFeats = _context4.sent; | ||
if (newMateFeats.length) { | ||
@@ -337,3 +341,3 @@ newMates = newMateFeats.reduce(function (result, current) {return ( | ||
chunk.minv.blockPosition, | ||
abortSignal));case 4:bytesRead = _context5.sent; | ||
{ signal: abortSignal }));case 4:bytesRead = _context5.sent; | ||
@@ -378,5 +382,10 @@ checkAbortSignal(abortSignal);if ( | ||
return this.index.hasRefSeq(seqId); | ||
} }]);return BamFile;}(); | ||
} }, { key: "indexCov", value: function () {var _indexCov = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6( | ||
module.exports = BamFile; | ||
seqName, start, end) {var range, seqId;return _regenerator.default.wrap(function _callee6$(_context6) {while (1) {switch (_context6.prev = _context6.next) {case 0:_context6.next = 2;return ( | ||
this.index.parse());case 2: | ||
range = start !== undefined; | ||
seqId = this.chrToIndex && this.chrToIndex[seqName];return _context6.abrupt("return", | ||
range ? | ||
this.index.indexCov(seqId, start, end) : | ||
this.index.indexCovTotal(seqId));case 5:case "end":return _context6.stop();}}}, _callee6, this);}));function indexCov(_x14, _x15, _x16) {return _indexCov.apply(this, arguments);}return indexCov;}() }]);return BamFile;}();exports.default = BamFile; |
@@ -1,2 +0,2 @@ | ||
"use strict";var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass")); // little class representing a chunk in the index | ||
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); // little class representing a chunk in the index | ||
var Chunk = /*#__PURE__*/function () { | ||
@@ -3,0 +3,0 @@ /** |
@@ -1,9 +0,9 @@ | ||
"use strict";var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");var _assign = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/assign"));var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/possibleConstructorReturn"));var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/getPrototypeOf"));var _inherits2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/inherits"));var Long = require('long');var _require = | ||
require('@gmod/bgzf-filehandle'),unzip = _require.unzip; | ||
"use strict";var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports, "__esModule", { value: true });exports.default = void 0;var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));var Long = _interopRequireWildcard(require("long")); | ||
var _bgzfFilehandle = require("@gmod/bgzf-filehandle"); | ||
var VirtualOffset = require('./virtualOffset'); | ||
var Chunk = require('./chunk'); | ||
var IndexFile = require('./indexFile');var _require2 = | ||
var _virtualOffset = require("./virtualOffset"); | ||
var _chunk = _interopRequireDefault(require("./chunk")); | ||
var _util = require("./util"); | ||
require('./util'),longToNumber = _require2.longToNumber,abortBreakPoint = _require2.abortBreakPoint; | ||
var IndexFile = require('./indexFile'); | ||
@@ -51,3 +51,3 @@ var CSI1_MAGIC = 21582659; // CSI\1 | ||
(0, _assign.default)( | ||
Object.assign( | ||
data, | ||
@@ -84,5 +84,7 @@ this._parseNameBytes( | ||
data = { csi: true, maxBlockSize: 1 << 16 };_context2.t0 = | ||
unzip;_context2.next = 4;return this.filehandle.readFile(abortSignal);case 4:_context2.t1 = _context2.sent;_context2.next = 7;return (0, _context2.t0)(_context2.t1);case 7:bytes = _context2.sent;if (!( | ||
_bgzfFilehandle.unzip;_context2.next = 4;return ( | ||
this.filehandle.readFile({ signal: abortSignal }));case 4:_context2.t1 = _context2.sent;_context2.next = 7;return (0, _context2.t0)(_context2.t1);case 7:bytes = _context2.sent;if (!( | ||
bytes.readUInt32LE(0) === CSI1_MAGIC)) {_context2.next = 12;break;} | ||
@@ -102,3 +104,3 @@ data.csiVersion = 1;_context2.next = 17;break;case 12:if (!( | ||
if (auxLength) { | ||
(0, _assign.default)(data, this.parseAuxData(bytes, 16, auxLength)); | ||
Object.assign(data, this.parseAuxData(bytes, 16, auxLength)); | ||
} | ||
@@ -111,3 +113,3 @@ data.refCount = bytes.readInt32LE(16 + auxLength); | ||
i = 0;case 26:if (!(i < data.refCount)) {_context2.next = 38;break;}_context2.next = 29;return ( | ||
abortBreakPoint(abortSignal));case 29: | ||
(0, _util.abortBreakPoint)(abortSignal));case 29: | ||
// the binning index | ||
@@ -126,3 +128,3 @@ binCount = bytes.readInt32LE(currOffset); | ||
} else { | ||
loffset = VirtualOffset.fromBytes(bytes, currOffset + 4); | ||
loffset = (0, _virtualOffset.fromBytes)(bytes, currOffset + 4); | ||
this._findFirstData(data, loffset); | ||
@@ -133,7 +135,7 @@ chunkCount = bytes.readInt32LE(currOffset + 12); | ||
for (k = 0; k < chunkCount; k += 1) { | ||
u = VirtualOffset.fromBytes(bytes, currOffset); | ||
v = VirtualOffset.fromBytes(bytes, currOffset + 8); | ||
u = (0, _virtualOffset.fromBytes)(bytes, currOffset); | ||
v = (0, _virtualOffset.fromBytes)(bytes, currOffset + 8); | ||
currOffset += 16; | ||
// this._findFirstData(data, u) | ||
chunks[k] = new Chunk(u, v, bin); | ||
chunks[k] = new _chunk.default(u, v, bin); | ||
} | ||
@@ -156,3 +158,3 @@ binIndex[bin] = chunks; | ||
// ) | ||
var lineCount = longToNumber( | ||
var lineCount = (0, _util.longToNumber)( | ||
Long.fromBytesLE(bytes.slice(offset + 28, offset + 36), true)); | ||
@@ -189,3 +191,3 @@ | ||
for (j = 0; j < chunks.length; j += 1) { | ||
off[numOffsets] = new Chunk( | ||
off[numOffsets] = new _chunk.default( | ||
chunks[j].minv, | ||
@@ -235,5 +237,15 @@ chunks[j].maxv, | ||
/** | ||
* calculate the list of bins that may overlap with region [beg,end) (zero-based half-open) | ||
* @returns {Array[number]} | ||
*/ }, { key: "reg2bins", value: function reg2bins( | ||
* @param {number} seqId | ||
* @param {AbortSignal} [abortSignal] | ||
* @returns {Promise} true if the index contains entries for | ||
* the given reference sequence ID, false otherwise | ||
*/ }, { key: "hasRefSeq", value: function () {var _hasRefSeq = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4( | ||
seqId, abortSignal) {return _regenerator.default.wrap(function _callee4$(_context4) {while (1) {switch (_context4.prev = _context4.next) {case 0:_context4.next = 2;return ( | ||
this.parse(abortSignal));case 2:_context4.t1 = seqId;_context4.t0 = _context4.sent.indices[_context4.t1];if (_context4.t0) {_context4.next = 6;break;}_context4.t0 = {};case 6:return _context4.abrupt("return", !!_context4.t0.binIndex);case 7:case "end":return _context4.stop();}}}, _callee4, this);}));function hasRefSeq(_x7, _x8) {return _hasRefSeq.apply(this, arguments);}return hasRefSeq;}() | ||
/** | ||
* calculate the list of bins that may overlap with region [beg,end) (zero-based half-open) | ||
* @returns {Array[number]} | ||
*/ }, { key: "reg2bins", value: function reg2bins( | ||
beg, end) { | ||
@@ -262,5 +274,2 @@ beg -= 1; // < convert to 1-based closed | ||
return bins; | ||
} }]);return CSI;}(IndexFile); | ||
module.exports = CSI; | ||
} }]);return CSI;}(IndexFile);exports.default = CSI; |
@@ -1,2 +0,2 @@ | ||
"use strict";var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/possibleConstructorReturn"));var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/getPrototypeOf"));var _inherits2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/inherits"));var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/wrapNativeSuper"));var BamError = /*#__PURE__*/function (_Error) {(0, _inherits2.default)(BamError, _Error);function BamError() {(0, _classCallCheck2.default)(this, BamError);return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(BamError).apply(this, arguments));}return BamError;}((0, _wrapNativeSuper2.default)(Error)); | ||
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));var BamError = /*#__PURE__*/function (_Error) {(0, _inherits2.default)(BamError, _Error);function BamError() {(0, _classCallCheck2.default)(this, BamError);return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(BamError).apply(this, arguments));}return BamError;}((0, _wrapNativeSuper2.default)(Error)); | ||
@@ -3,0 +3,0 @@ /** Error caused by encountering a part of the BAM spec that has not yet been implemented */var |
@@ -1,2 +0,2 @@ | ||
"use strict";var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");Object.defineProperty(exports, "__esModule", { value: true });Object.defineProperty(exports, "BAI", { enumerable: true, get: function get() {return _bai.default;} });Object.defineProperty(exports, "BamFile", { enumerable: true, get: function get() {return _bamFile.default;} });var _bai = _interopRequireDefault(require("./bai")); | ||
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports, "__esModule", { value: true });Object.defineProperty(exports, "BAI", { enumerable: true, get: function get() {return _bai.default;} });Object.defineProperty(exports, "BamFile", { enumerable: true, get: function get() {return _bamFile.default;} });var _bai = _interopRequireDefault(require("./bai")); | ||
var _bamFile = _interopRequireDefault(require("./bamFile")); |
@@ -1,2 +0,2 @@ | ||
"use strict";var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));var _abortablePromiseCache = _interopRequireDefault(require("abortable-promise-cache")); | ||
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _abortablePromiseCache = _interopRequireDefault(require("abortable-promise-cache")); | ||
var _quickLru = _interopRequireDefault(require("quick-lru"));var | ||
@@ -3,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");var _parseInt2 = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/parse-int"));var _keys = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/keys"));var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));var crc32 = require('buffer-crc32'); | ||
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));var crc32 = require('buffer-crc32'); | ||
var Constants = require('./constants'); | ||
@@ -99,3 +99,3 @@ | ||
(0, _keys.default)(this.data).forEach(function (k) { | ||
Object.keys(this.data).forEach(function (k) { | ||
if ( | ||
@@ -322,3 +322,3 @@ k[0] !== '_' && | ||
match(/\d+\D/g). | ||
map(function (op) {return [op.match(/\D/)[0].toUpperCase(), (0, _parseInt2.default)(op, 10)];}); | ||
map(function (op) {return [op.match(/\D/)[0].toUpperCase(), parseInt(op, 10)];}); | ||
} | ||
@@ -516,3 +516,3 @@ | ||
var data = {}; | ||
(0, _keys.default)(this).forEach(function (k) { | ||
Object.keys(this).forEach(function (k) { | ||
if (k.charAt(0) === '_' || k === 'bytes') return; | ||
@@ -519,0 +519,0 @@ data[k] = _this2[k]; |
@@ -1,2 +0,2 @@ | ||
"use strict";var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/slicedToArray"));var _toArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/toArray"));function parseHeaderText(text) { | ||
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports, "__esModule", { value: true });exports.parseHeaderText = parseHeaderText;var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _toArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toArray"));function parseHeaderText(text) { | ||
var lines = text.split(/\r?\n/); | ||
@@ -13,4 +13,2 @@ var data = []; | ||
return data; | ||
} | ||
module.exports = { parseHeaderText: parseHeaderText }; | ||
} |
@@ -1,5 +0,5 @@ | ||
"use strict";var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));var _minSafeInteger = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/number/min-safe-integer"));var _maxSafeInteger = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/number/max-safe-integer"));function longToNumber(long) { | ||
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));function longToNumber(long) { | ||
if ( | ||
long.greaterThan(_maxSafeInteger.default) || | ||
long.lessThan(_minSafeInteger.default)) | ||
long.greaterThan(Number.MAX_SAFE_INTEGER) || | ||
long.lessThan(Number.MIN_SAFE_INTEGER)) | ||
{ | ||
@@ -45,3 +45,3 @@ throw new Error('integer overflow'); | ||
abortBreakPoint(_x) {return _abortBreakPoint.apply(this, arguments);}function _abortBreakPoint() {_abortBreakPoint = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(signal) {return _regenerator.default.wrap(function _callee$(_context) {while (1) {switch (_context.prev = _context.next) {case 0:_context.next = 2;return ( | ||
_promise.default.resolve());case 2: | ||
Promise.resolve());case 2: | ||
checkAbortSignal(signal);case 3:case "end":return _context.stop();}}}, _callee);}));return _abortBreakPoint.apply(this, arguments);} | ||
@@ -48,0 +48,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));var VirtualOffset = /*#__PURE__*/function () { | ||
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports, "__esModule", { value: true });exports.fromBytes = fromBytes;exports.VirtualOffset = void 0;var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));var VirtualOffset = /*#__PURE__*/function () { | ||
function VirtualOffset(blockPosition, dataPosition) {(0, _classCallCheck2.default)(this, VirtualOffset); | ||
@@ -7,17 +7,2 @@ this.blockPosition = blockPosition; // < offset of the compressed data block | ||
{ | ||
@@ -31,3 +16,3 @@ return "".concat(this.blockPosition, ":").concat(this.dataPosition); | ||
} }], [{ key: "fromBytes", value: function fromBytes(bytes) {var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;var bigendian = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;if (bigendian) throw new Error('big-endian virtual file offsets not implemented');return new VirtualOffset(bytes[offset + 7] * 0x10000000000 + bytes[offset + 6] * 0x100000000 + bytes[offset + 5] * 0x1000000 + bytes[offset + 4] * 0x10000 + bytes[offset + 3] * 0x100 + bytes[offset + 2], bytes[offset + 1] << 8 | bytes[offset]);} }, { key: "min", value: function min() | ||
} }], [{ key: "min", value: function min() | ||
@@ -42,5 +27,17 @@ { | ||
return min; | ||
} }]);return VirtualOffset;}(); | ||
} }]);return VirtualOffset;}();exports.VirtualOffset = VirtualOffset; | ||
function fromBytes(bytes) {var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;var bigendian = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
if (bigendian) | ||
throw new Error('big-endian virtual file offsets not implemented'); | ||
module.exports = VirtualOffset; | ||
return new VirtualOffset( | ||
bytes[offset + 7] * 0x10000000000 + | ||
bytes[offset + 6] * 0x100000000 + | ||
bytes[offset + 5] * 0x1000000 + | ||
bytes[offset + 4] * 0x10000 + | ||
bytes[offset + 3] * 0x100 + | ||
bytes[offset + 2], | ||
bytes[offset + 1] << 8 | bytes[offset]); | ||
} |
{ | ||
"name": "@gmod/bam", | ||
"version": "1.0.15", | ||
"version": "1.0.16", | ||
"description": "Parser for BAM and BAM index (bai) files", | ||
@@ -40,8 +40,11 @@ "license": "MIT", | ||
"dependencies": { | ||
"@babel/runtime-corejs2": "^7.3.4", | ||
"@babel/runtime": "^7.4.3", | ||
"@gmod/bgzf-filehandle": "^1.2.3", | ||
"abortable-promise-cache": "^1.0.0", | ||
"buffer-crc32": "^0.2.13", | ||
"cross-fetch": "^3.0.2", | ||
"es6-promisify": "^6.0.1", | ||
"generic-filehandle": "^1.0.7", | ||
"long": "^4.0.0", | ||
"object.entries-ponyfill": "^1.0.1", | ||
"quick-lru": "^2.0.0" | ||
@@ -48,0 +51,0 @@ }, |
@@ -5,3 +5,2 @@ [![Generated with nod](https://img.shields.io/badge/generator-nod-2196F3.svg?style=flat-square)](https://github.com/diegohaz/nod) | ||
[![Coverage Status](https://img.shields.io/codecov/c/github/GMOD/bam-js/master.svg?style=flat-square)](https://codecov.io/gh/GMOD/bam-js/branch/master) | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/GMOD/bam-js.svg)](https://greenkeeper.io/) | ||
@@ -19,3 +18,3 @@ | ||
const t = new BamFile({ | ||
bamPath: 'test.bam', | ||
bamPath: 'test.bam', | ||
}); | ||
@@ -32,33 +31,73 @@ | ||
BAM class constructor infers BAI by default as bamPath+'.bai', or you can specify it explicitely via baiPath (also accepts csiPath) | ||
BAM({ bamPath: "yourfile.bam", baiPath: "yourfile.bai" }) | ||
### BAM constructor | ||
Or accepts filehandles, this is an abstract filehandle concept that can represent remote files. The remote file concept is not built into this repository, but see @gmod/cram for example of the remoteFile.js class | ||
BAM({ bamFilehandle: new FileHandle("http://localhost/file.bam", baiFilehandle: new FileHandle("yourfile.bai") }) | ||
The BAM class constructor accepts arguments | ||
* bamPath/baiUrl/bamFilehandle - a string file path to a local file or a class object with a read method | ||
* csiPath/csiUrl/csiFilehandle - a CSI index for the BAM file, required for long chromosomes greater than 2^29 in length | ||
* baiPath/baiUrl/baiFilehandle - a BAI index for the BAM file | ||
* fetchSizeLimit - total size of the number of chunks being fetched at once. default: ~50MB | ||
* chunkSizeLimit - size limit on any individual chunk. default: ~10MB | ||
* cacheSize - limit on number of chunks to cache. default: 50 | ||
Note: filehandles implement the Filehandle interface from https://www.npmjs.com/package/generic-filehandle. This module offers the path and url arguments as convenience methods for supplying the LocalFile and RemoteFile | ||
The method getRecordsForRange(refName, start, end, opts) has the opts blob that can contain | ||
### Documentation | ||
#### getRecordsForRange(refName, start, end, opts) | ||
* refName - a string for the chrom to fetch from | ||
* start - a 0 based half open start coordinate | ||
* end - a 0 based half open end coordinate | ||
* opts.signal - an AbortSignal to indicate stop processing | ||
* opts.viewAsPairs - re-dispatches requests to find mate pairs | ||
* opts.pairAcrossChr - control the viewAsPairs option behavior to pair across chromosomes | ||
* opts.maxInsertSize - control the viewAsPairs option behavior to limit distance within a chromosome to fetch | ||
* opts.viewAsPairs - re-dispatches requests to find mate pairs. default: false | ||
* opts.pairAcrossChr - control the viewAsPairs option behavior to pair across chromosomes. default: false | ||
* opts.maxInsertSize - control the viewAsPairs option behavior to limit distance within a chromosome to fetch. default: 200kb | ||
The returned features from BAM are lazy features meaning that it delays processing of all the feature tags until necessary. You can perform feature.get('field') to get the value of a feature attribute | ||
### indexCov(refName, start, end) | ||
* refName - a string for the chrom to fetch from | ||
* start - a 0 based half open start coordinate (optional, will fetch whole chromosome without) | ||
* end - a 0 based half open end coordinate (optional, will fetch whole chromosome without even if start is specified) | ||
Returns features of the form {start, end, score} containing estimated feature density across 16kb windows in the genome | ||
### Returned features | ||
The returned features from BAM are lazy features meaning that it delays processing of all the feature tags until necessary. | ||
You can access data feature.get('field') to get the value of a feature attribute | ||
Example | ||
feature.get('seq_id') | ||
feature.get('start') | ||
feature.get('name') // QNAME | ||
feature.get('seq') // get feature sequence | ||
feature.get('seq_id') // numerical sequence id corresponding to position in the sam header | ||
feature.get('start') // 0 based half open start coordinate | ||
feature.get('end') // 0 based half open end coordinate | ||
This may change in future versions to make it raw records but will be a major version bump | ||
## Fields | ||
feature.get('name') // QNAME | ||
feature.get('seq') // feature sequence | ||
feature.get('qual') // qualities | ||
feature.get('cigar') // cigar string | ||
feature.get('MD') // MD string | ||
feature.get('SA') // supplementary alignments | ||
feature.get('template_length') // TLEN | ||
feature.get('length_on_ref') // derived from CIGAR using standard algorithm | ||
### Flags | ||
feature.get('seq_reverse_complemented') | ||
feature.get('unmapped') | ||
feature.get('qc_failed') | ||
feature.get('duplicate') | ||
feature.get('secondary_alignment') | ||
feature.get('supplementary_alignment') | ||
The feature format may change in future versions to be more raw records but will be a major version bump | ||
## License | ||
MIT © [Colin Diesh](https://github.com/cmdcolin) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
99333
1401
101
1
0
10
16
+ Added@babel/runtime@^7.4.3
+ Addedcross-fetch@^3.0.2
+ Addedgeneric-filehandle@^1.0.7
+ Added@babel/runtime@7.26.0(transitive)
+ Addedcross-fetch@3.1.8(transitive)
+ Addedfile-uri-to-path@1.0.0(transitive)
+ Addedgeneric-filehandle@1.0.9(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addedobject.entries-ponyfill@1.0.1(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
- Removed@babel/runtime-corejs2@^7.3.4
- Removed@babel/runtime-corejs2@7.26.0(transitive)
- Removedcore-js@2.6.12(transitive)