Mercurial > repos > qfab > rdp_multiclassifier
comparison 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 | 
   comparison
  equal
  deleted
  inserted
  replaced
| -1:000000000000 | 0:a73ae72b47aa | 
|---|---|
| 1 # create OTU Table by merging pre otu table with taxonomy assign by | |
| 2 # rdpmulticlassifier | |
| 3 # Tab-separated fields: | |
| 4 # 1=OTU Label, 2=Count, 3=Sequence, 4 and following=Assigned taxonomy by | |
| 5 # RDP Multi Classifier | |
| 6 | |
| 7 import sys, os | |
| 8 | |
| 9 OTUtable = sys.argv[1] | |
| 10 PreOTUtable = sys.argv[2] | |
| 11 RdpTaxonomy = sys.argv[3] | |
| 12 | |
| 13 def merge(output, preotu, tax): | |
| 14 writeoutput = open(output, 'w') | |
| 15 lookup = {} | |
| 16 with open(tax) as f: | |
| 17 for x in f: | |
| 18 list = x.split('\t') | |
| 19 length = len(list) | |
| 20 rest ='' | |
| 21 for k in range(1, length): | |
| 22 item= list[k].replace(' ','') | |
| 23 item= item.replace('\n','') | |
| 24 rest = rest+ item + '\t' | |
| 25 lookup[list[0]] = rest | |
| 26 with open(preotu) as f: | |
| 27 for x in f: | |
| 28 columns = x.split('\t') | |
| 29 otu = columns[0].replace(' ','') | |
| 30 taxonomy = lookup[otu] | |
| 31 line = x.replace('\n','') | |
| 32 writeoutput.write(line+taxonomy+'\n') | |
| 33 | |
| 34 merge(OTUtable, PreOTUtable, RdpTaxonomy) | 
