Mercurial > repos > yating-l > gonramp_apollo_tools
comparison jbrowsehubToApollo.py @ 0:ce4f91831680 draft default tip
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 5367a00befb467f162d1870edb91f9face72e894
author | yating-l |
---|---|
date | Fri, 16 Feb 2018 10:57:13 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ce4f91831680 |
---|---|
1 #!/usr/bin/env python | |
2 import os | |
3 import sys | |
4 import argparse | |
5 import json | |
6 import logging | |
7 import socket | |
8 from apollo.ApolloInstance import ApolloInstance | |
9 from util.Reader import Reader | |
10 from util.Logger import Logger | |
11 | |
12 | |
13 def main(argv): | |
14 parser = argparse.ArgumentParser(description='Upload a hub to display on Apollo.') | |
15 parser.add_argument('-j', '--data_json', help='JSON file containing the metadata of the inputs') | |
16 parser.add_argument('-o', '--output', help='HTML output') | |
17 | |
18 # Get the args passed in parameter | |
19 args = parser.parse_args() | |
20 json_inputs_data = args.data_json | |
21 outputFile = args.output | |
22 | |
23 ##Parse JSON file with Reader | |
24 reader = Reader(json_inputs_data) | |
25 | |
26 # Begin init variables | |
27 extra_files_path = reader.getExtFilesPath() | |
28 jbrowse_hub = reader.getJBrowseHubDir() | |
29 #user_email = reader.getUserEmail() | |
30 species_name = reader.getSpeciesName() | |
31 #apollo_host = reader.getApolloHost() | |
32 apollo_port = reader.getPortNum() | |
33 apollo_host = "http://localhost:"+ apollo_port + "/apollo" | |
34 #apollo_host = "http://localhost:8080/apollo" | |
35 #apollo_user = reader.getApolloUser() | |
36 apollo_admin_user = reader.getAdminUser() | |
37 toolDirectory = reader.getToolDir() | |
38 debug_mode = reader.getDebugMode() | |
39 action = reader.getAction() | |
40 | |
41 #### Logging management #### | |
42 # If we are in Debug mode, also print in stdout the debug dump | |
43 log = Logger(tool_directory=toolDirectory, debug=debug_mode, extra_files_path=extra_files_path) | |
44 log.setup_logging() | |
45 | |
46 logging.info("#### JBrowsehub To Apollo: Start to %s JBrowse Hub to Apollo instance: %s #### ", action, apollo_host) | |
47 logging.debug('JSON parameters: %s\n\n', json.dumps(reader.args)) | |
48 | |
49 # Set up apollo | |
50 apollo = ApolloInstance(apollo_host, apollo_admin_user, toolDirectory) | |
51 jbrowse_hub_dir = _getHubDir(jbrowse_hub) | |
52 apollo.manageApolloOrganism(species_name, jbrowse_hub_dir, action) | |
53 outHtml(outputFile, apollo_host, species_name, action) | |
54 | |
55 logging.info('#### JBrowsehub To Apollo: Congratulation! JBrowse Hub is uploaded! ####\n') | |
56 | |
57 def _getHubDir(extra_files_path): | |
58 for root, dirs, files in os.walk(extra_files_path): | |
59 for name in files: | |
60 if name == "trackList.json": | |
61 logging.debug("JBrowse hub directory: %s", root) | |
62 return root | |
63 logging.error("Cannot find jbrowsehub") | |
64 exit(-1) | |
65 | |
66 def outHtml(outputFile, host_name, species_name, action): | |
67 with open(outputFile, 'w') as htmlfile: | |
68 if action == "add": | |
69 htmlstr = 'The Organism "%s" is added on Apollo: <br>' % species_name | |
70 elif action == "overwrite": | |
71 htmlstr = 'The Organism "%s" is overwritten on Apollo: <br>' % species_name | |
72 jbrowse_hub = '<li><a href = "%s" target="_blank">View JBrowse Hub on Apollo</a></li>' % host_name | |
73 htmlstr += jbrowse_hub | |
74 htmlfile.write(htmlstr) | |
75 | |
76 if __name__ == "__main__": | |
77 main(sys.argv) |