linux - 如何用file2中的相同编号替换file1中的相同编号

标签 linux bioinformatics biopython bioperl blast

我有一个查询列表,并在一个文件 (file1) 中点击 gi 。我有另一个文件,其中包含命中的完整名称(文件2),现在我想将具有完整命中名称的命中gi从文件1替换为文件2。我希望 gi 必须替换为每个相应查询前面的相同 gi。

文件1

 1  Query=gi_148659820 ref_YP_001281343.1_ Hit=gi_148659820 ref_YP_001281343.1_
 2  Query=gi_148659820 ref_YP_001281343.1_ Hit=gi_148821250 ref_YP_001286004.1_ 
 3  Query=gi_148659820 ref_YP_001281343.1_ Hit=gi_15607202 ref_NP_214574.1_  
 4  Query=gi_148659820 ref_YP_001281343.1_ Hit=gi_253796975 ref_YP_003029976.1_ 
 5  Query=gi_148659820 ref_YP_001281343.1_ Hit=gi_375294260 ref_YP_005098527.1_ 

文件2

1  >gi_375294260_ref_YP_005098527.1_ hypothetical protein TBSG_00059 [Mycobacterium tuberculosis KZN 4207]
2  >gi_253796975_ref_YP_003029976.1_ hypothetical protein TBMG_00059 [Mycobacterium tuberculosis KZN 1435]
3  >gi_15607202_ref_NP_214574.1_ Conserved hypothetical protein [Mycobacterium tuberculosis H37Rv]
4  >gi_148659820_ref_YP_001281343.1_ hypothetical protein MRA_0062 [Mycobacterium tuberculosis H37Ra]
5  >gi_148821250_ref_YP_001286004.1_ hypothetical protein TBFG_10059 [Mycobacterium tuberculosis F11]

期望的输出:

1  Query=gi_148659820 ref_YP_001281343.1_ Hit=gi_148659820_ref_YP_001281343.1_ hypothetical protein MRA_0062 [Mycobacterium tuberculosis H37Ra]
2  Query=gi_148659820 ref_YP_001281343.1_ Hit=gi_148821250_ref_YP_001286004.1_ hypothetical protein TBFG_10059 [Mycobacterium tuberculosis F11]
3  Query=gi_148659820 ref_YP_001281343.1_ Hit=gi_15607202_ref_NP_214574.1_ Conserved hypothetical protein [Mycobacterium tuberculosis H37Rv
4  Query=gi_148659820 ref_YP_001281343.1_ Hit=gi_253796975_ref_YP_003029976.1_ hypothetical protein TBMG_00059 [Mycobacterium tuberculosis KZN 1435]
5  Query=gi_148659820 ref_YP_001281343.1_ Hit=gi_375294260_ref_YP_005098527.1_ hypothetical protein TBSG_00059 [Mycobacterium tuberculosis KZN 4207]

最佳答案

逐步描述解决方案;

  1. 仅从 file1 中提取命中 GI;

    cat file1 | awk '{print $3}' | sed 's/Hit=//g' > file1-gi
    
  2. 从文件 2 中删除 # >

    sed 's/^....//g' file2 > file2_1
    
  3. 删除 file2 中的冗余(如果有);

    cat file2_1 | sort $1 | uniq > file2_2
    
  4. 使用系统命令grep对应的GI名称;

    cat file1-gi | awk '{system ("grep "$1" file2_2")}' >> file1-gi-name
    
  5. 打印 file1 的起始 3 列;

    cut -d" " -f-3 file1 > file1_1
    
  6. 粘贴两个文件;

    paste file1_1 file1-gi-name > output
    

关于linux - 如何用file2中的相同编号替换file1中的相同编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20835425/

相关文章:

python - BioPython:从 Blast 输出文件中提取序列 ID

python - 计算原子坐标之间的距离

c++ - 将数据序列化代码从 C++ linux/mac 移植到 C++ windows

python - 来自 requirements.txt 的 Python 包的磁盘缓存

linux - Linux 上的程序化 iPod 备份

linux - 如何在运行 Arch Linux 的 ARM 设备上使用 udev 启用持久网络接口(interface)命名?

algorithm - 重复有序序列搜索算法

java - Trimmomatic 不确认 Linux 集群上的命令

python - 字符串上的单次交换

python - 具有仿射间隙惩罚的 Smith-Waterman 算法中的回溯