annotate hubArchiveCreator.py @ 85:a65e52152476 draft default tip

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