楼主 | 收藏 | 举报 2018-03-27 00:00   浏览:201   回复:0

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

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.


> sq1
foofoofoobar
foofoofoo
> sq2
quxquxquxbar
quxquxquxbar
quxx
> sq3
paxpaxpax
pax

> sq1 foofoofoobarfoofoofoo
> sq2 quxquxquxbarquxquxquxbarquxx
> sq3 paxpaxpaxpax

For awk:

awk '/^>/&&NR>1{print "";}{ printf "%s",/^>/ ? $0" ":$0 }' YourFile

For sed:

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

Today, I want to extract contig which is more 500bp from my aseembly result, So I do that as following:

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}'

打赏
网站首页 | 关于我们 | 联系方式 | 使用协议 | 版权隐私 | 网站地图  |  排名推广  |  广告服务  |  积分换礼  |  网站留言  |  RSS订阅  |  违规举报
 
免责声明:本站有部分内容来自互联网,如无意中侵犯了某个媒体 、公司 、企业或个人等的知识产权,请来电或致函告之,本网站将在规定时间内给予删除等相关处理。