1 | import interval_index_file |
---|
2 | from interval_index_file import Indexes |
---|
3 | from tempfile import mktemp |
---|
4 | import random |
---|
5 | |
---|
6 | def test_offsets(): |
---|
7 | assert interval_index_file.offsets_for_max_size( 512*1024*1024 - 1 ) == [ 512 + 64 + 8 + 1, 64 + 8 + 1, 8 + 1, 1, 0 ] |
---|
8 | |
---|
9 | def test_interval_index_file(): |
---|
10 | ix = Indexes() |
---|
11 | chrs = [] |
---|
12 | for i in range( 5 ): |
---|
13 | intervals = [] |
---|
14 | name = "seq%d" % i |
---|
15 | max = random.randint( 0, interval_index_file.MAX ) |
---|
16 | # print name, "size", max |
---|
17 | for i in range( 500 ): |
---|
18 | start = random.randint( 0, max ) |
---|
19 | end = random.randint( 0, max ) |
---|
20 | if end < start: |
---|
21 | end, start = start, end |
---|
22 | ix.add( name, start, end, i, max=interval_index_file.MAX ) |
---|
23 | intervals.append( ( start, end, i ) ) |
---|
24 | chrs.append( intervals ) |
---|
25 | fname = mktemp() |
---|
26 | f = open( fname, "w" ) |
---|
27 | ix.write( f ) |
---|
28 | f.close() |
---|
29 | del ix |
---|
30 | |
---|
31 | ix = Indexes( fname ) |
---|
32 | for i in range( 5 ): |
---|
33 | intervals = chrs[i] |
---|
34 | name = "seq%d" % i |
---|
35 | for i in range( 100 ): |
---|
36 | start = random.randint( 0, max ) |
---|
37 | end = random.randint( 0, max ) |
---|
38 | if end < start: |
---|
39 | end, start = start, end |
---|
40 | query_intervals = set() |
---|
41 | for ( s, e, i ) in intervals: |
---|
42 | if e > start and s < end: |
---|
43 | query_intervals.add( ( s, e, i ) ) |
---|
44 | result = ix.find( name, start, end ) |
---|
45 | for inter in result: |
---|
46 | assert inter in query_intervals |
---|
47 | |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | |
---|
52 | |
---|
53 | |
---|
54 | |
---|
55 | |
---|
56 | |
---|