python 脚本统计fasta文件每条scaffold的碱基长度

 

001、

[root@pc1 test]# cat a.fa
>chr1
aatt
cc
>chr2
ttgg
ccgg
>chr3
aa
[root@pc1 test]# cat test.py
#!/usr/bin/python
in_file = open("a.fa", "r")
dict1 = dict()
for i in in_file:
        i = i.strip()
        if i.startswith(">"):
                key = i
                dict1[key] = ""
        else:
                dict1[key] += i
for i,j in dict1.items():
        print(i.strip(">"), len(j))
in_file.close()
[root@pc1 test]# python test.py
('chr1', 6)
('chr2', 8)
('chr3', 2)

 

posted @ 2022-10-27 23:22  小鲨鱼2018  阅读(52)  评论(0)    收藏  举报