# 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/sequence_metadata.py
# class Error (Exception): pass
# class SequenceMetadata:
#     def __init__(self, line):
#     def __eq__(self, other):
#     def __lt__(self, other):
#     def __hash__(self):
#     def __str__(self):
#     def to_string(self, separator='\t'):
#     def has_variant(self, seq):


import unittest
import filecmp
import os
import pyfastaq
from ariba import reference_data, sequence_metadata
        tests = [
            (pyfastaq.sequences.Fasta('x', 'ACGTG'), None, 'REMOVE\tToo short. Length: 5'),
            (pyfastaq.sequences.Fasta('x', 'A' * 100), None, 'REMOVE\tToo long. Length: 100'),
            (pyfastaq.sequences.Fasta('x', 'GAGGAGCCG'), None, 'REMOVE\tDoes not look like a gene (tried both strands and all reading frames) GAGGAGCCG'),
            (pyfastaq.sequences.Fasta('x', 'ATGTAACCT'), None, 'REMOVE\tDoes not look like a gene (tried both strands and all reading frames) ATGTAACCT'),
            (pyfastaq.sequences.Fasta('x', 'ATGCCTTAA'), pyfastaq.sequences.Fasta('x', 'ATGCCTTAA'), 'KEEP\tMade into gene. strand=+, frame=0')
        ]

        for seq, got_seq, message in tests:
            self.assertEqual((got_seq, message), reference_data.ReferenceData._try_to_get_gene_seq(seq, 6, 99))

    def test_check_noncoding_seq(self):
        '''Test _check_noncoding_seq'''
        tests = [
            (pyfastaq.sequences.Fasta('x', 'A' * 3), False, 'REMOVE\tToo short. Length: 3'),
            (pyfastaq.sequences.Fasta('x', 'A' * 21), False, 'REMOVE\tToo long. Length: 21'),
            (pyfastaq.sequences.Fasta('x', 'A' * 5), True, None),
            (pyfastaq.sequences.Fasta('x', 'A' * 4), True, None),
            (pyfastaq.sequences.Fasta('x', 'A' * 20), True, None)
        ]

        for seq, valid, message in tests:
            self.assertEqual((valid, message), reference_data.ReferenceData._check_noncoding_seq(seq, 4, 20))


    def test_remove_bad_genes(self):
        '''Test _remove_bad_genes'''
        test_seq_dict = {}
        fasta_file = os.path.join(data_dir, 'reference_data_remove_bad_genes.in.fa')
        metadata_file = os.path.join(data_dir, 'reference_data_remove_bad_genes.in.tsv')

# 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/sequence_metadata.py
# class Error (Exception): pass
# class SequenceMetadata:
#     def __init__(self, line):
#     def __eq__(self, other):
#     def __lt__(self, other):
#     def __hash__(self):
#     def __str__(self):
#     def to_string(self, separator='\t'):
#     def has_variant(self, seq):


# Path: ariba/tests/reference_data_test.py
import unittest
import filecmp
import os
import pyfastaq
from ariba import reference_data, sequence_metadata

        tests = [
            (pyfastaq.sequences.Fasta('x', 'ACGTG'), None, 'REMOVE\tToo short. Length: 5'),
            (pyfastaq.sequences.Fasta('x', 'A' * 100), None, 'REMOVE\tToo long. Length: 100'),
            (pyfastaq.sequences.Fasta('x', 'GAGGAGCCG'), None, 'REMOVE\tDoes not look like a gene (tried both strands and all reading frames) GAGGAGCCG'),
            (pyfastaq.sequences.Fasta('x', 'ATGTAACCT'), None, 'REMOVE\tDoes not look like a gene (tried both strands and all reading frames) ATGTAACCT'),
            (pyfastaq.sequences.Fasta('x', 'ATGCCTTAA'), pyfastaq.sequences.Fasta('x', 'ATGCCTTAA'), 'KEEP\tMade into gene. strand=+, frame=0')
        ]

        for seq, got_seq, message in tests:
            self.assertEqual((got_seq, message), reference_data.ReferenceData._try_to_get_gene_seq(seq, 6, 99))

    def test_check_noncoding_seq(self):
        '''Test _check_noncoding_seq'''
        tests = [
            (pyfastaq.sequences.Fasta('x', 'A' * 3), False, 'REMOVE\tToo short. Length: 3'),
            (pyfastaq.sequences.Fasta('x', 'A' * 21), False, 'REMOVE\tToo long. Length: 21'),
            (pyfastaq.sequences.Fasta('x', 'A' * 5), True, None),
            (pyfastaq.sequences.Fasta('x', 'A' * 4), True, None),
            (pyfastaq.sequences.Fasta('x', 'A' * 20), True, None)
        ]

        for seq, valid, message in tests:
            self.assertEqual((valid, message), reference_data.ReferenceData._check_noncoding_seq(seq, 4, 20))


    def test_remove_bad_genes(self):
        '''Test _remove_bad_genes'''
        test_seq_dict = {}
        fasta_file = os.path.join(data_dir, 'reference_data_remove_bad_genes.in.fa')
        metadata_file = os.path.join(data_dir, 'reference_data_remove_bad_genes.in.tsv')

        metadata = reference_data.ReferenceData._load_all_metadata_tsvs([metadata_file])