comparison hubArchiveCreator.py @ 1:85195e0d4b71 draft

planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
author yating-l
date Fri, 29 Sep 2017 13:32:23 -0400
parents
children
comparison
equal deleted inserted replaced
0:f9ccc5ad1713 1:85195e0d4b71
1 #!/usr/bin/python
2 # -*- coding: utf8 -*-
3
4 """
5 This Galaxy tool permits to prepare your files to be ready for
6 Assembly Hub visualization.
7 Program test arguments:
8 hubArchiveCreator.py -g test-data/augustusDbia3.gff3 -f '{"false_path": "./test-data/common/dbia3.fa", "name":"dbia3"}' -d . -u ./tools -o output.html
9 """
10
11 import argparse
12 import collections
13 import json
14 import logging
15 import os
16 import sys
17
18 # Internal dependencies
19 from util.Reader import Reader
20 from util.Logger import Logger
21 from TrackHub import TrackHub
22
23
24
25 # TODO: Verify each subprocessed dependency is accessible [gff3ToGenePred, genePredToBed, twoBitInfo, faToTwoBit, bedToBigBed, sort
26
27
28 def main(argv):
29
30 # Command Line parsing init
31 parser = argparse.ArgumentParser(description='Create a foo.txt inside the given folder.')
32 parser.add_argument('-j', '--data_json', help='JSON file containing the metadata of the inputs')
33 parser.add_argument('-o', '--output', help='Name of the HTML summarizing the content of the Track Hub Archive')
34
35 # Get the args passed in parameter
36 args = parser.parse_args()
37 json_inputs_data = args.data_json
38 outputFile = args.output
39
40 ##Parse JSON file with Reader
41 reader = Reader(json_inputs_data)
42
43 # Begin init variables
44 extra_files_path = reader.getExtFilesPath()
45 toolDirectory = reader.getToolDir()
46 #outputFile = reader.getOutputDir()
47 user_email = reader.getUserEmail()
48 reference_genome = reader.getRefGenome()
49 debug_mode = reader.getDebugMode()
50
51 #### Logging management ####
52 # If we are in Debug mode, also print in stdout the debug dump
53 log = Logger(tool_directory=toolDirectory, debug=debug_mode, extra_files_path=extra_files_path)
54 log.setup_logging()
55 logging.info('#### HubArchiveCreator: Start ####\n')
56 logging.debug('---- Welcome in HubArchiveCreator Debug Mode ----\n')
57 logging.debug('JSON parameters: %s\n\n', json.dumps(reader.args))
58 #### END Logging management ####
59
60 # Create the Track Hub folder
61 logging.info('#### HubArchiveCreator: Creating the Track Hub folder ####\n')
62 trackHub = TrackHub(reference_genome, user_email, outputFile, extra_files_path, toolDirectory)
63
64 # Create Ordered Dictionary to add the tracks in the tool form order
65 logging.info('#### HubArchiveCreator: Preparing track data ####\n')
66 all_datatype_dictionary = reader.getTracksData()
67 all_datatype_ordered_dictionary = collections.OrderedDict(all_datatype_dictionary)
68
69 logging.debug("----- End of all_datatype_dictionary processing -----")
70 #logging.debug("all_datatype_ordered_dictionary are: %s", json.dumps(all_datatype_ordered_dictionary))
71
72 logging.info('#### HubArchiveCreator: Adding tracks to Track Hub ####\n')
73 logging.debug("----- Beginning of Track adding processing -----")
74
75 for index, datatypeObject in all_datatype_ordered_dictionary.iteritems():
76 trackHub.addTrack(datatypeObject.track.track_db)
77
78 logging.debug("----- End of Track adding processing -----")
79
80 # We terminate the process and so create a HTML file summarizing all the files
81 logging.info('#### HubArchiveCreator: Creating the HTML file ####\n')
82 trackHub.terminate()
83
84 logging.debug('---- End of HubArchiveCreator Debug Mode: Bye! ----\n')
85 logging.info('#### HubArchiveCreator: Congratulation! Assembly Hub is created! ####\n')
86
87 sys.exit(0)
88
89 if __name__ == "__main__":
90 main(sys.argv)