import glob
import logging
import os
import subprocess
from plugins import BaseAssembler
from yapsy.IPlugin import IPlugin

class A5Assembler(BaseAssembler, IPlugin):
    OUTPUT = 'scaffolds'
    def run(self, reads):
        """ 
        Build the command and run.
        Return list of contig file(s)
        """
        
        cmd_args = [os.path.join(os.getcwd(),self.executable)]
        libfile =  open(os.path.join(self.outpath, 'a5lib.out'), 'w')
        for d in reads:
            libfile.write('[LIB]\n')
            if d['type'] == 'paired':
                if len(d['files']) == 1:
                    libfile.write('shuf={}\n'.format(d['files'][0]))
                elif len(d['files']) == 2:
                    libfile.write('p1={}\n'.format(d['files'][0]))
                    libfile.write('p2={}\n'.format(d['files'][1]))
            elif d['type'] == 'single':
                for up in d['files']:
                    libfile.write('up={}\n'.format(up))
            try:
                libfile.write('ins={}\n'.format(d['insert']))
            except:
                logging.info('No Insert Info Given')
        cmd_args.append(libfile.name)
        libfile.close()
        cmd_args.append('a5')
        self.arast_popen(cmd_args, cwd=self.outpath)

        contigs = glob.glob(self.outpath + '/*.contigs.fasta')
        scaffolds = glob.glob(self.outpath + '/*.final.scaffolds.fasta')

        return contigs, scaffolds



@@ -124,17 +124,17 @@
 %0Aclass A
-5
+6
 Assemble
@@ -185,16 +185,17 @@
 ffolds'%0A
+%0A
     def 
@@ -206,15 +206,8 @@
 self
-, reads
 ):%0A 
@@ -217,152 +217,55 @@
     
-%22%22%22 %0A        Build the command and run.%0A        Return list of contig file(s)%0A        %22%22%22%0A        %0A        cmd_args = %5Bos.path.join(os.getcwd(),
+reads = self.data.readsets%0A        cmd_args = %5B
 self
@@ -275,17 +275,16 @@
 ecutable
-)
 %5D%0A      
@@ -420,32 +420,29 @@
         if d
-%5B'
+.
 type
-'%5D
  == 'paired'
@@ -463,33 +463,30 @@
     if len(d
-%5B'
+.
 files
-'%5D
 ) == 1:%0A    
@@ -531,33 +531,30 @@
 %5Cn'.format(d
-%5B'
+.
 files
-'%5D
 %5B0%5D))%0A      
@@ -573,25 +573,22 @@
 if len(d
-%5B'
+.
 files
-'%5D
 ) == 2:%0A
@@ -639,25 +639,22 @@
 format(d
-%5B'
+.
 files
-'%5D
 %5B0%5D))%0A  
@@ -703,25 +703,22 @@
 format(d
-%5B'
+.
 files
-'%5D
 %5B1%5D))%0A  
@@ -737,16 +737,13 @@
 if d
-%5B'
+.
 type
-'%5D
  == 
@@ -783,17 +783,14 @@
 in d
-%5B'
+.
 files
-'%5D
 :%0A  
@@ -860,16 +860,60 @@
    try:%0A
+                assert d.insert is not None%0A
         
@@ -957,18 +957,15 @@
 at(d
-%5B'
+.
 insert
-'%5D
 ))%0A 
@@ -1124,17 +1124,17 @@
 ppend('a
-5
+6
 ')%0A     
@@ -1338,25 +1338,67 @@
 urn 
-contigs, scaffolds
+%7B'contigs': contigs,%0A                'scaffolds': scaffolds%7D
 %0A%0A%0A

update A6 plugin