# Path: unicycler/misc.py
# def get_nice_header(header):
#     """
#     For a header with a SPAdes/Velvet format, this function returns a simplified string that is
#     just NODE_XX where XX is the contig number.
#     For any other format, this function trims off everything following the first whitespace.
#     """
#     if is_header_spades_format(header):
#         return 'NODE_' + header.split('_')[1]
#     else:
#         return header.split()[0]
# 
# def reverse_complement(seq):
#     """
#     Given a DNA sequences, this function returns the reverse complement sequence.
#     """
#     return ''.join([complement_base(x) for x in seq][::-1])
# 
# def float_to_str(num, decimals, max_num=0):
#     """
#     Converts a number to a string. Will add left padding based on the max value to ensure numbers
#     align well. Will also add commas to numbers over 1000.
#     """
#     if decimals == 0:
#         return int_to_str(int(round(num)), max_num=max_num)
#     if num is None:
#         num_str = 'n/a'
#     else:
#         num_str = '%.' + str(decimals) + 'f'
#         num_str = num_str % num
#         parts = num_str.split('.')
#         before_decimal = parts[0]
#         after_decimal = parts[1]
#         num_str = int_to_str(int(before_decimal)) + '.' + after_decimal
#     if max_num > 0:
#         max_str = float_to_str(max_num, decimals)
#         num_str = num_str.rjust(len(max_str))
#     return num_str


import re
from .misc import get_nice_header, reverse_complement, float_to_str
                    if read_base == ref_base:
                        self.match_count += 1
                        cigar_score += scoring_scheme.match
                    else:
                        self.mismatch_count += 1
                        cigar_score += scoring_scheme.mismatch
                    read_i += 1
                    ref_i += 1

            self.raw_score += cigar_score
            align_i += cigar_count

        self.percent_identity = 100.0 * self.match_count / align_i
        self.edit_distance = self.mismatch_count + self.insertion_count + self.deletion_count
        self.alignment_length = align_i
        perfect_score = scoring_scheme.match * self.alignment_length
        worst_score = scoring_scheme.mismatch * self.alignment_length
        self.scaled_score = 100.0 * (self.raw_score - worst_score) / (perfect_score - worst_score)

    def __repr__(self):
        read_start, read_end = self.read_start_end_positive_strand()
        return_str = self.read.name + ' (' + str(read_start) + '-' + str(read_end) + ', '
        if self.rev_comp:
            return_str += 'strand: -), '
        else:
            return_str += 'strand: +), '
        return_str += self.ref.name + ' (' + str(self.ref_start_pos) + '-' + \
            str(self.ref_end_pos) + ')'
        if self.scaled_score is not None:
            return_str += ', raw score = ' + str(self.raw_score)

# Path: unicycler/misc.py
# def get_nice_header(header):
#     """
#     For a header with a SPAdes/Velvet format, this function returns a simplified string that is
#     just NODE_XX where XX is the contig number.
#     For any other format, this function trims off everything following the first whitespace.
#     """
#     if is_header_spades_format(header):
#         return 'NODE_' + header.split('_')[1]
#     else:
#         return header.split()[0]
# 
# def reverse_complement(seq):
#     """
#     Given a DNA sequences, this function returns the reverse complement sequence.
#     """
#     return ''.join([complement_base(x) for x in seq][::-1])
# 
# def float_to_str(num, decimals, max_num=0):
#     """
#     Converts a number to a string. Will add left padding based on the max value to ensure numbers
#     align well. Will also add commas to numbers over 1000.
#     """
#     if decimals == 0:
#         return int_to_str(int(round(num)), max_num=max_num)
#     if num is None:
#         num_str = 'n/a'
#     else:
#         num_str = '%.' + str(decimals) + 'f'
#         num_str = num_str % num
#         parts = num_str.split('.')
#         before_decimal = parts[0]
#         after_decimal = parts[1]
#         num_str = int_to_str(int(before_decimal)) + '.' + after_decimal
#     if max_num > 0:
#         max_str = float_to_str(max_num, decimals)
#         num_str = num_str.rjust(len(max_str))
#     return num_str


# Path: unicycler/alignment.py
import re
from .misc import get_nice_header, reverse_complement, float_to_str

                    if read_base == ref_base:
                        self.match_count += 1
                        cigar_score += scoring_scheme.match
                    else:
                        self.mismatch_count += 1
                        cigar_score += scoring_scheme.mismatch
                    read_i += 1
                    ref_i += 1

            self.raw_score += cigar_score
            align_i += cigar_count

        self.percent_identity = 100.0 * self.match_count / align_i
        self.edit_distance = self.mismatch_count + self.insertion_count + self.deletion_count
        self.alignment_length = align_i
        perfect_score = scoring_scheme.match * self.alignment_length
        worst_score = scoring_scheme.mismatch * self.alignment_length
        self.scaled_score = 100.0 * (self.raw_score - worst_score) / (perfect_score - worst_score)

    def __repr__(self):
        read_start, read_end = self.read_start_end_positive_strand()
        return_str = self.read.name + ' (' + str(read_start) + '-' + str(read_end) + ', '
        if self.rev_comp:
            return_str += 'strand: -), '
        else:
            return_str += 'strand: +), '
        return_str += self.ref.name + ' (' + str(self.ref_start_pos) + '-' + \
            str(self.ref_end_pos) + ')'
        if self.scaled_score is not None:
            return_str += ', raw score = ' + str(self.raw_score)

            return_str += ', scaled score = ' + float_to_str(self.scaled_score, 2)