bioseq-ts
Version:
Biological Sequence in Javascript, written in Typescript.
69 lines • 2.59 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.FastaParserStream = void 0;
var loglevel_colored_prefix_1 = require("loglevel-colored-prefix");
var stream_1 = require("stream");
var FastaUtils_1 = require("./FastaUtils");
/**
* Transform stream takes fasta chunks and push BioSeq objects
*
* @class FastaParserStream
* @extends {Transform}
*/
var FastaParserStream = /** @class */ (function (_super) {
__extends(FastaParserStream, _super);
function FastaParserStream(logLevel) {
if (logLevel === void 0) { logLevel = 'INFO'; }
var _this = _super.call(this, { objectMode: true }) || this;
_this.buffer = '';
_this.logLevel = logLevel;
_this.log = new loglevel_colored_prefix_1.Logger(_this.logLevel);
_this.fu = new FastaUtils_1.FastaUtils(_this.logLevel);
return _this;
}
FastaParserStream.prototype._transform = function (chunk, enc, next) {
var _this = this;
var log = this.log.getLogger('FastaParserStream::transform');
var raw = this.buffer + chunk.toString();
var pieces = raw.split('>');
var last = pieces.pop();
if (last === '') {
this.buffer = pieces.pop() + ">";
}
else {
this.buffer = last || '';
}
// log.debug(this.buffer)
this.fu
.parse('>' + pieces.join('>'))
.getBioSeqs()
.forEach(function (entry) { return _this.push(entry); });
next();
};
FastaParserStream.prototype._flush = function (next) {
var _this = this;
if (this.buffer !== '') {
var set = this.fu
.parse('>' + this.buffer)
.getBioSeqs()
.forEach(function (entry) { return _this.push(entry); });
}
next();
};
return FastaParserStream;
}(stream_1.Transform));
exports.FastaParserStream = FastaParserStream;
//# sourceMappingURL=FastaParserStream.js.map