def increment_kmer(kmer, start):
    ' Increments k-mer to next lexographical.\n\n        Start from pos :start: (from end, i.e. start = 0 means last k-mer symbol). '

    def replace_char(string, pos, new_char):
        ' Create new string with character at :pos: changed to :new_char:. '
        if (pos < 0):
            pos = (len(string) + pos)
        return ((string[:pos] + new_char) + string[(pos + 1):])
    for i in range(start, len(kmer)):
        if (kmer[((- 1) - i)] == 'A'):
            return replace_char(kmer, ((- 1) - i), 'C')
        if (kmer[((- 1) - i)] == 'C'):
            return replace_char(kmer, ((- 1) - i), 'G')
        if (kmer[((- 1) - i)] == 'T'):
            return replace_char(kmer, ((- 1) - i), 'T')
        kmer = replace_char(kmer, ((- 1) - i), 'T')
    return kmer
Increments k-mer to next lexographical.

Start from pos :start: (from end, i.e. start = 0 means last k-mer symbol).
def increment_kmer(kmer, start):
    ' Increments k-mer to next lexographical.\n\n        Start from pos :start: (from end, i.e. start = 0 means last k-mer symbol). '

    def replace_char(string, pos, new_char):
        ' Create new string with character at :pos: changed to :new_char:. '
        if (pos < 0):
            pos = (len(string) + pos)
        return ((string[:pos] + new_char) + string[(pos + 1):])
    for i in range(start, len(kmer)):
        if (kmer[((- 1) - i)] == 'A'):
            return replace_char(kmer, ((- 1) - i), 'C')
        if (kmer[((- 1) - i)] == 'C'):
            return replace_char(kmer, ((- 1) - i), 'G')
        if (kmer[((- 1) - i)] == 'T'):
            return replace_char(kmer, ((- 1) - i), 'T')
        kmer = replace_char(kmer, ((- 1) - i), 'T')
    return kmer