comparison retrieve_meta.py @ 0:36e37b29c1b0 draft default tip

"planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
author wolma
date Mon, 20 Dec 2021 10:15:18 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:36e37b29c1b0
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)