Mercurial > repos > george-weingart > lefse
comparison lefse2circlader.py @ 0:e7cd19afda2e draft
Lefse
author | george-weingart |
---|---|
date | Tue, 13 May 2014 21:57:00 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e7cd19afda2e |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 from __future__ import with_statement | |
4 | |
5 import sys | |
6 import os | |
7 import argparse | |
8 | |
9 def read_params(args): | |
10 parser = argparse.ArgumentParser(description='Convert LEfSe output to ' | |
11 'Circlader input') | |
12 parser.add_argument( 'inp_f', metavar='INPUT_FILE', nargs='?', | |
13 default=None, type=str, | |
14 help="the input file [stdin if not present]") | |
15 parser.add_argument( 'out_f', metavar='OUTPUT_FILE', nargs='?', | |
16 default=None, type=str, | |
17 help="the output file [stdout if not present]") | |
18 parser.add_argument('-l', metavar='levels with label', default=0, type=int) | |
19 | |
20 return vars(parser.parse_args()) | |
21 | |
22 def lefse2circlader(par): | |
23 finp,fout = bool(par['inp_f']), bool(par['out_f']) | |
24 | |
25 with open(par['inp_f']) if finp else sys.stdin as inpf: | |
26 put_bm = (l.strip().split('\t') for l in inpf.readlines()) | |
27 biomarkers = [p for p in put_bm if len(p) > 2] | |
28 | |
29 circ = [ [ b[0], | |
30 "" if b[0].count('.') > par['l'] else b[0].split('.')[-1], | |
31 b[2], | |
32 b[2]+"_col" ] for b in biomarkers] | |
33 | |
34 with open(par['out_f'],'w') if fout else sys.stdout as out_file: | |
35 for c in circ: | |
36 out_file.write( "\t".join( c ) + "\n" ) | |
37 | |
38 if __name__ == '__main__': | |
39 params = read_params(sys.argv) | |
40 lefse2circlader(params) | |
41 | |
42 | |
43 |