annotate commons/core/coord/SlidingWindow.py @ 36:44d5973c188c

Uploaded
author m-zytnicki
date Tue, 30 Apr 2013 15:02:29 -0400
parents 769e306b7933
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
1 class SlidingWindow(object):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 def __init__( self, length = 1, overlap = 1 ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
4 self._length = length
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
5 self._overlap = overlap
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
6 self._start = 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
7 self._end = length
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
8 self._step = length - overlap
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
9
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
10 def slideWindowOnce(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
11 self._start = self._start + self._step
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
12 self._end = self._end + self._step
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
13
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
14 def getStart(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
15 return self._start
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
16
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
17 def getEnd(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
18 return self._end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
19
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
20 def setStart(self, start):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
21 self._start = start
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
22
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
23 def setEnd(self, end):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
24 self._end = end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
25
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26 def getLength(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27 return self._length
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29 def getOverlap(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30 return self._overlap
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 def setLength(self, length):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 self._length = length
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 def setOverlap(self, overlap):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 self._overlap = overlap
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 def getSlidingMsg(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 return "Window is sliding : %s %s" %(self._start, self._end)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41 class SlidingWindowToCountMatchingBases(SlidingWindow):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 def getSetLengthOnWindow( self, iSet ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 if self._isSetIncludedInTheWindow(iSet):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 return iSet.getLength()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 if self._isWindowIncludedInTheSet(iSet):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 return self._length
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 elif self._isSetOverlapTheRightSideOfTheWindow(iSet):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 return self._end - iSet.getMin()+1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 elif self._isSetOverlapTheLeftSideOfTheWindow(iSet):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 return iSet.getMax() - self._start+1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 def getCoordSetOnWindow( self, iSet ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 if self._isSetIncludedInTheWindow(iSet):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 return iSet.getStart(), iSet.getEnd()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 if self._isWindowIncludedInTheSet(iSet):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 return self.getStart(), self.getEnd()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 elif self._isSetOverlapTheRightSideOfTheWindow(iSet):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 return iSet.getStart(), self.getEnd()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 elif self._isSetOverlapTheLeftSideOfTheWindow(iSet):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 return self.getStart(), iSet.getEnd()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 def _isSetIncludedInTheWindow(self, feature):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 return feature.getMin() >= self._start and feature.getMax() <= self._end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 def _isWindowIncludedInTheSet(self, feature):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 return self._start >= feature.getMin() and self._end <= feature.getMax()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 def _isSetOverlapTheRightSideOfTheWindow(self, feature):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 return feature.getMin() <= self._end and feature.getMin() >= self._start
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 def _isSetOverlapTheLeftSideOfTheWindow(self, feature):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 return feature.getMax() <= self._end and feature.getMax() >= self._start