Mercurial > repos > iuc > metaphlan_hclust_heatmap
annotate transform_json_to_pkl.py @ 2:2e3056f02c60 draft default tip
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit bfc25b2695b9689c60101f84162610194a33c886"
author | iuc |
---|---|
date | Fri, 19 Mar 2021 21:39:54 +0000 |
parents | f7353110d18c |
children |
rev | line source |
---|---|
0
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
1 #!/usr/bin/env python |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
3 |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
4 import argparse |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
5 import bz2 |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
6 import cPickle as pickle |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
7 import json |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
8 |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
9 |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
10 def transform_json_to_pkl(args): |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
11 with open(args.json_input, 'r') as json_file: |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
12 json_str = json_file.read() |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
13 metadata = json.loads(json_str) |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
14 |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
15 for marker in metadata["markers"]: |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
16 a_set = set(metadata["markers"][marker]["ext"]) |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
17 metadata["markers"][marker]["ext"] = a_set |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
18 |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
19 pkl_output = bz2.BZ2File(args.pkl_output, 'w') |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
20 pickle.dump(metadata, pkl_output, pickle.HIGHEST_PROTOCOL) |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
21 pkl_output.close() |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
22 |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
23 |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
24 if __name__ == '__main__': |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
25 parser = argparse.ArgumentParser() |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
26 parser.add_argument('--json_input', required=True) |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
27 parser.add_argument('--pkl_output', required=True) |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
28 args = parser.parse_args() |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
29 |
f7353110d18c
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan2/ commit 345fb7ef485456ae833be5ad2d2ce4f8765652c8
iuc
parents:
diff
changeset
|
30 transform_json_to_pkl(args) |