/
QualityScore.py
61 lines (52 loc) · 1.8 KB
/
QualityScore.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
50
51
52
53
54
55
56
57
58
59
60
61
from Trim_function import trim
class qualityScore:
def __init__(self,fastqQual):
'''Create a string attribute which represent the quality score
Create a quality list which will contain the quality score of each base
Input:
A string from the quality score in fastq format
Output:
self.qualString : String
self.qualList : List of integer
'''
self.qualString = fastqQual
self.qualList = []
self.convert()
def convert(self):
'''Transform the quality score string element into integer and record them in the qualityNumbers list
Input:
Output:
modify self.qualList
>>> x = qualityScore('^ac')
>>> x.convert()
>>> x.qualList
[94, 97, 99]
>>> x = qualityScore('')
>>> x.convert()
>>> x.qualList
[]
'''
for el in self.qualString:
self.qualList.append(ord(el)) #ord transform the ACSII character into integer
def trim(self,start,end):
'''
Given a start and an end index trim the quality score string attribute and keep the middle.
start and end are integers.
Input:
start : Integer
end : Integer
Output:
modify self.qualString and self.qualList
>>> x = qualityScore('^acebeg')
>>> x.convert()
>>> x.trim(1, 2)
>>> x.qualString
'ac'
>>> x.qualList
[97, 99]
'''
self.qualString = trim(self.qualString,start,end)
self.qualList = trim(self.qualList,start,end)
if __name__ == '__main__':
import doctest
doctest.testmod()