The Python solution is here. IMO Bash definitely isn't a good solution for this calculation.
from itertools import permutations, combinations
one2all ={'A': ('A', 'ALA', 'alanine'),
'R': ('R', 'ARG', 'arginine'),
'N': ('N', 'ASN', 'asparagine'),
'D': ('D', 'ASP', 'aspartic acid'),
'C': ('C', 'CYS', 'cysteine'),
'Q': ('Q', 'GLN', 'glutamine'),
'E': ('E', 'GLU', 'glutamic acid'),
'G': ('G', 'GLY', 'glycine'),
'H': ('H', 'HIS', 'histidine'),
'I': ('I', 'ILE', 'isoleucine'),
'L': ('L', 'LEU', 'leucine'),
'K': ('K', 'LYS', 'lysine'),
'M': ('M', 'MET', 'methionine'),
'F': ('F', 'PHE', 'phenylalanine'),
'P': ('P', 'PRO', 'proline'),
'S': ('S', 'SER', 'serine'),
'T': ('T', 'THR', 'threonine'),
'W': ('W', 'TRP', 'tryptophan'),
'Y': ('Y', 'TYR', 'tyrosine'),
'V': ('V', 'VAL', 'valine'),
'X': ('X', 'GLX', 'glutaminx'),
'Z': ('Z', 'GLI', 'glycine'),
'J': ('J', 'NLE', 'norleucine'),
'U': ('U', 'CYC', 'cysteinc')}
myprotein = [x for x in one2all.keys()]
tetrapeps = combinations(myprotein,4)
peptide = []
count = 0
for x in list(tetrapeps):
peptide.append(''.join(x))
for tetra in peptide:
permpeptides = list(permutations (tetra))
for i in permpeptides:
count +=1
print (''.join(i))
I get 255024 permutations so more than the estimate of 160000, however the code is correct (please see Validation below).
Truncated output
....
JUXV
UVXJ
UVJX
UXVJ
UXJV
UJVX
UJXV
VZJU
VZUJ
VJZU
VJUZ
VUZJ
VUJZ
ZVJU
ZVUJ
ZJVU
ZJUV
ZUVJ
ZUJV
JVZU
JVUZ
JZVU
JZUV
JUVZ
JUZV
UVZJ
UVJZ
UZVJ
UZJV
UJVZ
UJZV
XZJU
XZUJ
XJZU
XJUZ
XUZJ
XUJZ
ZXJU
ZXUJ
ZJXU
ZJUX
ZUXJ
ZUJX
JXZU
JXUZ
JZXU
JZUX
JUXZ
JUZX
UXZJ
UXJZ
UZXJ
UZJX
UJXZ
UJZX
I cut and paste the amino dictionary from here (I wasn't going to write it by hand), AminoAcid.py
by Pasteur.
Validation
The theoretical number of permutations from 4 samples of 20 amino acids is
116280
However, the amino acid chart I used comprised 24 amino acids (I just copied and pasted it). The theoretical number for 24 amino acids is therefore:
255024
This was the number observed in the output of the above code and validated the calculation.
A permutations calutation can be performed online here
I am not sure how the expected output of 160000 was derived but suspect it was a guess.
The permutation equation is as follows, the output of this equation and the code above coincide,
$$ P_{n, r}=\frac{n !}{(n-r) !}$$
n = no. amino acids
r = size of oligopeptide
Permutation by repetition
If the permutation by repetition equation is sought (comment below). The code is:
from itertools import product
myprotein = [x for x in one2all.keys()]
print(len([p for p in product(myprotein, repeat=4)]))
for 20 amino acids this is:
160000
for 24 amino acids:
331776