python脚本统计fastq数据的GC含量

 

001、

(base) [b20223040323@admin1 test]$ ls
SRR1770413_1.fastq  test.py
(base) [b20223040323@admin1 test]$ cat test.py              ## 脚本
#!/usr/bin/env python
# -*- coding:utf-8 -*-

in_file = open("SRR1770413_1.fastq", "r")
out_file = open("result.txt", "w")

gc_count = 0
total_base = 0

lines = 0
for i in in_file:
        lines += 1
        if lines % 4 == 2:
                i = i.strip().upper()
                gc_count += i.count("G") + i.count("C")
                total_base += len(i)

gc_percent = gc_count/total_base
out_file.write("SRR1770413_1.fastq: " + str(gc_percent) + "\n")

in_file.close()
out_file.close()
(base) [b20223040323@admin1 test]$ python test.py
(base) [b20223040323@admin1 test]$ ls
result.txt  SRR1770413_1.fastq  test.py
(base) [b20223040323@admin1 test]$ cat result.txt     ## 结果文件
SRR1770413_1.fastq: 0.5009478013778936

 

image

 。

 

posted @ 2025-10-02 11:02  小鲨鱼2018  阅读(8)  评论(0)    收藏  举报