I have a dictionary with multiple genes. The tuple(zip()) gives the nucleotide at each site. E.g. (A, A, A), (T, T, G), etc. I’m trying to count the number of nucleotides at each site. Such that site 1 shows 3 A’s, and site 2 shows 2 T’s and 1 G. When I run my code, it is only adding to A and nothing else.
List = tuple(zip(*myDict.values()))
A = 0
T = 0
G = 0
C = 0
site = 0
for value in List:
site +=1
if 'A':
A += 1
elif 'T':
T += 1
elif 'G':
G += 1
else:
C =+ 1
print 'Site:', site
print 'A:', A
print 'T:', T
print 'G:', G
print 'C:', C
You can (again), best use
collections.Counter():This will create a list of gene counts per site.
Demonstration: