Mercurial > repos > bebatut > compare_humann2_output
annotate compare_humann2_output.py @ 3:eaa95ea1195c draft
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
author | bgruening |
---|---|
date | Wed, 19 Oct 2022 14:49:06 +0000 |
parents | 05766022dfc4 |
children |
rev | line source |
---|---|
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
1 #!/usr/bin/env python |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
3 |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
4 import argparse |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
5 |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
6 |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
7 def extract_abundances(fp, nb_charact_to_extract): |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
8 abundances = {} |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
9 more_abund_charact = [] |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
10 abund_sum = 0 |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
11 with open(fp, "r") as abundance_f: |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
12 for line in abundance_f.readlines()[1:]: |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
13 split_line = line[:-1].split("\t") |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
14 charact_id = split_line[0] |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
15 abund = float(split_line[1]) |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
16 abundances[charact_id] = 100 * abund |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
17 abund_sum += abundances[charact_id] |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
18 |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
19 if len(more_abund_charact) < nb_charact_to_extract: |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
20 more_abund_charact.append(charact_id) |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
21 else: |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
22 best_pos = None |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
23 for i in range(len(more_abund_charact) - 1, -1, -1): |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
24 if abundances[more_abund_charact[i]] < abund: |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
25 best_pos = i |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
26 else: |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
27 break |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
28 if best_pos is not None: |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
29 tmp_more_abund_charact = more_abund_charact |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
30 more_abund_charact = tmp_more_abund_charact[:best_pos] |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
31 more_abund_charact += [charact_id] |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
32 more_abund_charact += tmp_more_abund_charact[best_pos:-1] |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
33 return abundances, more_abund_charact |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
34 |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
35 |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
36 def format_characteristic_name(all_name): |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
37 if all_name.find(":") != -1: |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
38 charact_id = all_name.split(":")[0] |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
39 char_name = all_name.split(":")[1][1:] |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
40 else: |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
41 charact_id = all_name |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
42 char_name = "" |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
43 |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
44 char_name = char_name.replace("/", " ") |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
45 char_name = char_name.replace("-", " ") |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
46 char_name = char_name.replace("'", "") |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
47 if char_name.find("(") != -1 and char_name.find(")") != -1: |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
48 open_bracket = char_name.find("(") |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
49 close_bracket = char_name.find(")") + 1 |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
50 char_name = char_name[:open_bracket] + char_name[close_bracket:] |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
51 return charact_id, char_name |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
52 |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
53 |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
54 def write_more_abundant_charat(abundances, more_abund_charact, output_fp): |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
55 with open(output_fp, "w") as output_f: |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
56 output_f.write("id\tname\t%s\n" % "\t".join(abundances.keys())) |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
57 |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
58 for mac in more_abund_charact: |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
59 charact_id, charact_name = format_characteristic_name(mac) |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
60 output_f.write("%s\t%s" % (charact_id, charact_name)) |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
61 for sample in abundances: |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
62 abund = abundances[sample].get(mac, 0) |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
63 output_f.write("\t%s" % (abund)) |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
64 output_f.write("\n") |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
65 |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
66 |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
67 def extract_similar_characteristics(abund, sim_output_fp, output_files): |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
68 abund_keys = list(abund) |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
69 sim_characteristics = set(abund[abund_keys[0]].keys()) |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
70 for sample in abund_keys[1:]: |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
71 sim_characteristics.intersection_update(abund[sample].keys()) |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
72 print("Similar between all samples: %s" % len(sim_characteristics)) |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
73 |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
74 with open(sim_output_fp, "w") as sim_output_f: |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
75 sim_output_f.write("id\tname\t%s\n" % "\t".join(abund_keys)) |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
76 for charact in list(sim_characteristics): |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
77 charact_id, charact_name = format_characteristic_name(charact) |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
78 sim_output_f.write("%s\t%s" % (charact_id, charact_name)) |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
79 for sample in abund_keys: |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
80 sim_output_f.write("\t%s" % abund[sample][charact]) |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
81 sim_output_f.write("\n") |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
82 |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
83 print("Specific to samples:") |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
84 diff_char = {} |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
85 for i in range(len(abund_keys)): |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
86 sample = abund_keys[i] |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
87 print(" %s" % sample) |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
88 print(" All: %s" % len(abund[sample].keys())) |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
89 diff_char[sample] = set(abund[sample].keys()) |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
90 diff_char[sample].difference_update(sim_characteristics) |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
91 perc = 100 * len(diff_char[sample]) / (1.0 * len(abund[sample].keys())) |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
92 print(" Number of specific characteristics: %s" % len(diff_char[sample])) |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
93 print(" Percentage of specific characteristics: %s" % perc) |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
94 |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
95 relative_abundance = 0 |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
96 with open(output_files[i], "w") as output_f: |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
97 output_f.write("id\tname\tabundances\n") |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
98 for charact in list(diff_char[sample]): |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
99 charact_id, charact_name = format_characteristic_name(charact) |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
100 output_f.write("%s\t%s" % (charact_id, charact_name)) |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
101 output_f.write("%s\n" % abund[sample][charact]) |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
102 relative_abundance += abund[sample][charact] |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
103 print( |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
104 " Relative abundance of specific characteristics: %s" |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
105 % relative_abundance |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
106 ) |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
107 |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
108 return sim_characteristics |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
109 |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
110 |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
111 def compare_humann2_output(args): |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
112 abund = {} |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
113 more_abund_charact = [] |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
114 |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
115 for i in range(len(args.sample_name)): |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
116 abund[args.sample_name[i]], mac = extract_abundances( |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
117 args.charact_input_fp[i], args.most_abundant_characteristics_to_extract |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
118 ) |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
119 more_abund_charact += mac |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
120 |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
121 write_more_abundant_charat( |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
122 abund, list(set(more_abund_charact)), args.more_abundant_output_fp |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
123 ) |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
124 extract_similar_characteristics( |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
125 abund, args.similar_output_fp, args.specific_output_fp |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
126 ) |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
127 |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
128 |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
129 if __name__ == "__main__": |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
130 parser = argparse.ArgumentParser() |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
131 parser.add_argument("--sample_name", required=True, action="append") |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
132 parser.add_argument("--charact_input_fp", required=True, action="append") |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
133 parser.add_argument( |
3
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
134 "--most_abundant_characteristics_to_extract", required=True, type=int |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
135 ) |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
136 parser.add_argument("--more_abundant_output_fp", required=True) |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
137 parser.add_argument("--similar_output_fp", required=True) |
eaa95ea1195c
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/compare_humann2_output commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
2
diff
changeset
|
138 parser.add_argument("--specific_output_fp", required=True, action="append") |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
139 args = parser.parse_args() |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
140 |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
141 if len(args.sample_name) != len(args.charact_input_fp): |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
142 string = "Same number of values (in same order) are expected for " |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
143 string += "--sample_name and --charact_input_fp" |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
144 raise ValueError(string) |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
145 if len(args.sample_name) != len(args.specific_output_fp): |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
146 string = "Same number of values (in same order) are expected for " |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
147 string += "--sample_name and --specific_output_fp" |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
148 raise ValueError(string) |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
149 |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
150 compare_humann2_output(args) |