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