首页 > 编程语言 >python中 把每条FASTA序列分割成特定个字母一行的序列

python中 把每条FASTA序列分割成特定个字母一行的序列

时间:2022-08-13 19:24:00浏览次数:66  
标签:成特定 test2 dict1 python ## 序列 home fasta

 

001、

(base) root@PC1:/home/test2# ls
a.fasta  test.py
(base) root@PC1:/home/test2# cat a.fasta           ## 测试fasta文件
>gene1 myc
AGCTGCCTAAGC
GGCATAGCTAATCG
>gene2 jun
ACCGAATCGGAGCGATG
GGCATTAAAGATCTAGCT
>gene3 malat1
AGGCTAGCGAG
GCGCGAG
GATTAGGCG
(base) root@PC1:/home/test2# cat test.py         ## 测试程序
#!/usr/bin/python
in_file = open("a.fasta", "r")
dict1 = dict()
for i in in_file:
    i = i.strip()
    if i[0] == ">":
        key = i
        dict1[key] = ""
    else:
        dict1[key] += i
step = 10                                    ## 此处指定每行的碱基数
for i,j in dict1.items():
    print(i)
    while len(j) > step:
        print(j[:step])
        j = j[step::]
    if len(j) != 0:
        print(j)

in_file.close()
(base) root@PC1:/home/test2# python test.py     ## 执行程序结果
>gene1 myc
AGCTGCCTAA
GCGGCATAGC
TAATCG
>gene2 jun
ACCGAATCGG
AGCGATGGGC
ATTAAAGATC
TAGCT
>gene3 malat1
AGGCTAGCGA
GGCGCGAGGA
TTAGGCG

 

参考:https://www.jianshu.com/p/403a23fdd7bb

 

标签:成特定,test2,dict1,python,##,序列,home,fasta
From: https://www.cnblogs.com/liujiaxin2018/p/16583837.html

相关文章