annotate data_manager/make_json.py @ 0:7e43f66abe9d draft

planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
author dfornika
date Thu, 28 Feb 2019 02:32:38 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
1 import argparse
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
2 import json
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
3 import os
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
4 import shutil
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
5
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
6
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
7 def main(args):
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
8 data_manager_entry = {}
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
9 data_manager_entry['value'] = args.database.lower()
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
10 data_manager_entry['name'] = args.database
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
11 data_manager_entry['path'] = '.'
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
12 data_manager_json = dict(data_tables=dict(kraken2_databases=data_manager_entry))
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
13 params = json.loads(open(args.output).read())
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
14 target_directory = params['output_data'][0]['extra_files_path']
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
15 os.mkdir(target_directory)
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
16 output_path = os.path.join(os.getcwd(), 'kraken2-database')
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
17 for filename in os.listdir(output_path):
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
18 shutil.move(os.path.join(output_path, filename), target_directory)
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
19 file(args.output, 'w').write(json.dumps(data_manager_json))
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
20
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
21
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
22 if __name__ == '__main__':
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
23 parser = argparse.ArgumentParser(description='Create data manager json.')
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
24 parser.add_argument('--db', dest='database', action='store', help='Database name')
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
25 parser.add_argument('--out', dest='output', action='store', help='JSON filename')
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
26 args = parser.parse_args()
7e43f66abe9d planemo upload for repository https://github.com/dfornika/galaxytools/tree/master/data_managers/data_manager_build_kraken2_database/ commit cc42cd530378bfa3df83b08b6b41aaf2f5072b49-dirty
dfornika
parents:
diff changeset
27 main(args)