# Path: kleborate/misc.py
# def load_fasta(filename):
#     """
#     Returns the names and sequences for the given fasta file as a list of tuples (name, seq).
#     """
#     fasta_seqs = []
#     with get_open_func(filename)(filename, 'rt') as fasta_file:
#         name = ''
#         sequence = ''
#         for line in fasta_file:
#             line = line.strip()
#             if not line:
#                 continue
#             if line[0] == '>':  # Header line = start of new contig
#                 if name:
#                     fasta_seqs.append((name.split()[0], sequence.upper()))
#                     sequence = ''
#                 name = line[1:]
#             else:
#                 sequence += line
#         if name:
#             fasta_seqs.append((name.split()[0], sequence.upper()))
#     return fasta_seqs


import collections
from .misc import load_fasta
"""
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/>.
"""




def get_contig_stat_results(contigs, kp_complex):
    contig_count, n50, longest_contig, total_size, ambiguous_bases = get_contig_stats(contigs)
    qc_warnings = get_qc_warnings(total_size, n50, ambiguous_bases, kp_complex)
    return {'contig_count': str(contig_count),
            'N50': str(n50),
            'largest_contig': str(longest_contig),
            'total_size': str(total_size),
            'ambiguous_bases': ambiguous_bases,
            'QC_warnings': qc_warnings}


def get_contig_stats(assembly):

# Path: kleborate/misc.py
# def load_fasta(filename):
#     """
#     Returns the names and sequences for the given fasta file as a list of tuples (name, seq).
#     """
#     fasta_seqs = []
#     with get_open_func(filename)(filename, 'rt') as fasta_file:
#         name = ''
#         sequence = ''
#         for line in fasta_file:
#             line = line.strip()
#             if not line:
#                 continue
#             if line[0] == '>':  # Header line = start of new contig
#                 if name:
#                     fasta_seqs.append((name.split()[0], sequence.upper()))
#                     sequence = ''
#                 name = line[1:]
#             else:
#                 sequence += line
#         if name:
#             fasta_seqs.append((name.split()[0], sequence.upper()))
#     return fasta_seqs


# Path: kleborate/contig_stats.py
import collections
from .misc import load_fasta

"""
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/>.
"""




def get_contig_stat_results(contigs, kp_complex):
    contig_count, n50, longest_contig, total_size, ambiguous_bases = get_contig_stats(contigs)
    qc_warnings = get_qc_warnings(total_size, n50, ambiguous_bases, kp_complex)
    return {'contig_count': str(contig_count),
            'N50': str(n50),
            'largest_contig': str(longest_contig),
            'total_size': str(total_size),
            'ambiguous_bases': ambiguous_bases,
            'QC_warnings': qc_warnings}


def get_contig_stats(assembly):

    fasta = load_fasta(assembly)