Python program that reads a fastq file and calculate Phred score
1
0
Entering edit mode
3.7 years ago
sherrygeek • 0

Hi!

I need help with solving the following question with Python3:

Write a Python program that reads a fastq file and calculate how many bases have Phred base read quality of zero, between 1 and 10 (inclusive), 11 and 20, 21 and 30, 31 and 40, and above 40.

The final results should be like:

Base quality zero: XXX bases

Base quality 1-10: YYY bases

Base quality 11-20: ZZZ bases

Base quality 21-30: QQQ bases

Base quality 31-40: RRR bases

Base quality above 40: SSS bases

I don't know where to start. Any help will be greatly appreciated!

phred fastq • 4.2k views
ADD COMMENT
0
Entering edit mode

And I know the post Python 3: Only Look at Quality Line. Still having difficulties.

ADD REPLY
0
Entering edit mode

No one wants to write your program for you. If you really want help, post your code, and people will probably be be to see why it's not working.

ADD REPLY
3
Entering edit mode
3.7 years ago

To decode a base quality of say character I can use the formula ord("I") - 33

 qual = ord("I") - 33
 print (qual)

prints the Phred quality for character I as

40

to apply this to multiple codes, put it into a function:

def decode(c):
    return ord(c) - 33

letters = "II93882$%@%%@"

values = map(decode, letters)
values = list(values)

print (values)

prints:

[40, 40, 24, 18, 23, 23, 17, 3, 4, 31, 4, 4, 31]

this should be sufficient to get your started

ADD COMMENT
0
Entering edit mode

Thank you so much!!!!

ADD REPLY

Login before adding your answer.

Traffic: 1960 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6