# Path: ariba/ref_seq_chooser.py
# class Error (Exception): pass
# class RefSeqChooser:
#     def __init__(self,
#         cluster_fasta,
#         all_refs_fasta,
#         assembly_fasta_in,
#         assembly_fasta_out,
#         log_fh,
#         contig_name_prefix='',
#         nucmer_min_id=90,
#         nucmer_min_len=20,
#         nucmer_breaklen=200,
#     ):
#     def _make_matching_contig_pieces_fasta(cls, contig_fasta, coords_list, outfile):
#     def _sequence_is_in_fasta_file(cls, seq_name, fasta_file):
#     def _load_nucmer_coords_file(cls, coords_file, log_fh=None):
#     def _l_and_c_from_contig_name(cls, name):
#     def _best_of_two_hits(cls, hit1, hit2, use_qry_length=False, check_flanking=False):
#     def _choose_best_nucmer_match(cls, matches, use_qry_length=False, check_flanking=False):
#     def _closest_nucmer_match_between_fastas(cls, ref_fasta, qry_fasta, log_fh, min_id, min_length, breaklen, use_qry_length, check_flanking):
#     def run(self):


import unittest
import sys
import os
import filecmp
import pymummer
from ariba import ref_seq_chooser
        self.assertTrue(filecmp.cmp(expected_file, tmp_file, shallow=False))
        os.unlink(tmp_file)


    def _sequence_is_in_fasta_file(self):
        '''Test _sequence_is_in_fasta_file'''
        fasta = os.path.join(data_dir, 'ref_seq_chooser_sequence_is_in_fasta_file.fa')
        self.assertFalse(ref_seq_chooser.RefSeqChooser._sequence_is_in_fasta_file('not there', fasta))
        self.assertTrue(ref_seq_chooser.RefSeqChooser._sequence_is_in_fasta_file('contig42', fasta))


    def test_run_no_match_in_cluster(self):
        '''Test full run when nearest match is not in the cluster'''
        all_ref_fasta = os.path.join(data_dir, 'ref_seq_chooser_full_run_not_in_cluster.allrefs.fa')
        cluster_fasta = os.path.join(data_dir, 'ref_seq_chooser_full_run_not_in_cluster.clusterrefs.fa')
        contig_fasta = os.path.join(data_dir, 'ref_seq_chooser_full_run_not_in_cluster.contigs.fa')
        tmp_out = 'tmp.ref_seq_chooser_full_run_not_in_cluster.fa'
        refchooser = ref_seq_chooser.RefSeqChooser(cluster_fasta, all_ref_fasta, contig_fasta, tmp_out, sys.stdout)
        refchooser.run()
        self.assertEqual(None, refchooser.closest_ref_from_all_refs)
        self.assertFalse(refchooser.closest_ref_is_in_cluster)
        self.assertFalse(os.path.exists(tmp_out))


    def test_run_no_nucmer_match(self):
        '''Test full run when there is nearest match in cluster, but no nucmer matches'''
        all_ref_fasta = os.path.join(data_dir, 'ref_seq_chooser_full_run_no_nucmer_match.allrefs.fa')
        cluster_fasta = os.path.join(data_dir, 'ref_seq_chooser_full_run_no_nucmer_match.clusterrefs.fa')
        contig_fasta = os.path.join(data_dir, 'ref_seq_chooser_full_run_no_nucmer_match.contigs.fa')
        tmp_out = 'tmp.ref_seq_chooser_full_run_no_nucmer_match.fa'

# Path: ariba/ref_seq_chooser.py
# class Error (Exception): pass
# class RefSeqChooser:
#     def __init__(self,
#         cluster_fasta,
#         all_refs_fasta,
#         assembly_fasta_in,
#         assembly_fasta_out,
#         log_fh,
#         contig_name_prefix='',
#         nucmer_min_id=90,
#         nucmer_min_len=20,
#         nucmer_breaklen=200,
#     ):
#     def _make_matching_contig_pieces_fasta(cls, contig_fasta, coords_list, outfile):
#     def _sequence_is_in_fasta_file(cls, seq_name, fasta_file):
#     def _load_nucmer_coords_file(cls, coords_file, log_fh=None):
#     def _l_and_c_from_contig_name(cls, name):
#     def _best_of_two_hits(cls, hit1, hit2, use_qry_length=False, check_flanking=False):
#     def _choose_best_nucmer_match(cls, matches, use_qry_length=False, check_flanking=False):
#     def _closest_nucmer_match_between_fastas(cls, ref_fasta, qry_fasta, log_fh, min_id, min_length, breaklen, use_qry_length, check_flanking):
#     def run(self):


# Path: ariba/tests/ref_seq_chooser_test.py
import unittest
import sys
import os
import filecmp
import pymummer
from ariba import ref_seq_chooser

        self.assertTrue(filecmp.cmp(expected_file, tmp_file, shallow=False))
        os.unlink(tmp_file)


    def _sequence_is_in_fasta_file(self):
        '''Test _sequence_is_in_fasta_file'''
        fasta = os.path.join(data_dir, 'ref_seq_chooser_sequence_is_in_fasta_file.fa')
        self.assertFalse(ref_seq_chooser.RefSeqChooser._sequence_is_in_fasta_file('not there', fasta))
        self.assertTrue(ref_seq_chooser.RefSeqChooser._sequence_is_in_fasta_file('contig42', fasta))


    def test_run_no_match_in_cluster(self):
        '''Test full run when nearest match is not in the cluster'''
        all_ref_fasta = os.path.join(data_dir, 'ref_seq_chooser_full_run_not_in_cluster.allrefs.fa')
        cluster_fasta = os.path.join(data_dir, 'ref_seq_chooser_full_run_not_in_cluster.clusterrefs.fa')
        contig_fasta = os.path.join(data_dir, 'ref_seq_chooser_full_run_not_in_cluster.contigs.fa')
        tmp_out = 'tmp.ref_seq_chooser_full_run_not_in_cluster.fa'
        refchooser = ref_seq_chooser.RefSeqChooser(cluster_fasta, all_ref_fasta, contig_fasta, tmp_out, sys.stdout)
        refchooser.run()
        self.assertEqual(None, refchooser.closest_ref_from_all_refs)
        self.assertFalse(refchooser.closest_ref_is_in_cluster)
        self.assertFalse(os.path.exists(tmp_out))


    def test_run_no_nucmer_match(self):
        '''Test full run when there is nearest match in cluster, but no nucmer matches'''
        all_ref_fasta = os.path.join(data_dir, 'ref_seq_chooser_full_run_no_nucmer_match.allrefs.fa')
        cluster_fasta = os.path.join(data_dir, 'ref_seq_chooser_full_run_no_nucmer_match.clusterrefs.fa')
        contig_fasta = os.path.join(data_dir, 'ref_seq_chooser_full_run_no_nucmer_match.contigs.fa')
        tmp_out = 'tmp.ref_seq_chooser_full_run_no_nucmer_match.fa'

        refchooser = ref_seq_chooser.RefSeqChooser(cluster_fasta, all_ref_fasta, contig_fasta, tmp_out, sys.stdout)