annotate commons/core/sql/TablePathAdaptator.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 # Copyright INRA (Institut National de la Recherche Agronomique)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2 # http://www.inra.fr
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 # http://urgi.versailles.inra.fr
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
4 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
5 # This software is governed by the CeCILL license under French law and
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
6 # abiding by the rules of distribution of free software. You can use,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
7 # modify and/ or redistribute the software under the terms of the CeCILL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
8 # license as circulated by CEA, CNRS and INRIA at the following URL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
9 # "http://www.cecill.info".
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
10 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
11 # As a counterpart to the access to the source code and rights to copy,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
12 # modify and redistribute granted by the license, users are provided only
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
13 # with a limited warranty and the software's author, the holder of the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
14 # economic rights, and the successive licensors have only limited
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
15 # liability.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
16 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
17 # In this respect, the user's attention is drawn to the risks associated
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
18 # with loading, using, modifying and/or developing or reproducing the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
19 # software by the user in light of its specific status of free software,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
20 # that may mean that it is complicated to manipulate, and that also
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
21 # therefore means that it is reserved for developers and experienced
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
22 # professionals having in-depth computer knowledge. Users are therefore
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
23 # encouraged to load and test the software's suitability as regards their
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
24 # requirements in conditions enabling the security of their systems and/or
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
25 # data to be ensured and, more generally, to use and operate it in the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26 # same conditions as regards security.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28 # The fact that you are presently reading this means that you have had
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29 # knowledge of the CeCILL license and that you accept its terms.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 from commons.core.coord.Path import Path
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 from commons.core.coord.PathUtils import PathUtils
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 from commons.core.sql.TableAdaptator import TableAdaptator
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 from commons.core.sql.ITablePathAdaptator import ITablePathAdaptator
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 ## Adaptator for a Path table
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40 class TablePathAdaptator( TableAdaptator, ITablePathAdaptator ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42 ## Give a list of Path instances having the same identifier
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 # @param id integer identifier number
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 # @return lPath a list of Path instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 def getPathListFromId( self, id ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 sqlCmd = "SELECT * FROM %s WHERE path='%d';" % ( self._table, id )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 lPath = self._iDb.getObjectListWithSQLCmd( sqlCmd, self._getInstanceToAdapt )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 return lPath
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 ## Give a list of Path instances according to the given list of identifier numbers
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 # @param lId integer list
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 # @return lPath a list of Path instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 def getPathListFromIdList( self, lId ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 lPath=[]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 if lId == []:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 return lPath
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 sqlCmd = "select * from %s where path=%d" % (self._table, lId[0])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 for i in lId[1:]:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 sqlCmd += " or path=%d" % (i)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 sqlCmd += ";"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 lPath = self._iDb.getObjectListWithSQLCmd( sqlCmd, self._getInstanceToAdapt )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 return lPath
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 ## Give a list of Path instances having the same given query name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 # @param query string name of the query
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 # @return lPath a list of Path instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 def getPathListFromQuery( self, query ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74 lPath = self._getPathListFromTypeName("query", query)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75 return lPath
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 ## Give a list of Path instances having the same given subject name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79 # @param subject string name of the subject
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 # @return lPath a list of Path instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82 def getPathListFromSubject( self, subject ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83 lPath = self._getPathListFromTypeName("subject", subject)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84 return lPath
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 ## Give a list of the distinct subject names present in the table
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88 # @return lDistinctSubjectNames string list
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90 def getSubjectList(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 lDistinctSubjectNames = self._getDistinctTypeNamesList("subject")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92 return lDistinctSubjectNames
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94 ## Give a list of the distinct query names present in the table
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96 # @return lDistinctQueryNames string list
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98 def getQueryList(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 lDistinctQueryNames = self._getDistinctTypeNamesList("query")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 return lDistinctQueryNames
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102 ## Give a list of the distinct query names present in the table
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103 # @note method to have correspondence with getSeqNameList() in TableSetAdaptator (for srptAutoPromote.py)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105 # @return lDistinctContigNames string list
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107 def getSeqNameList(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108 return self.getQueryList()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110 ## Give a list with all the distinct identifiers corresponding to the query
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112 # @param query string name of the subject
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113 # @return lId a list of integer
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115 def getIdListFromQuery( self, query ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116 lId = self._getIdListFromTypeName("query", query)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117 return lId
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119 ## Give a list with all the distinct identifiers corresponding to the subject
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121 # @param subject string name of the subject
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122 # @return lId a list of integer
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124 def getIdListFromSubject( self, subject ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125 lId = self._getIdListFromTypeName("subject", subject)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
126 return lId
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
127
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
128 ## Give a list of identifiers contained in the table
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
129 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
130 # @return lId integer list
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
131 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
132 def getIdList(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
133 sqlCmd = "SELECT DISTINCT path from %s;" % (self._table)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
134 lId = self._iDb.getIntegerListWithSQLCmd( sqlCmd )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
135 return lId
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
136
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
137 ## Give a list of the distinct subject names present in the table given a query name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
138 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
139 # @param queryName string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
140 # @return lDistinctSubjectNamesPerQuery string list
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
141 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
142 def getSubjectListFromQuery( self, queryName ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
143 sqlCmd = "SELECT DISTINCT subject_name FROM %s WHERE query_name='%s'" % ( self._table, queryName )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
144 lDistinctSubjectNamesPerQuery = self._iDb.getStringListWithSQLCmd(sqlCmd)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
145 return lDistinctSubjectNamesPerQuery
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
146
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
147 ## Give the data contained in the table as a list of Paths instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
148 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
149 # @return lPaths list of paths instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
150 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
151 def getListOfAllPaths( self ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
152 return self.getListOfAllCoordObject()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
153
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
154 ## Give a list of Path instances with the given query and subject, both on direct strand
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
155 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
156 # @param query string query name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
157 # @param subject string subject name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
158 # @return lPaths list of path instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
159 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
160 def getPathListWithDirectQueryDirectSubjectFromQuerySubject( self, query, subject ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
161 sqlCmd = "SELECT * FROM %s WHERE query_name='%s' AND subject_name='%s' AND query_start<query_end AND subject_start<subject_end ORDER BY query_name, subject_name, query_start;" % ( self._table, query, subject )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
162 lPaths = self._iDb.getObjectListWithSQLCmd( sqlCmd, self._getInstanceToAdapt )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
163 return lPaths
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
164
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
165 ## Give a list of Path instances with the given query on direct strand and the given subject on reverse strand
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
166 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
167 # @param query string query name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
168 # @param subject string subject name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
169 # @return lPaths list of path instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
170 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
171 def getPathListWithDirectQueryReverseSubjectFromQuerySubject( self, query, subject ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
172 sqlCmd = "SELECT * FROM %s WHERE query_name='%s' AND subject_name='%s' AND query_start<query_end AND subject_start>subject_end ORDER BY query_name, subject_name, query_start;" % ( self._table, query, subject )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
173 lPaths = self._iDb.getObjectListWithSQLCmd( sqlCmd, self._getInstanceToAdapt )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
174 return lPaths
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
175
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
176 ## Give the number of Path instances with the given query name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
177 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
178 # @param query string query name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
179 # @return pathNb integer the number of Path instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
180 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
181 def getNbPathsFromQuery( self, query ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
182 pathNb = self._getPathsNbFromTypeName("query", query)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
183 return pathNb
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
184
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
185 ## Give the number of Path instances with the given subject name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
186 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
187 # @param subject string subject name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
188 # @return pathNb integer the number of Path instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
189 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
190 def getNbPathsFromSubject( self, subject ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
191 pathNb = self._getPathsNbFromTypeName("subject", subject)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
192 return pathNb
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
193
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
194 ## Give the number of distinct path identifiers
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
195 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
196 # @return idNb integer the number of Path instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
197 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
198 def getNbIds( self ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
199 sqlCmd = "SELECT COUNT( DISTINCT path ) FROM %s" % ( self._table )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
200 idNb = self._iDb.getIntegerWithSQLCmd( sqlCmd )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
201 return idNb
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
202
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
203 ## Give the number of distinct path identifiers for a given subject
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
204 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
205 # @param subjectName string subject name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
206 # @return idNb integer the number of Path instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
207 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
208 def getNbIdsFromSubject( self, subjectName ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
209 idNb = self._getIdNbFromTypeName("subject", subjectName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
210 return idNb
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
211
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
212 ## Give the number of distinct path identifiers for a given query
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
213 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
214 # @param queryName string query name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
215 # @return idNb integer the number of Path instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
216 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
217 def getNbIdsFromQuery( self, queryName ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
218 idNb = self._getIdNbFromTypeName("query", queryName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
219 return idNb
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
220
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
221 ## Give a list of Path instances included in a given query region
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
222 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
223 # @param query string query name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
224 # @param start integer start coordinate
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
225 # @param end integer end coordinate
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
226 # @return lPaths list of Path instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
227 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
228 def getPathListIncludedInQueryCoord( self, query, start, end ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
229 if( start > end ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
230 tmp = start
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
231 start = end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
232 end = tmp
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
233 sqlCmd = "SELECT * FROM %s WHERE query_name='%s' AND query_start>=%i AND query_end<=%i" % ( self._table, query, start, end )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
234 lPaths = self._iDb.getObjectListWithSQLCmd( sqlCmd, self._getInstanceToAdapt )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
235 return lPaths
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
236
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
237 ## Give a list of Path instances overlapping a given region
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
238 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
239 # @param query string query name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
240 # @param start integer start coordinate
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
241 # @param end integer end coordinate
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
242 # @return lPath list of Path instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
243 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
244 def getPathListOverlappingQueryCoord( self, query, start, end ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
245 if( start > end ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
246 tmp = start
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
247 start = end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
248 end = tmp
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
249 sqlCmd = "SELECT * FROM %s WHERE query_name='%s'" % ( self._table, query )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
250 sqlCmd += " AND ( ( query_start < %i AND query_end >= %i AND query_end <= %i )" % ( start, start, end )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
251 sqlCmd += " OR ( query_start >= %i AND query_end <= %i )" % ( start, end )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
252 sqlCmd += " OR ( query_start >= %i AND query_start <= %i AND query_end > %i )" % ( start, end, end )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
253 sqlCmd += " OR ( query_start < %i AND query_end > %i ) )" % ( start, end )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
254 lPaths = self._iDb.getObjectListWithSQLCmd( sqlCmd, self._getInstanceToAdapt )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
255 return lPaths
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
256
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
257 ## Give a list of Path instances overlapping a given region
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
258 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
259 # @note whole chains are returned, even if only a fragment overlap with the given region
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
260 # @param query string query name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
261 # @param start integer start coordinate
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
262 # @param end integer end coordinate
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
263 # @return lPath list of Path instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
264 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
265 def getChainListOverlappingQueryCoord( self, query, start, end ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
266 if( start > end ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
267 tmp = start
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
268 start = end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
269 end = tmp
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
270 sqlCmd = "SELECT DISTINCT path FROM %s WHERE query_name='%s'" % ( self._table, query )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
271 sqlCmd += " AND ( ( query_start <= %i AND query_end >= %i AND query_end <= %i )" % ( start, start, end )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
272 sqlCmd += " OR ( query_start >= %i AND query_end <= %i )" % ( start, end )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
273 sqlCmd += " OR ( query_start >= %i AND query_start <= %i AND query_end >= %i )" % ( start, end, end )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
274 sqlCmd += " OR ( query_start <= %i AND query_end >= %i ) )" % ( start, end )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
275 lIdentifiers = self._iDb.getIntegerListWithSQLCmd( sqlCmd )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
276 lPaths = self.getPathListFromIdList( lIdentifiers )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
277 return lPaths
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
278
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
279 ## Give a list of Set instances overlapping a given region
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
280 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
281 # @param query string query name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
282 # @param start integer start coordinate
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
283 # @param end integer end coordinate
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
284 # @return lSet list of Set instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
285 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
286 def getSetListOverlappingQueryCoord(self, query, start, end):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
287 lPath = self.getPathListOverlappingQueryCoord(query, start, end)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
288 lSet = PathUtils.getSetListFromQueries(lPath)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
289 return lSet
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
290
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
291 ## Give a list of Set instances included in a given region
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
292 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
293 # @param query string query name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
294 # @param start integer start coordinate
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
295 # @param end integer end coordinate
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
296 # @return lSet list of Set instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
297 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
298 def getSetListIncludedInQueryCoord(self, query, start, end):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
299 lPath=self.getPathListIncludedInQueryCoord(query, start, end)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
300 lSet = PathUtils.getSetListFromQueries(lPath)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
301 return lSet
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
302
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
303 ## Give a a list of Path instances sorted by query coordinates
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
304 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
305 # @return lPaths list of Path instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
306 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
307 def getPathListSortedByQueryCoord( self ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
308 sqlCmd = "SELECT * FROM %s ORDER BY query_name, LEAST(query_start,query_end)" % ( self._table )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
309 lPaths = self._iDb.getObjectListWithSQLCmd( sqlCmd, self._getInstanceToAdapt )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
310 return lPaths
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
311
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
312 ## Give a a list of Path instances sorted by query coordinates for a given query
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
313 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
314 # @return lPaths list of Path instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
315 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
316 def getPathListSortedByQueryCoordFromQuery( self, queryName ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
317 sqlCmd = "SELECT * FROM %s WHERE query_name='%s' ORDER BY LEAST(query_start,query_end)" % ( self._table, queryName )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
318 lPaths = self._iDb.getObjectListWithSQLCmd( sqlCmd, self._getInstanceToAdapt )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
319 return lPaths
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
320
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
321 ## Give a a list of Path instances sorted by query coordinates and score for a given query
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
322 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
323 # @return lPaths list of Path instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
324 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
325 def getPathListSortedByQueryCoordAndScoreFromQuery(self, queryName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
326 sqlCmd = "SELECT * FROM %s WHERE query_name='%s' ORDER BY query_start, query_end, score" % (self._table, queryName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
327 lPaths = self._iDb.getObjectListWithSQLCmd( sqlCmd, self._getInstanceToAdapt )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
328 return lPaths
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
329
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
330 ## Give a cumulative length of all paths (fragments) for a given subject name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
331 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
332 # @param subjectName string subject name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
333 # @return nb Cumulative length for all path
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
334 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
335 # @warning doesn't take into account the overlaps !!
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
336 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
337 def getCumulLengthFromSubject( self, subjectName ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
338 sqlCmd = "SELECT SUM(ABS(query_end-query_start)+1) FROM %s WHERE subject_name='%s'" % ( self._table, subjectName )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
339 nb = self._iDb.getIntegerWithSQLCmd(sqlCmd)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
340 return nb
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
341
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
342 ## Give a list of the length of all chains of paths for a given subject name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
343 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
344 # @param subjectName string name of the subject
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
345 # @return lChainLengths list of lengths per chain of paths
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
346 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
347 # @warning doesn't take into account the overlaps !!
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
348 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
349 def getChainLengthListFromSubject( self, subjectName ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
350 sqlCmd = "SELECT SUM(ABS(query_end-query_start)+1) FROM %s WHERE subject_name='%s' GROUP BY PATH" % ( self._table, subjectName )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
351 lChainLengths = self._iDb.getIntegerListWithSQLCmd(sqlCmd)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
352 return lChainLengths
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
353
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
354 ## Give a list of identity of all chains of paths for a given subject name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
355 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
356 # @param subjectName string name of the subject
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
357 # @return lChainIdentities list of identities per chain of paths
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
358 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
359 # @warning doesn't take into account the overlaps !!
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
360 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
361 def getChainIdentityListFromSubject( self, subjectName ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
362 lChainIdentities = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
363 sqlCmd = "SELECT SUM(identity*(ABS(query_start-query_end)+1)) / SUM(ABS(query_end-query_start)+1) FROM %s WHERE subject_name='%s' GROUP BY PATH" % ( self._table, subjectName )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
364 self._iDb.execute( sqlCmd )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
365 res = self._iDb.fetchall()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
366 for i in res:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
367 if i[0] != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
368 lChainIdentities.append( round( float( i[0] ), 2 ) )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
369 return lChainIdentities
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
370
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
371 ## Give a list of the length of all paths for a given subject name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
372 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
373 # @param subjectName string name of the subject
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
374 # @return lPathLengths list of lengths per path
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
375 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
376 # @warning doesn't take into account the overlaps !!
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
377 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
378 def getPathLengthListFromSubject( self, subjectName ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
379 sqlCmd = "SELECT ABS(query_end-query_start)+1 FROM %s WHERE subject_name='%s'" % ( self._table, subjectName )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
380 lPathLengths = self._iDb.getIntegerListWithSQLCmd(sqlCmd)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
381 return lPathLengths
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
382
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
383 ## Give a a list with all distinct identifiers for a given subject sorted in decreasing order according to the length of the chains
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
384 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
385 # @param subjectName string subject name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
386 # @return lPathNums a list of paths Id
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
387 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
388 def getIdListSortedByDecreasingChainLengthFromSubject( self, subjectName ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
389 sqlCmd = "SELECT DISTINCT path, SUM( ABS(query_end - query_start) + 1 ) AS length"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
390 sqlCmd += " FROM %s" % ( self._table )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
391 sqlCmd += " WHERE subject_name='%s'" % ( subjectName )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
392 sqlCmd += " GROUP BY path"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
393 sqlCmd += " ORDER BY length DESC";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
394 lPathNums = self._iDb.getIntegerListWithSQLCmd(sqlCmd)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
395 return lPathNums
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
396
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
397 ## Give a a list with all distinct identifiers for a given subject where the chain lengths is above a given threshold
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
398 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
399 # @param subjectName string subject name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
400 # @lengthThreshold length threshold below which chains are filtered
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
401 # @return lPathNums a list of paths Id
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
402 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
403 def getIdListFromSubjectWhereChainsLongerThanThreshold( self, subjectName, lengthThreshold ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
404 lPathNums = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
405 sqlCmd = "SELECT DISTINCT path, SUM( ABS(query_end - query_start) + 1 ) AS length"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
406 sqlCmd += " FROM %s" % ( self._table )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
407 sqlCmd += " WHERE subject_name='%s'" % ( subjectName )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
408 sqlCmd += " GROUP BY path"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
409 sqlCmd += " ORDER BY length DESC";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
410 self._iDb.execute( sqlCmd )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
411 res = self._iDb.fetchall()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
412 for i in res:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
413 if int(i[1]) >= int(lengthThreshold):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
414 lPathNums.append( i[0] )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
415 return lPathNums
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
416
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
417 ## Give a Set instances list of a query annotation
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
418 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
419 # @param query string query name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
420 # @return lSets list of set instance
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
421 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
422 def getSetListFromQuery(self, query):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
423 lpath = self.getPathListFromQuery(query)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
424 lSets = PathUtils.getSetListFromQueries(lpath)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
425 return lSets
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
426
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
427 ## Give a Set instances list of a query annotation
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
428 # @note method to have correspondence with getSetListFromSeqName() in TableSetAdaptator (for srptAutoPromote.py)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
429 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
430 # @param query string query name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
431 # @return lSets list of set instance
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
432 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
433 def getSetListFromSeqName(self, query):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
434 return self.getSetListFromQuery(query)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
435
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
436 ## Delete path corresponding to a given identifier number
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
437 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
438 # @param id integer identifier number
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
439 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
440 def deleteFromId(self,id):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
441 sqlCmd = "delete from %s where path=%d;" % (self._table, id)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
442 self._iDb.execute(sqlCmd)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
443
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
444 ## Delete path corresponding to a given object path line
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
445 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
446 # @param path object
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
447 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
448 def deleteFromPath(self,path):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
449 sqlCmd = "delete from %s where path=%d and query_name='%s' and query_start=%s and query_end=%s and subject_name='%s' and subject_start=%s and subject_end=%s and E_value=%s and score=%s" % (self._table, path.getIdentifier(), path.getQueryName(), path.getQueryStart(), path.getQueryEnd(), path.getSubjectName(), path.getSubjectStart(), path.getSubjectEnd(), path.getEvalue(), int(path.getScore()))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
450 self._iDb.execute(sqlCmd)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
451
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
452 ## Delete path corresponding to a given list of identifier number
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
453 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
454 # @param lId list of identifier number
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
455 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
456 def deleteFromIdList(self,lId):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
457 if lId == []:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
458 return
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
459 sqlCmd = "delete from %s where path=%d" % (self._table, lId[0])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
460 for id in lId[1:]:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
461 sqlCmd += " or path=%d" %(id)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
462 sqlCmd += ";"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
463 self._iDb.execute(sqlCmd)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
464
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
465 ## Get a new id number
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
466 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
467 # @return newId integer new id
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
468 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
469 def getNewId(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
470 sqlCmd = 'select max(path) from %s;' % (self._table)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
471 maxId = self._iDb.getIntegerWithSQLCmd(sqlCmd)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
472 newId = int(maxId)+1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
473 return newId
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
474
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
475 ## Join two path by changing id number of id1 and id2 path to the least of id1 and id2
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
476 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
477 # @param id1 integer id path number
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
478 # @param id2 integer id path number
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
479 # @return newId integer minimum of id1 id2
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
480 # @note this method modify the ID even if this one not existing in the path table
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
481 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
482 def joinTwoPaths(self, id1, id2):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
483 if id1 < id2:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
484 newId = id1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
485 oldId = id2
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
486 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
487 newId = id2
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
488 oldId = id1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
489 sqlCmd = "UPDATE %s SET path=%d WHERE path=%d"\
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
490 % (self._table, newId, oldId)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
491 self._iDb.execute(sqlCmd)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
492 return newId
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
493
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
494 ## Create a 'pathRange' table from a 'path' table.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
495 # The output table summarizes the information per identifier.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
496 # The min and max value are taken.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
497 # The identity is averaged over the fragments.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
498 # It may overwrite an existing table.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
499 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
500 # @param outTable string name of the output table
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
501 # @return outTable string Table which summarizes the information per identifier
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
502 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
503 def path2PathRange( self, outTable="" ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
504 return self._path2PathRangeOrPath2PathRangeQuery(outTable)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
505
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
506 ## Create a 'pathrange' table from a 'path' table for the given query name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
507 # The output table summarizes the information per identifier
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
508 # The min and max value are taken
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
509 # The identity is averaged over the fragments, weighted by the length of the of the query
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
510 # It may overwrite an existing table
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
511 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
512 # @param outTable string name of the output table
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
513 # @param query string query name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
514 # @return outTable string Table which summarizes the information per identifier
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
515 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
516 def _path2PathRangeFromQuery( self, queryName, outTable="" ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
517 return self._path2PathRangeOrPath2PathRangeQuery(outTable, queryName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
518
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
519 def _path2PathRangeOrPath2PathRangeQuery(self, outTable, queryName=""):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
520 self._iDb.createIndex( self._table, "path" )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
521 if outTable == "":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
522 outTable = "%s_range" % ( self._table )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
523 self._iDb.dropTable( outTable )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
524
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
525 tmpTable = "%s_tmp" % ( self._table )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
526 self._iDb.dropTable( tmpTable )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
527
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
528 sqlCmd = self._genSqlCmdForTmpTableAccordingToQueryName(queryName, tmpTable)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
529 self._iDb.execute(sqlCmd)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
530
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
531 sqlCmd = "CREATE TABLE %s SELECT path, query_name, MIN(query_start) AS query_start, MAX(query_end) AS query_end, subject_name, MIN(subject_start) AS subject_start, MAX(subject_end) AS subject_end, MIN(e_value) AS e_value, SUM(score) AS score, TRUNCATE(SUM(identity)/SUM(ABS(query_end-query_start)+1),2) AS identity FROM %s WHERE query_start<query_end AND subject_start<subject_end GROUP BY path;" % ( outTable, tmpTable )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
532 self._iDb.execute( sqlCmd )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
533
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
534 sqlCmd = "INSERT into %s SELECT path, query_name, MIN(query_start) AS query_start, MAX(query_end) AS query_end, subject_name, MAX(subject_start) AS subject_start, MIN(subject_end) AS subject_end, MIN(e_value) AS e_value, SUM(score) AS score, TRUNCATE(SUM(identity)/SUM(ABS(query_end-query_start)+1),2) AS identity FROM %s WHERE query_start<query_end AND subject_start>subject_end GROUP BY path;" % ( outTable, tmpTable )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
535 self._iDb.execute( sqlCmd )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
536
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
537 self._iDb.createIndex( outTable, "path" )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
538 self._iDb.dropTable( tmpTable )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
539 return outTable
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
540
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
541 ## Give a list of Path lists sorted by weighted identity.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
542 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
543 # @return lChains list of chains
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
544 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
545 def getListOfChainsSortedByAscIdentityFromQuery( self, qry ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
546 lChains = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
547 tmpTable = self._path2PathRangeFromQuery( qry )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
548 sqlCmd = "SELECT path FROM %s ORDER BY identity" % ( tmpTable )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
549 self._iDb.execute( sqlCmd )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
550 lPathnums = self._iDb.fetchall()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
551 self._iDb.dropTable( tmpTable )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
552 for pathnum in lPathnums:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
553 lChains.append( self.getPathListFromId( int(pathnum[0]) ) )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
554 return lChains
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
555
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
556 ## Give a list of path instances sorted by increasing E-value
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
557 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
558 # @return lPaths list of path instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
559 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
560 def getPathListSortedByIncreasingEvalueFromQuery( self, queryName ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
561 sqlCmd = "SELECT * FROM %s WHERE query_name='%s' ORDER BY E_value ASC" % ( self._table, queryName )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
562 lPaths = self._iDb.getObjectListWithSQLCmd( sqlCmd, self._getInstanceToAdapt )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
563 return lPaths
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
564
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
565
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
566 ## Return the number of times a given instance is present in the table
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
567 # The identifier is not considered,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
568 # only coordinates, score, E-value and identity.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
569 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
570 # @return nbOcc integer
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
571 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
572 def getNbOccurrences( self, iPath ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
573 sqlCmd = "SELECT COUNT(*) FROM %s WHERE" % ( self._table )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
574 sqlCmd += " query_name='%s'" % ( iPath.range_query.seqname )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
575 sqlCmd += " AND query_start='%s'" % ( iPath.range_query.start )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
576 sqlCmd += " AND query_end='%s'" % ( iPath.range_query.end )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
577 sqlCmd += " AND subject_name='%s'" % ( iPath.range_subject.seqname )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
578 sqlCmd += " AND subject_start='%s'" % ( iPath.range_subject.start )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
579 sqlCmd += " AND subject_end='%s'" % ( iPath.range_subject.end )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
580 sqlCmd += " AND score='%s'" % ( iPath.score )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
581 sqlCmd += " AND e_value='%s'" % ( iPath.e_value )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
582 sqlCmd += " AND identity='%s'" % ( iPath.identity )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
583 nbOcc = self._iDb.getIntegerWithSQLCmd( sqlCmd )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
584 return nbOcc
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
585
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
586
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
587 def _getPathListFromTypeName( self, type, typeName ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
588 sqlCmd = "SELECT * FROM %s WHERE %s_name='%s';" % ( self._table, type, typeName )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
589 lPath = self._iDb.getObjectListWithSQLCmd( sqlCmd, self._getInstanceToAdapt )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
590 return lPath
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
591
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
592 def _getDistinctTypeNamesList( self, type ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
593 sqlCmd = "SELECT DISTINCT %s_name FROM %s" % ( type, self._table )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
594 lDistinctTypeNames = self._iDb.getStringListWithSQLCmd(sqlCmd)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
595 return lDistinctTypeNames
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
596
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
597 def _getPathsNbFromTypeName( self, type, typeName ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
598 sqlCmd = "SELECT COUNT(*) FROM %s WHERE %s_name='%s'" % ( self._table, type, typeName )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
599 pathNb = self._iDb.getIntegerWithSQLCmd( sqlCmd )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
600 return pathNb
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
601
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
602 def _getIdListFromTypeName( self, type, typeName ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
603 sqlCmd = "SELECT DISTINCT path FROM %s WHERE %s_name='%s'" % ( self._table, type, typeName )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
604 lId = self._iDb.getIntegerListWithSQLCmd( sqlCmd )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
605 return lId
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
606
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
607 def _getIdNbFromTypeName( self, type, typeName ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
608 sqlCmd = "SELECT COUNT( DISTINCT path ) FROM %s WHERE %s_name='%s'" % ( self._table, type, typeName )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
609 idNb = self._iDb.getIntegerWithSQLCmd( sqlCmd )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
610 return idNb
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
611
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
612 def _getTypeAndAttr2Insert(self, path):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
613 type2Insert = ("'%d'", "'%s'", "'%d'", "'%d'", "'%s'", "'%d'", "'%d'", "'%g'", "'%d'", "'%f'")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
614 if path.range_query.isOnDirectStrand():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
615 queryStart = path.range_query.start
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
616 queryEnd = path.range_query.end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
617 subjectStart = path.range_subject.start
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
618 subjectEnd = path.range_subject.end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
619 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
620 queryStart = path.range_query.end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
621 queryEnd = path.range_query.start
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
622 subjectStart = path.range_subject.end
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
623 subjectEnd = path.range_subject.start
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
624 attr2Insert = ( path.id,\
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
625 path.range_query.seqname,\
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
626 queryStart,\
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
627 queryEnd,\
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
628 path.range_subject.seqname,\
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
629 subjectStart,\
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
630 subjectEnd,\
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
631 path.e_value,\
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
632 path.score,\
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
633 path.identity\
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
634 )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
635 return type2Insert, attr2Insert
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
636
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
637 def _getInstanceToAdapt(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
638 iPath = Path()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
639 return iPath
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
640
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
641 def _escapeAntislash(self, obj):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
642 obj.range_query.seqname = obj.range_query.seqname.replace("\\", "\\\\")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
643 obj.range_subject.seqname = obj.range_subject.seqname.replace("\\", "\\\\")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
644
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
645 def _genSqlCmdForTmpTableAccordingToQueryName(self, queryName, tmpTable):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
646 sqlCmd = ""
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
647 if queryName == "":
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
648 sqlCmd = "CREATE TABLE %s SELECT path, query_name, query_start, query_end, subject_name, subject_start, subject_end, e_value, score, (ABS(query_end-query_start)+1)*identity AS identity FROM %s" % (tmpTable, self._table)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
649 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
650 sqlCmd = "CREATE TABLE %s SELECT path, query_name, query_start, query_end, subject_name, subject_start, subject_end, e_value, score, (ABS(query_end-query_start)+1)*identity AS identity FROM %s WHERE query_name='%s'" % (tmpTable, self._table, queryName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
651 return sqlCmd
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
652
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
653 ## return a filtered list with only one unique occurrence of path of a given list
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
654 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
655 # @param lPath a list of Path instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
656 # @return lUniquePath a list of Path instances
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
657 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
658 def getListOfUniqueOccPath(self, lPath):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
659 if len(lPath) < 2 :
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
660 return lPath
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
661
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
662 sortedListPath = sorted(lPath, key=lambda iPath: ( iPath.range_query.getSeqname(), iPath.range_query.getStart(), iPath.range_query.getEnd(), iPath.range_subject.getSeqname(), iPath.range_subject.getStart(), iPath.range_subject.getEnd()))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
663 lUniquePath = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
664 for i in xrange(1, len(sortedListPath)):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
665 previousPath = sortedListPath [i-1]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
666 currentPath = sortedListPath [i]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
667 if previousPath != currentPath:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
668 lUniquePath.append(previousPath)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
669
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
670 if previousPath != currentPath:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
671 lUniquePath.append(currentPath)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
672
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
673 return lUniquePath