用awk和sed快速将fasta格式的序列改成一行显示

1 5,160

Some time when you want to change the fasta seq into one line, just as following. Then it will help you to do other process.
I know that perl and other script will do that, however, I would introduce two simple and fast way do achieve that with awk and sed.

[code lang="text"]
> sq1
foofoofoobar
foofoofoo
> sq2
quxquxquxbar
quxquxquxbar
quxx
> sq3
paxpaxpax
pax
[/code]

[code lang="text"]
> sq1 foofoofoobarfoofoofoo
> sq2 quxquxquxbarquxquxquxbarquxx
> sq3 paxpaxpaxpax
[/code]

For awk:
[code lang="bash"]
awk '/^>/&&NR>1{print "";}{ printf "%s",/^>/ ? $0" ":$0 }' YourFile
[/code]

For sed:
[code lang="bash"]
sed -n '1{x;d;x};${H;x;s/\n/ /1;s/\n//g;p;b};/^>/{x;s/\n/ /1;s/\n//g;p;b};H' YourFile
[/code]

Today, I want to extract contig which is more 500bp from my aseembly result, So I do that as following:
[code lang="bash"]
sed -n '1{x;d;x};${H;x;s/\n/ /1;s/\n//g;p;b};/^>/{x;s/\n/ /1;s/\n//g;p;b};H' |awk '{if (length($5)>500 ) print ">contig-"FNR"\n"$5}'

[/code]

  • 本文由 发表
  • 转载请务必保留本文链接:https://www.plob.org/article/106.html
评论  1  访客  0  引用  1

发表评论

匿名网友 填写信息