Raises error if invalid SAM format detected

    Args:
        entries (list): A list of SamEntry instances

        line (int): Line number of first entry

    Raises:
        FormatError: Error when SAM format incorrect with descriptive message

def sam_verifier(entries, line=None):
    """Raises error if invalid SAM format detected

    Args:
        entries (list): A list of SamEntry instances

        line (int): Line number of first entry

    Raises:
        FormatError: Error when SAM format incorrect with descriptive message
    """

    regex = r'^[!-?A-~]{1,255}\t' \
            + r'([0-9]{1,4}|[0-5][0-9]{4}|' \
            + r'[0-9]{1,4}|[1-5][0-9]{4}|' \
            + r'6[0-4][0-9]{3}|65[0-4][0-9]{2}|' \
            + r'655[0-2][0-9]|6553[0-7])\t' \
            + r'\*|[!-()+-<>-~][!-~]*\t' \
            + r'([0-9]{1,9}|1[0-9]{9}|2(0[0-9]{8}|' \
            + r'1([0-3][0-9]{7}|4([0-6][0-9]{6}|' \
            + r'7([0-3][0-9]{5}|4([0-7][0-9]{4}|' \
            + r'8([0-2][0-9]{3}|3([0-5][0-9]{2}|' \
            + r'6([0-3][0-9]|4[0-7])))))))))\t' \
            + r'([0-9]{1,2}|1[0-9]{2}|' \
            + r'2[0-4][0-9]|25[0-5])\t' \
            + r'\*|([0-9]+[MIDNSHPX=])+\t' \
            + r'\*|=|[!-()+-<>-~][!-~]*\t' \
            + r'([0-9]{1,9}|1[0-9]{9}|2(0[0-9]{8}|' \
            + r'1([0-3][0-9]{7}|4([0-6][0-9]{6}|' \
            + r'7([0-3][0-9]{5}|4([0-7][0-9]{4}|' \
            + r'8([0-2][0-9]{3}|3([0-5][0-9]{2}|' \
            + r'6([0-3][0-9]|4[0-7])))))))))\t' \
            + r'-?([0-9]{1,9}|1[0-9]{9}|2(0[0-9]{8}|' \
            + r'1([0-3][0-9]{7}|4([0-6][0-9]{6}|' \
            + r'7([0-3][0-9]{5}|4([0-7][0-9]{4}|' \
            + r'8([0-2][0-9]{3}|3([0-5][0-9]{2}|' \
            + r'6([0-3][0-9]|4[0-7])))))))))\t' \
            + r'\*|[A-Za-z=.]+\t' \
            + r'[!-~]+{0}$'.format(os.linesep)
    delimiter = r'\t'

    for entry in entries:
        try:
            entry_verifier([entry.write()], regex, delimiter)
        except FormatError as error:
            # Format info on what entry error came from
            if line:
                intro = 'Line {0}'.format(str(line))
            elif error.part == 0:
                intro = 'An entry with reference {0}'.format(entry.rname)
            else:
                intro = 'An entry with query {0}'.format(entry.qname)

            # Generate error
            if error.part == 0:
                if len(entry.qname) == 0:
                    msg = '{0} has no query name'.format(intro)
                elif len(entry.qname) > 255:
                    msg = '{0} query name must be less than 255 ' \
                          'characters'.format(intro)
                else:
                    msg = '{0} query name contains characters not in ' \
                          '[!-?A-~]'.format(intro)
            elif error.part == 1:
                msg = '{0} flag not in range [0-(2^31-1)]'.format(intro)
            elif error.part == 2:
                if len(entry.rname) == 0:
                    msg = '{0} has no reference name'.format(intro)
                else:
                    msg = '{0} reference name has characters not in ' \
                          '[!-()+-<>-~][!-~]'.format(intro)
            elif error.part == 3:
                msg = '{0} leftmost position not in range ' \
                      '[0-(2^31-1)]'.format(intro)
            elif error.part == 4:
                msg = '{0} mapping quality not in range ' \
                      '[0-(2^8-1)]'.format(intro)
            elif error.part == 5:
                msg = '{0} CIGAR string has characters not in ' \
                      '[0-9MIDNSHPX=]'.format(intro)
            elif error.part == 6:
                msg = '{0} mate read name has characters not in ' \
                      '[!-()+-<>-~][!-~]'.format(intro)
            elif error.part == 7:
                msg = '{0} mate read position not in range ' \
                      '[0-(2^31-1)]'.format(intro)
            elif error.part == 8:
                msg = '{0} template length not in range ' \
                      '[(-2^31+1)-(2^31-1)]'.format(intro)
            elif error.part == 9:
                msg = '{0} sequence has characters not in ' \
                      '[A-Za-z=.]'.format(intro)
            elif error.part == 10:
                msg = '{0} quality scores has characters not in ' \
                      '[!-~]'.format(intro)
            else:
                msg = '{0}: Unknown Error: Likely a Bug'.format(intro)
            raise FormatError(message=msg)

        if line:
            line += 1