001、
root@PC1:/home/test# ls a.fastq test.py root@PC1:/home/test# cat a.fastq ## 测试fastq文件 @DJB775P1:248:D0MDGACXX:7:1202:12362:49613 TGCTTACTCTGCGTTGATACCACTGCTTAGATCGGAAGAGCACACGTCTGAA + JJJJJIIJJJJJJHIHHHGHFFFFFFCEEEEEDBD?DDDDDDBDDDABDDCA @DJB775P1:248:D0MDGACXX:7:1202:12782:49716 CTCTGCGTTGATACCACTGCTTACTCTGCGTTGATACCACTGCTTAGATCGG + IIIIIIIIIIIIIIIHHHHHHFFFFFFEECCCCBCECCCCCCCCCCCCCCCC root@PC1:/home/test# cat test.py ## 测试程序 #!/usr/bin/python in_file = open("a.fastq", "r") out_file = open("result.txt", "w") dict1 = {} idx = 0 for i in in_file: idx = idx + 1 i = i.strip() if idx % 4 == 1: key = "".join(i.split("@")[1:]) dict1[key] = "" elif idx % 4 == 2: dict1[key] = i for i,j in dict1.items(): print(">{0}\n{1}".format(i,j), file = out_file) in_file.close() out_file.close() root@PC1:/home/test# python test.py ## 执行程序 root@PC1:/home/test# ls a.fastq result.txt test.py root@PC1:/home/test# cat result.txt ## 执行程序结果 >DJB775P1:248:D0MDGACXX:7:1202:12362:49613 TGCTTACTCTGCGTTGATACCACTGCTTAGATCGGAAGAGCACACGTCTGAA >DJB775P1:248:D0MDGACXX:7:1202:12782:49716 CTCTGCGTTGATACCACTGCTTACTCTGCGTTGATACCACTGCTTAGATCGG
参考:https://www.jianshu.com/p/5ee54bea4cb0
标签:文件,python,fastq,PC1,file,test,home,root From: https://www.cnblogs.com/liujiaxin2018/p/16588749.html