I am in the process of shifting from Perl to Python, and I am struggling with what was a hash of hashes of arrays. I have this data structure return from a REST service:
[
{
"gene": "ENSG00000270076",
"minus_log10_p_value": 0.0271298550085406,
"tissue": "Thyroid",
"value": 0.939442373223424
},
{
"gene": "ENSG00000104643",
"minus_log10_p_value": 0.255628260060896,
"tissue": "Thyroid",
"value": 0.555100655197016
}
]
Speaking in Perl, I'd like to parse it and have the Python equivalent of
${$tissue}{$value} = [$gene]
${Throid}{0.5555} = [ENSG1, ENSG2, ENSG3]
In Python I tried things along the line:
d={}
d[hit['tissue']][hit['value']].append(hit[gene])
but encountered various errors.
In the end, I want d to look like:
{
'Thyroid': {
0.939442373223424: ['ENSG00000270076'],
0.555100655197016: ['ENSG00000104643']
}
}
so grouping by tissue, then by value, and for each value have a list of genes.
{'Thyroid': {0.555100655197016: 'ENSG00000104643', 0.939442373223424: 'ENSG00000270076'}}is what OP is looking for. It states clearly isn't it..${Throid}{0.5555} = [ENSG1, ENSG2, ENSG3]. So its d[tissue][value]=gene is what is expected.