Mercurial > repos > iuc > packaged_annotation_loader
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/retrieve_meta.py Tue Jan 04 18:34:48 2022 +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)
