Mercurial > repos > bebatut > combine_metaphlan2_humann2
annotate combine_metaphlan2_humann2.py @ 2:fdfb35745104 draft
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
author | bgruening |
---|---|
date | Wed, 19 Oct 2022 14:44:00 +0000 |
parents | e25efca0a49c |
children |
rev | line source |
---|---|
0
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
1 #!/usr/bin/env python |
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
3 |
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
4 import argparse |
1
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
5 |
0
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
6 |
1
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
7 def extract_clade_abundance(metaphlan2_fp): |
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
8 clade_abund = {} |
2
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
9 with open(metaphlan2_fp, "r") as metaphlan2_f: |
1
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
10 for line in metaphlan2_f.readlines(): |
2
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
11 if line.find("g__") == -1: |
0
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
12 continue |
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
13 |
2
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
14 split_line = line[:-1].split("\t") |
0
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
15 taxo = split_line[0] |
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
16 abundance = split_line[1] |
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
17 |
2
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
18 genus = taxo[(taxo.find("g__") + 3):] |
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
19 if genus.find("|") != -1: |
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
20 genus = genus[: (genus.find("|"))] |
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
21 clade_abund.setdefault(genus, {"abundance": 0, "species": {}}) |
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
22 if taxo.find("t__") != -1: |
0
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
23 continue |
2
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
24 elif taxo.find("s__") != -1: |
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
25 species = taxo[(taxo.find("s__") + 3):] |
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
26 clade_abund[genus]["species"].setdefault(species, abundance) |
0
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
27 else: |
2
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
28 clade_abund[genus]["abundance"] = abundance |
1
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
29 return clade_abund |
0
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
30 |
1
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
31 |
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
32 def compute_overall_abundance(humann2_fp): |
0
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
33 overall_abundance = 0 |
2
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
34 with open(humann2_fp, "r") as humann2_f: |
1
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
35 for line in humann2_f.readlines(): |
2
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
36 if line.find("|") != -1 or line.startswith("#"): |
0
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
37 continue |
2
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
38 split_line = line[:-1].split("\t") |
0
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
39 overall_abundance += float(split_line[1]) |
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
40 return overall_abundance |
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
41 |
1
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
42 |
0
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
43 def format_characteristic_name(name): |
1
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
44 formatted_n = name |
2
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
45 formatted_n = formatted_n.replace("/", " ") |
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
46 formatted_n = formatted_n.replace("-", " ") |
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
47 formatted_n = formatted_n.replace("'", "") |
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
48 if formatted_n.find("(") != -1 and formatted_n.find(")") != -1: |
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
49 open_bracket = formatted_n.find("(") |
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
50 close_bracket = formatted_n.find(")") + 1 |
1
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
51 formatted_n = formatted_n[:open_bracket] + formatted_n[close_bracket:] |
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
52 return formatted_n |
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
53 |
0
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
54 |
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
55 def combine_metaphlan2_humann2(args): |
1
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
56 clade_abund = extract_clade_abundance(args.metaphlan2_fp) |
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
57 overall_abund = compute_overall_abundance(args.humann2_fp) |
0
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
58 |
2
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
59 with open(args.output_fp, "w") as output_f: |
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
60 s = "genus\tgenus_abundance\tspecies\tspecies_abundance\t" |
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
61 s = "%s\t%s_id\t%s_name\t%s_abundance\n" % (s, args.type, args.type, args.type) |
1
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
62 output_f.write(s) |
2
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
63 with open(args.humann2_fp, "r") as humann2_f: |
1
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
64 for line in humann2_f.readlines(): |
2
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
65 if line.find("|") == -1: |
0
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
66 continue |
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
67 |
2
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
68 split_line = line[:-1].split("\t") |
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
69 abundance = 100 * float(split_line[1]) / overall_abund |
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
70 annotation = split_line[0].split("|") |
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
71 charact = annotation[0].split(":") |
1
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
72 charact_id = charact[0] |
2
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
73 char_name = "" |
1
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
74 if len(charact) > 1: |
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
75 char_name = format_characteristic_name(charact[-1]) |
2
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
76 taxo = annotation[1].split(".") |
1
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
77 |
2
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
78 if taxo[0] == "unclassified": |
0
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
79 continue |
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
80 genus = taxo[0][3:] |
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
81 species = taxo[1][3:] |
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
82 |
1
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
83 if genus not in clade_abund: |
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
84 print("no %s found in %s" % (genus, args.metaphlan2_fp)) |
0
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
85 continue |
2
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
86 if species not in clade_abund[genus]["species"]: |
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
87 print( |
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
88 "no %s found in %s for % s" |
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
89 % (species, args.metaphlan2_fp, genus) |
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
90 ) |
0
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
91 continue |
1
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
92 |
2
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
93 s = "%s\t%s\t" % (genus, clade_abund[genus]["abundance"]) |
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
94 s += "%s\t%s\t" % (species, clade_abund[genus]["species"][species]) |
1
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
95 s += "%s\t%s\t%s\n" % (charact_id, char_name, abundance) |
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
96 output_f.write(s) |
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
97 |
0
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
98 |
2
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
99 if __name__ == "__main__": |
0
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
100 parser = argparse.ArgumentParser() |
2
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
101 parser.add_argument("--humann2_fp", required=True) |
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
102 parser.add_argument("--metaphlan2_fp", required=True) |
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
103 parser.add_argument("--output_fp", required=True) |
fdfb35745104
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit eea46077010e699403ce6995d7d4aac77b2e0b43"
bgruening
parents:
1
diff
changeset
|
104 parser.add_argument("--type", required=True, choices=["gene_families", "pathways"]) |
0
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
105 args = parser.parse_args() |
31394a0c0242
planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff
changeset
|
106 |
1
e25efca0a49c
"planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 4a40a73a6eb981310a3c1c54dfa98b5460a843f9"
bebatut
parents:
0
diff
changeset
|
107 combine_metaphlan2_humann2(args) |