annotate transform_json_to_pkl.py @ 3:05c352d22fe8 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/humann2 commit 52d835f027b052a0a887be14a55faf9fa9e456ae"
author iuc
date Mon, 01 Feb 2021 18:14:30 +0000
parents b6f52c19973d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
1 #!/usr/bin/env python
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
2 # -*- coding: utf-8 -*-
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
3
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
4 import argparse
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
5 import bz2
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
6 import cPickle as pickle
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
7 import json
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
8
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
9
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
10 def transform_json_to_pkl(args):
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
11 with open(args.json_input, 'r') as json_file:
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
12 json_str = json_file.read()
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
13 metadata = json.loads(json_str)
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
14
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
15 for marker in metadata["markers"]:
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
16 a_set = set(metadata["markers"][marker]["ext"])
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
17 metadata["markers"][marker]["ext"] = a_set
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
18
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
19 pkl_output = bz2.BZ2File(args.pkl_output, 'w')
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
20 pickle.dump(metadata, pkl_output, pickle.HIGHEST_PROTOCOL)
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
21 pkl_output.close()
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
22
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
23
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
24 if __name__ == '__main__':
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
25 parser = argparse.ArgumentParser()
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
26 parser.add_argument('--json_input', required=True)
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
27 parser.add_argument('--pkl_output', required=True)
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
28 args = parser.parse_args()
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
29
b6f52c19973d planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff changeset
30 transform_json_to_pkl(args)