6
|
1 class SlidingWindow(object):
|
|
2
|
|
3 def __init__( self, length = 1, overlap = 1 ):
|
|
4 self._length = length
|
|
5 self._overlap = overlap
|
|
6 self._start = 1
|
|
7 self._end = length
|
|
8 self._step = length - overlap
|
|
9
|
|
10 def slideWindowOnce(self):
|
|
11 self._start = self._start + self._step
|
|
12 self._end = self._end + self._step
|
|
13
|
|
14 def getStart(self):
|
|
15 return self._start
|
|
16
|
|
17 def getEnd(self):
|
|
18 return self._end
|
|
19
|
|
20 def setStart(self, start):
|
|
21 self._start = start
|
|
22
|
|
23 def setEnd(self, end):
|
|
24 self._end = end
|
|
25
|
|
26 def getLength(self):
|
|
27 return self._length
|
|
28
|
|
29 def getOverlap(self):
|
|
30 return self._overlap
|
|
31
|
|
32 def setLength(self, length):
|
|
33 self._length = length
|
|
34
|
|
35 def setOverlap(self, overlap):
|
|
36 self._overlap = overlap
|
|
37
|
|
38 def getSlidingMsg(self):
|
|
39 return "Window is sliding : %s %s" %(self._start, self._end)
|
|
40
|
|
41 class SlidingWindowToCountMatchingBases(SlidingWindow):
|
|
42
|
|
43 def getSetLengthOnWindow( self, iSet ):
|
|
44 if self._isSetIncludedInTheWindow(iSet):
|
|
45 return iSet.getLength()
|
|
46 if self._isWindowIncludedInTheSet(iSet):
|
|
47 return self._length
|
|
48 elif self._isSetOverlapTheRightSideOfTheWindow(iSet):
|
|
49 return self._end - iSet.getMin()+1
|
|
50 elif self._isSetOverlapTheLeftSideOfTheWindow(iSet):
|
|
51 return iSet.getMax() - self._start+1
|
|
52
|
|
53 def getCoordSetOnWindow( self, iSet ):
|
|
54 if self._isSetIncludedInTheWindow(iSet):
|
|
55 return iSet.getStart(), iSet.getEnd()
|
|
56 if self._isWindowIncludedInTheSet(iSet):
|
|
57 return self.getStart(), self.getEnd()
|
|
58 elif self._isSetOverlapTheRightSideOfTheWindow(iSet):
|
|
59 return iSet.getStart(), self.getEnd()
|
|
60 elif self._isSetOverlapTheLeftSideOfTheWindow(iSet):
|
|
61 return self.getStart(), iSet.getEnd()
|
|
62
|
|
63 def _isSetIncludedInTheWindow(self, feature):
|
|
64 return feature.getMin() >= self._start and feature.getMax() <= self._end
|
|
65
|
|
66 def _isWindowIncludedInTheSet(self, feature):
|
|
67 return self._start >= feature.getMin() and self._end <= feature.getMax()
|
|
68
|
|
69 def _isSetOverlapTheRightSideOfTheWindow(self, feature):
|
|
70 return feature.getMin() <= self._end and feature.getMin() >= self._start
|
|
71
|
|
72 def _isSetOverlapTheLeftSideOfTheWindow(self, feature):
|
|
73 return feature.getMax() <= self._end and feature.getMax() >= self._start
|