annotate jbrowseArchiveCreator.py @ 12:9161beae834f draft

planemo upload for repository https://github.com/goeckslab/jbrowse-archive-creator.git commit 08f15daf5442def561713fb9c673bb06c9a3a05f
author yating-l
date Sat, 02 Jun 2018 13:08:46 -0400
parents 237707a6b74d
children 62dee5369e80
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
1 #!/usr/bin/env python
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
2 # -*- coding: utf8 -*-
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
3
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
4 """
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
5 This Galaxy tool permits to prepare your files to be ready for JBrowse visualization.
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
6 """
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
7
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
8 import sys
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
9 import argparse
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
10 import json
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
11 import logging
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
12 import collections
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
13
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
14
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
15 # Internal dependencies
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
16 from util.Reader import Reader
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
17 from util.Logger import Logger
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
18 from TrackHub import TrackHub
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
19
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
20
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
21 def main(argv):
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
22 parser = argparse.ArgumentParser(description='Create a hub to display in jbrowse.')
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
23 parser.add_argument('-j', '--data_json', help='JSON file containing the metadata of the inputs')
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
24 parser.add_argument('-o', '--output', help='Name of the HTML summarizing the content of the JBrowse Hub Archive')
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
25
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
26 # Get the args passed in parameter
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
27 args = parser.parse_args()
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
28 json_inputs_data = args.data_json
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
29 outputFile = args.output
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
30
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
31 ##Parse JSON file with Reader
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
32 reader = Reader(json_inputs_data)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
33
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
34 # Begin init variables
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
35 extra_files_path = reader.getExtFilesPath()
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
36 toolDirectory = reader.getToolDir()
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
37 #outputFile = reader.getOutputDir()
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
38 user_email = reader.getUserEmail()
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
39 reference_genome = reader.getRefGenome()
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
40 debug_mode = reader.getDebugMode()
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
41 track_type = reader.getTrackType()
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
42
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
43
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
44 #### Logging management ####
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
45 # If we are in Debug mode, also print in stdout the debug dump
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
46 log = Logger(tool_directory=toolDirectory, debug=debug_mode, extra_files_path=extra_files_path)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
47 log.setup_logging()
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
48 logging.info('#### JBrowseArchiveCreator: Start ####\n')
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
49 logging.debug('---- Welcome in JBrowseArchiveCreator Debug Mode ----\n')
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
50 logging.debug('JSON parameters: %s\n\n', json.dumps(reader.args))
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
51 #### END Logging management ####
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
52
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
53 # Create the Track Hub folder
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
54 logging.info('#### JBrowseArchiveCreator: Creating the Track Hub folder ####\n')
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
55 trackHub = TrackHub(reference_genome, outputFile, extra_files_path, toolDirectory, track_type)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
56
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
57 # Create Ordered Dictionary to add the tracks in the tool form order
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
58 logging.info('#### JBrowseArchiveCreator: Preparing track data ####\n')
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
59 all_datatype_dictionary = reader.getTracksData()
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
60 all_datatype_ordered_dictionary = collections.OrderedDict(all_datatype_dictionary)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
61
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
62 logging.debug("----- End of all_datatype_dictionary processing -----")
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
63 #logging.debug("all_datatype_ordered_dictionary are: %s", json.dumps(all_datatype_ordered_dictionary))
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
64
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
65 logging.info('#### JBrowseArchiveCreator: Adding tracks to Track Hub ####\n')
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
66 logging.debug("----- Beginning of Track adding processing -----")
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
67
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
68 for index, datatypeObject in all_datatype_ordered_dictionary.iteritems():
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
69 trackHub.addTrack(datatypeObject.track.track_db)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
70
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
71 logging.debug("----- End of Track adding processing -----")
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
72
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
73 # We terminate the process and so create a HTML file summarizing all the files
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
74 logging.info('#### JBrowseArchiveCreator: Creating the HTML file ####\n')
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
75 trackHub.terminate(debug_mode)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
76
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
77 logging.debug('---- End of JBrowseArchiveCreator Debug Mode: Bye! ----\n')
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
78 logging.info('#### JBrowseArchiveCreator: Congratulation! Assembly Hub is created! ####\n')
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
79
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
80 sys.exit(0)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
81
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
82 if __name__ == "__main__":
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents:
diff changeset
83 main(sys.argv)