|
|
@@ -77,90 +77,90 @@ var asyncBwaMem = function (refPath, reads,
|
|
|
// R1 : string | Array<string>,
|
|
|
// R2 : string | Array<string>,
|
|
|
runName, libName, outputDir, onData, options) {
|
|
|
- var defaultOptions = {
|
|
|
- output_discordant: true,
|
|
|
- output_splitted: true,
|
|
|
- output_unmapped: true
|
|
|
- };
|
|
|
- if (typeof options === 'undefined') {
|
|
|
- options = defaultOptions;
|
|
|
- }
|
|
|
- else {
|
|
|
- options = __assign(__assign({}, defaultOptions), options);
|
|
|
- }
|
|
|
- var refName = path_1.default.parse(refPath).name;
|
|
|
- var bwa = 'bwa';
|
|
|
- var samblaster = 'samblaster';
|
|
|
- var samtools = 'samtools';
|
|
|
- var sambamba = 'sambamba';
|
|
|
- var readsIn;
|
|
|
- var isPairedEnd = false;
|
|
|
- if (Array.isArray(reads)) {
|
|
|
- isPairedEnd = true;
|
|
|
- console.log('Assuming paired end reads');
|
|
|
- var R1 = reads[0], R2 = reads[1];
|
|
|
- var R1_arr = Array.isArray(R1) ? R1.join(' ') : R1;
|
|
|
- var R2_arr = Array.isArray(R2) ? R2.join(' ') : R2;
|
|
|
- var R1_kitty = R1_arr.slice(-2) === 'gz' ? 'zcat' : 'cat';
|
|
|
- var R2_kitty = R2_arr.slice(-2) === 'gz' ? 'zcat' : 'cat';
|
|
|
- var R1_in = "'< ".concat(R1_kitty, " ").concat(R1_arr, "'");
|
|
|
- var R2_in = "'< ".concat(R2_kitty, " ").concat(R2_arr, "'");
|
|
|
- readsIn = R1_in + ' ' + R2_in;
|
|
|
- }
|
|
|
- else {
|
|
|
- readsIn = reads;
|
|
|
- }
|
|
|
- var bam = path_1.default.join(outputDir, "bwa_mem_properly_on_".concat(refName, ".bam"));
|
|
|
- var bamSorted = path_1.default.join(outputDir, "bwa_mem_properly_on_".concat(refName, ".sorted.bam"));
|
|
|
- var retObj = { bamSorted: bamSorted };
|
|
|
- if (options === null || options === void 0 ? void 0 : options.remove_mapped) {
|
|
|
- bam = '/dev/null';
|
|
|
- delete retObj.bamSorted;
|
|
|
- }
|
|
|
- var threads = String((0, os_1.cpus)().length);
|
|
|
- var samblasterCmd = [];
|
|
|
- if ((options === null || options === void 0 ? void 0 : options.output_discordant) || (options === null || options === void 0 ? void 0 : options.output_splitted)) {
|
|
|
- console.log('Using samblaster');
|
|
|
- // https://github.com/GregoryFaust/samblaster
|
|
|
- samblasterCmd = ['|', samblaster,
|
|
|
- '--addMateTags',
|
|
|
- '-a',
|
|
|
- '-e', // Exclude reads marked as duplicates from discordant, splitter, and/or unmapped
|
|
|
- ];
|
|
|
- if (options === null || options === void 0 ? void 0 : options.output_discordant) {
|
|
|
- if (!isPairedEnd) {
|
|
|
- console.log('Discordant reads can be found only in paired reads, skipping');
|
|
|
- }
|
|
|
- else {
|
|
|
- var discordantFile = path_1.default.join(outputDir, "bwa_mem_discordants_on_".concat(refName, ".sam"));
|
|
|
- console.log('Discordant reads file path: ', discordantFile);
|
|
|
- samblasterCmd = __spreadArray(__spreadArray([], samblasterCmd, true), ['-d', discordantFile], false);
|
|
|
- retObj = __assign(__assign({}, retObj), { discordantFile: discordantFile });
|
|
|
- }
|
|
|
- }
|
|
|
- if (!isPairedEnd) {
|
|
|
- samblasterCmd = __spreadArray(__spreadArray([], samblasterCmd, true), ['--ignoreUnmated'], false);
|
|
|
- }
|
|
|
- if (options === null || options === void 0 ? void 0 : options.output_splitted) {
|
|
|
- var splitterFile = path_1.default.join(outputDir, "bwa_mem_splitters_on_".concat(refName, ".sam"));
|
|
|
- console.log('Splitted reads file path: ', splitterFile);
|
|
|
- samblasterCmd = __spreadArray(__spreadArray([], samblasterCmd, true), ['-s', splitterFile], false);
|
|
|
- retObj = __assign(__assign({}, retObj), { splitterFile: splitterFile });
|
|
|
- }
|
|
|
- console.log(options);
|
|
|
- if (options === null || options === void 0 ? void 0 : options.output_unmapped) {
|
|
|
- var unmappedFile = path_1.default.join(outputDir, "bwa_mem_unmapped_on_".concat(refName, ".fq"));
|
|
|
- console.log('Unmapped reads file path: ', unmappedFile);
|
|
|
- samblasterCmd = __spreadArray(__spreadArray([], samblasterCmd, true), ['-u', unmappedFile], false);
|
|
|
- retObj = __assign(__assign({}, retObj), { unmappedFile: unmappedFile });
|
|
|
- }
|
|
|
- }
|
|
|
return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
|
|
- var code, code_sort, err_1;
|
|
|
+ var defaultOptions, refName, bwa, samblaster, samtools, sambamba, readsIn, isPairedEnd, R1, R2, R1_arr, R2_arr, R1_kitty, R2_kitty, R1_in, R2_in, bam, bamSorted, retObj, threads, samblasterCmd, discordantFile, splitterFile, unmappedFile, code, code_sort, err_1;
|
|
|
return __generator(this, function (_a) {
|
|
|
switch (_a.label) {
|
|
|
case 0:
|
|
|
_a.trys.push([0, 6, , 7]);
|
|
|
+ defaultOptions = {
|
|
|
+ output_discordant: true,
|
|
|
+ output_splitted: true,
|
|
|
+ output_unmapped: true
|
|
|
+ };
|
|
|
+ if (typeof options === 'undefined') {
|
|
|
+ options = defaultOptions;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ options = __assign(__assign({}, defaultOptions), options);
|
|
|
+ }
|
|
|
+ refName = path_1.default.parse(refPath).name;
|
|
|
+ bwa = 'bwa';
|
|
|
+ samblaster = 'samblaster';
|
|
|
+ samtools = 'samtools';
|
|
|
+ sambamba = 'sambamba';
|
|
|
+ readsIn = void 0;
|
|
|
+ isPairedEnd = false;
|
|
|
+ if (Array.isArray(reads)) {
|
|
|
+ isPairedEnd = true;
|
|
|
+ console.log('Assuming paired end reads');
|
|
|
+ R1 = reads[0], R2 = reads[1];
|
|
|
+ R1_arr = Array.isArray(R1) ? R1.join(' ') : R1;
|
|
|
+ R2_arr = Array.isArray(R2) ? R2.join(' ') : R2;
|
|
|
+ R1_kitty = R1_arr.slice(-2) === 'gz' ? 'zcat' : 'cat';
|
|
|
+ R2_kitty = R2_arr.slice(-2) === 'gz' ? 'zcat' : 'cat';
|
|
|
+ R1_in = "'< ".concat(R1_kitty, " ").concat(R1_arr, "'");
|
|
|
+ R2_in = "'< ".concat(R2_kitty, " ").concat(R2_arr, "'");
|
|
|
+ readsIn = R1_in + ' ' + R2_in;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ readsIn = reads;
|
|
|
+ }
|
|
|
+ bam = path_1.default.join(outputDir, "bwa_mem_properly_on_".concat(refName, ".bam"));
|
|
|
+ bamSorted = path_1.default.join(outputDir, "bwa_mem_properly_on_".concat(refName, ".sorted.bam"));
|
|
|
+ retObj = { bamSorted: bamSorted };
|
|
|
+ if (options === null || options === void 0 ? void 0 : options.remove_mapped) {
|
|
|
+ bam = '/dev/null';
|
|
|
+ delete retObj.bamSorted;
|
|
|
+ }
|
|
|
+ threads = String((0, os_1.cpus)().length);
|
|
|
+ samblasterCmd = [];
|
|
|
+ if ((options === null || options === void 0 ? void 0 : options.output_discordant) || (options === null || options === void 0 ? void 0 : options.output_splitted)) {
|
|
|
+ console.log('Using samblaster');
|
|
|
+ // https://github.com/GregoryFaust/samblaster
|
|
|
+ samblasterCmd = ['|', samblaster,
|
|
|
+ '--addMateTags',
|
|
|
+ '-a',
|
|
|
+ '-e', // Exclude reads marked as duplicates from discordant, splitter, and/or unmapped
|
|
|
+ ];
|
|
|
+ if (options === null || options === void 0 ? void 0 : options.output_discordant) {
|
|
|
+ if (!isPairedEnd) {
|
|
|
+ console.log('Discordant reads can be found only in paired reads, skipping');
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ discordantFile = path_1.default.join(outputDir, "bwa_mem_discordants_on_".concat(refName, ".sam"));
|
|
|
+ console.log('Discordant reads file path: ', discordantFile);
|
|
|
+ samblasterCmd = __spreadArray(__spreadArray([], samblasterCmd, true), ['-d', discordantFile], false);
|
|
|
+ retObj = __assign(__assign({}, retObj), { discordantFile: discordantFile });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!isPairedEnd) {
|
|
|
+ samblasterCmd = __spreadArray(__spreadArray([], samblasterCmd, true), ['--ignoreUnmated'], false);
|
|
|
+ }
|
|
|
+ if (options === null || options === void 0 ? void 0 : options.output_splitted) {
|
|
|
+ splitterFile = path_1.default.join(outputDir, "bwa_mem_splitters_on_".concat(refName, ".sam"));
|
|
|
+ console.log('Splitted reads file path: ', splitterFile);
|
|
|
+ samblasterCmd = __spreadArray(__spreadArray([], samblasterCmd, true), ['-s', splitterFile], false);
|
|
|
+ retObj = __assign(__assign({}, retObj), { splitterFile: splitterFile });
|
|
|
+ }
|
|
|
+ console.log(options);
|
|
|
+ if (options === null || options === void 0 ? void 0 : options.output_unmapped) {
|
|
|
+ unmappedFile = path_1.default.join(outputDir, "bwa_mem_unmapped_on_".concat(refName, ".fq"));
|
|
|
+ console.log('Unmapped reads file path: ', unmappedFile);
|
|
|
+ samblasterCmd = __spreadArray(__spreadArray([], samblasterCmd, true), ['-u', unmappedFile], false);
|
|
|
+ retObj = __assign(__assign({}, retObj), { unmappedFile: unmappedFile });
|
|
|
+ }
|
|
|
+ }
|
|
|
if (!!fs_1.default.existsSync(refPath + '.amb')) return [3 /*break*/, 2];
|
|
|
return [4 /*yield*/, async_exec(bwa, ['index', refPath], function (message) { return onData('[BWA-INDEX] ' + message); })];
|
|
|
case 1:
|