Mercurial > repos > bebatut > compare_humann2_output
annotate compare_humann2_output.py @ 2:05766022dfc4 draft
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
author | bebatut |
---|---|
date | Mon, 14 Sep 2020 13:50:30 +0000 |
parents | 9959fa526f1a |
children | eaa95ea1195c |
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 |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
11 with open(fp, 'r') as abundance_f: |
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:]: |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
13 split_line = line[:-1].split('\t') |
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]) |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
16 abundances[charact_id] = 100*abund |
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 |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
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): |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
37 if all_name.find(':') != -1: |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
38 charact_id = all_name.split(':')[0] |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
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 |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
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 |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
44 char_name = char_name.replace('/', ' ') |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
45 char_name = char_name.replace('-', ' ') |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
46 char_name = char_name.replace("'", '') |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
47 if char_name.find('(') != -1 and char_name.find(')') != -1: |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
48 open_bracket = char_name.find('(') |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
49 close_bracket = char_name.find(')')+1 |
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): |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
55 with open(output_fp, 'w') as output_f: |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
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) |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
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) |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
63 output_f.write('\t%s' % (abund)) |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
64 output_f.write('\n') |
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()) |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
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 |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
74 with open(sim_output_fp, 'w') as sim_output_f: |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
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) |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
78 sim_output_f.write('%s\t%s' % (charact_id, charact_name)) |
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: |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
80 sim_output_f.write('\t%s' % abund[sample][charact]) |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
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 |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
83 print('Specific to samples:') |
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] |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
87 print(' %s' % sample ) |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
88 print(' All: %s' % len(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
|
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) |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
91 perc = 100*len(diff_char[sample])/(1.*len(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
|
92 print(' Number of specific characteristics: %s' % len(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
|
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 |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
96 with open(output_files[i], 'w') as output_f: |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
97 output_f.write('id\tname\tabundances\n') |
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) |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
100 output_f.write('%s\t%s' % (charact_id, charact_name)) |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
101 output_f.write('%s\n' % abund[sample][charact]) |
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] |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
103 print(' Relative abundance of specific characteristics: %s' % relative_abundance) |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
104 |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
105 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
|
106 |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
107 |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
108 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
|
109 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
|
110 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
|
111 |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
112 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
|
113 abund[args.sample_name[i]], mac = extract_abundances( |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
114 args.charact_input_fp[i], |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
115 args.most_abundant_characteristics_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
|
116 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
|
117 |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
118 write_more_abundant_charat( |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
119 abund, |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
120 list(set(more_abund_charact)), |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
121 args.more_abundant_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
|
122 extract_similar_characteristics( |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
123 abund, |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
124 args.similar_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
|
125 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
|
126 |
0
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
127 |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
128 if __name__ == '__main__': |
9959fa526f1a
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit c16428041ae3d60b61b6570035c9268726730543-dirty
bebatut
parents:
diff
changeset
|
129 parser = argparse.ArgumentParser() |
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.add_argument('--sample_name', 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
|
131 parser.add_argument('--charact_input_fp', required=True, action='append') |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
132 parser.add_argument( |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
133 '--most_abundant_characteristics_to_extract', |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
134 required=True, |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
135 type=int) |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
136 parser.add_argument('--more_abundant_output_fp', required=True) |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
137 parser.add_argument('--similar_output_fp', required=True) |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
138 parser.add_argument( |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
139 '--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
|
140 required=True, |
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
141 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
|
142 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
|
143 |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 |
2
05766022dfc4
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/compare_humann2_output commit dc55dc3b5275d1d6aac390698c0c6e0ab8fbf2f7"
bebatut
parents:
0
diff
changeset
|
153 compare_humann2_output(args) |