【发布时间】:2016-08-26 10:27:22
【问题描述】:
我正在从 HMMER 生成的输出文件中提取序列坐标(在基因组组装文件中查找 DNA 序列,匹配查询)。
我创建了一个 python 字典,其中键是源序列名称(字符串),值是包含目标序列的开始和结束坐标的列表。但是,HMMER 通常会在单个源序列(重叠群/染色体)上找到多个匹配项。
这意味着当我添加到字典中时,如果我在一个 contig 上遇到多个匹配项,每个匹配项都会被以下匹配项覆盖。
例如HMMER 找到以下匹配项:
名称开始结束
4415 16723 17556
127 1290 1145
1263 34900 37834
4415 2073 3899
4415 4580 6004
但这会产生以下字典(我希望每个匹配项都有单独的条目):
{'127': ['1290', '1145'], '1263': ['34900', '37834'], '4415': ['4580', '6004']}
如何在键上附加一个字母,以便后续匹配是唯一的,并且不会覆盖之前的匹配,即 4415、4415a、4415b 等?
matches = {}
for each line of HMMER file:
split the line
make a list of fields 4 & 5 (the coordinates)
# at this stage I need a way of checking whether the key (sequenceName)
# is already in the dictionary (easy), and if it is, appending a letter
# to sequenceName to make it unique
matches[sequenceName] = list
【问题讨论】:
-
如果我不在 iPhone 应用程序上,我的答案是使用名称属性创建一个自定义类,然后使用拆分字符串创建一个实例列表。您使用 dict 而不是 numpy 数组是否有特定原因?
标签: python dictionary key unique