-
Notifications
You must be signed in to change notification settings - Fork 4
/
partitioner.py
executable file
·37 lines (28 loc) · 1.17 KB
/
partitioner.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
#!/usr/bin/env python2
from lib.PipeTool import PipeTool
DESCRIPTION = """Extracts sub sequences from sequence using a sliding
window"""
class SequencePartitioner(PipeTool):
def __init__(self):
PipeTool.__init__(self, DESCRIPTION)
self.argParser.add_argument('-w', '--window', type=int,
default=5,
help="""The size of the sliding
window. Default: 5.""")
self.argParser.add_argument('-s', '--step', type=int,
default=1,
help="""The step size of the sliding
window. Default: 1.""")
def processLine(self, line):
sequence = line.strip().split(' ')
start = 0
end = start + self.args.window
while start < len(sequence) - self.args.window:
window = sequence[start:end]
start += self.args.step
end = start + self.args.window
win_str = ' '.join(window) + '\n'
self.output(win_str)
if __name__ == '__main__':
tool = SequencePartitioner()
tool.run()