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