linux 中shell统计fasta文件中每条染色体中的碱基数目
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
分类:
linux shell
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2021-04-15 R语言中sample函数
2021-04-15 linux系统awk命令求一行值的和、平均值、最大值和最小值
2021-04-15 linux系统中awk命令求一列值的最大值、最小值、和及平均值
2021-04-15 R语言中找交集、并集、找不同、判断是否相同
2021-04-15 R语言中unique函数
2021-04-15 linux系统中将一列数据转换为指定的行
2021-04-15 linux系统中实现文本转置