comparison retrieve_meta.py @ 0:0de428c589f3 draft default tip

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/packaged_annotation_loader commit 339a6c16fb6d944d4e147b5192cbeb0ebd26d18e"
author iuc
date Tue, 04 Jan 2022 18:34:48 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0de428c589f3
1 #!/usr/bin/env python
2
3 import argparse
4 import json
5 import os
6
7 import yaml
8
9 if __name__ == "__main__":
10 parser = argparse.ArgumentParser()
11
12 parser.add_argument('galaxy_json')
13 parser.add_argument(
14 '-o', '--ofile',
15 required=True
16 )
17 parser.add_argument(
18 '--format', choices=['yaml', 'tab'], default='yaml'
19 )
20 args = parser.parse_args()
21
22 galaxy_collection_info = json.load(open(args.galaxy_json))
23 annotation_info = next(iter(galaxy_collection_info.values()))['elements']
24 selected_ids = {i['name'] for i in annotation_info}
25 package_meta_file = os.path.join(
26 os.path.dirname(annotation_info[0]['filename']),
27 'meta.yml'
28 )
29 meta = yaml.safe_load(open(package_meta_file))
30 meta['records'] = [
31 rec for rec in meta['records'] if rec['id'] in selected_ids
32 ]
33
34 with open(args.ofile, 'w') as fo:
35 if args.format == 'yaml':
36 yaml.dump(
37 meta, fo, allow_unicode=False, default_flow_style=False
38 )
39 else:
40 print('Annotation\tVersion', file=fo)
41 for record in meta['records']:
42 print(record['name'], record['version'], sep='\t', file=fo)