6
|
1 class PathNum2Id( object ):
|
|
2
|
|
3 def __init__(self):
|
|
4 self._inFileName = None
|
|
5 self._outFileName = None
|
|
6
|
|
7 def setInFileName(self, fileName):
|
|
8 self._inFileName = fileName
|
|
9
|
|
10 def setOutFileName(self, fileName):
|
|
11 self._outFileName = fileName
|
|
12
|
|
13 def run( self ):
|
|
14 """
|
|
15 Adapt the path IDs as the input file is the concatenation of several 'path' files.
|
|
16 """
|
|
17 self._inFile = open( self._inFileName, "r" )
|
|
18 self._outFile = open( self._outFileName, "w" )
|
|
19 lines = self._inFile.readlines()
|
|
20 dID2count = {}
|
|
21 count = 1
|
|
22 for line in lines:
|
|
23 if line == "":
|
|
24 break
|
|
25 strippedLine = line.strip('\n')
|
|
26 data = strippedLine.split("\t")
|
|
27 path = data[0]
|
|
28 qryName = data[1]
|
|
29 qryStart = int(data[2])
|
|
30 qryEnd = int(data[3])
|
|
31 sbjName = data[4]
|
|
32 sbjStart = int(data[5])
|
|
33 sbjEnd = int(data[6])
|
|
34 BLAST_Eval = data[7]
|
|
35 BLAST_score = data[8]
|
|
36 percId = data[9]
|
|
37 key_id = path + "-" + qryName + "-" + sbjName
|
|
38 if key_id not in dID2count.keys():
|
|
39 newPath = count
|
|
40 count += 1
|
|
41 dID2count[ key_id ] = newPath
|
|
42 else:
|
|
43 newPath = dID2count[ key_id ]
|
|
44 cmd = "%i\t%s\t%i\t%i\t%s\t%i\t%i\t%s\t%s\t%s\n" % ( newPath, qryName, qryStart, qryEnd, sbjName, sbjStart, sbjEnd, BLAST_Eval, BLAST_score, percId )
|
|
45 self._outFile.write( cmd )
|
|
46 self._inFile.close()
|
|
47 self._outFile.close()
|