def generate_kmers(seq, k=<NUM_LIT:4>):
if isinstance(seq, basestring):<EOL><INDENT>for i in range(len(seq) - k + <NUM_LIT:1>):<EOL><INDENT>yield seq[i:i + k]<EOL><DEDENT><DEDENT>elif isinstance(seq, (int, float, Decimal)):<EOL><INDENT>for s in generate_kmers(str(seq)):<EOL><INDENT>yield s<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for s in seq:<EOL><INDENT>yield generate_kmers(s, k)<EOL><DEDENT><DEDENT>
Return a generator of all the unique substrings (k-mer or q-gram strings) within a sequence/string

    Not effiicent for large k and long strings.
    Doesn't form substrings that are shorter than k, only exactly k-mers

    Used for algorithms like UniqTag for genome unique identifier locality sensitive hashing.

    jellyfish is a C implementation of k-mer counting

    If seq is a string generate a sequence of k-mer string
    If seq is a sequence of strings then generate a sequence of generators or sequences of k-mer strings
    If seq is a sequence of sequences of strings generate a sequence of sequence of generators ...

    Default k = 4 because that's the length of a gene base-pair?

    >>> ' '.join(generate_kmers('AGATAGATAGACACAGAAATGGGACCACAC'))
    'AGAT GATA ATAG TAGA AGAT GATA ATAG TAGA AGAC GACA ACAC CACA ACAG ... CCAC CACA ACAC'