How to create all possible k-mers with a set of alphabets?

join.(Iterators.product(Iterators.repeated(nucs,3)...))

may be what you are looking for. Notice the ... compared to what you suggested: this is called splatting.

Its performance can be problematic if you splat large iterators, but in this case the cost of calling Iterators.product will be much higher anyway so it shouldn’t matter. I would not advise replacing 3 with a number larger than 10 though, as you will probably need a few Gb to store the resulting array.

3 Likes