comparison util/santitizer.py @ 6:237707a6b74d draft

planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
author yating-l
date Thu, 15 Feb 2018 17:05:05 -0500
parents
children
comparison
equal deleted inserted replaced
5:e762f4b9e4bd 6:237707a6b74d
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(' ', '_')
62
63 def sanitize_name(input_name):
64 """
65 Galaxy will name all the files and dirs as *.dat,
66 the function can replace '.' to '_' for the dirs
67 """
68 validChars = "_-%s%s" % (string.ascii_letters, string.digits)
69 sanitized_name = ''.join([c if c in validChars else '_' for c in input_name])
70 return "gonramp_" + sanitized_name