def convert_seq_to_kmer_embedding(seq, k, kmer2idx_dic,
                                  l2d=False):
    """
    Convert RNA sequence to k-mer embedding (mapping k-mers to numbers). Returns
    k-mer index list with length LL = ((LS - k) / s) + 1
    So e.g. s = 1 (stride), k = 3, LS = 5 (sequence length),
    LL (returned list length)
    LL = 5-3+1 = 3

    l2d:
        Instead of returning list of indices, return list of lists of indices.

    >>> seq = "ACGUA"
    >>> kmer2idx_dic = {'AA': 1, 'AC': 2, 'AG': 3, 'AU': 4, 'CA': 5, 'CC': 6, 'CG': 7, 'CU': 8, 'GA': 9, 'GC': 10, 'GG': 11, 'GU': 12, 'UA': 13, 'UC': 14, 'UG': 15, 'UU': 16}
    >>> k = 2
    >>> convert_seq_to_kmer_embedding(seq, k, kmer2idx_dic)
    [2, 7, 12, 13]
    >>> convert_seq_to_kmer_embedding(seq, k, kmer2idx_dic, l2d=True)
    [[2], [7], [12], [13]]


    """
    assert seq, "invalid seq given"
    kmer_idx_list = []
    l_seq = len(seq)
    for ki in range(l_seq):
        win_s = ki
        win_e = ki + k
        if win_e > l_seq:
            break
        kmer = seq[win_s:win_e]
        assert kmer in kmer2idx_dic, "k-mer %s not in kmer2idx_dic" %(kmer)
        k_idx = kmer2idx_dic[kmer]
        if l2d:
            kmer_idx_list.append([k_idx])
        else:
            kmer_idx_list.append(k_idx)
    assert kmer_idx_list, "kmer_idx_list empty"
    return kmer_idx_list