# 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/reference_data.py
# class Error (Exception): pass
# class ReferenceData:
#     def __init__(self,
#         fasta_files,
#         metadata_tsv_files,
#         rename_file=None,
#         min_gene_length=6,
#         max_gene_length=10000,
#         min_noncoding_length=6,
#         max_noncoding_length=20000,
#         genetic_code=11,
#         parameters_file=None,
#     ):
#     def _load_rename_file(cls, filename):
#     def _load_metadata_tsv(cls, filename, metadata_dict):
#     def _load_all_metadata_tsvs(cls, filenames):
#     def _load_fasta_file(cls, filename, seq_dict):
#     def _load_all_fasta_files(cls, filenames):
#     def _load_input_files_and_check_seq_names(fasta_files, metadata_files):
#     def _write_metadata_tsv(cls, metadata, filename):
#     def _write_sequences_to_files(cls, sequences, metadata, outprefix):
#     def _filter_bad_variant_data(cls, sequences, all_metadata, out_prefix, removed_sequences):
#     def _try_to_get_gene_seq(cls, seq, min_length, max_length):
#     def _check_noncoding_seq(cls, seq, min_length, max_length):
#     def _remove_bad_genes(cls, sequences, metadata, log_file, min_gene_length, max_gene_length):
#     def _remove_bad_noncoding_seqs(cls, sequences, metadata, log_file, min_noncoding_length, max_noncoding_length):
#     def sanity_check(self, outprefix):
#     def _new_seq_name(cls, name):
#     def _seq_names_to_rename_dict(cls, names):
#     def _rename_names_in_seq_dict(cls, seq_dict, rename_dict):
#     def _rename_metadata_set(cls, metadata_set, new_name):
#     def _rename_names_in_metadata(cls, meta_dict, rename_dict):
#     def rename_sequences(self, outfile):
#     def sequence_type(self, sequence_name):
#     def sequence(self, sequence_name):
#     def all_non_wild_type_variants(self, ref_name):
#     def write_cluster_allocation_file(clusters, outfile):
#     def cluster_with_cdhit(self, outprefix, seq_identity_threshold=0.9, threads=1, length_diff_cutoff=0.0, memory_limit=None, nocluster=False, verbose=False, clusters_file=None):
#     def write_seqs_to_fasta(self, outfile, names):


import sys
import os
import pickle
import pyfastaq
from ariba import common, reference_data
        return new_clusters


    def run(self, outdir):
        original_dir = os.getcwd()

        if self.force and os.path.exists(outdir):
            common.rmtree(outdir)

        if os.path.exists(outdir):
            raise Error('Error! Output directory ' + outdir + ' already exists. Cannot continue')

        try:
            os.mkdir(outdir)
        except:
            raise Error('Error making output directory ' + outdir + '. Cannot continue')

        with open(os.path.join(outdir, '00.version_info.txt'), 'w') as f:
            print('ARIBA run with this command:', file=f)
            print(' '.join([sys.argv[0]] + ['prepareref'] + sys.argv[1:]), file=f)
            print('from this directory:', original_dir, file=f)
            print(file=f)
            print(*self.version_report_lines, sep='\n', file=f)

        if self.all_coding is not None:
            assert len(self.metadata_tsv_files) == 0
            assert self.all_coding in {'yes', 'no'}
            self.metadata_tsv_files = [os.path.join(outdir, '00.auto_metadata.tsv')]
            f_out = pyfastaq.utils.open_file_write(self.metadata_tsv_files[0])
            for fasta_file in self.fasta_files:

# 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/reference_data.py
# class Error (Exception): pass
# class ReferenceData:
#     def __init__(self,
#         fasta_files,
#         metadata_tsv_files,
#         rename_file=None,
#         min_gene_length=6,
#         max_gene_length=10000,
#         min_noncoding_length=6,
#         max_noncoding_length=20000,
#         genetic_code=11,
#         parameters_file=None,
#     ):
#     def _load_rename_file(cls, filename):
#     def _load_metadata_tsv(cls, filename, metadata_dict):
#     def _load_all_metadata_tsvs(cls, filenames):
#     def _load_fasta_file(cls, filename, seq_dict):
#     def _load_all_fasta_files(cls, filenames):
#     def _load_input_files_and_check_seq_names(fasta_files, metadata_files):
#     def _write_metadata_tsv(cls, metadata, filename):
#     def _write_sequences_to_files(cls, sequences, metadata, outprefix):
#     def _filter_bad_variant_data(cls, sequences, all_metadata, out_prefix, removed_sequences):
#     def _try_to_get_gene_seq(cls, seq, min_length, max_length):
#     def _check_noncoding_seq(cls, seq, min_length, max_length):
#     def _remove_bad_genes(cls, sequences, metadata, log_file, min_gene_length, max_gene_length):
#     def _remove_bad_noncoding_seqs(cls, sequences, metadata, log_file, min_noncoding_length, max_noncoding_length):
#     def sanity_check(self, outprefix):
#     def _new_seq_name(cls, name):
#     def _seq_names_to_rename_dict(cls, names):
#     def _rename_names_in_seq_dict(cls, seq_dict, rename_dict):
#     def _rename_metadata_set(cls, metadata_set, new_name):
#     def _rename_names_in_metadata(cls, meta_dict, rename_dict):
#     def rename_sequences(self, outfile):
#     def sequence_type(self, sequence_name):
#     def sequence(self, sequence_name):
#     def all_non_wild_type_variants(self, ref_name):
#     def write_cluster_allocation_file(clusters, outfile):
#     def cluster_with_cdhit(self, outprefix, seq_identity_threshold=0.9, threads=1, length_diff_cutoff=0.0, memory_limit=None, nocluster=False, verbose=False, clusters_file=None):
#     def write_seqs_to_fasta(self, outfile, names):


# Path: ariba/ref_preparer.py
import sys
import os
import pickle
import pyfastaq
from ariba import common, reference_data

        return new_clusters


    def run(self, outdir):
        original_dir = os.getcwd()

        if self.force and os.path.exists(outdir):
            common.rmtree(outdir)

        if os.path.exists(outdir):
            raise Error('Error! Output directory ' + outdir + ' already exists. Cannot continue')

        try:
            os.mkdir(outdir)
        except:
            raise Error('Error making output directory ' + outdir + '. Cannot continue')

        with open(os.path.join(outdir, '00.version_info.txt'), 'w') as f:
            print('ARIBA run with this command:', file=f)
            print(' '.join([sys.argv[0]] + ['prepareref'] + sys.argv[1:]), file=f)
            print('from this directory:', original_dir, file=f)
            print(file=f)
            print(*self.version_report_lines, sep='\n', file=f)

        if self.all_coding is not None:
            assert len(self.metadata_tsv_files) == 0
            assert self.all_coding in {'yes', 'no'}
            self.metadata_tsv_files = [os.path.join(outdir, '00.auto_metadata.tsv')]
            f_out = pyfastaq.utils.open_file_write(self.metadata_tsv_files[0])
            for fasta_file in self.fasta_files:

                RefPreparer._fasta_to_metadata(fasta_file, f_out, self.all_coding=='yes')