Thomas 3 年之前
父节点
当前提交
dbe2d27763
共有 2 个文件被更改,包括 28 次插入16 次删除
  1. 12 5
      dist/index.js
  2. 16 11
      index.ts

+ 12 - 5
dist/index.js

@@ -113,6 +113,10 @@ runName, libName, outputDir, onData, options) {
     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)) {
@@ -155,7 +159,7 @@ runName, libName, outputDir, onData, options) {
         return __generator(this, function (_a) {
             switch (_a.label) {
                 case 0:
-                    _a.trys.push([0, 3, , 4]);
+                    _a.trys.push([0, 4, , 5]);
                     return [4 /*yield*/, async_exec(bwa, __spreadArray(__spreadArray(['mem',
                             '-t', threads,
                             '-R', "\"@RG\\tPL:Illumina\\tID:".concat(+(new Date), "\\tSM:").concat(runName, "\\tLB:").concat(libName, "\""), refPath,
@@ -169,6 +173,7 @@ runName, libName, outputDir, onData, options) {
                 case 1:
                     code = _a.sent();
                     onData('[BWA-MEM][EXIT CODE] ' + code);
+                    if (!retObj.bamSorted) return [3 /*break*/, 3];
                     return [4 /*yield*/, async_exec(sambamba, ['sort',
                             '-t', threads,
                             bam
@@ -177,13 +182,15 @@ runName, libName, outputDir, onData, options) {
                     code_sort = _a.sent();
                     onData('[SAMBAMBA-SORT][EXIT CODE] ' + code_sort);
                     fs_1.default.unlinkSync(bam);
-                    resolve(retObj);
-                    return [3 /*break*/, 4];
+                    _a.label = 3;
                 case 3:
+                    resolve(retObj);
+                    return [3 /*break*/, 5];
+                case 4:
                     err_1 = _a.sent();
                     reject(err_1);
-                    return [3 /*break*/, 4];
-                case 4: return [2 /*return*/];
+                    return [3 /*break*/, 5];
+                case 5: return [2 /*return*/];
             }
         });
     }); });

+ 16 - 11
index.ts

@@ -66,10 +66,14 @@ const asyncBwaMem = (
     } else {
       readsIn = reads
     }
-    const bam            = path.join(outputDir, `bwa_mem_properly_on_${refName}.bam`)
-    const bamSorted      = path.join(outputDir, `bwa_mem_properly_on_${refName}.sorted.bam`)
 
+    let bam       = path.join(outputDir, `bwa_mem_properly_on_${refName}.bam`)
+    let bamSorted = path.join(outputDir, `bwa_mem_properly_on_${refName}.sorted.bam`)
     let retObj: any = { bamSorted } 
+    if(options?.remove_mapped) {
+      bam = '/dev/null'
+      delete retObj.bamSorted
+    }
 
     const threads = String(cpus().length)
 
@@ -133,14 +137,15 @@ const asyncBwaMem = (
         ], (message: string) => onData('[BWA-MEM] ' + message))
         onData('[BWA-MEM][EXIT CODE] ' + code)
         
-        const code_sort = await async_exec(
-          sambamba, ['sort',
-            '-t', threads,
-            bam
-        ], (message: string) => onData('[SAMBAMBA-SORT] ' + message))
-        onData('[SAMBAMBA-SORT][EXIT CODE] ' + code_sort)
-  
-        fs.unlinkSync(bam)
+        if(retObj.bamSorted) {
+          const code_sort = await async_exec(
+            sambamba, ['sort',
+              '-t', threads,
+              bam
+          ], (message: string) => onData('[SAMBAMBA-SORT] ' + message))
+          onData('[SAMBAMBA-SORT][EXIT CODE] ' + code_sort)
+          fs.unlinkSync(bam)
+        }
         
         resolve(retObj)
       } catch (err) {
@@ -149,4 +154,4 @@ const asyncBwaMem = (
     })
 }
 
-export { asyncBwaMem }  
+export { asyncBwaMem }