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