forked from igemsoftware2021/Aachen_dna-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhomonucleotide.py
34 lines (29 loc) · 1.08 KB
/
homonucleotide.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
from read import Read
class Homonucleotide():
def __init__(self, read: Read):
self.nucleotide = read.seq[0]
self.length = len(read.seq)
self.quality = sum(read.qual)/self.length
def __str__(self):
return "Nucleotide: " + self.nucleotide + ", Length: " + str(self.length) + ", Quality: " + str(self.quality)
class Homonucleotides():
def __init__(self, read: Read):
self.homonucleotides = []
prev = "" # read.seq[0]
length = 0
for i, base in enumerate(read.seq):
if base == prev:
length += 1
else:
if not length == 0:
self.homonucleotides.append(Homonucleotide(Read(
description=read.description,
seq=read.seq[i-length:i],
qual=(ord(x) for x in read.qual[i-length:i])
)))
length = 1
prev = base
def __iter__(self):
return iter(self.homonucleotides)
def __len__(self):
return len(self.homonucleotides)