-
Notifications
You must be signed in to change notification settings - Fork 0
/
hpc_clust2qiime.py
executable file
·31 lines (28 loc) · 1.03 KB
/
hpc_clust2qiime.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python
import sys,os
import re
import argparse
from collections import defaultdict
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--input_file", help="the otu file created using the make-otus.sh script found in htc-clust", required=True)
parser.add_argument("-o", "--output_file", help="the output file in qiime otu table format", required=True)
args = parser.parse_args()
INFILE = os.path.abspath(args.input_file)
OUTFILE = os.path.abspath(args.output_file)
out = open(OUTFILE, "w")
otus = defaultdict(list)
#test = ''
with open(INFILE) as f:
for line in f:
line = line.rstrip()
if not re.match("#", line):
if re.match(">", line):
(otu, size) = line.split()
otuid = re.search("[0-9]+", otu)
#test += ("\n{0}\t".format(otuid.group()))
out.write("\n{0}\t".format(otuid.group()))
else:
out.write("{0}\t".format(line))
#test += ("{0}\t".format(line))
#print OUTFILE test
out.close()