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