Mercurial > repos > devteam > data_manager_fetch_ncbi_taxonomy
comparison data_manager/data_manager.py @ 5:9de2fb1ce1fb draft
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 02d2967f77e3fa5a18aea63dc84aa9ab418dc165"
author | iuc |
---|---|
date | Sun, 22 Nov 2020 12:48:48 +0000 |
parents | d6acd5cd497b |
children | 6dd9e00dea95 |
comparison
equal
deleted
inserted
replaced
4:d6acd5cd497b | 5:9de2fb1ce1fb |
---|---|
3 import json | 3 import json |
4 import os | 4 import os |
5 import shutil | 5 import shutil |
6 import tarfile | 6 import tarfile |
7 import zipfile | 7 import zipfile |
8 try: | 8 from urllib.request import Request, urlopen |
9 # For Python 3.0 and later | |
10 from urllib.request import Request, urlopen | |
11 except ImportError: | |
12 # Fall back to Python 2 imports | |
13 from urllib2 import Request, urlopen | |
14 | 9 |
15 | 10 |
16 def url_download(url, workdir): | 11 def url_download(url, workdir): |
17 file_path = os.path.join(workdir, 'download.dat') | 12 file_path = os.path.join(workdir, 'download.dat') |
18 if not os.path.exists(workdir): | 13 if not os.path.exists(workdir): |
48 data_manager_entry = {} | 43 data_manager_entry = {} |
49 data_manager_entry['value'] = args.name.lower() | 44 data_manager_entry['value'] = args.name.lower() |
50 data_manager_entry['name'] = args.name | 45 data_manager_entry['name'] = args.name |
51 data_manager_entry['path'] = '.' | 46 data_manager_entry['path'] = '.' |
52 data_manager_json = dict(data_tables=dict(ncbi_taxonomy=data_manager_entry)) | 47 data_manager_json = dict(data_tables=dict(ncbi_taxonomy=data_manager_entry)) |
53 params = json.loads(open(args.output).read()) | 48 with open(args.output) as fh: |
49 params = json.load(fh) | |
54 target_directory = params['output_data'][0]['extra_files_path'] | 50 target_directory = params['output_data'][0]['extra_files_path'] |
55 os.mkdir(target_directory) | 51 os.mkdir(target_directory) |
56 output_path = os.path.abspath(os.path.join(os.getcwd(), 'taxonomy')) | 52 output_path = os.path.abspath(os.path.join(os.getcwd(), 'taxonomy')) |
57 for filename in os.listdir(workdir): | 53 for filename in os.listdir(workdir): |
58 shutil.move(os.path.join(output_path, filename), target_directory) | 54 shutil.move(os.path.join(output_path, filename), target_directory) |
59 with open(args.output, 'w') as out: | 55 with open(args.output, 'w') as fh: |
60 out.write(json.dumps(data_manager_json, sort_keys=True)) | 56 json.dump(data_manager_json, fh, sort_keys=True) |
61 | 57 |
62 | 58 |
63 if __name__ == '__main__': | 59 if __name__ == '__main__': |
64 parser = argparse.ArgumentParser(description='Create data manager json.') | 60 parser = argparse.ArgumentParser(description='Create data manager json.') |
65 parser.add_argument('--out', dest='output', action='store', help='JSON filename') | 61 parser.add_argument('--out', dest='output', action='store', help='JSON filename') |