【问题标题】:Modifying FASTA headers with Unix command line tools使用 Unix 命令行工具修改 FASTA 标头
【发布时间】:2013-03-01 20:49:23
【问题描述】:

我再次陷入修改文本的困境。我想更改大文本文件,例如:

>hg19_ct_UserTrack_3545_691 range=chr1:8121498-8121502 5'pad=0 3'pad=0 strand=+ repeatMasking=none
GATGG
>hg19_ct_UserTrack_3545_690 range=chr1:8121587-8121591 5'pad=0 3'pad=0 strand=+ repeatMasking=none
GATAG

>chr1:8121498-8121502 5'pad=0 3'pad=0 strand=+ repeatMasking=none
GATGG
>chr1:8121587-8121591 5'pad=0 3'pad=0 strand=+ repeatMasking=none
GATAG

我一直在使用 sed '/^>/s/[^ ]* />/',它删除了第一部分 (>hg19_ct_UserTrack_3545_690),但我真的不知道如何删除 range=。我尝试了//grep 的各种组合,但没有任何乐趣。

谢谢

【问题讨论】:

    标签: unix sed awk grep fasta


    【解决方案1】:

    试试这条线:

    sed 's/[^=>]*=//' file
    

    使用您的输入进行测试:

    kent$  echo ">hg19_ct_UserTrack_3545_691 range=chr1:8121498-8121502 5'pad=0 3'pad=0 strand=+ repeatMasking=none
    GATGG
    >hg19_ct_UserTrack_3545_690 range=chr1:8121587-8121591 5'pad=0 3'pad=0 strand=+ repeatMasking=none
    GATAG"|sed 's/[^=>]*=//'
    >chr1:8121498-8121502 5'pad=0 3'pad=0 strand=+ repeatMasking=none
    GATGG
    >chr1:8121587-8121591 5'pad=0 3'pad=0 strand=+ repeatMasking=none
    GATAG
    

    【讨论】:

      【解决方案2】:

      尝试各种 shell 命令 =)

      awk -F'range=' '/^>/{print ">" $2}' file
      

      或者

       sed '/^>/s/.*range=(.*)/>\1/' file
      

      【讨论】:

      • 这些不能正常工作,因为它们会遗漏“>”字符。 awk 和带有 perl 正则表达式的 GNU grep 也会省略非“>”行...
      • 帖子已相应编辑。误解了你的问题,对不起;)
      • 你可能 sed -E 用于 BSD sed 或 GNU sed(或 sed -r 用于 GNU sed)用于 ERE ...
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-22
      • 2021-03-01
      • 2014-05-14
      相关资源
      最近更新 更多