# Path: ariba/common.py
# class Error (Exception): pass
# def syscall(cmd, allow_fail=False, verbose=False, verbose_filehandle=sys.stdout, print_errors=True, shell=True):
# def decode(x):
# def cat_files(infiles, outfile):
# def download_file(url, outfile, max_attempts=3, sleep_time=2, verbose=False):
# def rmtree(input_dir):
# 
# Path: ariba/external_progs.py
# class Error (Exception): pass
# class ExternalProgs:
#     def __init__(self, verbose=False, fail_on_error=True, using_spades=False):
#     def exe(self, prog):
#     def version(self, prog):
#     def _get_exe(prog):
#     def _get_version(prog, path):


import tempfile
import sys
import os
import pyfastaq
from ariba import common, external_progs
        pyfastaq.utils.close(f)
        return clusters


    def get_run_cmd(self, output_file):
        cmd = ' '.join([
            self.cd_hit_est,
            '-i', self.infile,
            '-o', output_file,
            '-c', str(self.seq_identity_threshold),
            '-T', str(self.threads),
            '-s', str(self.length_diff_cutoff),
            '-d 0',
            '-bak 1',
        ])

        # Add in cdhit memory allocation if one has been specified
        if self.memory_limit is not None:
            cmd = ' '.join([cmd, '-M', str(self.memory_limit)])

        return cmd


    def run(self):
        tmpdir = tempfile.mkdtemp(prefix='tmp.run_cd-hit.', dir=os.getcwd())
        cdhit_fasta = os.path.join(tmpdir, 'cdhit')
        cluster_info_outfile = cdhit_fasta + '.bak.clstr'
        cmd = self.get_run_cmd(cdhit_fasta)
        common.syscall(cmd, verbose=self.verbose)
        clusters = self._get_clusters_from_bak_file(cluster_info_outfile, self.min_cluster_number)

# Path: ariba/common.py
# class Error (Exception): pass
# def syscall(cmd, allow_fail=False, verbose=False, verbose_filehandle=sys.stdout, print_errors=True, shell=True):
# def decode(x):
# def cat_files(infiles, outfile):
# def download_file(url, outfile, max_attempts=3, sleep_time=2, verbose=False):
# def rmtree(input_dir):
# 
# Path: ariba/external_progs.py
# class Error (Exception): pass
# class ExternalProgs:
#     def __init__(self, verbose=False, fail_on_error=True, using_spades=False):
#     def exe(self, prog):
#     def version(self, prog):
#     def _get_exe(prog):
#     def _get_version(prog, path):


# Path: ariba/cdhit.py
import tempfile
import sys
import os
import pyfastaq
from ariba import common, external_progs

        pyfastaq.utils.close(f)
        return clusters


    def get_run_cmd(self, output_file):
        cmd = ' '.join([
            self.cd_hit_est,
            '-i', self.infile,
            '-o', output_file,
            '-c', str(self.seq_identity_threshold),
            '-T', str(self.threads),
            '-s', str(self.length_diff_cutoff),
            '-d 0',
            '-bak 1',
        ])

        # Add in cdhit memory allocation if one has been specified
        if self.memory_limit is not None:
            cmd = ' '.join([cmd, '-M', str(self.memory_limit)])

        return cmd


    def run(self):
        tmpdir = tempfile.mkdtemp(prefix='tmp.run_cd-hit.', dir=os.getcwd())
        cdhit_fasta = os.path.join(tmpdir, 'cdhit')
        cluster_info_outfile = cdhit_fasta + '.bak.clstr'
        cmd = self.get_run_cmd(cdhit_fasta)
        common.syscall(cmd, verbose=self.verbose)
        clusters = self._get_clusters_from_bak_file(cluster_info_outfile, self.min_cluster_number)

        common.rmtree(tmpdir)