# 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 os
import tempfile
from ariba import common, external_progs
                    raise Error('Error parsing the following line of cd-hit-est-2d output from file "' + infile + '":\n' + line)

                reads.add(int(fields[2][1:-5]))

        return reads


    def run(self, reads_out1, reads_out2):
        tmpdir = tempfile.mkdtemp(prefix='tmp.filter_reads.', dir=os.getcwd())
        all_reads_fasta = os.path.join(tmpdir, 'all_reads_for_cdhit.fa')
        self.readstore.get_reads(self.cluster_name, all_reads_fasta, fasta=True, log_fh=self.log_fh)
        cdhit_out = os.path.join(tmpdir, 'cdhit')
        ReadFilter._run_cdhit_est_2d(
            self.references_fa,
            all_reads_fasta,
            cdhit_out,
            self.extern_progs.exe('cdhit2d'),
            verbose=True,
            verbose_fh=self.log_fh
        )

        wanted_read_ids = ReadFilter._cdhit_clstr_to_reads(cdhit_out + '.clstr')
        total_reads, total_bases = self.readstore.get_reads(
            self.cluster_name,
            reads_out1,
            out2=reads_out2,
            log_fh=self.log_fh,
            wanted_ids=wanted_read_ids
        )


# 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/read_filter.py
import os
import tempfile
from ariba import common, external_progs

                    raise Error('Error parsing the following line of cd-hit-est-2d output from file "' + infile + '":\n' + line)

                reads.add(int(fields[2][1:-5]))

        return reads


    def run(self, reads_out1, reads_out2):
        tmpdir = tempfile.mkdtemp(prefix='tmp.filter_reads.', dir=os.getcwd())
        all_reads_fasta = os.path.join(tmpdir, 'all_reads_for_cdhit.fa')
        self.readstore.get_reads(self.cluster_name, all_reads_fasta, fasta=True, log_fh=self.log_fh)
        cdhit_out = os.path.join(tmpdir, 'cdhit')
        ReadFilter._run_cdhit_est_2d(
            self.references_fa,
            all_reads_fasta,
            cdhit_out,
            self.extern_progs.exe('cdhit2d'),
            verbose=True,
            verbose_fh=self.log_fh
        )

        wanted_read_ids = ReadFilter._cdhit_clstr_to_reads(cdhit_out + '.clstr')
        total_reads, total_bases = self.readstore.get_reads(
            self.cluster_name,
            reads_out1,
            out2=reads_out2,
            log_fh=self.log_fh,
            wanted_ids=wanted_read_ids
        )


        common.rmtree(tmpdir)