comparison hubArchiveCreator.py @ 13:25809f699cb3 draft

planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 65ab931ef2b05a5acf06cbde3a746c94a0a0a4cb
author rmarenco
date Thu, 11 Aug 2016 19:02:29 -0400
parents d05236b15f81
children 3233451a3bd6
comparison
equal deleted inserted replaced
12:747475757cb0 13:25809f699cb3
9 """ 9 """
10 10
11 import argparse 11 import argparse
12 import collections 12 import collections
13 import json 13 import json
14 import logging
15 import os
14 import sys 16 import sys
15 17
16 # Internal dependencies 18 # Internal dependencies
17 from Bam import Bam 19 from Bam import Bam
18 from BedSimpleRepeats import BedSimpleRepeats 20 from BedSimpleRepeats import BedSimpleRepeats
19 from Bed import Bed 21 from Bed import Bed
20 from BigWig import BigWig 22 from BigWig import BigWig
21 from util.Fasta import Fasta 23 from util.Fasta import Fasta
24 from util.Filters import TraceBackFormatter
22 from Gff3 import Gff3 25 from Gff3 import Gff3
23 from Gtf import Gtf 26 from Gtf import Gtf
24 from TrackHub import TrackHub 27 from TrackHub import TrackHub
25
26 28
27 # TODO: Verify each subprocessed dependency is accessible [gff3ToGenePred, genePredToBed, twoBitInfo, faToTwoBit, bedToBigBed, sort 29 # TODO: Verify each subprocessed dependency is accessible [gff3ToGenePred, genePredToBed, twoBitInfo, faToTwoBit, bedToBigBed, sort
28 30
29 31
30 def main(argv): 32 def main(argv):
65 67
66 parser.add_argument('--user_email', help='Email of the user who launched the Hub Archive Creation') 68 parser.add_argument('--user_email', help='Email of the user who launched the Hub Archive Creation')
67 69
68 parser.add_argument('--genome_name', help='UCSC Genome Browser assembly ID') 70 parser.add_argument('--genome_name', help='UCSC Genome Browser assembly ID')
69 71
70 ucsc_tools_path = '' 72 parser.add_argument('--debug_mode', action='store_true', help='Allow more details about the errors')
73
74 # Begin init variables
71 75
72 toolDirectory = '.' 76 toolDirectory = '.'
73 extra_files_path = '.' 77 extra_files_path = '.'
74 78
75 # Get the args passed in parameter 79 # Get the args passed in parameter
76 args = parser.parse_args() 80 args = parser.parse_args()
81
82 extra_files_path = args.extra_files_path
83 toolDirectory = args.directory
84
85 #### Logging management ####
86 # If we are in Debug mode, also print in stdout the debug dump
87
88 configure_logger(extra_files_path=extra_files_path, debug=args.debug_mode)
89
90 #### END Logging management ####
77 91
78 array_inputs_reference_genome = json.loads(args.fasta) 92 array_inputs_reference_genome = json.loads(args.fasta)
79 93
80 # TODO: Replace these with the object Fasta 94 # TODO: Replace these with the object Fasta
81 input_fasta_file = array_inputs_reference_genome["false_path"] 95 input_fasta_file = array_inputs_reference_genome["false_path"]
98 array_inputs_gtf = args.gtf 112 array_inputs_gtf = args.gtf
99 array_inputs_bam = args.bam 113 array_inputs_bam = args.bam
100 array_inputs_bigwig = args.bigwig 114 array_inputs_bigwig = args.bigwig
101 115
102 outputFile = args.output 116 outputFile = args.output
103 json_inputs_data = args.data_json
104 117
105 json_inputs_data = args.data_json 118 json_inputs_data = args.data_json
106 119
107 inputs_data = json.loads(json_inputs_data) 120 inputs_data = json.loads(json_inputs_data)
108 # We remove the spaces in ["name"] of inputs_data 121 # We remove the spaces in ["name"] of inputs_data
109 sanitize_name_inputs(inputs_data) 122 sanitize_name_inputs(inputs_data)
110 123
111 if args.directory:
112 toolDirectory = args.directory
113 if args.extra_files_path:
114 extra_files_path = args.extra_files_path
115 124
116 # TODO: Check here all the binaries / tools we need. Exception if missing 125 # TODO: Check here all the binaries / tools we need. Exception if missing
117 126
118 # Create the Track Hub folder 127 # Create the Track Hub folder
119 trackHub = TrackHub(reference_genome, user_email, outputFile, extra_files_path, toolDirectory) 128 trackHub = TrackHub(reference_genome, user_email, outputFile, extra_files_path, toolDirectory)
139 #trackHub.createZip() 148 #trackHub.createZip()
140 149
141 # We terminate le process and so create a HTML file summarizing all the files 150 # We terminate le process and so create a HTML file summarizing all the files
142 trackHub.terminate() 151 trackHub.terminate()
143 152
144 print "\t" 153 logging.debug('#### End of HubArchiveCreator Debug Mode: Bye! ####')
145 print "--------------"
146 print "Well done guys! Your data are ready to be displayed in UCSC Track Hub."
147 154
148 sys.exit(0) 155 sys.exit(0)
149 156
150 157
151 def sanitize_name_input(string_to_sanitize): 158 def sanitize_name_input(string_to_sanitize):
182 if key == input_false_path: 189 if key == input_false_path:
183 extensionObject = ExtensionClass(input_false_path, data_value) 190 extensionObject = ExtensionClass(input_false_path, data_value)
184 datatype_dictionary.update({data_value["order_index"]: extensionObject}) 191 datatype_dictionary.update({data_value["order_index"]: extensionObject})
185 return datatype_dictionary 192 return datatype_dictionary
186 193
194 def configure_logger(extra_files_path=None, debug=False):
195 if not extra_files_path:
196 raise Exception("Extra files path is not set. Stopping the application")
197
198
199 # All case log: log everything in a .log file
200 logger_file_name = ''.join([__name__, '.log'])
201 logging_file_path = os.path.join(extra_files_path, logger_file_name)
202
203 logging.basicConfig(filename=logging_file_path, level=logging.DEBUG)
204
205 log_stdout = logging.StreamHandler(sys.stdout)
206 if not debug:
207 configure_logger_user(log_stdout)
208 else:
209 configure_logger_dev(log_stdout)
210
211 # stderr configuration
212 configure_logger_stderr()
213
214 logging.debug('#### Welcome in HubArchiveCreator Debug Mode ####\n')
215
216 def configure_logger_user(log_stdout=None):
217 """
218 User Logger is defined as following:
219 - User needs to have WARN, ERROR and CRITICAL but well formatted / without traceback
220 in STDOUT
221 - Still access to full, brute and traceback for errors
222 in STDERR
223 - And further access to debug if needed
224 in .log
225 :return:
226 """
227 if not log_stdout:
228 raise Exception("No log_stdout given. Stopping the application")
229
230 # stdout for INFO / WARN / ERROR / CRITICAL
231 log_stdout.setLevel(logging.INFO)
232
233 formatter = TraceBackFormatter('%(message)s')
234
235 log_stdout.setFormatter(formatter)
236
237 logging.getLogger().addHandler(log_stdout)
238
239 def configure_logger_dev(log_stdout=None):
240 """
241 Dev Logger is defined as following:
242 - Dev needs to have WARN, ERROR and CRITICAL but well formatted / without traceback, in stdout
243 - Still access to full, brute and traceback in stderr for errors
244 - And further access to debug if needed
245 :return:
246 """
247 if not log_stdout:
248 raise Exception("No log_stdout given. Stopping the application")
249 log_format = '%(message)s'
250
251 # stdout and stderr and both identical for INFO / WARN / ERROR / CRITICAL
252 log_stdout.setLevel(logging.DEBUG)
253
254 formatter = logging.Formatter(log_format)
255
256 log_stdout.setFormatter(formatter)
257
258 logging.getLogger().addHandler(log_stdout)
259
260 def configure_logger_stderr():
261 """
262 Configure what should be logged in stderr
263 :return:
264 """
265 log_error = logging.StreamHandler(sys.stderr)
266 log_error.setLevel(logging.ERROR)
267 log_error_format = '%(message)s'
268
269 formatter_error = logging.Formatter(log_error_format)
270
271 log_error.setFormatter(formatter_error)
272
273 logging.getLogger().addHandler(log_error)
274
187 if __name__ == "__main__": 275 if __name__ == "__main__":
276 logging.getLogger(__name__)
188 main(sys.argv) 277 main(sys.argv)