annotate commons/core/parsing/PathNum2Id.py @ 14:c79b9ae3f65f

Deleted selected files
author m-zytnicki
date Fri, 19 Apr 2013 10:13:11 -0400
parents 769e306b7933
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
1 class PathNum2Id( object ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 def __init__(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
4 self._inFileName = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
5 self._outFileName = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
7 def setInFileName(self, fileName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
8 self._inFileName = fileName
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
9
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
10 def setOutFileName(self, fileName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
11 self._outFileName = fileName
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
12
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
13 def run( self ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
14 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
15 Adapt the path IDs as the input file is the concatenation of several 'path' files.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
16 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
17 self._inFile = open( self._inFileName, "r" )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
18 self._outFile = open( self._outFileName, "w" )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
19 lines = self._inFile.readlines()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
20 dID2count = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
21 count = 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
22 for line in lines:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
23 if line == "":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
24 break
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
25 strippedLine = line.strip('\n')
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26 data = strippedLine.split("\t")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27 path = data[0]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28 qryName = data[1]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29 qryStart = int(data[2])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30 qryEnd = int(data[3])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31 sbjName = data[4]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 sbjStart = int(data[5])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 sbjEnd = int(data[6])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 BLAST_Eval = data[7]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 BLAST_score = data[8]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 percId = data[9]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37 key_id = path + "-" + qryName + "-" + sbjName
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 if key_id not in dID2count.keys():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 newPath = count
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40 count += 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41 dID2count[ key_id ] = newPath
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 newPath = dID2count[ key_id ]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
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 )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 self._outFile.write( cmd )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 self._inFile.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 self._outFile.close()