# Path: circlator/common.py
# class Error (Exception): pass
# def syscall(cmd, allow_fail=False, verbose=False):
# def syscall_get_stdout(cmd):
# def decode(x):
# def check_files_exist(filenames):
# 
# Path: circlator/external_progs.py
# class Error (Exception): pass
# def handle_error(message, raise_error=True):
# def make_and_check_prog(name, verbose=False, raise_error=True, filehandle=None, debug=False, required=False):
# def check_all_progs(verbose=False, raise_error=False, filehandle=None, debug=False, assembler=None):


import os
import tempfile
import sys
import shutil
import pyfastaq
from circlator import common, external_progs
    def __init__(self,
      reads,
      outdir,
      threads=1,
      spades_kmers=None,
      careful=True,
      only_assembler=True,
      verbose=False,
      spades_use_first_success=False,
      assembler='spades',
      genomeSize=100000, # only matters for Canu if correcting reads (which we're not)
      data_type='pacbio-corrected',
    ):
        self.outdir = os.path.abspath(outdir)
        self.reads = os.path.abspath(reads)
        if not os.path.exists(self.reads):
            raise Error('Reads file not found:' + self.reads)

        self.verbose = verbose
        self.samtools = external_progs.make_and_check_prog('samtools', verbose=self.verbose)
        self.threads = threads
        self.assembler = assembler

        if self.assembler == 'spades':
            self.spades = external_progs.make_and_check_prog('spades', verbose=self.verbose, required=True)
            self.spades_kmers = self._build_spades_kmers(spades_kmers)
            self.spades_use_first_success = spades_use_first_success
            self.careful = careful
            self.only_assembler = only_assembler
        elif self.assembler == 'canu':

# Path: circlator/common.py
# class Error (Exception): pass
# def syscall(cmd, allow_fail=False, verbose=False):
# def syscall_get_stdout(cmd):
# def decode(x):
# def check_files_exist(filenames):
# 
# Path: circlator/external_progs.py
# class Error (Exception): pass
# def handle_error(message, raise_error=True):
# def make_and_check_prog(name, verbose=False, raise_error=True, filehandle=None, debug=False, required=False):
# def check_all_progs(verbose=False, raise_error=False, filehandle=None, debug=False, assembler=None):


# Path: circlator/assemble.py
import os
import tempfile
import sys
import shutil
import pyfastaq
from circlator import common, external_progs

    def __init__(self,
      reads,
      outdir,
      threads=1,
      spades_kmers=None,
      careful=True,
      only_assembler=True,
      verbose=False,
      spades_use_first_success=False,
      assembler='spades',
      genomeSize=100000, # only matters for Canu if correcting reads (which we're not)
      data_type='pacbio-corrected',
    ):
        self.outdir = os.path.abspath(outdir)
        self.reads = os.path.abspath(reads)
        if not os.path.exists(self.reads):
            raise Error('Reads file not found:' + self.reads)

        self.verbose = verbose
        self.samtools = external_progs.make_and_check_prog('samtools', verbose=self.verbose)
        self.threads = threads
        self.assembler = assembler

        if self.assembler == 'spades':
            self.spades = external_progs.make_and_check_prog('spades', verbose=self.verbose, required=True)
            self.spades_kmers = self._build_spades_kmers(spades_kmers)
            self.spades_use_first_success = spades_use_first_success
            self.careful = careful
            self.only_assembler = only_assembler
        elif self.assembler == 'canu':

            self.canu = external_progs.make_and_check_prog('canu', verbose=self.verbose, required=True)