# 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 all is good with the CIGAR, then we should never end up with a ref_end_pos out of the
        # reference range. But we check just to be safe.
        if self.ref_end_pos > len(self.ref.sequence):
            self.ref_end_pos = len(self.ref.sequence)

    def tally_up_score_and_errors(self, scoring_scheme):
        """
        This function steps through the CIGAR string for the alignment to get the score, identity
        and count/locations of errors.
        """
        # Clear any existing tallies.
        self.match_count = 0
        self.mismatch_count = 0
        self.insertion_count = 0
        self.deletion_count = 0
        self.percent_identity = 0.0
        self.raw_score = 0

        # Remove the soft clipping parts of the CIGAR string for tallying.
        cigar_parts = self.cigar_parts[:]
        if cigar_parts[0][-1] == 'S':
            cigar_parts.pop(0)
        if cigar_parts and cigar_parts[-1][-1] == 'S':
            cigar_parts.pop()
        if not cigar_parts:
            return

        read_len = self.read.get_length()
        if self.rev_comp:

# 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 all is good with the CIGAR, then we should never end up with a ref_end_pos out of the
        # reference range. But we check just to be safe.
        if self.ref_end_pos > len(self.ref.sequence):
            self.ref_end_pos = len(self.ref.sequence)

    def tally_up_score_and_errors(self, scoring_scheme):
        """
        This function steps through the CIGAR string for the alignment to get the score, identity
        and count/locations of errors.
        """
        # Clear any existing tallies.
        self.match_count = 0
        self.mismatch_count = 0
        self.insertion_count = 0
        self.deletion_count = 0
        self.percent_identity = 0.0
        self.raw_score = 0

        # Remove the soft clipping parts of the CIGAR string for tallying.
        cigar_parts = self.cigar_parts[:]
        if cigar_parts[0][-1] == 'S':
            cigar_parts.pop(0)
        if cigar_parts and cigar_parts[-1][-1] == 'S':
            cigar_parts.pop()
        if not cigar_parts:
            return

        read_len = self.read.get_length()
        if self.rev_comp:

            read_seq = reverse_complement(self.read.sequence)