Mercurial > repos > eric-rasche > circos
diff wiggle.py @ 0:e8475d0195fe draft
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
author | eric-rasche |
---|---|
date | Wed, 01 Mar 2017 22:47:20 -0500 |
parents | |
children | 4ff5ff4c84fa |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wiggle.py Wed Mar 01 22:47:20 2017 -0500 @@ -0,0 +1,55 @@ +class Wiggle: + + def fixedStepParser(self, line): + value = line.strip() + start_position = self.stepIdx * self.parserConfig['step'] + self.parserConfig['start'] + stop_position = start_position + self.parserConfig['span'] - 1 + self.stepIdx += 1 + + for position in xrange(start_position, stop_position): + yield (self.parserConfig['chrom'], position, value) + + def variableStepParser(self, line): + (start, value) = line.strip().split() + start = int(start) + start_position = start + stop_position = start + self.parserConfig['span'] + + for position in xrange(start_position, stop_position): + yield (self.parserConfig['chrom'], position, value) + + def walk(self, handle): + + parser = None + for line in handle: + if line.startswith('track'): + continue + elif line.startswith('fixedStep'): + parser = self.fixedStepParser + lineData = line.split() + fields = {x.split('=')[0]: x.split('=')[1] for x in lineData[1:]} + self.parserConfig = fields + + for numField in ('step', 'start', 'span'): + if numField in self.parserConfig: + self.parserConfig[numField] = int(self.parserConfig[numField]) + self.stepIdx = 0 + elif line.startswith('variableStep'): + parser = self.variableStepParser + lineData = line.split() + fields = {x.split('=')[0]: x.split('=')[1] for x in lineData[1:]} + # Default value + if 'span' not in fields: + fields['span'] = 1 + self.parserConfig = fields + + for numField in ('span',): + if numField in self.parserConfig: + self.parserConfig[numField] = int(self.parserConfig[numField]) + + self.stepIdx = 0 + elif len(line.strip()) == 0: + continue + else: + for data in parser(line): + yield data