Mercurial > repos > eric-rasche > circos
annotate wiggle.py @ 4:4ff5ff4c84fa draft
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit e4192d8d51efd2bf52c8094df65c164d90168e66
author | eric-rasche |
---|---|
date | Sun, 05 Mar 2017 17:02:17 -0500 |
parents | e8475d0195fe |
children |
rev | line source |
---|---|
0
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
1 class Wiggle: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
2 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
3 def fixedStepParser(self, line): |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
4 value = line.strip() |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
5 start_position = self.stepIdx * self.parserConfig['step'] + self.parserConfig['start'] |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
6 stop_position = start_position + self.parserConfig['span'] - 1 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
7 self.stepIdx += 1 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
8 |
4
4ff5ff4c84fa
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit e4192d8d51efd2bf52c8094df65c164d90168e66
eric-rasche
parents:
0
diff
changeset
|
9 for position in range(start_position, stop_position): |
0
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
10 yield (self.parserConfig['chrom'], position, value) |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
11 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
12 def variableStepParser(self, line): |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
13 (start, value) = line.strip().split() |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
14 start = int(start) |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
15 start_position = start |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
16 stop_position = start + self.parserConfig['span'] |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
17 |
4
4ff5ff4c84fa
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit e4192d8d51efd2bf52c8094df65c164d90168e66
eric-rasche
parents:
0
diff
changeset
|
18 for position in range(start_position, stop_position): |
0
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
19 yield (self.parserConfig['chrom'], position, value) |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
20 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
21 def walk(self, handle): |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
22 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
23 parser = None |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
24 for line in handle: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
25 if line.startswith('track'): |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
26 continue |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
27 elif line.startswith('fixedStep'): |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
28 parser = self.fixedStepParser |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
29 lineData = line.split() |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
30 fields = {x.split('=')[0]: x.split('=')[1] for x in lineData[1:]} |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
31 self.parserConfig = fields |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
32 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
33 for numField in ('step', 'start', 'span'): |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
34 if numField in self.parserConfig: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
35 self.parserConfig[numField] = int(self.parserConfig[numField]) |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
36 self.stepIdx = 0 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
37 elif line.startswith('variableStep'): |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
38 parser = self.variableStepParser |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
39 lineData = line.split() |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
40 fields = {x.split('=')[0]: x.split('=')[1] for x in lineData[1:]} |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
41 # Default value |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
42 if 'span' not in fields: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
43 fields['span'] = 1 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
44 self.parserConfig = fields |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
45 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
46 for numField in ('span',): |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
47 if numField in self.parserConfig: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
48 self.parserConfig[numField] = int(self.parserConfig[numField]) |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
49 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
50 self.stepIdx = 0 |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
51 elif len(line.strip()) == 0: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
52 continue |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
53 else: |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
54 for data in parser(line): |
e8475d0195fe
planemo upload for repository https://github.com/TAMU-CPT/galaxy-circos-tool commit 358dd35a2150af4183d9303af1df4f63be0737cd
eric-rasche
parents:
diff
changeset
|
55 yield data |