Python 2.7 比较两个字典,一个是每个键的浮点值列表,另一个是每个键的值(python)

Python 2.7 比较两个字典,一个是每个键的浮点值列表,另一个是每个键的值(python),python-2.7,dictionary,bioinformatics,Python 2.7,Dictionary,Bioinformatics,我有一个查询序列,我使用NCBIWWW.qblast在网上创建了它。在我的xml blast文件结果中,我获得了一个查询序列的命中列表(即:gi |)。每个hit或gi都有多个hsp。我制作了一本字典作为我的dict1,其中我将gi作为键,并附加了位分数作为值。因此,每个键都有多个值 my_dict1 = { gi|1002819492|: [437.702, 384.47, 380.86, 380.86, 362.83], gi|675820360| : [2617.97, 2614.37

我有一个查询序列,我使用NCBIWWW.qblast在网上创建了它。在我的xml blast文件结果中,我获得了一个查询序列的命中列表(即:gi |)。每个hit或gi都有多个hsp。我制作了一本字典作为我的dict1,其中我将gi作为键,并附加了位分数作为值。因此,每个键都有多个值

my_dict1 = {

gi|1002819492|: [437.702, 384.47, 380.86, 380.86, 362.83],

gi|675820360| : [2617.97, 2614.37, 122.112],

gi|953764029| : [414.258, 318.66, 122.112, 86.158],

gi|675820410| : [450.653, 388.08, 386.27] }
然后,我使用以下方法查找每个关键点的最大值:

for key, value in my_dict1.items():

    max_value = max(value)
并把第二本字典作为我的口述2:

my_dict2 = {

gi|1002819492|: 437.702,   

gi|675820360| : 2617.97,

gi|953764029| : 414.258,

gi|675820410| : 450.653 }

I want to compare both dictionary. So I can extract the hsp with the highest score bits. I am also including other parameters like query coverage and identity percentage (Not shown here). The finality is to get the best gi| with the highest bit scores, coverage and identity percentage.

I tried many things to compare both dictionary like this :
第一个代码:

matches[]

if my_dict1.keys() not in my_dict2.keys():

    matches[hit_id] = bit_score

else:

    matches = matches[hit_id], bit_score
第二个代码:

if hit_id not in matches.keys():

    matches[hit_id]= bit_score

else:

    matches = matches[hit_id], bit_score
第三个代码:

intersection = set(set(my_dict1.items()) & set(my_dict2.items()))
然而,我总是会出现两种类型的错误:

1)TypeError:列表索引必须是整数,而不是unicode

2)。。。浮动不可编辑


我需要一些帮助和指导。提前非常感谢您抽出时间。致以最诚挚的问候。

不清楚您想做什么。什么是
hit\u id
?什么是比特分数?如果您通过拉动第一个
dict
的每个键的最大值来创建第二个
dict
时,它看起来总是与第一个具有相同的键

你说你想比较它们,但不要说你实际上想做什么。找到那些值低于某个最大值的值?找到那些最大值最高的

您的第一个代码不起作用,因为我假设您试图使用
dict
键值作为
匹配项的索引,您将其定义为
列表
。这可能是您的第一个错误的来源,尽管您没有给出错误实际发生的行

请参见下面的代码注释:

# First off, this needs to be a dict.
matches{}

# This will never happen if you've created these dicts as you stated.
if my_dict1.keys() not in my_dict2.keys():


    matches[hit_id] = bit_score  # Not clear what bit_score is?

else:
    # Also not sure what you're trying to do here. This will assign a tuple
    # to matches with whatever the value of matches[hit_id] is and bit_score.
    matches = matches[hit_id], bit_score

无论如何,我们确实需要更多的信息和完整的代码来找出你的实际目标和哪里出了问题。

我最终改变了我的整个策略。我甚至无法理解我想要什么。很抱歉,python和bioinformatic都是新手。无论如何谢谢你的帮助:)我想这个问题可以删除。对不起,我给你添了麻烦