I have the following dict:
{'A1137': {'Called': 10, 'hom_alt': 10, 'private_hom': 8},
'A2160': {'Called': 10, 'hom_alt': 1, 'hom_ref': 9},
'A2579': {'Called': 10, 'hom_alt': 1, 'hom_ref': 9},
'A2594': {'Called': 9, 'hom_alt': 1, 'hom_ref': 8}}
My desired output is:
stats A1137 A2160 A2579 A2594
Called 10 10 10 9
hom_alt 10 1 1 1
hom_ref 0 9 9 8
private_hom 8 0 0 0
As can be observed, if any subset misses a 'counter', a zero should take the place. I have tried different ways to do it but I can't achieve it. I'm able to do the printing with a simple dict but not with a nested one:
with open(res, 'w') as csvfile:
w = csv.writer(csvfile, delimiter='\t')
w.writerow(['#Global Statistics:'])
for key, value in d.items():
w.writerow([key, value])
w.writerow(['\n'])
return res