072debd0d5afc88a8f14178384e9c0323ff121e4
[qpalma.git] / qpalma / parsers.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 class ReadParser:
5 """
6 A base class for the Solexa reads parsers.
7 """
8
9 def __init__(self,filename):
10 self.fh = open(filename)
11
12 def __iter__(self):
13 return self
14
15 def next(self):
16 pass
17
18
19 class FilteredReadParser(ReadParser):
20 """
21 This class offers a parser for the reads that are created by the first
22 filtering step performed to cut and join new reads.
23 """
24
25 def __init__(self,filename):
26 ReadParser.__init__(filename)
27
28 def parseLine(self,line):
29 """
30 We assume that a line has the following entires:
31
32 """
33 return id,chr,pos,strand,mismatches,align_len,offset,alignment = line.split()
34
35 def next(self):
36 for line in self.fh:
37 line = line.strip()
38 yield self.parseLine
39
40 raise StopIteration
41
42
43 class RemappedReadParser(ReadParser):
44 """
45 This class offers a parser for the reads that are remapped by the vmatch
46 utility.
47 """
48
49 def __init__(self,filename):
50 ReadParser.__init__(filename)
51
52 def parseLine(self,line):
53 """
54 We assume that a line has the following entires:
55
56 """
57 return id,chr,pos,strand,mismatches,align_len,offset,alignment = line.split()
58
59 def next(self):
60 for line in self.fh:
61 line = line.strip()
62 yield self.parseLine
63
64 raise StopIteration