Mercurial > repos > qfab > rdp_multiclassifier
diff rdpmulticlassifier/scripts/.svn/text-base/generateOTUtable.py.svn-base @ 0:a73ae72b47aa draft default tip
Uploaded
author | qfab |
---|---|
date | Thu, 29 May 2014 02:27:56 -0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rdpmulticlassifier/scripts/.svn/text-base/generateOTUtable.py.svn-base Thu May 29 02:27:56 2014 -0400 @@ -0,0 +1,34 @@ +# create OTU Table by merging pre otu table with taxonomy assign by +# rdpmulticlassifier +# Tab-separated fields: +# 1=OTU Label, 2=Count, 3=Sequence, 4 and following=Assigned taxonomy by +# RDP Multi Classifier + +import sys, os + +OTUtable = sys.argv[1] +PreOTUtable = sys.argv[2] +RdpTaxonomy = sys.argv[3] + +def merge(output, preotu, tax): + writeoutput = open(output, 'w') + lookup = {} + with open(tax) as f: + for x in f: + list = x.split('\t') + length = len(list) + rest ='' + for k in range(1, length): + item= list[k].replace(' ','') + item= item.replace('\n','') + rest = rest+ item + '\t' + lookup[list[0]] = rest + with open(preotu) as f: + for x in f: + columns = x.split('\t') + otu = columns[0].replace(' ','') + taxonomy = lookup[otu] + line = x.replace('\n','') + writeoutput.write(line+taxonomy+'\n') + +merge(OTUtable, PreOTUtable, RdpTaxonomy)