Mercurial > repos > wolma > packaged_annotation_loader
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/retrieve_meta.py Mon Dec 20 10:15:18 2021 +0000 @@ -0,0 +1,42 @@ +#!/usr/bin/env python + +import argparse +import json +import os + +import yaml + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + + parser.add_argument('galaxy_json') + parser.add_argument( + '-o', '--ofile', + required=True + ) + parser.add_argument( + '--format', choices=['yaml', 'tab'], default='yaml' + ) + args = parser.parse_args() + + galaxy_collection_info = json.load(open(args.galaxy_json)) + annotation_info = next(iter(galaxy_collection_info.values()))['elements'] + selected_ids = {i['name'] for i in annotation_info} + package_meta_file = os.path.join( + os.path.dirname(annotation_info[0]['filename']), + 'meta.yml' + ) + meta = yaml.safe_load(open(package_meta_file)) + meta['records'] = [ + rec for rec in meta['records'] if rec['id'] in selected_ids + ] + + with open(args.ofile, 'w') as fo: + if args.format == 'yaml': + yaml.dump( + meta, fo, allow_unicode=False, default_flow_style=False + ) + else: + print('Annotation\tVersion', file=fo) + for record in meta['records']: + print(record['name'], record['version'], sep='\t', file=fo)
