annotate transform_json_to_pkl.py @ 7:d05ac93eabf3 draft default tip

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