如何将制表符分隔表中的值粘贴到与第一个fi的第1列中的单词匹配的第二个文件中

2021-05-16 07:39:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个CD-hit结果文件(对于熟悉CD-hit的人)。我想将另一个文件中的第二列值粘贴到CD-hit文件中,该文件是一个两列制表符分隔的表,位于相应匹配的RUN ID旁边(如示例图像中用绿色突出显示的那个)。RUN ID是制表符分隔表(下面)中的第1列。sample image for CD-hit file

CD命中结果文件(第一个文件)

>Cluster 0
0   108nt, >ERR123456.1016542.1... *
1   108nt, >ERR123456.3114223.2... at +/93.52%
2   108nt, >ERR345678.217087.1... at -/89.81%
3   108nt, >ERR345678.291581.2... at -/92.59%
4   108nt, >ERR567890.3381351.2... at +/87.96%
5   108nt, >ERR987654.126640.2... at -/86.11%
6   108nt, >ERR987654.2492930.2... at +/84.26%
7   108nt, >ERR987654.3327702.1... at +/92.59%
>Cluster 1
0   108nt, >ERR876543.626414.2... *
1   108nt, >ERR123456.3213598.2... at +/85.19%
2   108nt, >ERR567890.1158706.2... at +/97.22%
3   108nt, >ERR345678.146372.1... at -/88.89%
4   108nt, >ERR765432.201531.2... at -/92.59%
5   108nt, >ERR765432.2770540.1... at -/87.04%

制表符分隔表(第二个文件)

 ERR123456   1650
 ERR345678   2350
 ERR567890   1520
 ERR876543   4520
 ERR987654   3960
 ERR765432   2550

我希望输出文件包含制表符分隔表的第2列中的值,该表位于包含相应运行ID的行(表中的第1列)旁边。你知道吗

>Cluster 0
0   108nt, >ERR123456.1016542.1... *             1650  #matching RUN ID
1   108nt, >ERR123456.3114223.2... at +/93.52%   1650
2   108nt, >ERR345678.217087.1... at -/89.81%    2350
3   108nt, >ERR345678.291581.2... at -/92.59%    2350
4   108nt, >ERR567890.3381351.2... at +/87.96%   1520
5   108nt, >ERR987654.126640.2... at -/86.11%    3960
6   108nt, >ERR987654.2492930.2... at +/84.26%   3960
7   108nt, >ERR987654.3327702.1... at +/92.59%   3960
>Cluster 1
0   108nt, >ERR876543.626414.2... *              4520
1   108nt, >ERR123456.3213598.2... at +/85.19%   1650
2   108nt, >ERR567890.1158706.2... at +/97.22%   1520
3   108nt, >ERR345678.146372.1... at -/88.89%    2350
4   108nt, >ERR765432.201531.2... at -/92.59%    2550
5   108nt, >ERR765432.2770540.1... at -/87.04%   2550