Answering on stux's comments:
However it looks like you need auxiliary tables to do so?
Almost no. I can number out nucleotide triplets just like numbers at base \$4\$ of length \$3\$. itertools.product
does the job well. But yes, we have to know what nucleotides do encode peptid amino-acids and which do not, for this we need the first link.
However, it's rather tricky to get the right sequence for orf1ab
because of it's code consists of \$2\$ overlapping sequences, which is rather rare in the real world, IMHO. They do overlap on the nucleotide at position \$13468\$ (see join(266..13468,13468..21555)
in the above link), so we double this nucleotide, compress, and then cut it out after de-compression (with cut_out
).
Then we compress joined sequences of triplets (not separately because orf1ab+S is rather large compared to other parts and the encoding table (frequences) will not differ much for orf1ab+S compared to all peptid-coding parts joined). Also we compress the non-peptid-encoding parts because we also need them in the output. Joined too.
Then we have to cut
both sequences into apropriate pieces (pieces lengths are genes_len
and rest_len
) and interleave (with for i,j in zip(cut(...,rest_len),cut(...,genes_len))
). \$269\$ is compressed non-peptid-encoding nucleotides length and \$6985\$ is compressed triplets length.
Looking back at the comments it's left only to explain how cut
works. The python reduce
function takes \$3\$ argumets: function(accumulator,item), the sequence and the optional accumulator initial value. Then accumulator on the next step = function(accumulator on the previous step,item from sequence). In other words, reduce
feeds the sequence into the function and returns the accumulator when the sequence runs out. E.g. a way to replace math.prod
: lambda z:reduce(lambda x,y:x*y,z,1)
.
So the accumulator in this particular case is chosen to contain [the sequence to cut,array ot already cut pieces] and acc[0]
is the sequence to cut, acc[1]
is already cut pieces, so acc[0][n:],acc[1]+[acc[0][:n]]
makes perfect sense now, doesn't it? And we need only the reduce
return value at index \$1\$ (i.e. the pieces sequence).
Did I answer all the questions?)