Mercurial > repos > iuc > data_manager_gemini_database_downloader
comparison data_manager/data_manager_gemini_download.py @ 5:b4b2b284230a draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_gemini_database_downloader commit 9981ac1338c91a3ab46557ce6b821da3d5b4bc86
author | iuc |
---|---|
date | Wed, 19 Dec 2018 12:36:22 -0500 |
parents | fe5a9a7d95b0 |
children | f57426daa04d |
comparison
equal
deleted
inserted
replaced
4:fe5a9a7d95b0 | 5:b4b2b284230a |
---|---|
7 import sys | 7 import sys |
8 | 8 |
9 import yaml | 9 import yaml |
10 | 10 |
11 | 11 |
12 def write_gemini_config(config, config_file): | |
13 with open(config_file, 'w') as fo: | |
14 yaml.dump(config, fo, allow_unicode=False, default_flow_style=False) | |
15 | |
16 | |
12 def main(): | 17 def main(): |
13 today = datetime.date.today() | 18 today = datetime.date.today() |
14 params = json.loads( open( sys.argv[1] ).read() ) | 19 params = json.loads( open( sys.argv[1] ).read() ) |
15 target_directory = params[ 'output_data' ][0]['extra_files_path'] | 20 target_directory = params[ 'output_data' ][0]['extra_files_path'] |
16 os.mkdir( target_directory ) | 21 os.mkdir( target_directory ) |
17 # The target_directory needs to be specified twice for the following | 22 |
18 # invocation of gemini. | 23 # Generate a minimal configuration file for GEMINI update |
19 # In essence, the GEMINI_CONFIG environment variable makes gemini store | 24 # to instruct the tool to download the annotation data into a |
20 # its yaml configuration file in that directory, while the | 25 # subfolder of the target directory. |
21 # --annotation-dir argument makes it write the same path into the yaml | 26 config_file = os.path.join(target_directory, 'gemini-config.yaml') |
22 # file, which is then used for determining where the actual annotation | 27 anno_dir = os.path.join(target_directory, 'gemini/data') |
23 # files should be stored. | 28 gemini_bootstrap_config = {'annotation_dir': anno_dir} |
29 write_gemini_config(gemini_bootstrap_config, config_file) | |
30 | |
31 # Now gemini update can be called to download the data. | |
32 # The GEMINI_CONFIG environment variable lets the tool discover | |
33 # the configuration file we prepared for it. | |
34 # Note that the tool will rewrite the file turning it into a | |
35 # complete gemini configuration file. | |
24 gemini_env = os.environ.copy() | 36 gemini_env = os.environ.copy() |
25 gemini_env['GEMINI_CONFIG'] = target_directory | 37 gemini_env['GEMINI_CONFIG'] = target_directory |
26 cmd = "gemini --annotation-dir %s update --dataonly %s %s" % ( | 38 cmd = "gemini update --dataonly %s %s" % ( |
27 target_directory, | |
28 params['param_dict']['gerp_bp'], | 39 params['param_dict']['gerp_bp'], |
29 params['param_dict']['cadd'] | 40 params['param_dict']['cadd'] |
30 ) | 41 ) |
31 subprocess.check_call( cmd, shell=True, env=gemini_env ) | 42 subprocess.check_call( cmd, shell=True, env=gemini_env ) |
32 | 43 |
33 # modify the newly created gemini config file to contain a relative | 44 # GEMINI tool wrappers that need access to the annotation files |
34 # annotation dir path, which will be interpreted as relative to | 45 # are supposed to symlink them into a gemini/data subfolder of |
35 # the job working directory at runtime by any gemini tool | 46 # the job working directory. To have GEMINI discover them there, |
36 config_file = os.path.join(target_directory, 'gemini-config.yaml') | 47 # we need to set this location as the 'annotation_dir' in the |
48 # configuration file. | |
37 with open(config_file) as fi: | 49 with open(config_file) as fi: |
38 config = yaml.load(fi) | 50 config = yaml.load(fi) |
39 config['annotation_dir'] = 'gemini/data' | 51 config['annotation_dir'] = 'gemini/data' |
40 with open(config_file, 'w') as fo: | 52 write_gemini_config(config, config_file) |
41 yaml.dump(config, fo, allow_unicode=False, default_flow_style=False) | |
42 | 53 |
54 # Finally, we prepare the metadata for the new data table record ... | |
43 data_manager_dict = { | 55 data_manager_dict = { |
44 'data_tables': { | 56 'data_tables': { |
45 'gemini_versioned_databases': [ | 57 'gemini_versioned_databases': [ |
46 { | 58 { |
47 'value': today.isoformat(), | 59 'value': today.isoformat(), |
53 } | 65 } |
54 ] | 66 ] |
55 } | 67 } |
56 } | 68 } |
57 | 69 |
58 # save info to json file | 70 # ... and save it to the json results file |
59 with open( sys.argv[1], 'wb' ) as out: | 71 with open( sys.argv[1], 'wb' ) as out: |
60 out.write( json.dumps( data_manager_dict ) ) | 72 out.write( json.dumps( data_manager_dict ) ) |
61 | 73 |
62 | 74 |
63 if __name__ == "__main__": | 75 if __name__ == "__main__": |