-
Notifications
You must be signed in to change notification settings - Fork 2
/
reads_quality.py
36 lines (31 loc) · 975 Bytes
/
reads_quality.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
def readFastq(filename):
sequences = []
qualities = []
with open(filename) as fh:
while True:
fh.readline() # skip name line
seq = fh.readline().rstrip() # read base sequence
fh.readline() # skip placeholder line
qual = fh.readline().rstrip() #base quality line
if len(seq) == 0:
break
sequences.append(seq)
qualities.append(qual)
return sequences, qualities
seqs, quals = readFastq('SRR835775_1.first1000.fastq')
def phred33ToQ(qual):
return ord(qual) - 33
def createHist(qualityStrings):
# Create a histogram of quality scores
hist = [0]*50
for read in qualityStrings:
for phred in read:
q = phred33ToQ(phred)
hist[q] += 1
return hist
h = createHist(quals)
print(h)
# Plot the histogram
import matplotlib.pyplot as plt
plt.plot(range(len(h)), h)
plt.show()