首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在linux中重新格式化Kegg输出?

如何在linux中重新格式化Kegg输出?
EN

Unix & Linux用户
提问于 2018-10-23 13:42:41
回答 1查看 40关注 0票数 0

我需要重新格式化kegg reconstruct pathway输出,在file1中有这样的内容:

代码语言:javascript
复制
00550 Peptidoglycan biosynthesis (2)

K01000

K02563

00511 Other glycan degradation (8) K01190   K01191

K01192

K01201

K01227

K12309

在file2中,我需要一些类似的东西:

代码语言:javascript
复制
00550 Peptidoglycan biosynthesis (2)   K01000   K02563
00511 Other glycan degradation (6)   K01190   K01191   K01192   K01201   K01227   K12309

我如何在linux或python中重新格式化?

谢谢

EN

回答 1

Unix & Linux用户

回答已采纳

发布于 2018-10-23 14:25:31

这能让你走多远?

代码语言:javascript
复制
awk '
!NF             {next                                                   # don"t process empty lines
                }
/^[0-9]+ /      {sub (/\([0-9]*\)/, "(" CNT ")", PRT)                   # for the "glycan" lines (leading numerical)
                                                                        # correct the count in parentheses
                 if (PRT) print PRT                                     # print the PRT buffer (NOT first line when empty)
                 PRT = ""                                               # empty it after print
                 CNT = gsub (/K[0-9]*/, "&") - 1                        # get this line"s "K..." count, corr.for later incr.
                }
                {PRT = sprintf ("%s%s%s", PRT, PRT?" ":"", $0)          # append this line to buffer
                 CNT++                                                  # increment "K..." count
                }
END             {sub (/\([0-9]*\)/, "(" CNT ")", PRT)                   # see above
                 print PRT
                }
' file
00550 Peptidoglycan biosynthesis (2) K01000 K02563
00511 Other glycan degradation (6) K01190   K01191 K01192 K01201 K01227 K12309
票数 0
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/477268

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档