comparison util/santitizer.py @ 29:7e8a8b732db3 draft

planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 1a81ebd0ddea950b84af3fc830e9267a4814b29f
author yating-l
date Wed, 16 May 2018 18:04:20 -0400
parents
children
comparison
equal deleted inserted replaced
28:6aa28a85cc38 29:7e8a8b732db3
1 #!/usr/bin/python
2 # -*- coding: utf8 -*-
3
4 """
5 This class handles the subprocess calls of the different tools used
6 in HubArchiveCreator
7 """
8
9 import logging
10 import os
11 import subprocess
12 import sys
13 import string
14 import tempfile
15
16
17 def prefixTrackName(filename):
18 """
19 santitize trackName. Because track name must begin with a letter and
20 contain only the following chars: [a-zA-Z0-9_].
21 See the "track" Common settings at:
22 https://genome.ucsc.edu/goldenpath/help/trackDb/trackDbHub.html#bigPsl_-_Pairwise_Alignments
23 skip the santitization for cytoBandIdeo track
24 """
25 if filename == 'cytoBandIdeo':
26 return filename
27 valid_chars = "_%s%s" % (string.ascii_letters, string.digits)
28 sanitize_name = ''.join([c if c in valid_chars else '_' for c in filename])
29 sanitize_name = "gonramp_" + sanitize_name
30 return sanitize_name
31
32 def sanitize_name_input(string_to_sanitize):
33 """
34 Sanitize the string passed in parameter by replacing '/' and ' ' by '_'
35
36 :param string_to_sanitize:
37 :return :
38
39 :Example:
40
41 >>> sanitize_name_input('this/is an//example')
42 this_is_an__example
43 """
44 return string_to_sanitize \
45 .replace("/", "_") \
46 .replace(" ", "_")
47
48 def sanitize_name_inputs(inputs_data):
49 """
50 Sanitize value of the keys "name" of the dictionary passed in parameter.
51
52 Because sometimes output from Galaxy, or even just file name, from user inputs, have spaces.
53 Also, it can contain '/' character and could break the use of os.path function.
54
55 :param inputs_data: dict[string, dict[string, string]]
56 """
57 for key in inputs_data:
58 inputs_data[key]["name"] = sanitize_name_input(inputs_data[key]["name"])
59
60 def sanitize_group_name(group_name):
61 return group_name.lower().replace(' ', '_')