annotate commons/tools/setnum2id.py @ 19:9bcfa7936eec

Deleted selected files
author m-zytnicki
date Mon, 29 Apr 2013 03:23:29 -0400
parents 94ab73e8a190
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
1 #!/usr/bin/env python
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
2
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
3 import os
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
4 import sys
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
5 import getopt
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
6 import exceptions
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
7
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
8 #-----------------------------------------------------------------------------
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
9
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
10 def help():
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
11
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
12 print "\nusage:",sys.argv[0]," [ options ]"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
13 print "option:"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
14 print " -h: this help"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
15 print " -i: input set file"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
16 print "output on stdout\n"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
17
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
18 #-----------------------------------------------------------------------------
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
19
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
20 def main():
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
21
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
22 inFileName = ""
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
23
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
24 try:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
25 opts, args = getopt.getopt(sys.argv[1:],"hi:")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
26 except getopt.GetoptError:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
27 help()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
28 sys.exit(1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
29 for o,a in opts:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
30 if o == "-h":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
31 help()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
32 sys.exit(0)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
33 if o == "-i":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
34 inFileName = a
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
35
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
36 if inFileName == "":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
37 print "*** Error: missing input file name"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
38 help()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
39 sys.exit(1)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
40
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
41 inFile = open( inFileName, "r" )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
42 line = inFile.readline()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
43
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
44 dID2count = {}
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
45 count = 1
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
46
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
47 while 1:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
48
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
49 if line == "":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
50 break
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
51
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
52 line = line.split()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
53
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
54 path = line[0]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
55 sbjName = line[1]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
56 qryName = line[2]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
57 qryStart = line[3]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
58 qryEnd = line[4]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
59
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
60 key_id = path + "-" + qryName + "-" + sbjName
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
61 if key_id not in dID2count.keys():
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
62 newPath = count
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
63 count += 1
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
64 dID2count[ key_id ] = newPath
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
65 else:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
66 newPath = dID2count[ key_id ]
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
67
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
68 data = str(newPath) + "\t" + sbjName + "\t" + qryName + "\t"
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
69 data += qryStart + "\t" + qryEnd
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
70
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
71 print data
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
72 sys.stdout.flush()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
73
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
74 line = inFile.readline()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
75
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
76 inFile.close()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
77
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
78 return 0
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
79
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
80 #-----------------------------------------------------------------------------
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
81
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
82 if __name__ == '__main__':
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
83 main()