Mercurial > repos > rmarenco > hubarchivecreator
comparison util/subtools.py @ 25:99dad5f9444c draft
planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 93e2e2fb59f99677425104a80c17f665fa7b2b4a-dirty
author | yating-l |
---|---|
date | Fri, 02 Jun 2017 17:36:24 -0400 |
parents | fcc1021bd496 |
children | df42241d3731 |
comparison
equal
deleted
inserted
replaced
24:fcc1021bd496 | 25:99dad5f9444c |
---|---|
9 import logging | 9 import logging |
10 import os | 10 import os |
11 import subprocess | 11 import subprocess |
12 import sys | 12 import sys |
13 import string | 13 import string |
14 import tempfile | |
14 | 15 |
15 class PopenError(Exception): | 16 class PopenError(Exception): |
16 def __init__(self, cmd, error, return_code): | 17 def __init__(self, cmd, error, return_code): |
17 self.cmd = cmd | 18 self.cmd = cmd |
18 self.error = error | 19 self.error = error |
126 Call gff3ToGenePred and write the result into gene_pred_file_name | 127 Call gff3ToGenePred and write the result into gene_pred_file_name |
127 :param input_gff3_file_name: | 128 :param input_gff3_file_name: |
128 :param gene_pred_file_name: | 129 :param gene_pred_file_name: |
129 :return: | 130 :return: |
130 """ | 131 """ |
131 array_call = ['gff3ToGenePred', input_gff3_file_name, gene_pred_file_name] | 132 valid_gff3_file = tempfile.NamedTemporaryFile(bufsize=0, suffix=".gff3") |
133 validateGff(input_gff3_file_name, valid_gff3_file.name) | |
134 array_call = ['gff3ToGenePred', valid_gff3_file.name, gene_pred_file_name] | |
132 p = _handleExceptionAndCheckCall(array_call) | 135 p = _handleExceptionAndCheckCall(array_call) |
133 return p | 136 return p |
134 | 137 |
135 def genePredToBigGenePred(gene_pred_file_name, unsorted_bigGenePred_file_name): | 138 def genePredToBigGenePred(gene_pred_file_name, unsorted_bigGenePred_file_name): |
136 """ | 139 """ |
254 return filename | 257 return filename |
255 valid_chars = "_%s%s" % (string.ascii_letters, string.digits) | 258 valid_chars = "_%s%s" % (string.ascii_letters, string.digits) |
256 sanitize_name = ''.join([c if c in valid_chars else '_' for c in filename]) | 259 sanitize_name = ''.join([c if c in valid_chars else '_' for c in filename]) |
257 sanitize_name = "gonramp_" + sanitize_name | 260 sanitize_name = "gonramp_" + sanitize_name |
258 return sanitize_name | 261 return sanitize_name |
262 | |
263 def validateGff(orig_gff3, valid_gff3): | |
264 """ | |
265 Remove extra meta line: ##gff-version 3 | |
266 """ | |
267 valid = open(valid_gff3, 'w') | |
268 num = 0 | |
269 with open(orig_gff3, 'r') as f: | |
270 for line in f: | |
271 if '##gff-version 3' in line: | |
272 if num == 0: | |
273 num += 1 | |
274 else: | |
275 continue | |
276 valid.write(line) | |
277 |