001、
(base) [email protected]:/home/test2# ls a.fasta test.py (base) [email protected]:/home/test2# cat a.fasta ## 测试fasta文件 >gene1 myc AGCTGCCTAAGC GGCATAGCTAATCG >gene2 jun ACCGAATCGGAGCGATG GGCATTAAAGATCTAGCT >gene3 malat1 AGGCTAGCGAG GCGCGAG GATTAGGCG (base) [email protected]:/home/test2# cat test.py ## 测试程序 #!/usr/bin/python in_file = open("a.fasta", "r") for i in in_file: i = i.strip() if i.startswith(">"): print(i.split(" ")[0].split(">")[1]) else: print(i) (base) [email protected]:/home/test2# python test.py ## 运行程序 gene1 AGCTGCCTAAGC GGCATAGCTAATCG gene2 ACCGAATCGGAGCGATG GGCATTAAAGATCTAGCT gene3 AGGCTAGCGAG GCGCGAG GATTAGGCG
参考:https://www.jianshu.com/p/403a23fdd7bb