将 STRING 别名映射到 UniProt ID
在最近的一个项目中,我需要将 STRING 记录与其他 PPI 数据库进行比较。然而,这并不总是听起来那么容易,因为 STRING 使用 KEGG 蛋白质标识符。幸运的是,在 STRING 下载页面,可以自由下载别名映射列表。
然而还有一个主要问题:我找不到任何关于格式的文档。一旦你弄清楚基础知识,它似乎相当容易,但我创建了一个可重用的 Python 函数,过滤给定生物体并输出 STRING ID, UniProt ID CSV:
string_aliases_to_uniprot.py
# STRING 别名映射过滤器和转换器
# 在 Apache License v2.0 下发布
# 版权所有 (c) 2013 Uli Köhler
# 版本 1.0
import gzip
def filterSTRINGAliases(infilename, outfilename, taxonomyFilter):
"""
过滤和转换 STRING 别名为 CSV。
关键字参数:
infilename:gzip 压缩的 STRING 别名下载的文件名
outfilename:要写入转换和过滤映射的 CSV 文件
taxonomyFilter:包含要过滤的 NCBI Taxonomy 标识符的字符串
"""
recordCtr = 0
with gzip.open(infilename, "rt") as infile, open(outfilename, "w") as outfile:
for line in infile:
# 一些粗略统计
recordCtr += 1
if recordCtr % 1000000 == 0:
print("Processed %d records..." % recordCtr)
# 此行确保我们映射 STRING ID --> UniProt ID
if "_UniProt_AC" not in line:
continue
parts = line.split()
if taxonomyFilter != parts[0]:
continue
# 提取并写入别名
outfile.write(",".join([parts[1], parts[2]]) + "\n")
print("Processed %d records" % recordCtr)
if __name__ == "__main__":
# 示例用法:过滤 Saccharomyces cerevisiae (4932),写入 string-aliases.csv
filterSTRINGAliases("/tmp/protein.aliases.v9.05.txt.gz", "string-aliases.csv", "4932")Check out similar posts by category:
Allgemein
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow