Mercurial > repos > yufei-luo > s_mart
comparison commons/core/parsing/WigParser.py @ 18:94ab73e8a190
Uploaded
author | m-zytnicki |
---|---|
date | Mon, 29 Apr 2013 03:20:15 -0400 |
parents | 769e306b7933 |
children |
comparison
equal
deleted
inserted
replaced
17:b0e8584489e6 | 18:94ab73e8a190 |
---|---|
121 m1 = re.search(r"^\s*-?\d+\.?\d*\s*$", line) | 121 m1 = re.search(r"^\s*-?\d+\.?\d*\s*$", line) |
122 m2 = re.search(r"^\s*(\d+)\s+-?\d+\.?\d*\s*$", line) | 122 m2 = re.search(r"^\s*(\d+)\s+-?\d+\.?\d*\s*$", line) |
123 m3 = re.search(r"^\s*fixedStep\s+chrom=(\S+)\s+start=(\d+)\s+step=1\s*$", line) | 123 m3 = re.search(r"^\s*fixedStep\s+chrom=(\S+)\s+start=(\d+)\s+step=1\s*$", line) |
124 m4 = re.search(r"^\s*fixedStep\s+chrom=\S+\s+start=\d+\s+step=\d+\s+span=\d+\s*$", line) | 124 m4 = re.search(r"^\s*fixedStep\s+chrom=\S+\s+start=\d+\s+step=\d+\s+span=\d+\s*$", line) |
125 m5 = re.search(r"^\s*variableStep\s+chrom=(\S+)\s*$", line) | 125 m5 = re.search(r"^\s*variableStep\s+chrom=(\S+)\s*$", line) |
126 m6 = re.search(r"^\s*variableStep\s+chrom=(\S+)span=(\d+)\s*$", line) | 126 m6 = re.search(r"^\s*variableStep\s+chrom=(\S+)\s+span=(\d+)\s*$", line) |
127 | 127 |
128 if m1 != None: | 128 if m1 != None: |
129 outputFile.write(struct.pack("Q", mark)) | 129 outputFile.write(struct.pack("Q", mark)) |
130 index += 1 | 130 index += 1 |
131 elif m2 != None: | 131 elif m2 != None: |
154 outputFile = open(self.makeIndexName(newChromosome), "wb") | 154 outputFile = open(self.makeIndexName(newChromosome), "wb") |
155 index = 0 | 155 index = 0 |
156 outputFile.write(self.filler) | 156 outputFile.write(self.filler) |
157 chromosome = newChromosome | 157 chromosome = newChromosome |
158 elif m6 != None: | 158 elif m6 != None: |
159 raise Exception("Error! Cannot parse variable step WIG files with step > 1 or span > 1") | 159 if m6.group(2) != "1": |
160 raise Exception("Error! Cannot parse variable step WIG files with step > 1 or span > 1") | |
161 newChromosome = m6.group(1) | |
162 if newChromosome != chromosome: | |
163 if outputFile != None: | |
164 outputFile.close() | |
165 outputFile = open(self.makeIndexName(newChromosome), "wb") | |
166 index = 0 | |
167 outputFile.write(self.filler) | |
168 chromosome = newChromosome | |
160 elif (len(line) == 0) or line[0] == "#" or line.startswith("track"): | 169 elif (len(line) == 0) or line[0] == "#" or line.startswith("track"): |
161 pass | 170 pass |
162 else: | 171 else: |
163 raise Exception("Error! Cannot understand line '%s' of WIG file while creating index file! Aborting." % (line)) | 172 raise Exception("Error! Cannot understand line '%s' of WIG file while creating index file! Aborting." % (line)) |
164 | 173 |