-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuc.py
More file actions
149 lines (127 loc) · 2.86 KB
/
uc.py
File metadata and controls
149 lines (127 loc) · 2.86 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import re
import sys
import progress
# Tab-separated fields:
# 1=Type, 2=ClusterNr, 3=SeqLength or ClusterSize, 4=PctId, 5=Strand, 6=QueryStart, 7=SeedStart, 8=Alignment, 9=Label
# Record types (field 1): L=LibSeed, S=NewSeed, H=Hit, R=Reject, D=LibCluster, C=NewCluster, N=NotMatched
# For C and D types, PctId is average id with seed.
# QueryStart and SeedStart are zero-based relative to start of sequence.
# If minus strand, SeedStart is relative to reverse-complemented seed.
MaxError = -1
Type = '?'
ClusterNr = -1
Size = -1
PctId = -1.0
LocalScore = -1.0
Evalue = -1.0
Strand = '.'
QueryStart = -1
SeedStart = -1
Alignment = ""
QueryLabel = ""
TargetLabel = ""
FileName = "?"
Line = ""
def Die(s):
print >> sys.stderr, "*** ERROR ***", s, sys.argv
sys.exit(1)
def ProgressFile(File, FileSize):
# if not sys.stderr.isatty():
# return
Pos = File.tell()
Pct = (100.0*Pos)/FileSize
Str = "%s %5.1f%%\r" % (FileName, Pct)
sys.stderr.write(Str)
def Progress(i, N):
# if not sys.stderr.isatty():
return
Pct = (100.0*i)/N
Str = "%5.1f%%\r" % Pct
sys.stderr.write(Str)
def PrintLine():
print Line
def ParseRec(Line):
global Type
global ClusterNr
global Size
global PctId
global Strand
global QueryStart
global SeedStart
global Alignment
global QueryLabel
global TargetLabel
global LocalScore
global Evalue
Fields = Line.split("\t")
N = len(Fields)
if N != 9 and N != 10:
Die("Expected 9 or 10 fields in .uc record, got: " + Line)
Type = Fields[0]
try:
ClusterNr = int(Fields[1])
except:
ClusterNr = -1
try:
Size = int(Fields[2])
except:
Size = -1
Fields2 = Fields[3].split('/')
LocalScore = -1.0
Evalue = -1.0
if len(Fields2) == 3:
try:
PctId = float(Fields2[0])
LocalScore = float(Fields2[1])
Evalue = float(Fields2[2])
except:
PctId = -1.0
else:
try:
PctId = float(Fields[3])
except:
PctId = -1.0
Strand = Fields[4]
try:
QueryStart = int(Fields[5])
except:
QueryStart = -1
try:
SeedStart = int(Fields[6])
except:
SeedStart = -1
Alignment = Fields[7]
QueryLabel = Fields[8]
if len(Fields) > 9:
TargetLabel = Fields[9]
def GetRec(File, OnRecord):
global Line
while 1:
Line = File.readline()
if len(Line) == 0:
return 0
if Line[0] == '#':
continue
Line = Line.strip()
if len(Line) == 0:
return 1
ParseRec(Line)
Ok = OnRecord()
if Ok != None and Ok == 0:
return 0
return 1
def ReadRecs(argFileName, OnRecord, ShowProgress = True):
return ReadFile(argFileName, OnRecord, ShowProgress)
def GetRecs(argFileName, OnRecord, ShowProgress = True):
return ReadFile(argFileName, OnRecord, ShowProgress)
def ReadFile(argFileName, OnRecord, ShowProgress = True):
global FileName
FileName = argFileName
File = open(FileName)
if ShowProgress:
progress.InitFile(File, FileName)
while GetRec(File, OnRecord):
if ShowProgress:
progress.File()
if ShowProgress:
progress.FileDone()