def sampleIdKey(id_):
    """
    Get a sort key for a sample id.

    @param id_: The C{str} id of a sample. This will normally take the form
        of DA222 (letters followed by some digits), but may also have trailing
        non-digits, as in VK211-G.
    @raise ValueError: If id_ contains a digit that is not followed by
        characters that are all also digits.
    @return: A 3-C{tuple} containing the initial C{str} part of id_ then
        the C{int} suffix, if any (else C{0}), then the trailing C{str}, if
        any.
    """
    prefix = ''
    value = 0
    trailing = ''
    state = 'PREFIX'
    for offset, c in enumerate(id_):
        if state == 'PREFIX':
            if c.isdigit():
                state = 'VALUE'
                value = 10 * value + int(c)
            else:
                prefix += c
        elif state == 'VALUE':
            if c.isdigit():
                value = 10 * value + int(c)
            else:
                state = 'TRAILING'
                trailing += c
        else:
            trailing += c
    return prefix, value, trailing
