annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
1 #!/usr/bin/env python
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
2
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
3 import argparse
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
4 import json
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
5 import os
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
6
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
7 import yaml
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
8
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
9 if __name__ == "__main__":
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
10 parser = argparse.ArgumentParser()
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
11
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
12 parser.add_argument('galaxy_json')
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
13 parser.add_argument(
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
14 '-o', '--ofile',
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
15 required=True
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
16 )
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
17 parser.add_argument(
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
18 '--format', choices=['yaml', 'tab'], default='yaml'
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
19 )
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
20 args = parser.parse_args()
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
21
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
22 galaxy_collection_info = json.load(open(args.galaxy_json))
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
23 annotation_info = next(iter(galaxy_collection_info.values()))['elements']
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
24 selected_ids = {i['name'] for i in annotation_info}
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
25 package_meta_file = os.path.join(
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
26 os.path.dirname(annotation_info[0]['filename']),
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
27 'meta.yml'
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
28 )
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
29 meta = yaml.safe_load(open(package_meta_file))
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
30 meta['records'] = [
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
31 rec for rec in meta['records'] if rec['id'] in selected_ids
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
32 ]
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
33
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
34 with open(args.ofile, 'w') as fo:
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
35 if args.format == 'yaml':
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
36 yaml.dump(
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
37 meta, fo, allow_unicode=False, default_flow_style=False
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
38 )
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
39 else:
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
40 print('Annotation\tVersion', file=fo)
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
41 for record in meta['records']:
36e37b29c1b0 "planemo upload commit 3dc5291eccd1fb516be67694c18a27bda5f69f91-dirty"
wolma
parents:
diff changeset
42 print(record['name'], record['version'], sep='\t', file=fo)