# 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 pysam
import pyfastaq
from circlator import common, external_progs
    missing = [not os.path.exists(outprefix + '.' + x) for x in index_extensions]
    if True not in missing:
        return

    cmd = ' '.join([
        bwa.exe(),  'index',
        '-p', outprefix,
        infile
    ])
    common.syscall(cmd, verbose=verbose)


def bwa_index_clean(prefix):
    for e in index_extensions:
        try:
            os.unlink(prefix + '.' + e)
        except:
            pass


def bwa_mem(
      ref,
      reads,
      outfile,
      threads=1,
      bwa_options = '-x pacbio',
      verbose=False,
      index=None
    ):


# 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/mapping.py
import os
import pysam
import pyfastaq
from circlator import common, external_progs

    missing = [not os.path.exists(outprefix + '.' + x) for x in index_extensions]
    if True not in missing:
        return

    cmd = ' '.join([
        bwa.exe(),  'index',
        '-p', outprefix,
        infile
    ])
    common.syscall(cmd, verbose=verbose)


def bwa_index_clean(prefix):
    for e in index_extensions:
        try:
            os.unlink(prefix + '.' + e)
        except:
            pass


def bwa_mem(
      ref,
      reads,
      outfile,
      threads=1,
      bwa_options = '-x pacbio',
      verbose=False,
      index=None
    ):


    samtools = external_progs.make_and_check_prog('samtools', verbose=verbose)