存储更新的python多级字典值

存储更新的python多级字典值,python,Python,在代码流程行下面的代码段中,这些行是位置,这些位置在8个示例中有一些标识符。我之前已经创建了一个字典,基于查找,我正在尝试将位置集处理为基因。基因基本上是放在一起的不同位置。如代码字典中所示,SampleHash为每个样本的每个位置存储分数,但由于基因有多个位置,字典SampleHash处理多个位置,因此每次移动到下一个位置时分数都会被覆盖。我正试图找到一种方法,通过将每个基因和所有样本的当前分数与前一个分数相加来更新分数。目标是最终得到一个矩阵,其中基因作为行,列作为样本(可能通过创建Main

在代码流程行下面的代码段中,这些行是位置,这些位置在8个示例中有一些标识符。我之前已经创建了一个字典,基于查找,我正在尝试将位置集处理为基因。基因基本上是放在一起的不同位置。如代码字典中所示,SampleHash为每个样本的每个位置存储分数,但由于基因有多个位置,字典SampleHash处理多个位置,因此每次移动到下一个位置时分数都会被覆盖。我正试图找到一种方法,通过将每个基因和所有样本的当前分数与前一个分数相加来更新分数。目标是最终得到一个矩阵,其中基因作为行,列作为样本(可能通过创建MainGeneHash[geneA][sample]=updated_scores\u samples\u geneA之类的东西)。 我感谢所有的意见和建议。谢谢:)


这个代码有什么问题?另外,请提供一个
record
的示例,以便我们运行代码。
MainGeneHash={}
for data in record:
    chromosome = str(data.CHROM)
    position = str(data.POS)
    if dictionary[chromosome][position]:     ### dictionary is created in previous section not shown in the code snippet here. 
        gene = dictionary[chromosome][position]
        SampleHash=()
        for samples in data.samples:
            allele_array=[]
            genotype=samples['GT']
            sample_name=str(samples.sample)
            processedGenotypes = processAllele(genotype)    ## function processAllele not shown
            if processedGenotypes is not None:
                for alt in processedGenotypes:
                    allele_array.append(str(Alternate_allele[alt]))
                newHash=Frequency(allele_array)
                value = list(newHash.values())
                total=sum(value)
                SampleHash[sample_name]=total  ### May be I can do something like SampleHash[sample_name][position]=total