001、
(base) root@PC1:/home/test2# ls a.fasta test.py (base) root@PC1:/home/test2# cat a.fasta ## 测试数据 >scaffold_1 CCCGGGTAAAACGGGTCTTCAAGAAAACGCTCCTCCGTTAATGCCGGCCGATTCAAATAA CGCTGATTCTGATTCAGGATATACAATCTGACATGATGAACAGGTTTTCCAATTGGAATC >scaffold_2 CACGCCGCCAGCGTTCGTCCTGAGCCAGGATCAAACTCTCCGATAAATGGATCACAGGTT AAGTTCACCGCATCCTGCGGCGACACCTGTGTGGCCTGCGTCGTGCAGGCCCTAGTTTGA CTGACTACGCACATCGCTGTGCGATTTATAAAAATGAATTAACAGGTACGTTTTGTCTTG >scaffold_3 TTGATCCAGTGGCTCCGGTTACTCCAGTTGATCCTGTTGCGCCTGTTGCTCCAGTTTCTC CGGTTGGTCCGGTTGATCCGGTTGCA >scaffold_4 CCTGAGCCAGGATCAAACTCTCCGATAAATGGATCACAGGTTAAGTTCACCGCATCCTGC GGCGACACCTGTGAGGTACGTTTTGTCTTGT (base) root@PC1:/home/test2# cat test.py ## 测试脚本 #!/usr/bin/python in_file = open("a.fasta", "r") out_file = open("result.txt", "w") dict1 = dict() for i in in_file: i = i.strip() if i[0] == ">": key = i dict1[key] = "" else: dict1[key] += i step = 40 ## 此处指定每行的碱基数目 for i,j in dict1.items(): out_file.write(i + "\n") while len(j) > step: out_file.write(j[:step] + "\n") j = j[step:] out_file.write(j[::] + "\n") in_file.close() out_file.close() (base) root@PC1:/home/test2# python test.py ## 执行程序 (base) root@PC1:/home/test2# ls a.fasta result.txt test.py (base) root@PC1:/home/test2# cat result.txt ## 查看结果 >scaffold_1 CCCGGGTAAAACGGGTCTTCAAGAAAACGCTCCTCCGTTA ATGCCGGCCGATTCAAATAACGCTGATTCTGATTCAGGAT ATACAATCTGACATGATGAACAGGTTTTCCAATTGGAATC >scaffold_2 CACGCCGCCAGCGTTCGTCCTGAGCCAGGATCAAACTCTC CGATAAATGGATCACAGGTTAAGTTCACCGCATCCTGCGG CGACACCTGTGTGGCCTGCGTCGTGCAGGCCCTAGTTTGA CTGACTACGCACATCGCTGTGCGATTTATAAAAATGAATT AACAGGTACGTTTTGTCTTG >scaffold_3 TTGATCCAGTGGCTCCGGTTACTCCAGTTGATCCTGTTGC GCCTGTTGCTCCAGTTTCTCCGGTTGGTCCGGTTGATCCG GTTGCA >scaffold_4 CCTGAGCCAGGATCAAACTCTCCGATAAATGGATCACAGG TTAAGTTCACCGCATCCTGCGGCGACACCTGTGAGGTACG TTTTGTCTTGT
参考:https://mp.weixin.qq.com/s?__biz=MzIxNzc1Mzk3NQ==&mid=2247491492&idx=1&sn=d9bfd396369b802700ef764d8174669d&chksm=97f5afbca08226aa255d2ee747a179a1e13e9160baf87b4186f871e396e8b86c826a5ca51ef4&scene=178&cur_album_id=2403674812188688386#rd