comparison wiggle.py @ 0:ef5f8bbf7730 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/circos commit a41493893bdcbe330434db9c5851719012b62fa8
author iuc
date Wed, 09 Aug 2017 09:52:52 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:ef5f8bbf7730
1 class Wiggle:
2
3 def fixedStepParser(self, line):
4 value = line.strip()
5 start_position = self.stepIdx * self.parserConfig['step'] + self.parserConfig['start']
6 stop_position = start_position + self.parserConfig['span'] - 1
7 self.stepIdx += 1
8
9 for position in range(start_position, stop_position):
10 yield (self.parserConfig['chrom'], position, value)
11
12 def variableStepParser(self, line):
13 (start, value) = line.strip().split()
14 start = int(start)
15 start_position = start
16 stop_position = start + self.parserConfig['span']
17
18 for position in range(start_position, stop_position):
19 yield (self.parserConfig['chrom'], position, value)
20
21 def walk(self, handle):
22
23 parser = None
24 for line in handle:
25 if line.startswith('track'):
26 continue
27 elif line.startswith('fixedStep'):
28 parser = self.fixedStepParser
29 lineData = line.split()
30 fields = {x.split('=')[0]: x.split('=')[1] for x in lineData[1:]}
31 self.parserConfig = fields
32
33 for numField in ('step', 'start', 'span'):
34 if numField in self.parserConfig:
35 self.parserConfig[numField] = int(self.parserConfig[numField])
36 self.stepIdx = 0
37 elif line.startswith('variableStep'):
38 parser = self.variableStepParser
39 lineData = line.split()
40 fields = {x.split('=')[0]: x.split('=')[1] for x in lineData[1:]}
41 # Default value
42 if 'span' not in fields:
43 fields['span'] = 1
44 self.parserConfig = fields
45
46 for numField in ('span',):
47 if numField in self.parserConfig:
48 self.parserConfig[numField] = int(self.parserConfig[numField])
49
50 self.stepIdx = 0
51 elif len(line.strip()) == 0:
52 continue
53 else:
54 for data in parser(line):
55 yield data