-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuc2otutab.py
More file actions
54 lines (44 loc) · 1011 Bytes
/
uc2otutab.py
File metadata and controls
54 lines (44 loc) · 1011 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import sys
import uc
import die
import fasta
FileName = sys.argv[1]
def GetSampleId(Label):
Fields = Label.split(";")
for Field in Fields:
if Field.startswith("barcodelabel="):
return Field[13:]
die.Die("barcodelabel= not found in read label '%s'" % Label)
def OnRec():
global OTUs, Samples, OTUTable
if uc.Type != 'H':
return
OTUId = uc.TargetLabel
if OTUId not in OTUIds:
OTUIds.append(OTUId)
OTUTable[OTUId] = {}
SampleId = GetSampleId(uc.QueryLabel)
if SampleId not in SampleIds:
SampleIds.append(SampleId)
N = fasta.GetSizeFromLabel(uc.QueryLabel, 1)
try:
OTUTable[OTUId][SampleId] += N
except:
OTUTable[OTUId][SampleId] = N
OTUIds = []
SampleIds = []
OTUTable = {}
uc.ReadRecs(FileName, OnRec)
s = "OTUId"
for SampleId in SampleIds:
s += "\t" + SampleId
print s
for OTUId in OTUIds:
s = OTUId
for SampleId in SampleIds:
try:
n = OTUTable[OTUId][SampleId]
except:
n = 0
s += "\t" + str(n)
print s