comparison hubArchiveCreator.py @ 2:4ced8f116509 draft

planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 23b12dd763c0235674988ebdf6a258afd1ad629a-dirty
author yating-l
date Tue, 22 Nov 2016 17:13:18 -0500
parents 3e0c61b52a06
children 44577d6784b7
comparison
equal deleted inserted replaced
1:42337785f87b 2:4ced8f116509
120 120
121 outputFile = args.output 121 outputFile = args.output
122 122
123 json_inputs_data = args.data_json 123 json_inputs_data = args.data_json
124 124
125 # TODO: Instead use a class to properly store the objects, with object_hook
125 inputs_data = json.loads(json_inputs_data) 126 inputs_data = json.loads(json_inputs_data)
126 # We remove the spaces in ["name"] of inputs_data 127 # We remove the spaces in ["name"] of inputs_data
127 sanitize_name_inputs(inputs_data) 128 sanitize_name_inputs(inputs_data)
128 129
129 # TODO: Check here all the binaries / tools we need. Exception if missing 130 # TODO: Check here all the binaries / tools we need. Exception if missing
165 166
166 sys.exit(0) 167 sys.exit(0)
167 168
168 169
169 def sanitize_name_input(string_to_sanitize): 170 def sanitize_name_input(string_to_sanitize):
170 return string_to_sanitize \ 171 """
172 Sanitize the string passed in parameter by replacing '/' and ' ' by '_'
173
174 :param string_to_sanitize:
175 :return :
176
177 :Example:
178
179 >>> sanitize_name_input('this/is an//example')
180 this_is_an__example
181 """
182 return string_to_sanitize \
171 .replace("/", "_") \ 183 .replace("/", "_") \
172 .replace(" ", "_") 184 .replace(" ", "_")
173 185
174 186
175 def sanitize_name_inputs(inputs_data): 187 def sanitize_name_inputs(inputs_data):
176 """ 188 """
177 Sometimes output from Galaxy, or even just file name from user have spaces 189 Sanitize value of the keys "name" of the dictionary passed in parameter.
178 Also, it can contain '/' character and could break the use of os.path function 190
191 Because sometimes output from Galaxy, or even just file name, from user inputs, have spaces.
192 Also, it can contain '/' character and could break the use of os.path function.
193
179 :param inputs_data: dict[string, dict[string, string]] 194 :param inputs_data: dict[string, dict[string, string]]
180 :return:
181 """ 195 """
182 for key in inputs_data: 196 for key in inputs_data:
183 inputs_data[key]["name"] = sanitize_name_input(inputs_data[key]["name"]) 197 inputs_data[key]["name"] = sanitize_name_input(inputs_data[key]["name"])
184 198
185 199
186 def create_ordered_datatype_objects(ExtensionClass, array_inputs, inputs_data): 200 def create_ordered_datatype_objects(ExtensionClass, array_inputs, inputs_data):
187 """ 201 """
188 Function which executes the creation all the necessary files / folders for a special Datatype, for TrackHub 202 Function which executes the creation all the necessary files / folders for a special Datatype, for TrackHub
189 and update the dictionary of datatype 203 and update the dictionary of datatype
190 :param ExtensionClass: T <= Datatype 204
191 :param array_inputs: list[string] 205 :param ExtensionClass:
206 :param array_inputs:
192 :param inputs_data: 207 :param inputs_data:
208 :type ExtensionClass: Datatype
209 :type array_inputs: list[string]
210 :type inputs_data: dict
211 :rtype: dict
193 """ 212 """
194 213
195 datatype_dictionary = {} 214 datatype_dictionary = {}
196 215
197 # TODO: Optimize this double loop 216 # TODO: Optimize this double loop
233 in STDOUT 252 in STDOUT
234 - Still access to full, brute and traceback for errors 253 - Still access to full, brute and traceback for errors
235 in STDERR 254 in STDERR
236 - And further access to debug if needed 255 - And further access to debug if needed
237 in .log 256 in .log
238 :return: 257
239 """ 258 """
259
240 if not log_stdout: 260 if not log_stdout:
241 raise Exception("No log_stdout given. Stopping the application") 261 raise Exception("No log_stdout given. Stopping the application")
242 262
243 # stdout for INFO / WARN / ERROR / CRITICAL 263 # stdout for INFO / WARN / ERROR / CRITICAL
244 log_stdout.setLevel(logging.INFO) 264 log_stdout.setLevel(logging.INFO)
253 """ 273 """
254 Dev Logger is defined as following: 274 Dev Logger is defined as following:
255 - Dev needs to have WARN, ERROR and CRITICAL but well formatted / without traceback, in stdout 275 - Dev needs to have WARN, ERROR and CRITICAL but well formatted / without traceback, in stdout
256 - Still access to full, brute and traceback in stderr for errors 276 - Still access to full, brute and traceback in stderr for errors
257 - And further access to debug if needed 277 - And further access to debug if needed
258 :return: 278
259 """ 279 """
260 if not log_stdout: 280 if not log_stdout:
261 raise Exception("No log_stdout given. Stopping the application") 281 raise Exception("No log_stdout given. Stopping the application")
262 log_format = '%(message)s' 282 log_format = '%(message)s'
263 283
271 logging.getLogger().addHandler(log_stdout) 291 logging.getLogger().addHandler(log_stdout)
272 292
273 def configure_logger_stderr(): 293 def configure_logger_stderr():
274 """ 294 """
275 Configure what should be logged in stderr 295 Configure what should be logged in stderr
276 :return:
277 """ 296 """
278 log_error = logging.StreamHandler(sys.stderr) 297 log_error = logging.StreamHandler(sys.stderr)
279 log_error.setLevel(logging.ERROR) 298 log_error.setLevel(logging.ERROR)
280 log_error_format = '%(message)s' 299 log_error_format = '%(message)s'
281 300