# Path: circlator/start_fixer.py
# class Error (Exception): pass
# class StartFixer:
#     def __init__(self,
#         input_assembly_fa,
#         outprefix,
#         min_percent_identity=70,
#         promer_mincluster=None,
#         genes_fa=None,
#         ignore=None,
#         verbose=False,
#     ):
#     def _rename_contigs(cls, contigs_dict):
#     def _write_renamed_contigs(cls, contigs_dict, rename_dict, outfile):
#     def _max_length_from_fasta_file(cls, infile):
#     def _write_fasta_plus_circularized_ends(cls, contigs, outfile, end_length, ignore=None):
#     def _find_circular_using_promer(cls, outprefix, ref_genes_fa, contigs_dict, min_percent_id, end_length, log_fh, ignore=None, promer_mincluster=None):
#     def _find_circular_using_prodigal(cls, outprefix, contigs_dict, circular_from_promer, log_fh, ignore=None):
#     def _rearrange_contigs(cls, contigs_dict, circular_from_promer, circular_from_prodigal, to_ignore, end_length, log_filename):
#     def run(self):


import unittest
import shutil
import filecmp
import copy
import os
import sys
import pyfastaq
import pymummer
from circlator import start_fixer
        self.assertEqual({'ignore_me1', 'ignore_me2'}, sfixer.ignore)


    def test_rename_contigs(self):
        '''Test _rename_contigs'''
        contigs_in = {
            'ctg1': pyfastaq.sequences.Fasta('ctg1', 'ACGT'),
            'ctg2 foo bar': pyfastaq.sequences.Fasta('ctg2 foo bar', 'AAA'),
        }
        expected_contigs = {
            'ctg1': pyfastaq.sequences.Fasta('ctg1', 'ACGT'),
            'ctg2': pyfastaq.sequences.Fasta('ctg2', 'AAA'),
        }
        expected_names = {'ctg1': 'ctg1', 'ctg2': 'ctg2 foo bar'}
        got_contigs, got_names = start_fixer.StartFixer._rename_contigs(contigs_in)
        self.assertEqual(expected_names, got_names)
        self.assertEqual(expected_contigs, got_contigs)
        contigs_in['ctg2 abc'] = pyfastaq.sequences.Fasta('ctg2 abc', 'AAA')
        with self.assertRaises(start_fixer.Error):
            start_fixer.StartFixer._rename_contigs(contigs_in)


    def test_write_renamed_contigs(self):
        '''Test _write_renamed_contigs'''
        contigs_dict = {
            'ctg1': pyfastaq.sequences.Fasta('ctg1', 'ACGT'),
            'ctg2': pyfastaq.sequences.Fasta('ctg2', 'AAA'),
        }
        rename_dict = {'ctg1': 'ctg1', 'ctg2': 'ctg2 foo bar'}
        tmp_out = 'tmp.test_write_renamed_contigs.fa'

# Path: circlator/start_fixer.py
# class Error (Exception): pass
# class StartFixer:
#     def __init__(self,
#         input_assembly_fa,
#         outprefix,
#         min_percent_identity=70,
#         promer_mincluster=None,
#         genes_fa=None,
#         ignore=None,
#         verbose=False,
#     ):
#     def _rename_contigs(cls, contigs_dict):
#     def _write_renamed_contigs(cls, contigs_dict, rename_dict, outfile):
#     def _max_length_from_fasta_file(cls, infile):
#     def _write_fasta_plus_circularized_ends(cls, contigs, outfile, end_length, ignore=None):
#     def _find_circular_using_promer(cls, outprefix, ref_genes_fa, contigs_dict, min_percent_id, end_length, log_fh, ignore=None, promer_mincluster=None):
#     def _find_circular_using_prodigal(cls, outprefix, contigs_dict, circular_from_promer, log_fh, ignore=None):
#     def _rearrange_contigs(cls, contigs_dict, circular_from_promer, circular_from_prodigal, to_ignore, end_length, log_filename):
#     def run(self):


# Path: circlator/tests/start_fixer_test.py
import unittest
import shutil
import filecmp
import copy
import os
import sys
import pyfastaq
import pymummer
from circlator import start_fixer

        self.assertEqual({'ignore_me1', 'ignore_me2'}, sfixer.ignore)


    def test_rename_contigs(self):
        '''Test _rename_contigs'''
        contigs_in = {
            'ctg1': pyfastaq.sequences.Fasta('ctg1', 'ACGT'),
            'ctg2 foo bar': pyfastaq.sequences.Fasta('ctg2 foo bar', 'AAA'),
        }
        expected_contigs = {
            'ctg1': pyfastaq.sequences.Fasta('ctg1', 'ACGT'),
            'ctg2': pyfastaq.sequences.Fasta('ctg2', 'AAA'),
        }
        expected_names = {'ctg1': 'ctg1', 'ctg2': 'ctg2 foo bar'}
        got_contigs, got_names = start_fixer.StartFixer._rename_contigs(contigs_in)
        self.assertEqual(expected_names, got_names)
        self.assertEqual(expected_contigs, got_contigs)
        contigs_in['ctg2 abc'] = pyfastaq.sequences.Fasta('ctg2 abc', 'AAA')
        with self.assertRaises(start_fixer.Error):
            start_fixer.StartFixer._rename_contigs(contigs_in)


    def test_write_renamed_contigs(self):
        '''Test _write_renamed_contigs'''
        contigs_dict = {
            'ctg1': pyfastaq.sequences.Fasta('ctg1', 'ACGT'),
            'ctg2': pyfastaq.sequences.Fasta('ctg2', 'AAA'),
        }
        rename_dict = {'ctg1': 'ctg1', 'ctg2': 'ctg2 foo bar'}
        tmp_out = 'tmp.test_write_renamed_contigs.fa'

        start_fixer.StartFixer._write_renamed_contigs(contigs_dict, rename_dict, tmp_out)