001、 shell实现
[root@PC1 test]# ls test.fa [root@PC1 test]# cat test.fa ## 测试fasta文件 > chr1 ddddgggg ddfgg > chr2 eertttt dddddg > chr3 dfdfgggg lljhhhh ## 拆分脚本 [root@PC1 test]# grep -n "^>" test.fa | cut -d ":" -f 1 | paste - <(grep -n "^>" test.fa | cut -d ":" -f 1 | awk '{print $0 - 1}' | sed 1d | sed '$a $') | awk '{OFS = "\t"; print $0, NR}' | while read {i,j,k}; do sed -n "$i, $j"p test.fa > chr$k.fa; done [root@PC1 test]# ls chr1.fa chr2.fa chr3.fa test.fa [root@PC1 test]# cat chr1.fa ## 第一个scaffold > chr1 ddddgggg ddfgg
002、python实现