annotate commons/core/sql/TableBinSetAdaptator.py @ 16:6135c3075bc5

Deleted selected files
author m-zytnicki
date Mon, 22 Apr 2013 11:09:41 -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 from commons.core.sql.TableSetAdaptator import TableSetAdaptator
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 from commons.core.coord.SetUtils import SetUtils
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 ## Adaptator for Set tables with bin indexes
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 class TableBinSetAdaptator(TableSetAdaptator):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 ## constructor
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40 # @param iDb DbMySql instance instance of DbMySql
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41 # @param tableName string table name (default = "")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 def __init__(self, iDb, tableName = ""):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 TableSetAdaptator.__init__(self, iDb, tableName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 self._table_idx = "%s_idx" % (self._table)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 ## Insert a set instance in a set bin table
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 # @param iSet set instance an instance of set object
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 # @param delayed boolean an insert delayed or not
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 def insASetInSetAndBinTable(self, iSet, delayed = False):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 self.insert(iSet, delayed)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 iSet.seqname = iSet.seqname.replace("\\", "\\\\")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 iSet.name = iSet.name.replace("\\", "\\\\")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 bin = iSet.getBin()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 max = iSet.getMax()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 min = iSet.getMin()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 strand = iSet.isOnDirectStrand()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 sql_prefix = ''
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 if delayed:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 sql_prefix = 'INSERT DELAYED INTO '
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 sql_prefix = 'INSERT INTO '
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 sql_cmd = sql_prefix + '%s VALUES (%d,%f,"%s",%d,%d,%d)'\
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 %(self._table_idx,\
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 iSet.id,\
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 bin,\
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 iSet.seqname,\
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 min,\
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 max,\
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 strand)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 self._iDb.execute(sql_cmd)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75 ## Delete set corresponding to a given identifier number in set and bin set table
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 # @param id integer identifier number
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 # @note old name was delSet_from_num
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79 def deleteFromIdFromSetAndBinTable(self, id):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 self.deleteFromId(id)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 sql_cmd = 'delete from %s where path=%d' % (self._table_idx, id)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82 self._iDb.execute(sql_cmd)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84 ## Delete path corresponding to a given list of identifier number
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 # @param lId integer list list of identifier number
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87 # @note old name was delSet_from_listnum
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89 def deleteFromListIdFromSetAndBinTable(self, lId):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90 if lId != []:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 self.deleteFromIdList(lId)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92 sql_cmd = 'delete from %s where path=%d' % (self._table_idx, lId[0])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93 for i in lId[1:]:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94 sql_cmd += " or path=%d" % (i)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95 self._iDb.execute(sql_cmd)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97 ## Join two set by changing id number of id1 and id2 path
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98 # to the least of id1 and id2
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 # @param id1 integer id path number
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101 # @param id2 integer id path number
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102 # @return id integer new id
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103 # @note old name was joinSet
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105 def joinTwoSetsFromSetAndBinTable(self, id1, id2):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106 self.joinTwoSets(id1, id2)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107 if id1 < id2:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108 new_id = id1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109 old_id = id2
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111 new_id = id2
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112 old_id = id1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113 sql_cmd = 'UPDATE %s SET path=%d WHERE path=%d'\
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114 % (self._table_idx, new_id, old_id)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115 self._iDb.execute(sql_cmd)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116 return new_id
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118 ## Get a new id number from set bin table
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120 def getNewId(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121 sql_cmd = 'select max(path) from %s;' % (self._table_idx)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122 self._iDb.execute(sql_cmd)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123 max_id = self._iDb.fetchall()[0][0]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124 if max_id != None:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125 return int(max_id)+1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
126 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
127 return 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
128
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
129 ## Get a set list instance between start and end parameters
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
130 # using the bin scheme
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
131 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
132 # @param seqName reference seq name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
133 # @param start start coordinate
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
134 # @param end end coordinate
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
135 # @return lSet set list
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
136 # @note old name was getSetList_from_qcoord
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
137 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
138 def getSetListFromQueryCoord(self, seqName, start, end):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
139
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
140 min_coord = min(start,end)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
141 max_coord = max(start,end)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
142
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
143 sql_cmd = 'select path from %s where contig="%s" and ('\
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
144 % (self._table + "_idx", seqName)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
145 for i in xrange(8, 2, -1):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
146 bin_lvl = pow(10, i)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
147 if int(start/bin_lvl) == int(end/bin_lvl):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
148 bin = float(bin_lvl + (int(start / bin_lvl) / 1e10))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
149 sql_cmd += 'bin=%f' % (bin)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
150 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
151 bin1 = float(bin_lvl + (int(start / bin_lvl) / 1e10))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
152 bin2 = float(bin_lvl + (int(end /bin_lvl) / 1e10))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
153 sql_cmd += 'bin between %f and %f' % (bin1, bin2)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
154 if bin_lvl != 1000:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
155 sql_cmd += " or "
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
156
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
157 sql_cmd += ") and min<=%d and max>=%d" % (max_coord, min_coord);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
158 self._iDb.execute(sql_cmd)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
159 res = self._iDb.fetchall()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
160 lId = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
161 for i in res:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
162 lId.append(int(i[0]))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
163 lSet = self.getSetListFromIdList(lId)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
164 return lSet
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
165
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
166 ## Get a set list instances strictly included between start and end parameters
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
167 # using the bin scheme
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
168 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
169 # @param seqName reference seq name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
170 # @param start start coordinate
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
171 # @param end end coordinate
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
172 # @return lSet set list
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
173 # @note old name was getInSetList_from_qcoord
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
174 # @warning the implementation has been changed : I added the two first lines
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
175 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
176 def getSetListStrictlyIncludedInQueryCoord(self, contig, start, end):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
177 min_coord = min(start,end)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
178 max_coord = max(start,end)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
179 lSet = self.getSetListFromQueryCoord(contig, start, end)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
180 lSetStrictlyIncluded = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
181 for iSet in lSet:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
182 if iSet.getMin() > min_coord and \
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
183 iSet.getMax() < max_coord:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
184 lSetStrictlyIncluded.append(iSet)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
185
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
186 return lSetStrictlyIncluded
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
187
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
188 ## Get a list of the identifier Id contained in the table bin
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
189 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
190 # @return lId list of int list of identifier
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
191 # @note old name was getSet_num
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
192 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
193 def getIdList(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
194 sql_cmd = 'select distinct path from %s;' % (self._table_idx)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
195 self._iDb.execute(sql_cmd)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
196 res = self._iDb.fetchall()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
197 lId = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
198 for t in res:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
199 lId.append(int(t[0]))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
200 return lId
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
201
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
202 ## Get a list of the query sequence name contained in the table bin
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
203 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
204 # @return lSeqName list of string list of query sequence name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
205 # @note old name was getContig_name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
206 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
207 def getSeqNameList(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
208 sql_cmd = 'select distinct contig from %s;' % (self._table_idx)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
209 self._iDb.execute(sql_cmd)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
210 res = self._iDb.fetchall()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
211 lSeqName = []
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
212 for t in res:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
213 lSeqName.append(t[0])
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
214 return lSeqName
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
215
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
216 ## Insert a Set list with the same new identifier in the table bin and set
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
217 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
218 # @note old name was insAddSetList
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
219 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
220 def insertListInSetAndBinTable(self, lSets, delayed = False):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
221 id = self.getNewId()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
222 SetUtils.changeIdInList( lSets, id )
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
223 for iSet in lSets:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
224 self.insASetInSetAndBinTable(iSet, delayed)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
225
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
226 ## Insert a set list instances In table Bin and Set and merge all overlapping sets
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
227 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
228 # @param lSets reference seq name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
229 # @note old name was insMergeSetList
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
230 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
231 def insertListInSetAndBinTableAndMergeAllSets(self, lSets):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
232 min, max = SetUtils.getListBoundaries(lSets)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
233 oldLSet = self.getSetListFromQueryCoord(lSets[0].seqname, min, max)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
234 oldQueryhash = SetUtils.getDictOfListsWithIdAsKey(oldLSet)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
235 qhash = SetUtils.getDictOfListsWithIdAsKey(lSets)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
236 for lNewSetById in qhash.values():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
237 found = False
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
238 for currentId, oldLsetById in oldQueryhash.items():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
239 if SetUtils.areSetsOverlappingBetweenLists(lNewSetById, oldLsetById):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
240 oldLsetById.extend(lNewSetById)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
241 oldLsetById = SetUtils.mergeSetsInList(oldLsetById)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
242 self.deleteFromIdFromSetAndBinTable(currentId)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
243 found = True
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
244 if not found:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
245 self.insertListInSetAndBinTable(lNewSetById)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
246 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
247 id = self.getNewId()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
248 SetUtils.changeIdInList(oldLsetById, id)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
249 self.insertListInSetAndBinTable(oldLsetById)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
250
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
251 ## Insert a set list instances In table Bin and Set after removing all overlaps between database and lSets
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
252 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
253 # @param lSets reference seq name
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
254 # @note old name was insDiffSetList
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
255 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
256 def insertListInSetAndBinTableAndRemoveOverlaps(self, lSets):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
257 min, max = SetUtils.getListBoundaries(lSets)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
258 oldLSet = self.getSetListFromQueryCoord(lSets[0].seqname, min, max)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
259 oldQueryHash = SetUtils.getDictOfListsWithIdAsKey(oldLSet)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
260 newQueryHash = SetUtils.getDictOfListsWithIdAsKey(lSets)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
261 for lNewSetById in newQueryHash.values():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
262 for lOldSetById in oldQueryHash.values():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
263 if SetUtils.areSetsOverlappingBetweenLists(lNewSetById, lOldSetById):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
264 lNewSetById = SetUtils.getListOfSetWithoutOverlappingBetweenTwoListOfSet(lOldSetById, lNewSetById)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
265 self.insertListInSetAndBinTable(lNewSetById)