1、测试数据
[root@centos7 test]# ls test.fa [root@centos7 test]# cat test.fa >chr1 addgg ddges df >chr2 ertfg sdf >chr3 edret dfdff sfdfd d >chr4 iejie sdgg
2、在末尾生成一个标记染色体
[root@centos7 test]# sed -i '$a >chrxxx' test.fa [root@centos7 test]# cat test.fa >chr1 addgg ddges df >chr2 ertfg sdf >chr3 edret dfdff sfdfd d >chr4 iejie sdgg >chrxxx
3、生成循环配置文件
[root@centos7 test]# grep ">chr" test.fa | sed '$d' | paste - <(grep ">chr" test.fa | sed '1d') >chr1 >chr2 >chr2 >chr3 >chr3 >chr4 >chr4 >chrxxx [root@centos7 test]# grep ">chr" test.fa | sed '$d' | paste - <(grep ">chr" test.fa | sed '1d') > conf.txt [root@centos7 test]# ls conf.txt test.fa [root@centos7 test]# cat conf.txt >chr1 >chr2 >chr2 >chr3 >chr3 >chr4 >chr4 >chrxxx
4、统计每条染色体上的染色体数目
[root@centos7 test]# ls conf.txt test.fa [root@centos7 test]# cat conf.txt >chr1 >chr2 >chr2 >chr3 >chr3 >chr4 >chr4 >chrxxx [root@centos7 test]# cat conf.txt | while read {i,j}; do sed -n "/$i/,/$j/{/$i\|$j/b; p}" test.fa | sed 's/[\t ]*//g' | paste -d "" -s | awk -v a=$i '{print a, length}' >> result.txt; done [root@centos7 test]# ls conf.txt result.txt test.fa [root@centos7 test]# cat result.txt ## 查看结果 >chr1 12 >chr2 8 >chr3 16 >chr4 9 [root@centos7 test]# cat test.fa ## 验证结果 >chr1 addgg ddges df >chr2 ertfg sdf >chr3 edret dfdff sfdfd d >chr4 iejie sdgg >chrxxx
5、或者
[root@centos7 test]# ls test.fa [root@centos7 test]# awk '/^>/{if (l!="") print l; print; l=0; next}{l+=length($0)}END{print l}' test.fa >chr1 12 >chr2 8 >chr3 16 >chr4 9 [root@centos7 test]# cat test.fa ## 验证结果 >chr1 addgg ddges df >chr2 ertfg sdf >chr3 edret dfdff sfdfd d >chr4 iejie sdgg
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。