Browse Source

sam name restriction

Thomas 3 năm trước cách đây
mục cha
commit
74dd625e8e
2 tập tin đã thay đổi với 12 bổ sung3 xóa
  1. 8 2
      dist/index.js
  2. 4 1
      index.ts

+ 8 - 2
dist/index.js

@@ -73,19 +73,25 @@ var async_exec = function (prog, args, onData) {
         child.on('exit', function (code) { return resolve(code); });
     });
 };
+var invReplace = function (regex, string, by) {
+    if (by === void 0) { by = '_'; }
+    return string.split('').map(function (letter) { return letter.match(regex) ? letter : by; }).join('');
+};
 var makeReference = function (sequenceName, sequence, filePath, lineN) {
     if (lineN === void 0) { lineN = 80; }
     return __awaiter(void 0, void 0, void 0, function () {
         return __generator(this, function (_a) {
             return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
-                    var r, error_1;
+                    var r, regex_sam_restriction, nSeqName, error_1;
                     var _a;
                     return __generator(this, function (_b) {
                         switch (_b.label) {
                             case 0:
                                 _b.trys.push([0, 3, , 4]);
                                 r = new RegExp(".{1," + lineN + "}", "g");
-                                return [4 /*yield*/, fs_1.default.promises.writeFile(filePath, '>' + sequenceName + '\n' + ((_a = sequence.match(r)) === null || _a === void 0 ? void 0 : _a.join('\n')))];
+                                regex_sam_restriction = /[>0-9A-Za-z!#$%&+\./:;?@^_|~-]|[\n\t]/g;
+                                nSeqName = invReplace(regex_sam_restriction, sequenceName);
+                                return [4 /*yield*/, fs_1.default.promises.writeFile(filePath, '>' + nSeqName + '\n' + ((_a = sequence.match(r)) === null || _a === void 0 ? void 0 : _a.join('\n')))];
                             case 1:
                                 _b.sent();
                                 return [4 /*yield*/, async_exec('bwa', ['index', filePath], function () { return console.log; })];

+ 4 - 1
index.ts

@@ -14,12 +14,15 @@ const async_exec = (prog: string, args: string[], onData: Function) => {
         child.on('exit', code => resolve(code))
     })
 }
+const invReplace = (regex: RegExp, string: string, by = '_') => string.split('').map(letter => letter.match(regex) ? letter : by).join('')
 
 const makeReference = async (sequenceName:string, sequence:string, filePath: string, lineN = 80) => {
   return new Promise<boolean>(async(resolve, reject) => {
     try {
       const r = new RegExp(".{1," + lineN + "}","g");
-      await fs.promises.writeFile(filePath, '>'+sequenceName+'\n'+ sequence.match(r)?.join('\n'))
+      const regex_sam_restriction: RegExp = /[>0-9A-Za-z!#$%&+\./:;?@^_|~-]|[\n\t]/g;
+      const nSeqName = invReplace(regex_sam_restriction, sequenceName)
+      await fs.promises.writeFile(filePath, '>' + nSeqName + '\n' + sequence.match(r)?.join('\n'))
       await async_exec('bwa', ['index',filePath], () => console.log)
       resolve(true)
     } catch (error) {