In this code I am trying to create a dictionary containing the one letter amino-acid code as keys. For each key, there is a sub-dictionary which is the same as the first one, except that this sub-dictionary key's value should be the number of occurrences of firstkey/subkey
which is indicated in the dictionary ref2
.
For some reason I don't know yet, my code is giving the wrong values.
AA = ['G', 'A', 'L', 'M', 'F', 'W', 'K', 'Q', 'E', 'S', 'P', 'V', 'I', 'C', 'Y', 'H', 'R', 'N', 'D', 'T']
d = {}
ref2 = {'A/T': 211, 'V/I': 177, 'I/V': 163, 'R/Q': 160, 'T/A': 159, 'P/L': 131, 'R/H': 124, 'A/V': 121, 'V/A': 120, 'Q/R': 115, 'R/C': 105, 'N/S': 100, 'H/R': 98, 'L/P': 97, 'G/S': 93, 'V/M': 91, 'P/S': 88, 'M/V': 88, 'T/I': 87, 'E/K': 85, 'S/N': 82, 'T/M': 79, 'S/G': 79, 'S/P': 79, 'L/V': 76, 'K/R': 76, 'G/R': 74, 'R/G': 73, 'R/W': 73, 'D/N': 71, 'M/T': 68, 'E/D': 66, 'I/T': 65, 'K/E': 63, 'V/L': 61, 'D/E': 58, 'F/L': 58, 'N/D': 54, 'L/F': 53, 'S/T': 52, 'R/K': 51, 'R/S': 51, 'C/R': 50, 'E/G': 49, 'A/S': 46, 'S/L': 45, 'G/D': 45, 'A/P': 43, 'G/A': 43, 'Q/H': 43, 'D/G': 42, 'M/I': 42, 'W/R': 42, 'S/A': 41, 'P/R': 39, 'P/A': 38, 'A/G': 38, 'R/P': 38, 'Q/E': 38, 'E/Q': 37, 'T/S': 36, 'H/Q': 36, 'G/E': 36, 'I/M': 34, 'Y/C': 33, 'K/N': 33, 'S/R': 32, 'L/S': 31, 'H/Y': 31, 'F/S': 30, 'Y/H': 30, 'G/V': 29, 'P/T': 28, 'T/P': 28, 'S/C': 28, 'C/Y': 26, 'N/K': 25, 'K/T': 24, 'R/L': 23, 'M/L': 23, 'T/N': 22, 'S/F': 21, 'C/S': 21, 'Q/K': 21, 'L/M': 20, 'Y/F': 20, 'G/C': 19, 'I/L': 19, 'D/A': 18, 'L/I': 17, 'V/F': 16, 'T/R': 16, 'L/R': 16, 'T/K': 16, 'K/Q': 16, 'E/V': 16, 'D/H': 15, 'Q/P': 15, 'A/D': 14, 'E/A': 14, 'A/E': 13, 'C/G': 13, 'Q/L': 13, 'V/G': 12, 'P/Q': 12, 'D/V': 12, 'S/Y': 12, 'H/N': 12, 'R/T': 12, 'F/I': 12, 'P/H': 11, 'L/H': 11, 'H/P': 11, 'N/T': 11, 'I/N': 11, 'V/D': 10, 'D/Y': 10, 'L/Q': 9, 'C/F': 9, 'N/H': 9, 'Y/D': 8, 'Y/S': 8, 'S/I': 7, 'C/W': 7, 'K/M': 7, 'N/I': 7, 'F/V': 7, 'F/Y': 7, 'I/F': 6, 'H/D': 6, 'N/Y': 6, 'I/S': 5, 'S/W': 5, 'K/I': 5, 'M/K': 5, 'F/C': 5, 'W/G': 5, 'V/E': 4, 'Y/N': 4, 'R/M': 4, 'M/R': 4, 'W/L': 4, 'L/W': 3, 'H/L': 3, 'G/W': 3, 'W/C': 3, 'I/R': 2, 'W/S': 2, 'I/K': 2, 'R/I': 1, 'RE/RK': 1}
for i in AA:
d.update({i:0})
D = {}
for j in AA:
D.update({j:d})
for i in D:
for x in D[i]:
if (i + '/' + x) in ref2:
add = i + '/' + x
D[i][x]= ref2[add]
print (D)
Output:
{'A': {'A': 120, 'C': 33, 'E': 4, 'D': 8, 'G': 12, 'F': 20, 'I': 177, 'H': 30, 'K': 16, 'M': 91, 'L': 61, 'N': 4, 'Q': 160, 'P': 28, 'S': 8, 'R': 42, 'T': 12, 'W': 73, 'V': 76, 'Y': 12}, 'C': {'A': 120, 'C': 33, 'E': 4, 'D': 8, 'G': 12, 'F': 20, 'I': 177, 'H': 30, 'K': 16, 'M': 91, 'L': 61, 'N': 4, 'Q': 160, 'P': 28, 'S': 8, 'R': 42, 'T': 12, 'W': 73, 'V': 76, 'Y': 12}, 'E': {'A': 120, 'C': 33, 'E': 4, 'D': 8, 'G': 12, 'F': 20, 'I': 177, 'H': 30, 'K': 16, 'M': 91, 'L': 61, 'N': 4, 'Q': 160, 'P': 28, 'S': 8, 'R': 42, 'T': 12, 'W': 73, 'V': 76, 'Y': 12}, 'D': {'A': 120, 'C': 33, 'E': 4, 'D': 8, 'G': 12, 'F': 20, 'I': 177, 'H': 30, 'K': 16, 'M': 91, 'L': 61, 'N': 4, 'Q': 160, 'P': 28, 'S': 8, 'R': 42, 'T': 12, 'W': 73, 'V': 76, 'Y': 12}, 'G': {'A': 120, 'C': 33, 'E': 4, 'D': 8, 'G': 12, 'F': 20, 'I': 177, 'H': 30, 'K': 16, 'M': 91, 'L': 61, 'N': 4, 'Q': 160, 'P': 28, 'S': 8, 'R': 42, 'T': 12, 'W': 73, 'V': 76, 'Y': 12}, 'F': {'A': 120, 'C': 33, 'E': 4, 'D': 8, 'G': 12, 'F': 20, 'I': 177, 'H': 30, 'K': 16, 'M': 91, 'L': 61, 'N': 4, 'Q': 160, 'P': 28, 'S': 8, 'R': 42, 'T': 12, 'W': 73, 'V': 76, 'Y': 12}, 'I': {'A': 120, 'C': 33, 'E': 4, 'D': 8, 'G': 12, 'F': 20, 'I': 177, 'H': 30, 'K': 16, 'M': 91, 'L': 61, 'N': 4, 'Q': 160, 'P': 28, 'S': 8, 'R': 42, 'T': 12, 'W': 73, 'V': 76, 'Y': 12}, 'H': {'A': 120, 'C': 33, 'E': 4, 'D': 8, 'G': 12, 'F': 20, 'I': 177, 'H': 30, 'K': 16, 'M': 91, 'L': 61, 'N': 4, 'Q': 160, 'P': 28, 'S': 8, 'R': 42, 'T': 12, 'W': 73, 'V': 76, 'Y': 12}, 'K': {'A': 120, 'C': 33, 'E': 4, 'D': 8, 'G': 12, 'F': 20, 'I': 177, 'H': 30, 'K': 16, 'M': 91, 'L': 61, 'N': 4, 'Q': 160, 'P': 28, 'S': 8, 'R': 42, 'T': 12, 'W': 73, 'V': 76, 'Y': 12}, 'M': {'A': 120, 'C': 33, 'E': 4, 'D': 8, 'G': 12, 'F': 20, 'I': 177, 'H': 30, 'K': 16, 'M': 91, 'L': 61, 'N': 4, 'Q': 160, 'P': 28, 'S': 8, 'R': 42, 'T': 12, 'W': 73, 'V': 76, 'Y': 12}, 'L': {'A': 120, 'C': 33, 'E': 4, 'D': 8, 'G': 12, 'F': 20, 'I': 177, 'H': 30, 'K': 16, 'M': 91, 'L': 61, 'N': 4, 'Q': 160, 'P': 28, 'S': 8, 'R': 42, 'T': 12, 'W': 73, 'V': 76, 'Y': 12}, 'N': {'A': 120, 'C': 33, 'E': 4, 'D': 8, 'G': 12, 'F': 20, 'I': 177, 'H': 30, 'K': 16, 'M': 91, 'L': 61, 'N': 4, 'Q': 160, 'P': 28, 'S': 8, 'R': 42, 'T': 12, 'W': 73, 'V': 76, 'Y': 12}, 'Q': {'A': 120, 'C': 33, 'E': 4, 'D': 8, 'G': 12, 'F': 20, 'I': 177, 'H': 30, 'K': 16, 'M': 91, 'L': 61, 'N': 4, 'Q': 160, 'P': 28, 'S': 8, 'R': 42, 'T': 12, 'W': 73, 'V': 76, 'Y': 12}, 'P': {'A': 120, 'C': 33, 'E': 4, 'D': 8, 'G': 12, 'F': 20, 'I': 177, 'H': 30, 'K': 16, 'M': 91, 'L': 61, 'N': 4, 'Q': 160, 'P': 28, 'S': 8, 'R': 42, 'T': 12, 'W': 73, 'V': 76, 'Y': 12}, 'S': {'A': 120, 'C': 33, 'E': 4, 'D': 8, 'G': 12, 'F': 20, 'I': 177, 'H': 30, 'K': 16, 'M': 91, 'L': 61, 'N': 4, 'Q': 160, 'P': 28, 'S': 8, 'R': 42, 'T': 12, 'W': 73, 'V': 76, 'Y': 12}, 'R': {'A': 120, 'C': 33, 'E': 4, 'D': 8, 'G': 12, 'F': 20, 'I': 177, 'H': 30, 'K': 16, 'M': 91, 'L': 61, 'N': 4, 'Q': 160, 'P': 28, 'S': 8, 'R': 42, 'T': 12, 'W': 73, 'V': 76, 'Y': 12}, 'T': {'A': 120, 'C': 33, 'E': 4, 'D': 8, 'G': 12, 'F': 20, 'I': 177, 'H': 30, 'K': 16, 'M': 91, 'L': 61, 'N': 4, 'Q': 160, 'P': 28, 'S': 8, 'R': 42, 'T': 12, 'W': 73, 'V': 76, 'Y': 12}, 'W': {'A': 120, 'C': 33, 'E': 4, 'D': 8, 'G': 12, 'F': 20, 'I': 177, 'H': 30, 'K': 16, 'M': 91, 'L': 61, 'N': 4, 'Q': 160, 'P': 28, 'S': 8, 'R': 42, 'T': 12, 'W': 73, 'V': 76, 'Y': 12}, 'V': {'A': 120, 'C': 33, 'E': 4, 'D': 8, 'G': 12, 'F': 20, 'I': 177, 'H': 30, 'K': 16, 'M': 91, 'L': 61, 'N': 4, 'Q': 160, 'P': 28, 'S': 8, 'R': 42, 'T': 12, 'W': 73, 'V': 76, 'Y': 12}, 'Y': {'A': 120, 'C': 33, 'E': 4, 'D': 8, 'G': 12, 'F': 20, 'I': 177, 'H': 30, 'K': 16, 'M': 91, 'L': 61, 'N': 4, 'Q': 160, 'P': 28, 'S': 8, 'R': 42, 'T': 12, 'W': 73, 'V': 76, 'Y': 12}}
You can use
itertools.groupby
:Output:
What I think you are looking for is this:
Output: