Mercurial > repos > iuc > humann2_rna_dna_norm
annotate transform_json_to_pkl.py @ 5:de70d23958de 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 07:01:39 +0000 |
parents | c8ef30c8451d |
children |
rev | line source |
---|---|
0
c8ef30c8451d
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff
changeset
|
1 #!/usr/bin/env python |
c8ef30c8451d
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
c8ef30c8451d
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff
changeset
|
3 |
c8ef30c8451d
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff
changeset
|
4 import argparse |
c8ef30c8451d
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff
changeset
|
5 import bz2 |
c8ef30c8451d
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff
changeset
|
6 import cPickle as pickle |
c8ef30c8451d
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff
changeset
|
7 import json |
c8ef30c8451d
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff
changeset
|
8 |
c8ef30c8451d
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff
changeset
|
9 |
c8ef30c8451d
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): |
c8ef30c8451d
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: |
c8ef30c8451d
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() |
c8ef30c8451d
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) |
c8ef30c8451d
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff
changeset
|
14 |
c8ef30c8451d
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"]: |
c8ef30c8451d
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"]) |
c8ef30c8451d
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 |
c8ef30c8451d
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff
changeset
|
18 |
c8ef30c8451d
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') |
c8ef30c8451d
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) |
c8ef30c8451d
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff
changeset
|
21 pkl_output.close() |
c8ef30c8451d
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff
changeset
|
22 |
c8ef30c8451d
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff
changeset
|
23 |
c8ef30c8451d
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff
changeset
|
24 if __name__ == '__main__': |
c8ef30c8451d
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff
changeset
|
25 parser = argparse.ArgumentParser() |
c8ef30c8451d
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) |
c8ef30c8451d
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) |
c8ef30c8451d
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff
changeset
|
28 args = parser.parse_args() |
c8ef30c8451d
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 6753a2c0fec9222f5977cab43a855c63fa9f7bee
iuc
parents:
diff
changeset
|
29 |
c8ef30c8451d
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) |