python中实现依据序列名称排序并输出
2022/8/14 1:53:56
本文主要是介绍python中实现依据序列名称排序并输出,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
001、
(base) [email protected]:/home/test2# ls a.fasta test.py (base) [email protected]:/home/test2# cat a.fasta ## 测试fasta文件 >gene2 myc AGCTGCCTAAGC GGCATAGCTAATCG >gene1 jun ACCGAATCGGAGCGATG GGCATTAAAGATCTAGCT >gene4 malat1 AGGCTAGCGAG GCGCGAG GATTAGGCG >gene3 jun ACCGAATCGG GGCATTAAAGATCTAGCT (base) [email protected]:/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) [email protected]:/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
这篇关于python中实现依据序列名称排序并输出的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python
- 2024-03-12python colon equals