Mercurial > repos > bebatut > combine_metaphlan2_humann2
annotate combine_metaphlan_humann.py @ 4:662a334004b4 draft default tip
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
author | bgruening |
---|---|
date | Sat, 04 Nov 2023 18:59:48 +0000 |
parents | 01ac9954c27f |
children |
rev | line source |
---|---|
3
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
1 #!/usr/bin/env python |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
3 |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
4 import argparse |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
5 |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
6 |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
7 def extract_clade_abundance(metaphlan_fp): |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
8 clade_abund = {} |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
9 with open(metaphlan_fp, "r") as metaphlan_f: |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
10 is_metaphlan_v4 = False |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
11 for line in metaphlan_f.readlines(): |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
12 if 'SGB' in line: |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
13 # New versions of metaphlan against a recent DB contain a header line with DB name, which contains SGB |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
14 is_metaphlan_v4 = True |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
15 if line.find("g__") == -1: |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
16 continue |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
17 |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
18 split_line = line[:-1].split("\t") |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
19 taxo = split_line[0] |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
20 if is_metaphlan_v4: |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
21 # Column order in new metaphlan versions: |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
22 # clade_name NCBI_tax_id relative_abundance additional_species |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
23 abundance = split_line[2] |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
24 else: |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
25 # Column order in the old metaphlan versions: |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
26 # clade_name relative_abundance coverage average_genome_length_in_the_clade estimated_number_of_reads_from_the_clade |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
27 abundance = split_line[1] |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
28 |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
29 genus = taxo[(taxo.find("g__") + 3):] |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
30 if genus.find("|") != -1: |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
31 genus = genus[: (genus.find("|"))] |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
32 clade_abund.setdefault(genus, {"abundance": 0, "species": {}}) |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
33 if taxo.find("t__") != -1: |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
34 continue |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
35 elif taxo.find("s__") != -1: |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
36 species = taxo[(taxo.find("s__") + 3):] |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
37 clade_abund[genus]["species"].setdefault(species, abundance) |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
38 else: |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
39 clade_abund[genus]["abundance"] = abundance |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
40 return clade_abund |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
41 |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
42 |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
43 def compute_overall_abundance(humann_fp): |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
44 overall_abundance = 0 |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
45 with open(humann_fp, "r") as humann_f: |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
46 for line in humann_f.readlines(): |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
47 if line.find("|") != -1 or line.startswith("#"): |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
48 continue |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
49 split_line = line[:-1].split("\t") |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
50 overall_abundance += float(split_line[1]) |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
51 return overall_abundance |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
52 |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
53 |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
54 def format_characteristic_name(name): |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
55 formatted_n = name |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
56 formatted_n = formatted_n.replace("/", " ") |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
57 formatted_n = formatted_n.replace("-", " ") |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
58 formatted_n = formatted_n.replace("'", "") |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
59 if formatted_n.find("(") != -1 and formatted_n.find(")") != -1: |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
60 open_bracket = formatted_n.find("(") |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
61 close_bracket = formatted_n.find(")") + 1 |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
62 formatted_n = formatted_n[:open_bracket] + formatted_n[close_bracket:] |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
63 return formatted_n |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
64 |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
65 |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
66 def combine_metaphlan_humann(args): |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
67 clade_abund = extract_clade_abundance(args.metaphlan_fp) |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
68 overall_abund = compute_overall_abundance(args.humann_fp) |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
69 |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
70 with open(args.output_fp, "w") as output_f: |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
71 s = "genus\tgenus_abundance\tspecies\tspecies_abundance\t" |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
72 s = "%s\t%s_id\t%s_name\t%s_abundance\n" % (s, args.type, args.type, args.type) |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
73 output_f.write(s) |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
74 with open(args.humann_fp, "r") as humann_f: |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
75 for line in humann_f.readlines(): |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
76 if line.find("|") == -1: |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
77 continue |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
78 |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
79 split_line = line[:-1].split("\t") |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
80 abundance = 100 * float(split_line[1]) / overall_abund |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
81 annotation = split_line[0].split("|") |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
82 charact = annotation[0].split(":") |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
83 charact_id = charact[0] |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
84 char_name = "" |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
85 if len(charact) > 1: |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
86 char_name = format_characteristic_name(charact[-1]) |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
87 taxo = annotation[1].split(".") |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
88 |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
89 if taxo[0] == "unclassified": |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
90 continue |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
91 genus = taxo[0][3:] |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
92 species = taxo[1][3:] |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
93 |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
94 if genus not in clade_abund: |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
95 print("no %s found in %s" % (genus, args.metaphlan_fp)) |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
96 continue |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
97 if species not in clade_abund[genus]["species"]: |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
98 print( |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
99 "No %s found in %s for % s" |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
100 % (species, args.metaphlan_fp, genus) |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
101 ) |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
102 continue |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
103 |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
104 s = "%s\t%s\t" % (genus, clade_abund[genus]["abundance"]) |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
105 s += "%s\t%s\t" % (species, clade_abund[genus]["species"][species]) |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
106 s += "%s\t%s\t%s\n" % (charact_id, char_name, abundance) |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
107 output_f.write(s) |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
108 |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
109 |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
110 if __name__ == "__main__": |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
111 parser = argparse.ArgumentParser() |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
112 parser.add_argument("--humann_fp", required=True) |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
113 parser.add_argument("--metaphlan_fp", required=True) |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
114 parser.add_argument("--output_fp", required=True) |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
115 parser.add_argument("--type", required=True, choices=["gene_families", "pathways"]) |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
116 args = parser.parse_args() |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
117 |
01ac9954c27f
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit b84cbcbffa25c55acd1a31df76e4a4f78772cbd7
bgruening
parents:
diff
changeset
|
118 combine_metaphlan_humann(args) |