annotate commons/core/parsing/BlatFileParser.py @ 6:769e306b7933

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