如何使用python或linux命令通过在本地数据库中搜索将蛋白质ID转换为蛋白质名称?
How to use python or linux command to convert protein ID into protein name by searching in a local database?
我有两个文件:
ID.txt 包含蛋白质 ID,如下所示:
KKP65897.1
KKP42119.1
KKP91065.1
OGY93232.1
另一个文件是nr.faa。它是从 NCBI 下载的数据库 fasta-format 文件。是这样的:
>KKP42119.1 hypothetical protein DDB_G027.......
MASTQNTVEEVAQJML.......
>KKP65897.1 hypothetical protein DDB_G127.......
MATSREEQNTVEEVAQJML.......
我想通过 IDs.txt 中的名称和 return 蛋白质名称在这个 fasta 数据库文件中搜索,例如 'hypothetical protein',并将它们存储在 txt 文件中。这样,我就linkID加上蛋白名称了
数据库文件很大~7G,我还提取了header行'> .....'并保存到一个txt文件(~3G)。也许在该文件中搜索更快。
如何在 Python 或 linux 命令行中执行此操作?
谢谢。
在 bash 中,您可以简单地使用 grep 获取与搜索字符串匹配的行:
grep "KKP65897.1" database.txt
and return the protein names, like 'hypothetical protein', and store
them in a txt file
使用强大的awk工具:
awk 'NR==FNR{ a[];next }/^>/ && (substr(,2) in a){ print , }' id.txt nr.fa > prot_names.txt
生成的 prot_names.txt
文件如下所示:
hypothetical protein
hypothetical protein
...
如果你想 grep 包含蛋白质名称的整行 - 使用以下 grep 方法:
grep -Ff id.txt nr.fa > prot_names.txt
在这种情况下 prot_names.txt
文件将包含:
>KKP42119.1 hypothetical protein DDB_G027.......
>KKP65897.1 hypothetical protein DDB_G127.......
...
我有两个文件: ID.txt 包含蛋白质 ID,如下所示:
KKP65897.1
KKP42119.1
KKP91065.1
OGY93232.1
另一个文件是nr.faa。它是从 NCBI 下载的数据库 fasta-format 文件。是这样的:
>KKP42119.1 hypothetical protein DDB_G027.......
MASTQNTVEEVAQJML.......
>KKP65897.1 hypothetical protein DDB_G127.......
MATSREEQNTVEEVAQJML.......
我想通过 IDs.txt 中的名称和 return 蛋白质名称在这个 fasta 数据库文件中搜索,例如 'hypothetical protein',并将它们存储在 txt 文件中。这样,我就linkID加上蛋白名称了
数据库文件很大~7G,我还提取了header行'> .....'并保存到一个txt文件(~3G)。也许在该文件中搜索更快。
如何在 Python 或 linux 命令行中执行此操作?
谢谢。
在 bash 中,您可以简单地使用 grep 获取与搜索字符串匹配的行:
grep "KKP65897.1" database.txt
and return the protein names, like 'hypothetical protein', and store them in a txt file
使用强大的awk工具:
awk 'NR==FNR{ a[];next }/^>/ && (substr(,2) in a){ print , }' id.txt nr.fa > prot_names.txt
生成的 prot_names.txt
文件如下所示:
hypothetical protein
hypothetical protein
...
如果你想 grep 包含蛋白质名称的整行 - 使用以下 grep 方法:
grep -Ff id.txt nr.fa > prot_names.txt
在这种情况下 prot_names.txt
文件将包含:
>KKP42119.1 hypothetical protein DDB_G027.......
>KKP65897.1 hypothetical protein DDB_G127.......
...