Thomas 4 лет назад
Родитель
Сommit
400906a21f
4 измененных файлов с 17 добавлено и 17 удалено
  1. 7 7
      index.js
  2. 6 6
      index.ts
  3. 2 2
      test.js
  4. 2 2
      test.ts

+ 7 - 7
index.js

@@ -246,8 +246,14 @@ const makeRefSeqFromReg = (dbPath, reg, distFile, limit) => __awaiter(void 0, vo
                         try {
                         try {
                             const file = path_1.default.join(tmpDir, (res === null || res === void 0 ? void 0 : res.version) || res.accession + '.fa');
                             const file = path_1.default.join(tmpDir, (res === null || res === void 0 ? void 0 : res.version) || res.accession + '.fa');
                             if (!createdFiles.includes(file)) {
                             if (!createdFiles.includes(file)) {
+                                if (createdFiles.length === 0)
+                                    if (fs_1.default.existsSync(distFile))
+                                        yield fs_1.default.promises.rm(distFile);
                                 yield (0, aligner_1.writeSequence)((res === null || res === void 0 ? void 0 : res.version) || res.accession, res === null || res === void 0 ? void 0 : res.sequence, file);
                                 yield (0, aligner_1.writeSequence)((res === null || res === void 0 ? void 0 : res.version) || res.accession, res === null || res === void 0 ? void 0 : res.sequence, file);
                                 createdFiles.push(file);
                                 createdFiles.push(file);
+                                const tmp = yield fs_1.default.promises.readFile(file);
+                                yield fs_1.default.promises.appendFile(distFile, tmp.toString() + '\n');
+                                yield fs_1.default.promises.rm(file);
                                 counter++;
                                 counter++;
                                 if (counter % 100 === 0)
                                 if (counter % 100 === 0)
                                     console.log('Already ' + counter + ' sequence parsed');
                                     console.log('Already ' + counter + ' sequence parsed');
@@ -274,13 +280,7 @@ const makeRefSeqFromReg = (dbPath, reg, distFile, limit) => __awaiter(void 0, vo
             if (counter === limit)
             if (counter === limit)
                 break;
                 break;
     }
     }
-    console.log(createdFiles.length + ' sequences');
-    if (fs_1.default.existsSync(distFile))
-        yield fs_1.default.promises.rm(distFile);
-    for (const createdFile of createdFiles) {
-        const tmp = yield fs_1.default.promises.readFile(createdFile);
-        yield fs_1.default.promises.appendFile(distFile, tmp.toString() + '\n');
-    }
+    console.log(createdFiles.length + ' sequences were extracted');
     yield fs_1.default.promises.rm(tmpDir, { recursive: true });
     yield fs_1.default.promises.rm(tmpDir, { recursive: true });
     yield async_exec('bwa', ['index', distFile], () => console.log);
     yield async_exec('bwa', ['index', distFile], () => console.log);
 });
 });

+ 6 - 6
index.ts

@@ -218,6 +218,7 @@ const makeRefSeqFromReg = async (
     await fs.promises.mkdir(tmpDir)
     await fs.promises.mkdir(tmpDir)
     const createdFiles: string[] = []
     const createdFiles: string[] = []
     let counter = 0
     let counter = 0
+
     for (const jsiFile of jsiFiles) {
     for (const jsiFile of jsiFiles) {
         console.log('reading ' + jsiFile)
         console.log('reading ' + jsiFile)
         for await (const line of line$(jsiFile)) {
         for await (const line of line$(jsiFile)) {
@@ -228,8 +229,12 @@ const makeRefSeqFromReg = async (
                     try {
                     try {
                         const file = path.join(tmpDir, res?.version || res.accession + '.fa')
                         const file = path.join(tmpDir, res?.version || res.accession + '.fa')
                         if (!createdFiles.includes(file)) {
                         if (!createdFiles.includes(file)) {
+                            if (createdFiles.length === 0) if (fs.existsSync(distFile)) await fs.promises.rm(distFile)
                             await writeSequence(res?.version || res.accession, res?.sequence, file)
                             await writeSequence(res?.version || res.accession, res?.sequence, file)
                             createdFiles.push(file)
                             createdFiles.push(file)
+                            const tmp = await fs.promises.readFile(file)
+                            await fs.promises.appendFile(distFile, tmp.toString() + '\n')
+                            await fs.promises.rm(file)
                             counter++
                             counter++
                             if (counter%100 === 0) console.log('Already ' + counter + ' sequence parsed')
                             if (counter%100 === 0) console.log('Already ' + counter + ' sequence parsed')
                         }
                         }
@@ -242,13 +247,8 @@ const makeRefSeqFromReg = async (
         }
         }
         if (limit) if (counter === limit) break
         if (limit) if (counter === limit) break
     }
     }
-    console.log(createdFiles.length + ' sequences')
+    console.log(createdFiles.length + ' sequences were extracted')
     
     
-    if (fs.existsSync(distFile)) await fs.promises.rm(distFile)
-    for (const createdFile of createdFiles) {
-        const tmp = await fs.promises.readFile(createdFile)
-        await fs.promises.appendFile(distFile, tmp.toString() + '\n')
-    }
     await fs.promises.rm(tmpDir, {recursive: true})
     await fs.promises.rm(tmpDir, {recursive: true})
     await async_exec('bwa', ['index', distFile], () => console.log)
     await async_exec('bwa', ['index', distFile], () => console.log)
 }
 }

+ 2 - 2
test.js

@@ -23,6 +23,6 @@ const _1 = require(".");
     const rnaDBPath = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(n => '/home/thomas/NGS/ref/ncbi/RNA/human.' + n + '.rna.gbff');
     const rnaDBPath = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(n => '/home/thomas/NGS/ref/ncbi/RNA/human.' + n + '.rna.gbff');
     // const res = await getSymbol('NOTCH1', LRGPath, tablePath, geneDBPath, rnaDBPath)
     // const res = await getSymbol('NOTCH1', LRGPath, tablePath, geneDBPath, rnaDBPath)
     // await fs.promises.writeFile('test/test-getSymbol.json', JSON.stringify(res, null, 4))
     // await fs.promises.writeFile('test/test-getSymbol.json', JSON.stringify(res, null, 4))
-    yield (0, _1.makeRefSeqFromReg)(rnaDBPath, /NM_/, '/home/thomas/NGS/ref/ncbi/RNA/human_NM.fa');
-    // await makeRefSeqFromReg(rnaDBPath, /NM_/, 'test/human_NM.fa', 10)
+    // await makeRefSeqFromReg(rnaDBPath, /NM_/, '/home/thomas/NGS/ref/ncbi/RNA/human_NM.fa')
+    yield (0, _1.makeRefSeqFromReg)(rnaDBPath, /NM_/, 'test/human_NM.fa', 10);
 }))();
 }))();

+ 2 - 2
test.ts

@@ -16,7 +16,7 @@ import fs from 'fs'
 
 
     // const res = await getSymbol('NOTCH1', LRGPath, tablePath, geneDBPath, rnaDBPath)
     // const res = await getSymbol('NOTCH1', LRGPath, tablePath, geneDBPath, rnaDBPath)
     // await fs.promises.writeFile('test/test-getSymbol.json', JSON.stringify(res, null, 4))
     // await fs.promises.writeFile('test/test-getSymbol.json', JSON.stringify(res, null, 4))
-    await makeRefSeqFromReg(rnaDBPath, /NM_/, '/home/thomas/NGS/ref/ncbi/RNA/human_NM.fa')
-    // await makeRefSeqFromReg(rnaDBPath, /NM_/, 'test/human_NM.fa', 10)
+    // await makeRefSeqFromReg(rnaDBPath, /NM_/, '/home/thomas/NGS/ref/ncbi/RNA/human_NM.fa')
+    await makeRefSeqFromReg(rnaDBPath, /NM_/, 'test/human_NM.fa', 10)
 })()
 })()