-
Notifications
You must be signed in to change notification settings - Fork 9
/
q30.py
executable file
·49 lines (43 loc) · 1.1 KB
/
q30.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
import os,sys
import fastq
import time
def qual_stat(qstr):
q20 = 0
q30 = 0
for q in qstr:
qual = ord(q) - 33
if qual >= 30:
q30 += 1
q20 += 1
elif qual >= 20:
q20 += 1
return q20, q30
def stat(filename):
reader = fastq.Reader(filename)
total_count = 0
q20_count = 0
q30_count = 0
while True:
read = reader.nextRead()
if read == None:
break
total_count += len(read[3])
q20, q30 = qual_stat(read[3])
q20_count += q20
q30_count += q30
print("total bases:", total_count)
print("q20 bases:", q20_count)
print("q30 bases:", q30_count)
print("q20 percents:", 100 * float(q20_count)/float(total_count))
print("q30 percents:", 100 * float(q30_count)/float(total_count))
def main():
if len(sys.argv) < 2:
print("usage: python q30.py <fastq_file>")
sys.exit(1)
stat(sys.argv[1])
if __name__ == "__main__":
time1 = time.time()
main()
time2 = time.time()
print('Time used: ' + str(time2-time1))