6
|
1 from commons.core.parsing.BlatParser import BlatParser
|
|
2 import os
|
|
3
|
|
4 class BlatFileParser(object):
|
|
5
|
|
6 def __init__(self, blatFileName = None):
|
|
7 self._blatFileName = blatFileName
|
|
8 self._lBlatHits = []
|
|
9 self._dBlatHitsByQueries = {}
|
|
10 self._dQueries = {}
|
|
11
|
|
12 def getDictOfQueries(self):
|
|
13 return self._dQueries
|
|
14
|
|
15 def getResultLinesOfOneQuery(self, queryName):
|
|
16 return self._dBlatHitsByQueries[queryName]
|
|
17
|
|
18 def getDictOfBlatHitsByQueries(self):
|
|
19 return self._dBlatHitsByQueries
|
|
20
|
|
21 def getListsOfHits(self):
|
|
22 return self._lBlatHits
|
|
23
|
|
24 def parseBlatFile(self):
|
|
25 blatFile = open(self._blatFileName, 'r')
|
|
26 line = blatFile.readline()
|
|
27 n = 1
|
|
28 while line != "":
|
|
29 if self._isInteger(line.split("\t")[0]):
|
|
30 iBlatParser = BlatParser()
|
|
31 iBlatParser.setAttributesFromString(line, n)
|
|
32 queryHeader = iBlatParser.getQName()
|
|
33 self._dQueries[queryHeader] = 1
|
|
34 self._lBlatHits.append(iBlatParser)
|
|
35 line = blatFile.readline()
|
|
36 n += 1
|
|
37 return self._lBlatHits
|
|
38
|
|
39 def parseBlatFileByQueries(self):
|
|
40 blatFile = open(self._blatFileName, 'r')
|
|
41 line = blatFile.readline()
|
|
42 n = 1
|
|
43 while line != "":
|
|
44 if self._isInteger(line.split("\t")[0]):
|
|
45 iBlatParser = BlatParser()
|
|
46 iBlatParser.setAttributesFromString(line, n)
|
|
47 queryHeader = iBlatParser.getQName()
|
|
48 self._dQueries[queryHeader] = 1
|
|
49 if self._dBlatHitsByQueries.has_key(queryHeader):
|
|
50 self._dBlatHitsByQueries[queryHeader].append(iBlatParser)
|
|
51 else:
|
|
52 self._dBlatHitsByQueries[queryHeader] = [iBlatParser]
|
|
53 line = blatFile.readline()
|
|
54 n += 1
|
|
55 blatFile.close()
|
|
56 return self._dBlatHitsByQueries
|
|
57
|
|
58 def _isInteger(self, string):
|
|
59 try:
|
|
60 int(string)
|
|
61 return True
|
|
62 except ValueError:
|
|
63 return False
|