# 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
        self.raw_score = None
        self.scaled_score = None
        self.milliseconds = None

        # How some of the values are gotten depends on whether this alignment came from SAM
        # or a Seqan alignment.
        if seqan_output:
            self.setup_using_seqan_output(seqan_output, read, reference_dict)
        elif sam_line:
            self.setup_using_sam(sam_line, read_dict, reference_dict)

        self.tally_up_score_and_errors(scoring_scheme)

    def setup_using_seqan_output(self, seqan_output, read, reference_dict):
        """
        This function sets up the Alignment using the Seqan results. This kind of alignment has
        complete details about the alignment.
        """
        seqan_parts = seqan_output.split(',', 9)
        assert len(seqan_parts) >= 10

        self.rev_comp = (seqan_parts[1] == '-')
        self.cigar_parts = re.findall(r'\d+\w', seqan_parts[9])
        self.milliseconds = int(seqan_parts[8])

        self.read = read
        self.read_start_pos = int(seqan_parts[2])
        self.read_end_pos = int(seqan_parts[3])
        self.read_end_gap = self.read.get_length() - self.read_end_pos


# 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

        self.raw_score = None
        self.scaled_score = None
        self.milliseconds = None

        # How some of the values are gotten depends on whether this alignment came from SAM
        # or a Seqan alignment.
        if seqan_output:
            self.setup_using_seqan_output(seqan_output, read, reference_dict)
        elif sam_line:
            self.setup_using_sam(sam_line, read_dict, reference_dict)

        self.tally_up_score_and_errors(scoring_scheme)

    def setup_using_seqan_output(self, seqan_output, read, reference_dict):
        """
        This function sets up the Alignment using the Seqan results. This kind of alignment has
        complete details about the alignment.
        """
        seqan_parts = seqan_output.split(',', 9)
        assert len(seqan_parts) >= 10

        self.rev_comp = (seqan_parts[1] == '-')
        self.cigar_parts = re.findall(r'\d+\w', seqan_parts[9])
        self.milliseconds = int(seqan_parts[8])

        self.read = read
        self.read_start_pos = int(seqan_parts[2])
        self.read_end_pos = int(seqan_parts[3])
        self.read_end_gap = self.read.get_length() - self.read_end_pos


        self.ref = reference_dict[get_nice_header(seqan_parts[0])]