001、
[email protected]:/home/test# ls a.fastq test.py [email protected]:/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 [email protected]:/home/test# cat test.py ## 测试程序 #!/usr/bin/python in_file = open("a.fastq", "r") out_file = open("result.txt", "w") idx = 0 str1 = "" for i in in_file: idx += 1 i = i.strip() if idx % 4 == 2: str1 += i gc = str1.count("G") + str1.count("C") out_file.write(str(gc/len(str1)) + "/n") in_file.close() out_file.close() [email protected]:/home/test# python test.py ## 运行程序 [email protected]:/home/test# ls a.fastq result.txt test.py [email protected]:/home/test# cat result.txt ## 运行结果 0.49038461538461536
参考:https://www.jianshu.com/p/5ee54bea4cb0
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/python/280692.html