annotate util/santitizer.py @ 25:31a41ce128cc draft

planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
author yating-l
date Fri, 13 Oct 2017 12:44:31 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
1 #!/usr/bin/python
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
2 # -*- coding: utf8 -*-
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
3
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
4 """
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
5 This class handles the subprocess calls of the different tools used
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
6 in HubArchiveCreator
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
7 """
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
8
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
9 import logging
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
10 import os
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
11 import subprocess
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
12 import sys
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
13 import string
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
14 import tempfile
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
15
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
16
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
17 def prefixTrackName(filename):
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
18 """
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
19 santitize trackName. Because track name must begin with a letter and
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
20 contain only the following chars: [a-zA-Z0-9_].
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
21 See the "track" Common settings at:
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
22 https://genome.ucsc.edu/goldenpath/help/trackDb/trackDbHub.html#bigPsl_-_Pairwise_Alignments
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
23 skip the santitization for cytoBandIdeo track
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
24 """
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
25 if filename == 'cytoBandIdeo':
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
26 return filename
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
27 valid_chars = "_%s%s" % (string.ascii_letters, string.digits)
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
28 sanitize_name = ''.join([c if c in valid_chars else '_' for c in filename])
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
29 sanitize_name = "gonramp_" + sanitize_name
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
30 return sanitize_name
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
31
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
32 def sanitize_name_input(string_to_sanitize):
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
33 """
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
34 Sanitize the string passed in parameter by replacing '/' and ' ' by '_'
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
35
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
36 :param string_to_sanitize:
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
37 :return :
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
38
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
39 :Example:
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
40
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
41 >>> sanitize_name_input('this/is an//example')
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
42 this_is_an__example
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
43 """
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
44 return string_to_sanitize \
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
45 .replace("/", "_") \
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
46 .replace(" ", "_")
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
47
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
48 def sanitize_name_inputs(inputs_data):
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
49 """
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
50 Sanitize value of the keys "name" of the dictionary passed in parameter.
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
51
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
52 Because sometimes output from Galaxy, or even just file name, from user inputs, have spaces.
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
53 Also, it can contain '/' character and could break the use of os.path function.
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
54
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
55 :param inputs_data: dict[string, dict[string, string]]
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
56 """
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
57 for key in inputs_data:
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
58 inputs_data[key]["name"] = sanitize_name_input(inputs_data[key]["name"])
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
59
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
60 def sanitize_group_name(group_name):
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
61 return group_name.lower().replace(' ', '_')
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
62
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
63 def sanitize_name(input_name):
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
64 """
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
65 Galaxy will name all the files and dirs as *.dat,
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
66 the function can replace '.' to '_' for the dirs
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
67 """
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
68 validChars = "_-%s%s" % (string.ascii_letters, string.digits)
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
69 sanitized_name = ''.join([c if c in validChars else '_' for c in input_name])
31a41ce128cc planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
yating-l
parents:
diff changeset
70 return "gonramp_" + sanitized_name