I have a sample that looks like
tt = [AAT, AAA, ATGA]
Calculate frequency of occurrence of each character in the element and square it
eg. AAT => 2 A's and 1 T ===> p = (2/3)^2 + (1/3)^2 Here, p = 0.55555
Then, q = 1 - p Here, q = 0.44444
Altough I am using float, I am getting rounded-off values for q
Output:
[1.0, 0.0, 1.0]
I need the output to be :
Desired Output:
[0.44444,0.0,0.625]
My program
## Calculatting 1-p
q = []
for idx, element in enumerate(tt):
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:
square_freq = (count_dict[allele] / nn[idx])**2 #nn is the number of characters in the element, here it is a list of [3,3,4]
square_dict[allele] = square_freq
pf = 0.0
for i in square_dict:
pf += square_dict[i] # pf --> pi^2 + pj^2...pn^2
het = 1-pf
q.append(het)