001、
root@PC1:/home/test# ls a.fasta test.py root@PC1:/home/test# cat test.py ## 测试程序 #!/usr/bin/python in_file = open("a.fasta", "r") dict1 = {} for i in in_file: i = i.strip() if i.startswith(">"): key = i dict1[key] = [] else: i = i.replace("T","U") dict1[key].append(i) for i,j in dict1.items(): print(i) j = "".join(j) for k in range(0, len(j), 6): print(j[k:k+6]) in_file.close() root@PC1:/home/test# cat a.fasta ## 测试fasta文件 >gene1 myc AGCTGCCTAAGC GGCATAGCTAATCG >gene2 jun ACCGAATCGGAGCGATG GGCATTAAAGATCTAGCT >gene3 malat1 AGGCTAGCGAG GCGCGAG GATTAGGCG root@PC1:/home/test# python test.py ## 执行程序 >gene1 myc AGCUGC CUAAGC GGCAUA GCUAAU CG >gene2 jun ACCGAA UCGGAG CGAUGG GCAUUA AAGAUC UAGCU >gene3 malat1 AGGCUA GCGAGG CGCGAG GAUUAG GCG
参考:https://www.jianshu.com/p/5ee54bea4cb0