Mercurial > repos > yating-l > suite_gonramp_apollo2
comparison jbrowsehubToApollo.py @ 0:9945eba268e6 draft default tip
planemo upload for repository https://github.com/Yating-L/suite_gonramp_apollo.git commit 9009fa8663038d2cb4a1c5130600a51f31f654a1-dirty
author | yating-l |
---|---|
date | Mon, 27 Nov 2017 12:49:27 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:9945eba268e6 |
---|---|
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 #user_email = reader.getUserEmail() | |
29 species_name = reader.getSpeciesName() | |
30 #apollo_host = reader.getApolloHost() | |
31 apollo_port = reader.getPortNum() | |
32 apollo_host = "http://localhost:"+ apollo_port + "/apollo" | |
33 #apollo_host = "http://localhost:8080/apollo" | |
34 #apollo_user = reader.getApolloUser() | |
35 apollo_admin_user = reader.getAdminUser() | |
36 toolDirectory = reader.getToolDir() | |
37 #jbrowse_hub = reader.getJBrowseHubDir() | |
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) | |
44 log.setup_logging() | |
45 | |
46 <<<<<<< HEAD | |
47 logging.info("#### JBrowsehub To Apollo: Start to %s JBrowse Hub to Apollo instance: %s #### ", action, apollo_host) | |
48 ======= | |
49 logging.info("#### JBrowseArchiveCreator: Start to %s JBrowse Hub to Apollo instance: %s #### ", action, apollo_host) | |
50 >>>>>>> 8b9a3b41d4dd4689764592d278ec2d67f67fbca4 | |
51 logging.debug('JSON parameters: %s\n\n', json.dumps(reader.args)) | |
52 | |
53 # Set up apollo | |
54 apollo = ApolloInstance(apollo_host, apollo_admin_user, toolDirectory) | |
55 jbrowse_hub_dir = _getHubDir(extra_files_path) | |
56 <<<<<<< HEAD | |
57 apollo.manageApolloOrganism(species_name, jbrowse_hub_dir, action) | |
58 ======= | |
59 apollo.loadHubToApollo(species_name, jbrowse_hub_dir, action) | |
60 >>>>>>> 8b9a3b41d4dd4689764592d278ec2d67f67fbca4 | |
61 outHtml(outputFile, apollo_host, species_name) | |
62 | |
63 logging.info('#### JBrowsehub To Apollo: Congratulation! JBrowse Hub is uploaded! ####\n') | |
64 | |
65 def _getHubDir(extra_files_path): | |
66 for root, dirs, files in os.walk(extra_files_path): | |
67 for name in files: | |
68 if name == "trackList.json": | |
69 logging.debug("JBrowse hub directory: %s", root) | |
70 return root | |
71 logging.error("Cannot find jbrowsehub") | |
72 exit(-1) | |
73 | |
74 def outHtml(outputFile, host_name, species_name): | |
75 with open(outputFile, 'w') as htmlfile: | |
76 htmlstr = 'The new Organism "%s" is created on Apollo: <br>' % species_name | |
77 jbrowse_hub = '<li><a href = "%s" target="_blank">View JBrowse Hub on Apollo</a></li>' % host_name | |
78 htmlstr += jbrowse_hub | |
79 htmlfile.write(htmlstr) | |
80 | |
81 if __name__ == "__main__": | |
82 main(sys.argv) |