File: fix_BIN_OFFSETS_MAX

package info (click to toggle)
python-bx 0.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,160 kB
  • sloc: python: 21,252; ansic: 2,326; makefile: 78; sh: 8
file content (32 lines) | stat: -rw-r--r-- 1,316 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
From: Michael R. Crusoe <michael.crusoe@gmail.com>
Subject: fix error for 32bit systems
--- a/lib/bx/interval_index_file.py
+++ b/lib/bx/interval_index_file.py
@@ -123,7 +123,7 @@ for i in range(BIN_LEVELS - 2):
     BIN_OFFSETS_MAX.insert(0, (BIN_OFFSETS_MAX[0] << BIN_NEXT_SHIFT))
 # The maximum size for the top bin is actually bigger than the signed integers
 # we use to store positions in the file, so we'll change it to prevent confusion
-BIN_OFFSETS_MAX[0] = sys.maxsize
+BIN_OFFSETS_MAX[0] = 2**63
 
 # Constants for the minimum and maximum size of the overall interval
 MIN = 0
@@ -136,12 +136,14 @@ def offsets_for_max_size(max_size):
     """
     Return the subset of offsets needed to contain intervals over (0,max_size)
     """
-    for i, max in enumerate(reversed(BIN_OFFSETS_MAX)):
-        if max_size < max:
+    offset_index = None
+    for i, off_max in enumerate(reversed(BIN_OFFSETS_MAX)):
+        if max_size <= off_max:
+            offset_index = i
             break
-    else:
+    if offset_index is None:
         raise Exception("%d is larger than the maximum possible size (%d)" % (max_size, BIN_OFFSETS_MAX[0]))
-    return BIN_OFFSETS[(len(BIN_OFFSETS) - i - 1) :]
+    return BIN_OFFSETS[(len(BIN_OFFSETS) - offset_index - 1):]
 
 
 def bin_for_range(start, end, offsets=None):