annotate combine_metaphlan2_humann2.py @ 0:31394a0c0242 draft

planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
author bebatut
date Fri, 15 Apr 2016 09:15:21 -0400
parents
children e25efca0a49c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 sys
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
5 import os
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
6 import argparse
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
7 import re
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
8
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
9 def extract_clade_abundance(metaphlan2_filepath):
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
10 clade_abundance = {}
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
11 with open(metaphlan2_filepath, 'r') as metaphlan2_file:
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
12 for line in metaphlan2_file.readlines():
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
13 if line.find('g__') == -1:
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
14 continue
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
15
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
16 split_line = line[:-1].split('\t')
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
17 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
18 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
19
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
20 genus = taxo[(taxo.find('g__')+3):]
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
21 if genus.find('|') != -1:
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
22 genus = genus[:(genus.find('|'))]
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
23 clade_abundance.setdefault(genus, {'abundance':0, 'species':{}})
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
24 if taxo.find('t__') != -1:
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
25 continue
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
26 elif taxo.find('s__') != -1:
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
27 species = taxo[(taxo.find('s__')+3):]
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
28 clade_abundance[genus]['species'].setdefault(species, abundance)
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
29 else:
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
30 clade_abundance[genus]['abundance'] = abundance
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
31 return clade_abundance
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
32
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
33 def compute_overall_abundance(humann2_file):
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
34 overall_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
35 with open(args.humann2_file, 'r') as humann2_file:
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
36 for line in humann2_file.readlines():
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
37 if line.find('|') != -1 or line.startswith('#'):
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
38 continue
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
39 split_line = line[:-1].split('\t')
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
40 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
41 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
42
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):
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
44 formatted_name = name
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
45 formatted_name = formatted_name.replace('/',' ')
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
46 formatted_name = formatted_name.replace('-',' ')
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
47 formatted_name = formatted_name.replace("'",'')
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
48 if formatted_name.find('(') != -1 and formatted_name.find(')') != -1:
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
49 open_bracket = formatted_name.find('(')
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
50 close_bracket = formatted_name.find(')')+1
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
51 formatted_name = formatted_name[:open_bracket] + formatted_name[close_bracket:]
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
52 return formatted_name
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
53
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
54 def combine_metaphlan2_humann2(args):
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
55 clade_abundance = extract_clade_abundance(args.metaphlan2_file)
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
56 overall_abundance = compute_overall_abundance(args.humann2_file)
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
57
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
58 with open(args.output_file, 'w') as output_file:
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
59 output_file.write('genus\t')
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
60 output_file.write('genus_abundance\t')
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
61 output_file.write('species\t')
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
62 output_file.write('species_abundance\t')
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
63 output_file.write(args.type + '_id\t')
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
64 output_file.write(args.type + '_name\t')
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
65 output_file.write(args.type + '_abundance\n')
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
66 with open(args.humann2_file, 'r') as humann2_file:
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
67 for line in humann2_file.readlines():
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
68 if line.find('|') == -1:
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
69 continue
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
70
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
71 split_line = line[:-1].split('\t')
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
72 abundance = 100*float(split_line[1])/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
73 annotation = split_line[0].split('|')
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
74 characteristic = annotation[0].split(':')
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
75 characteristic_id = characteristic[0]
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
76 characteristic_name = ''
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
77 if len(characteristic) > 1:
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
78 characteristic_name = format_characteristic_name(characteristic[-1])
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
79 taxo = annotation[1].split('.')
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
80
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
81 if taxo[0] == 'unclassified':
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
82 continue
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
83 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
84 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
85
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
86 if not clade_abundance.has_key(genus):
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
87 print "no", genus, "found in", args.metaphlan2_file
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
88 continue
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
89 if not clade_abundance[genus]['species'].has_key(species):
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
90 print "no", species, "found in", args.metaphlan2_file,
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
91 print "for", genus
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
92 continue
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
93 output_file.write(genus + '\t')
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
94 output_file.write(clade_abundance[genus]['abundance'] + '\t')
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
95 output_file.write(species + '\t')
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
96 output_file.write(clade_abundance[genus]['species'][species] + '\t')
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
97 output_file.write(characteristic_id + '\t')
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
98 output_file.write(characteristic_name + '\t')
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
99 output_file.write(str(abundance) + '\n')
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
100
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
101 if __name__ == '__main__':
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
102 parser = argparse.ArgumentParser()
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
103 parser.add_argument('--humann2_file', required=True)
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
104 parser.add_argument('--metaphlan2_file', required=True)
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
105 parser.add_argument('--output_file', required=True)
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
106 parser.add_argument('--type', required=True,
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
107 choices = ['gene_families','pathways'])
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
108 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
109
31394a0c0242 planemo upload for repository https://github.com/asaim/galaxytools/tree/master/tools/combine_metaphlan2_humann2 commit e6bee6545960c2a1ae3ca3031ec74d7c26d0b0ce-dirty
bebatut
parents:
diff changeset
110 combine_metaphlan2_humann2(args)