# Path: kleborate/__main__.py
# def get_chromosome_mlst_results(data_folder, contigs, kp_complex, args):
#     chromosome_mlst_header = get_chromosome_mlst_header()
# 
#     if kp_complex:
#         seqs = data_folder + '/Klebsiella_pneumoniae.fasta'
#         database = data_folder + '/kpneumoniae.txt'
#         chr_st, chr_st_detail, _, _ = \
#             mlst_blast(seqs, database, 'no', [contigs], min_cov=args.min_coverage,
#                        min_ident=args.min_identity, max_missing=3, allow_multiple=False)
#         if chr_st != '0':
#             chr_st = 'ST' + chr_st
#         chr_st_with_subsp = get_kp_subspecies_based_on_st(chr_st)
# 
#         assert len(chromosome_mlst_header) == len(chr_st_detail)
# 
#         results = {'ST': chr_st_with_subsp,
#                    'Chr_ST': chr_st}
# 
#     else:
#         results = {'ST': "NA",
#                    'Chr_ST': "NA"}
#         chr_st_detail = ['-'] * len(chromosome_mlst_header)
# 
#     results.update(dict(zip(get_chromosome_mlst_header(), chr_st_detail)))
#     return results
# 
# def gunzip_contigs_if_necessary(contigs, temp_dir):
#     if get_compression_type(contigs) == 'gz':
#         name = get_strain_name(contigs)
#         new_contigs = temp_dir + '/' + name + '.fasta'
#         decompress_file(contigs, new_contigs)
#         return new_contigs
#     else:
#         return contigs
# 
# def get_kp_subspecies_based_on_st(chr_st):
#     ozaenae_sts = {'ST90', 'ST91', 'ST92', 'ST93', 'ST95', 'ST96', 'ST97', 'ST381', 'ST777',
#                    'ST3193', 'ST3766', 'ST3768', 'ST3771', 'ST3781', 'ST3782', 'ST3784', 'ST3802',
#                    'ST3803'}
#     rhinoscleromatis_sts = {'ST67', 'ST68', 'ST69', 'ST3772', 'ST3819'}
#     chr_st_minus_1lv = chr_st.replace('-1LV', '')  # 1LV still results in a subspecies call
#     if chr_st_minus_1lv in ozaenae_sts:
#         return chr_st + ' (subsp. ozaenae)'
#     if chr_st_minus_1lv in rhinoscleromatis_sts:
#         return chr_st + ' (subsp. rhinoscleromatis)'
#     return chr_st


import collections
import tempfile
import unittest
from kleborate.__main__ import get_chromosome_mlst_results, gunzip_contigs_if_necessary, \
    get_kp_subspecies_based_on_st
Copyright 2020 Kat Holt
Copyright 2020 Ryan Wick (rrwick@gmail.com)
https://github.com/katholt/Kleborate/

This file is part of Kleborate. Kleborate is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version. Kleborate is distributed in
the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
details. You should have received a copy of the GNU General Public License along with Kleborate. If
not, see <http://www.gnu.org/licenses/>.
"""




class TestMlst(unittest.TestCase):
    """
    Tests chromosomal MLST calls.
    """

    def setUp(self):
        self.data_dir = 'test/test_mlst/data'
        Args = collections.namedtuple('Args', ['min_coverage', 'min_identity'])
        self.args = Args(min_coverage=80.0, min_identity=90.0)

    def test_chromosome_random(self):
        """
        This test has just random sequence and should give no MLST call.
        """

# Path: kleborate/__main__.py
# def get_chromosome_mlst_results(data_folder, contigs, kp_complex, args):
#     chromosome_mlst_header = get_chromosome_mlst_header()
# 
#     if kp_complex:
#         seqs = data_folder + '/Klebsiella_pneumoniae.fasta'
#         database = data_folder + '/kpneumoniae.txt'
#         chr_st, chr_st_detail, _, _ = \
#             mlst_blast(seqs, database, 'no', [contigs], min_cov=args.min_coverage,
#                        min_ident=args.min_identity, max_missing=3, allow_multiple=False)
#         if chr_st != '0':
#             chr_st = 'ST' + chr_st
#         chr_st_with_subsp = get_kp_subspecies_based_on_st(chr_st)
# 
#         assert len(chromosome_mlst_header) == len(chr_st_detail)
# 
#         results = {'ST': chr_st_with_subsp,
#                    'Chr_ST': chr_st}
# 
#     else:
#         results = {'ST': "NA",
#                    'Chr_ST': "NA"}
#         chr_st_detail = ['-'] * len(chromosome_mlst_header)
# 
#     results.update(dict(zip(get_chromosome_mlst_header(), chr_st_detail)))
#     return results
# 
# def gunzip_contigs_if_necessary(contigs, temp_dir):
#     if get_compression_type(contigs) == 'gz':
#         name = get_strain_name(contigs)
#         new_contigs = temp_dir + '/' + name + '.fasta'
#         decompress_file(contigs, new_contigs)
#         return new_contigs
#     else:
#         return contigs
# 
# def get_kp_subspecies_based_on_st(chr_st):
#     ozaenae_sts = {'ST90', 'ST91', 'ST92', 'ST93', 'ST95', 'ST96', 'ST97', 'ST381', 'ST777',
#                    'ST3193', 'ST3766', 'ST3768', 'ST3771', 'ST3781', 'ST3782', 'ST3784', 'ST3802',
#                    'ST3803'}
#     rhinoscleromatis_sts = {'ST67', 'ST68', 'ST69', 'ST3772', 'ST3819'}
#     chr_st_minus_1lv = chr_st.replace('-1LV', '')  # 1LV still results in a subspecies call
#     if chr_st_minus_1lv in ozaenae_sts:
#         return chr_st + ' (subsp. ozaenae)'
#     if chr_st_minus_1lv in rhinoscleromatis_sts:
#         return chr_st + ' (subsp. rhinoscleromatis)'
#     return chr_st


# Path: test/test_mlst.py
import collections
import tempfile
import unittest
from kleborate.__main__ import get_chromosome_mlst_results, gunzip_contigs_if_necessary, \
    get_kp_subspecies_based_on_st

Copyright 2020 Kat Holt
Copyright 2020 Ryan Wick (rrwick@gmail.com)
https://github.com/katholt/Kleborate/

This file is part of Kleborate. Kleborate is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version. Kleborate is distributed in
the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
details. You should have received a copy of the GNU General Public License along with Kleborate. If
not, see <http://www.gnu.org/licenses/>.
"""




class TestMlst(unittest.TestCase):
    """
    Tests chromosomal MLST calls.
    """

    def setUp(self):
        self.data_dir = 'test/test_mlst/data'
        Args = collections.namedtuple('Args', ['min_coverage', 'min_identity'])
        self.args = Args(min_coverage=80.0, min_identity=90.0)

    def test_chromosome_random(self):
        """
        This test has just random sequence and should give no MLST call.
        """

        results = get_chromosome_mlst_results(self.data_dir,