Thomas 4 жил өмнө
parent
commit
418bad7fbd
2 өөрчлөгдсөн 24 нэмэгдсэн , 4 устгасан
  1. 11 2
      index.js
  2. 13 2
      index.ts

+ 11 - 2
index.js

@@ -32,6 +32,15 @@ const async_exec = (prog, args, onData, onErr) => {
 const rmList = (list) => {
     return Promise.all(list.map(e => fs_1.default.promises.rm(e, { recursive: true })));
 };
+const isDone = (rsltDir) => {
+    let done = false;
+    if (fs_1.default.existsSync(path_1.default.join(rsltDir, 'contigs.fasta'))) {
+        if (fs_1.default.statSync(path_1.default.join(rsltDir, 'contigs.fasta')).size > 1) {
+            done = true;
+        }
+    }
+    return done;
+};
 const denovoAssemblage = (reads, rnames, spadesPath) => {
     return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
         let readsIn = [];
@@ -62,11 +71,11 @@ const denovoAssemblage = (reads, rnames, spadesPath) => {
         const args = isPairedEnd ? ['-1', tmpSubReads[0], '-2', tmpSubReads[1]] : ['-s', tmpSubReads[0]];
         const rsltDir = path_1.default.join(os_1.default.tmpdir(), (+new Date) + '_spades');
         yield async_exec(spadesPath, ['-t', threads, '--isolate', ...args, '-o', rsltDir], console.log, console.log);
-        if (!fs_1.default.existsSync(path_1.default.join(rsltDir, 'contigs.fasta'))) {
+        if (!isDone(rsltDir)) {
             yield rmList([rsltDir]);
             console.log('Trying meta');
             yield async_exec(spadesPath, ['-t', threads, '--meta', ...args, '-o', rsltDir], console.log, console.log);
-            if (!fs_1.default.existsSync(path_1.default.join(rsltDir, 'contigs.fasta'))) {
+            if (!isDone(rsltDir)) {
                 yield rmList([rsltDir, ...tmpSubReads]);
                 reject('No convergence');
             }

+ 13 - 2
index.ts

@@ -23,6 +23,16 @@ const rmList = (list: string[]) => {
     return Promise.all(list.map(e => fs.promises.rm(e, {recursive: true})))
 }
 
+const isDone = (rsltDir:string) => {
+    let done = false
+    if(fs.existsSync(path.join(rsltDir, 'contigs.fasta'))) {
+        if(fs.statSync(path.join(rsltDir, 'contigs.fasta')).size > 1) {
+            done = true
+        }
+    }
+    return done
+}
+
 const denovoAssemblage = (
     reads : string | string[],
     rnames: string[],
@@ -59,12 +69,13 @@ const denovoAssemblage = (
         const rsltDir = path.join(os.tmpdir(), (+new Date)  + '_spades')
         
         await async_exec(spadesPath, ['-t', threads, '--isolate', ...args, '-o', rsltDir], console.log, console.log)
-        if(!fs.existsSync(path.join(rsltDir, 'contigs.fasta'))) {
+
+        if(!isDone(rsltDir)) {
             await rmList([rsltDir])
             console.log('Trying meta')
             await async_exec(spadesPath, ['-t', threads, '--meta', ...args, '-o', rsltDir], console.log, console.log)
             
-            if(!fs.existsSync(path.join(rsltDir, 'contigs.fasta'))) {
+            if(!isDone(rsltDir)) {
                 await rmList([rsltDir, ...tmpSubReads])
                 reject('No convergence')
             }