|
| 1 | +import math |
1 | 2 | import os |
2 | 3 | import sqlite3 |
3 | 4 | import random |
|
18 | 19 | 1 + 16 + 256 + 4096 + 65536 + 1048576 + 16777216, |
19 | 20 | 1 + 16 + 256 + 4096 + 65336 + 1048576 + 16777216 + 268435456, |
20 | 21 | ] |
| 22 | +POS_OFFSETS = [ |
| 23 | + 0, |
| 24 | + 134217728, |
| 25 | + 8388608, |
| 26 | + 524288, |
| 27 | + 32768, |
| 28 | + 2048, |
| 29 | + 128, |
| 30 | + 8, |
| 31 | + 0, |
| 32 | +] |
21 | 33 |
|
22 | 34 |
|
23 | 35 | def test_genomic_range_bin(): |
@@ -191,6 +203,39 @@ def fanout(query): |
191 | 203 | assert fanout(query) == 9 |
192 | 204 |
|
193 | 205 |
|
| 206 | +def test_boundaries(): |
| 207 | + # test abutting intervals near bin boundaries |
| 208 | + |
| 209 | + con = sqlite3.connect(":memory:") |
| 210 | + con.executescript("CREATE TABLE features(rid INTEGER, beg INTEGER, end INTEGER)") |
| 211 | + |
| 212 | + insert = "INSERT INTO features(rid,beg,end) values(?,?,?)" |
| 213 | + for depth in range(2, 9): |
| 214 | + boundary = 3 * (16 ** (9 - depth)) + POS_OFFSETS[depth] |
| 215 | + for ofs in range(-2, 3): |
| 216 | + featlen = math.ceil(16 ** (9 - depth) / 2) |
| 217 | + con.execute(insert, (42, boundary + ofs - featlen, boundary + ofs)) |
| 218 | + con.execute(insert, (42, boundary + ofs, boundary + ofs + featlen)) |
| 219 | + |
| 220 | + con.executescript( |
| 221 | + genomicsqlite.create_genomic_range_index_sql(con, "features", "rid", "beg", "end") |
| 222 | + ) |
| 223 | + |
| 224 | + query = genomicsqlite.genomic_range_rowids_sql(con, "features")[1:-1] |
| 225 | + control = "SELECT _rowid_ FROM features NOT INDEXED WHERE rid = ? AND NOT (? > end OR ? < beg) ORDER BY _rowid_" |
| 226 | + total_results = 0 |
| 227 | + for depth in range(2, 9): |
| 228 | + boundary = 3 * (16 ** (9 - depth)) + POS_OFFSETS[depth] |
| 229 | + for qlen in range(3): |
| 230 | + for ofs in range(-3, 4): |
| 231 | + tup = (42, boundary + ofs, boundary + ofs + qlen) |
| 232 | + query_results = list(con.execute(query, tup)) |
| 233 | + control_results = list(con.execute(control, tup)) |
| 234 | + assert query_results == control_results |
| 235 | + total_results += len(query_results) |
| 236 | + assert total_results == 938 |
| 237 | + |
| 238 | + |
194 | 239 | def test_refseq(): |
195 | 240 | con = sqlite3.connect(":memory:") |
196 | 241 |
|
|
0 commit comments