I have a list of lists:
sample = [['TTTT', 'CCCZ'], ['ATTA', 'CZZC']]
count = [[4,3],[4,2]]
correctionfactor = [[1.33, 1.5],[1.33,2]]
I calculate the frequency of each character (pi), the square of it, and then sum (and then calculate het = 1 - sum).
The desired output [[1,2],[1,2]]
Problem: I do not pass the list of lists (sample, count) in this loop to extract the desired values. Previously, I used only this list (e.g. ['TACT','TTTT'..]).
- I suspect that I need to add a larger loop that indexes each element in the pattern (i.e. indices above
sample[0] = ['TTTT', 'CCCZ']and sample[1] = ['ATTA', 'CZZC']). I am not sure how to include this in the code.
** The code
list_of_hets = []
for idx, element in enumerate(sample):
count_dict = {}
square_dict = {}
for base in list(element):
if base in count_dict:
count_dict[base] += 1
else:
count_dict[base] = 1
for allele in count_dict: #Calculate frequency of every character
square_freq = (count_dict[allele] / count[idx])**2 #Square the frequencies
square_dict[allele] = square_freq
pf = 0.0
for i in square_dict:
pf += square_dict[i] # pf --> pi^2 + pj^2...pn^2 #Sum the frequencies
het = 1-pf
list_of_hets.append(het)
print list_of_hets
"Failed" OUTPUT:
line 70, in <module>
square_freq = (count_dict[allele] / count[idx])**2
TypeError: unsupported operand type(s) for /: 'int' and 'list'er
source
share