编程语言
首页 > 编程语言> > python中实现依据序列名称排序并输出

python中实现依据序列名称排序并输出

作者:互联网

 

001、

(base) root@PC1:/home/test2# ls
a.fasta  test.py
(base) root@PC1:/home/test2# cat a.fasta                   ## 测试fasta文件
>gene2 myc
AGCTGCCTAAGC
GGCATAGCTAATCG
>gene1 jun
ACCGAATCGGAGCGATG
GGCATTAAAGATCTAGCT
>gene4 malat1
AGGCTAGCGAG
GCGCGAG
GATTAGGCG
>gene3 jun
ACCGAATCGG
GGCATTAAAGATCTAGCT
(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.startswith(">"):
        key = i
        dict1[key] = []
    else:
        dict1[key].append(i)
for i in sorted(dict1.keys()):
    print(i)
    for j in dict1[i]:
        print(j)
in_file.close()
(base) root@PC1:/home/test2# python test.py                  ## 运行程序
>gene1 jun
ACCGAATCGGAGCGATG
GGCATTAAAGATCTAGCT
>gene2 myc
AGCTGCCTAAGC
GGCATAGCTAATCG
>gene3 jun
ACCGAATCGG
GGCATTAAAGATCTAGCT
>gene4 malat1
AGGCTAGCGAG
GCGCGAG
GATTAGGCG

 

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

 

标签:GGCATTAAAGATCTAGCT,test2,dict1,python,jun,序列,home,fasta,排序
来源: https://www.cnblogs.com/liujiaxin2018/p/16584456.html