Mercurial > repos > bebatut > humann2
annotate transform_json_to_pkl.py @ 1:bcd414bb721b draft default tip
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
author | bebatut |
---|---|
date | Thu, 02 Jun 2016 04:23:09 -0400 |
parents | |
children |
rev | line source |
---|---|
1
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
1 #!/usr/bin/env python |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
3 |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
4 import cPickle as pickle |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
5 import bz2 |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
6 import json |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
7 import argparse |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
8 |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
9 def transform_json_to_pkl(args): |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
10 with open(args.json_input, 'r') as json_file: |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
11 json_str = json_file.read() |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
12 metadata = json.loads(json_str) |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
13 |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
14 for marker in metadata["markers"]: |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
15 metadata["markers"][marker]["ext"] = set(metadata["markers"][marker]["ext"]) |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
16 |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
17 pkl_output = bz2.BZ2File(args.pkl_output, 'w') |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
18 pickle.dump(metadata, pkl_output, pickle.HIGHEST_PROTOCOL) |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
19 pkl_output.close() |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
20 |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
21 if __name__ == '__main__': |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
22 parser = argparse.ArgumentParser() |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
23 parser.add_argument('--json_input', required=True) |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
24 parser.add_argument('--pkl_output', required=True) |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
25 |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
26 args = parser.parse_args() |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
27 |
bcd414bb721b
planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/tools/humann2/ commit 79571d981d7d56657699be8aa24a40a36a8d0ab5-dirty
bebatut
parents:
diff
changeset
|
28 transform_json_to_pkl(args) |