annotate customizemetadata.py @ 2:487da152fb43 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit f1c6f4fe1e572ace84cf9106bc253603f55aac55"
author iuc
date Mon, 14 Jun 2021 12:48:54 +0000
parents a6c3f4f439f7
children 892a0629e2ed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
1 #!/usr/bin/env python
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
2 # -*- coding: utf-8 -*-
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
3
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
4 import argparse
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
5 import bz2
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
6 import json
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
7 import pickle
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
8 import re
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
9 from pathlib import Path
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
10
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
11
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
12 def load_from_json(json_fp):
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
13 '''
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
14 Read JSON file with marker metadata
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
15
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
16 :param json_fp: Path to JSON file
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
17 '''
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
18 with open(json_fp, 'r') as json_f:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
19 data = json.load(json_f)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
20
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
21 for m in data['markers']:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
22 data['markers'][m]['ext'] = set(data['markers'][m]['ext'])
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
23
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
24 for t in data['taxonomy']:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
25 if isinstance(data['taxonomy'][t], list):
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
26 data['taxonomy'][t] = tuple(data['taxonomy'][t])
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
27 return data
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
28
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
29
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
30 def dump_to_json(data, json_fp):
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
31 '''
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
32 Dump marker metadata to JSON file
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
33
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
34 :param json_fp: Path to JSON file
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
35 '''
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
36 for m in data['markers']:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
37 data['markers'][m]['ext'] = list(data['markers'][m]['ext'])
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
38
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
39 with open(json_fp, 'w') as json_f:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
40 json.dump(data, json_f)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
41
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
42
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
43 def transform_pkl_to_json(pkl_fp, json_fp):
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
44 '''
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
45 Read Pickle file and drop it to a JSON file
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
46
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
47 :param pkl_fp: Path to input Pickle file
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
48 :param json_fp: Path to output JSON file
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
49 '''
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
50 # load metadata from Pickle file
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
51 with bz2.BZ2File(pkl_fp, 'r') as pkl_f:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
52 in_metadata = pickle.load(pkl_f)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
53
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
54 out_metadata = {
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
55 'markers': in_metadata['markers'],
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
56 'taxonomy': in_metadata['taxonomy'],
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
57 'merged_taxon': {}
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
58 }
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
59 # transform merged_taxons tuple keys to string
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
60 for k in in_metadata['merged_taxon']:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
61 n = ' , '.join(k)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
62 out_metadata[n] = in_metadata['merged_taxon'][k]
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
63
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
64 # dump metadata to JSON file
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
65 dump_to_json(out_metadata, json_fp)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
66
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
67
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
68 def transform_json_to_pkl(json_fp, pkl_fp):
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
69 '''
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
70 Read JSON file and drop it to a Pickle file
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
71
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
72 :param json_fp: Path to input JSON file
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
73 :param pkl_fp: Path to output Pickle file
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
74 '''
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
75 # load metadata from JSON file
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
76 in_metadata = load_from_json(json_fp)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
77
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
78 out_metadata = {
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
79 'markers': in_metadata['markers'],
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
80 'taxonomy': in_metadata['taxonomy'],
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
81 'merged_taxon': {}
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
82 }
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
83 # transform merged_taxons keys to tuple
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
84 for k in in_metadata['merged_taxon']:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
85 n = ' , '.split(k)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
86 out_metadata[n] = in_metadata['merged_taxon'][k]
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
87
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
88 # dump metadata to Pickle file
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
89 with bz2.BZ2File(pkl_fp, 'w') as pkl_f:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
90 pickle.dump(out_metadata, pkl_f)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
91
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
92
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
93 def add_marker(in_json_fp, out_json_fp, name, m_length, g_length, gca, k_name, k_id, p_name, p_id, c_name, c_id, o_name, o_id, f_name, f_id, g_name, g_id, s_name, s_id, t_name):
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
94 '''
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
95 Add marker to JSON file
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
96
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
97 :param in_json_fp: Path to input JSON file
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
98 :param out_json_fp: Path to output JSON file
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
99 :param name: Name of new marker
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
100 :param m_length: Length of new marker
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
101 :param g_length: List with lengths of genomes from which the new marker has been extracted
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
102 :param gca: List with GCA of genomes from which the new marker has been extracted
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
103 :param k_name: List with Name of Kingdom for genomes from which the new marker has been extracted
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
104 :param k_id: List with NCBI id of Kingdom for genomes from which the new marker has been extracted
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
105 :param p_name: List with Name of Phylum for genomes from which the new marker has been extracted
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
106 :param p_id: List with NCBI id of Phylum for genomes from which the new marker has been extracted
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
107 :param c_name: List with Name of Class for genomes from which the new marker has been extracted
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
108 :param c_id: List with NCBI id of Class for genomes from which the new marker has been extracted
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
109 :param o_name: List with Name of Order for genomes from which the new marker has been extracted
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
110 :param o_id: List with NCBI id of Order for genomes from which the new marker has been extracted
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
111 :param f_name: List with Name of Family for genomes from which the new marker has been extracted
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
112 :param f_id: List with NCBI id of Family for genomes from which the new marker has been extracted
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
113 :param g_name: List with Name of Genus for genomes from which the new marker has been extracted
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
114 :param g_id: List with NCBI id of Genus for genomes from which the new marker has been extracted
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
115 :param s_name: List with Name of Species for genomes from which the new marker has been extracted
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
116 :param s_id: List with NCBI id of Species for genomes from which the new marker has been extracted
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
117 :param t_name: List with Name of Strain for genomes from which the new marker has been extracted
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
118 '''
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
119 metadata = load_from_json(in_json_fp)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
120
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
121 # check that all lists have same size
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
122 genome_n = len(g_length)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
123 if len(gca) != genome_n:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
124 raise ValueError("Missing/Extra values in GCA list")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
125 if len(k_name) != genome_n:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
126 raise ValueError("Missing/Extra values in Kingdom name list")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
127 if len(k_id) != genome_n:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
128 raise ValueError("Missing/Extra values in Kingdom ID list")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
129 if len(p_name) != genome_n:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
130 raise ValueError("Missing/Extra values in Phylum name list")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
131 if len(p_id) != genome_n:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
132 raise ValueError("Missing/Extra values in Phylum ID list")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
133 if len(c_name) != genome_n:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
134 raise ValueError("Missing/Extra values in Class name list")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
135 if len(c_id) != genome_n:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
136 raise ValueError("Missing/Extra values in Class ID list")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
137 if len(o_name) != genome_n:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
138 raise ValueError("Missing/Extra values in Order name list")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
139 if len(o_id) != genome_n:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
140 raise ValueError("Missing/Extra values in Order ID list")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
141 if len(f_name) != genome_n:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
142 raise ValueError("Missing/Extra values in Family name list")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
143 if len(f_id) != genome_n:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
144 raise ValueError("Missing/Extra values in Family ID list")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
145 if len(g_name) != genome_n:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
146 raise ValueError("Missing/Extra values in Genus name list")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
147 if len(g_id) != genome_n:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
148 raise ValueError("Missing/Extra values in Genus ID list")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
149 if len(s_name) != genome_n:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
150 raise ValueError("Missing/Extra values in Species name list")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
151 if len(s_id) != genome_n:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
152 raise ValueError("Missing/Extra values in Species ID list")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
153 if len(t_name) != genome_n:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
154 raise ValueError("Missing/Extra values in Strain name list")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
155
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
156 # create dictionary to aggregate genome taxonomies and identify marker taxonomy
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
157 taxonomy = {
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
158 'k': set(),
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
159 'p': set(),
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
160 'c': set(),
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
161 'o': set(),
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
162 'f': set(),
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
163 'g': set(),
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
164 's': set(),
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
165 't': set(),
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
166 }
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
167
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
168 # parse genomes
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
169 for i in range(genome_n):
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
170 # add taxonomy of new genome
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
171 g_taxo_names = "k__%s|p__%s|c__%s|o__%s|f__%s|g__%s|s__%s|t__%s" % (
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
172 k_name[i],
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
173 p_name[i],
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
174 c_name[i],
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
175 o_name[i],
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
176 f_name[i],
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
177 g_name[i],
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
178 s_name[i],
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
179 t_name[i]
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
180 )
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
181 g_taxo_ids = "%s|%s|%s|%s|%s|%s|%s" % (
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
182 k_id[i],
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
183 p_id[i],
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
184 c_id[i],
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
185 o_id[i],
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
186 f_id[i],
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
187 g_id[i],
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
188 s_id[i]
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
189 )
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
190 metadata['taxonomy'][g_taxo_names] = (g_taxo_ids, g_length[i])
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
191 # aggregate taxon levels using sets
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
192 taxonomy['k'].add(k_name[i])
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
193 taxonomy['p'].add(p_name[i])
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
194 taxonomy['c'].add(c_name[i])
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
195 taxonomy['o'].add(o_name[i])
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
196 taxonomy['f'].add(f_name[i])
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
197 taxonomy['g'].add(g_name[i])
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
198 taxonomy['s'].add(s_name[i])
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
199 taxonomy['t'].add(t_name[i])
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
200
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
201 # extract clade and taxon of marker
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
202 clade = '' # last level before taxomy of genomes diverge
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
203 taxon = '' # combination of levels before divergence
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
204 for level in ['k', 'p', 'c', 'o', 'f', 'g', 's', 't']:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
205 taxo = list(taxonomy[level])
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
206 if len(taxo) == 1:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
207 clade = taxo[0]
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
208 taxon = "%s|%s__%s" % (taxon, level, taxo)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
209
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
210 # add information about the new marker
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
211 metadata['markers'][name] = {
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
212 'clade': clade,
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
213 'ext': set(gca),
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
214 'len': m_length,
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
215 'taxon': taxon
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
216 }
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
217
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
218 dump_to_json(metadata, out_json_fp)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
219
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
220
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
221 def format_markers(marker_l):
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
222 '''
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
223 Format markers
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
224
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
225 :param marker_l: list of markers
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
226 '''
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
227 markers = []
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
228 for m in marker_l:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
229 m = m.rstrip()
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
230 if ' ' in m:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
231 markers.append(m.split(' ')[0])
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
232 else:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
233 markers.append(m)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
234 return markers
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
235
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
236
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
237 def get_markers(marker_fp):
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
238 '''
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
239 Get markers from a file
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
240
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
241 :param marker_fp: Path to file with markers (1 per line)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
242 '''
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
243 # load markers
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
244 with open(marker_fp, 'r') as marker_f:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
245 markers = marker_f.readlines()
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
246
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
247 # format markers
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
248 markers = format_markers(markers)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
249
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
250 return markers
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
251
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
252
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
253 def check_not_found_markers(found_markers, original_markers):
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
254 '''
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
255 Check list of markers
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
256
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
257 :param found_markers: list of found markers
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
258 :param original_markers: list of original markers
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
259 '''
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
260 if len(found_markers) != len(original_markers):
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
261 print('markers not found:')
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
262 for m in original_markers:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
263 if m not in found_markers:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
264 print('- "%s"' % m)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
265
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
266
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
267 def prune_taxonomy(in_taxonomy, taxon_s, gca_s):
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
268 '''
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
269 Prune taxonomy to keep only listed taxonomy
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
270
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
271 :param in_taxonomy: dictionary with list of taxonomy
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
272 :param taxon_s: set of taxons to keep
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
273 :param gca_s: set of GCA ids to keep
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
274 '''
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
275 out_taxonomy = {}
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
276 kept_taxonomy = set()
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
277 kept_taxons = set()
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
278 kept_gca = set()
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
279 for t, v in in_taxonomy.items():
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
280 # check if t match element in list of taxon_s
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
281 kept_taxon = False
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
282 for t_k in taxon_s:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
283 if t_k in t:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
284 kept_taxon = True
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
285 out_taxonomy[t] = v
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
286 kept_taxonomy.add(t)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
287 kept_taxons.add(t_k)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
288 break
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
289 # check if GCA in the taxon id
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
290 s = re.search(r'GCA_\d+$', t)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
291 if s:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
292 gca = s[0]
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
293 # check if GCA in taxon id is in the list GCA to keep
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
294 if gca in gca_s:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
295 kept_gca.add(gca)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
296 if not kept_taxon:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
297 out_taxonomy[t] = v
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
298 kept_taxonomy.add(t)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
299
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
300 print('%s kept taxonomy' % len(kept_taxonomy))
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
301 print('%s / %s taxons not found' % (len(taxon_s) - len(kept_taxons), len(taxon_s)))
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
302 print('%s / %s GCA taxons not found' % (len(gca_s) - len(kept_gca), len(gca_s)))
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
303 return out_taxonomy
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
304
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
305
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
306 def remove_markers(in_json_fp, marker_fp, out_json_fp, kept_marker_fp):
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
307 '''
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
308 Remove markers from JSON file
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
309
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
310 :param in_json_fp: Path to input JSON file
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
311 :param marker_fp: Path to file with markers to remove (1 per line)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
312 :param out_json_fp: Path to output JSON file
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
313 :param kept_marker_fp: Path to file with kept markers
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
314 '''
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
315 in_metadata = load_from_json(in_json_fp)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
316
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
317 # load markers
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
318 markers_to_remove = set(get_markers(marker_fp))
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
319 print('%s markers to remove' % len(markers_to_remove))
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
320
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
321 # keep merged_taxon
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
322 out_metadata = {
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
323 'markers': {},
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
324 'taxonomy': {},
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
325 'merged_taxon': in_metadata['merged_taxon']
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
326 }
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
327
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
328 # parse markers to keep
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
329 removed_markers = []
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
330 kept_markers = []
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
331 taxons_to_keep = set()
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
332 gca_to_keep = set()
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
333 for m, v in in_metadata['markers'].items():
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
334 if m not in markers_to_remove:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
335 out_metadata['markers'][m] = v
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
336 kept_markers.append(m)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
337 taxons_to_keep.add(v['taxon'])
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
338 gca_to_keep.update(v['ext'])
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
339 else:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
340 removed_markers.append(m)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
341 print('%s removed markers' % len(removed_markers))
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
342
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
343 # check markers that are not found
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
344 check_not_found_markers(removed_markers, markers_to_remove)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
345
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
346 # keep only taxonomy in taxons_to_keep or with GCA in gca_to_keep
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
347 out_metadata['taxonomy'] = prune_taxonomy(in_metadata['taxonomy'], taxons_to_keep, gca_to_keep)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
348
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
349 # save to JSON
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
350 dump_to_json(out_metadata, out_json_fp)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
351
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
352 # write list of kept markers
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
353 with open(kept_marker_fp, 'w') as kept_marker_f:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
354 for m in kept_markers:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
355 kept_marker_f.write("%s\n" % m)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
356
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
357
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
358 def keep_markers(in_json_fp, marker_fp, out_json_fp):
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
359 '''
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
360 Keep markers from JSON file, others will be removed
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
361
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
362 :param in_json_fp: Path to input JSON file
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
363 :param marker_fp: Path to file with markers to keep (1 per line)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
364 :param out_json_fp: Path to output JSON file
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
365 '''
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
366 in_metadata = load_from_json(in_json_fp)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
367
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
368 # load markers
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
369 markers_to_keep = set(get_markers(marker_fp))
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
370 print('%s markers to keep' % len(markers_to_keep))
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
371
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
372 # keep merged_taxon
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
373 out_metadata = {
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
374 'markers': {},
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
375 'taxonomy': {},
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
376 'merged_taxon': in_metadata['merged_taxon']
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
377 }
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
378
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
379 # parse markers to keep
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
380 kept_markers = []
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
381 taxons_to_keep = set()
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
382 gca_to_keep = set()
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
383 for m, v in in_metadata['markers'].items():
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
384 if m in markers_to_keep:
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
385 out_metadata['markers'][m] = v
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
386 kept_markers.append(m)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
387 taxons_to_keep.add(v['taxon'])
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
388 gca_to_keep.update(v['ext'])
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
389 print('%s kept markers' % len(kept_markers))
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
390
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
391 # check markers that are not found
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
392 check_not_found_markers(kept_markers, markers_to_keep)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
393
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
394 # keep only taxonomy in taxons_to_keep or with GCA in gca_to_keep
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
395 out_metadata['taxonomy'] = prune_taxonomy(in_metadata['taxonomy'], taxons_to_keep, gca_to_keep)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
396
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
397 # save to JSON
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
398 dump_to_json(out_metadata, out_json_fp)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
399
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
400
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
401 if __name__ == '__main__':
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
402 # Read command line
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
403 parser = argparse.ArgumentParser(description='Customize MetaPhlan database')
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
404 subparsers = parser.add_subparsers(dest='function')
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
405 # transform_pkl_to_json subcommand
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
406 pkl_to_json_parser = subparsers.add_parser('transform_pkl_to_json', help='Transform Pickle to JSON to get marker metadata')
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
407 pkl_to_json_parser.add_argument('--pkl', help="Path to input Pickle file")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
408 pkl_to_json_parser.add_argument('--json', help="Path to output JSON file")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
409 # transform_json_to_pkl subcommand
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
410 json_to_pkl_parser = subparsers.add_parser('transform_json_to_pkl', help='Transform JSON to Pickle to push marker metadata')
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
411 json_to_pkl_parser.add_argument('--json', help="Path to input JSON file")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
412 json_to_pkl_parser.add_argument('--pkl', help="Path to output Pickle file")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
413 # add_marker subcommand
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
414 add_marker_parser = subparsers.add_parser('add_marker', help='Add new marker to JSON file')
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
415 add_marker_parser.add_argument('--in_json', help="Path to input JSON file")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
416 add_marker_parser.add_argument('--out_json', help="Path to output JSON file")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
417 add_marker_parser.add_argument('--name', help="Name of new marker")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
418 add_marker_parser.add_argument('--m_length', help="Length of new marker")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
419 add_marker_parser.add_argument('--g_length', help="Length of genome from which the new marker has been extracted", action="append")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
420 add_marker_parser.add_argument('--gca', help="GCA of genome from which the new marker has been extracted", action="append")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
421 add_marker_parser.add_argument('--k_name', help="Name of Kingdom for genome from which the new marker has been extracted", action="append")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
422 add_marker_parser.add_argument('--k_id', help="NCBI id of Kingdom for genome from which the new marker has been extracted", action="append")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
423 add_marker_parser.add_argument('--p_name', help="Name of Phylum for genome from which the new marker has been extracted", action="append")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
424 add_marker_parser.add_argument('--p_id', help="NCBI id of Phylum for genome from which the new marker has been extracted", action="append")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
425 add_marker_parser.add_argument('--c_name', help="Name of Class for genome from which the new marker has been extracted", action="append")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
426 add_marker_parser.add_argument('--c_id', help="NCBI id of Class for genome from which the new marker has been extracted", action="append")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
427 add_marker_parser.add_argument('--o_name', help="Name of Order for genome from which the new marker has been extracted", action="append")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
428 add_marker_parser.add_argument('--o_id', help="NCBI id of Order for genome from which the new marker has been extracted", action="append")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
429 add_marker_parser.add_argument('--f_name', help="Name of Family for genome from which the new marker has been extracted", action="append")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
430 add_marker_parser.add_argument('--f_id', help="NCBI id of Family for genome from which the new marker has been extracted", action="append")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
431 add_marker_parser.add_argument('--g_name', help="Name of Genus for genome from which the new marker has been extracted", action="append")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
432 add_marker_parser.add_argument('--g_id', help="NCBI id of Genus for genome from which the new marker has been extracted", action="append")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
433 add_marker_parser.add_argument('--s_name', help="Name of Species for genome from which the new marker has been extracted", action="append")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
434 add_marker_parser.add_argument('--s_id', help="NCBI id of Species for genome from which the new marker has been extracted", action="append")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
435 add_marker_parser.add_argument('--t_name', help="Name of Strain for genome from which the new marker has been extracted", action="append")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
436 # remove_markers subcommand
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
437 remove_markers_parser = subparsers.add_parser('remove_markers', help='Remove markers from JSON file')
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
438 remove_markers_parser.add_argument('--in_json', help="Path to input JSON file")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
439 remove_markers_parser.add_argument('--markers', help="Path to file with markers to remove (1 per line)")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
440 remove_markers_parser.add_argument('--out_json', help="Path to output JSON file")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
441 remove_markers_parser.add_argument('--kept_markers', help="Path to file with kept markers")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
442 # keep_markers subcommand
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
443 keep_markers_parser = subparsers.add_parser('keep_markers', help='Keep markers from JSON file, others will be removed')
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
444 keep_markers_parser.add_argument('--in_json', help="Path to input JSON file")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
445 keep_markers_parser.add_argument('--markers', help="Path to file with markers to keep (1 per line)")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
446 keep_markers_parser.add_argument('--out_json', help="Path to output JSON file")
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
447
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
448 args = parser.parse_args()
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
449
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
450 if args.function == 'transform_pkl_to_json':
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
451 transform_pkl_to_json(Path(args.pkl), Path(args.json))
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
452 elif args.function == 'transform_json_to_pkl':
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
453 transform_json_to_pkl(Path(args.json), Path(args.pkl))
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
454 elif args.function == 'add_marker':
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
455 add_marker(
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
456 args.in_json,
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
457 args.out_json,
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
458 args.name,
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
459 args.m_length,
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
460 args.g_length,
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
461 args.gca,
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
462 args.k_name,
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
463 args.k_id,
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
464 args.p_name,
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
465 args.p_id,
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
466 args.c_name,
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
467 args.c_id,
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
468 args.o_name,
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
469 args.o_id,
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
470 args.f_name,
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
471 args.f_id,
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
472 args.g_name,
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
473 args.g_id,
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
474 args.s_name,
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
475 args.s_id,
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
476 args.t_name)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
477 elif args.function == 'remove_markers':
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
478 remove_markers(args.in_json, args.markers, args.out_json, args.kept_markers)
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
479 elif args.function == 'keep_markers':
a6c3f4f439f7 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/metaphlan/ commit 1e543a44ceffd8e4c5537b9015606ab3b90a114c"
iuc
parents:
diff changeset
480 keep_markers(args.in_json, args.markers, args.out_json)