Mercurial > repos > iuc > humann2_rename_table
annotate transform_json_to_pkl.py @ 4:939d053a96b3 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:19:04 +0000 |
parents | dd4b5b9daf6b |
children |
rev | line source |
---|---|
0
dd4b5b9daf6b
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 |
dd4b5b9daf6b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit b46aa969c01b7e5f4f133192899fa4da286ecf89-dirty
iuc
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
dd4b5b9daf6b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit b46aa969c01b7e5f4f133192899fa4da286ecf89-dirty
iuc
parents:
diff
changeset
|
3 |
dd4b5b9daf6b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit b46aa969c01b7e5f4f133192899fa4da286ecf89-dirty
iuc
parents:
diff
changeset
|
4 import argparse |
dd4b5b9daf6b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit b46aa969c01b7e5f4f133192899fa4da286ecf89-dirty
iuc
parents:
diff
changeset
|
5 import bz2 |
dd4b5b9daf6b
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 |
dd4b5b9daf6b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit b46aa969c01b7e5f4f133192899fa4da286ecf89-dirty
iuc
parents:
diff
changeset
|
7 import json |
dd4b5b9daf6b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit b46aa969c01b7e5f4f133192899fa4da286ecf89-dirty
iuc
parents:
diff
changeset
|
8 |
dd4b5b9daf6b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit b46aa969c01b7e5f4f133192899fa4da286ecf89-dirty
iuc
parents:
diff
changeset
|
9 |
dd4b5b9daf6b
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): |
dd4b5b9daf6b
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: |
dd4b5b9daf6b
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() |
dd4b5b9daf6b
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) |
dd4b5b9daf6b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit b46aa969c01b7e5f4f133192899fa4da286ecf89-dirty
iuc
parents:
diff
changeset
|
14 |
dd4b5b9daf6b
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"]: |
dd4b5b9daf6b
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"]) |
dd4b5b9daf6b
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 |
dd4b5b9daf6b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit b46aa969c01b7e5f4f133192899fa4da286ecf89-dirty
iuc
parents:
diff
changeset
|
18 |
dd4b5b9daf6b
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') |
dd4b5b9daf6b
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) |
dd4b5b9daf6b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit b46aa969c01b7e5f4f133192899fa4da286ecf89-dirty
iuc
parents:
diff
changeset
|
21 pkl_output.close() |
dd4b5b9daf6b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit b46aa969c01b7e5f4f133192899fa4da286ecf89-dirty
iuc
parents:
diff
changeset
|
22 |
dd4b5b9daf6b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit b46aa969c01b7e5f4f133192899fa4da286ecf89-dirty
iuc
parents:
diff
changeset
|
23 |
dd4b5b9daf6b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit b46aa969c01b7e5f4f133192899fa4da286ecf89-dirty
iuc
parents:
diff
changeset
|
24 if __name__ == '__main__': |
dd4b5b9daf6b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit b46aa969c01b7e5f4f133192899fa4da286ecf89-dirty
iuc
parents:
diff
changeset
|
25 parser = argparse.ArgumentParser() |
dd4b5b9daf6b
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) |
dd4b5b9daf6b
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) |
dd4b5b9daf6b
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() |
dd4b5b9daf6b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit b46aa969c01b7e5f4f133192899fa4da286ecf89-dirty
iuc
parents:
diff
changeset
|
29 |
dd4b5b9daf6b
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) |