annotate transform_json_to_pkl.py @ 0:ec422794133f draft

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