about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArun Isaac2023-01-18 17:16:08 +0000
committerArun Isaac2023-01-18 17:52:10 +0000
commitfaba68fbfa096117d09d54928b1d55a2a676a60e (patch)
tree8d0d04e3177d001fe830c38b5f554b7fba3954d6
parent411526a3d6fb3f52e9f2aca0eb394fefc6f53ead (diff)
downloadgenenetwork3-faba68fbfa096117d09d54928b1d55a2a676a60e.tar.gz
search: Convert point locations to a +/- 50 kbase range.
* gn3/api/search.py (parse_location_field): Convert point locations to a +/-
50 kbase range.
-rw-r--r--gn3/api/search.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/gn3/api/search.py b/gn3/api/search.py
index 7f7a4ff..2038a14 100644
--- a/gn3/api/search.py
+++ b/gn3/api/search.py
@@ -164,12 +164,18 @@ def parse_location_field(species_query: xapian.Query,
     """
     def split_query(query: str) -> ChromosomalInterval:
         """Split query into chromosome and location tuple."""
-        chromosome, location = query.lower().split(":")
+        chromosome, location_str = query.lower().split(":")
         if not chromosome.startswith("chr"):
             raise ValueError
-        return ChromosomalInterval(chromosome.removeprefix("chr"),
-                                   *[location.map(apply_si_suffix)
-                                     for location in parse_range(location)])
+        location: tuple[Maybe[int], Maybe[int]]
+        if ".." in location_str:
+            location = tuple(limit.map(apply_si_suffix) for limit in parse_range(location_str))
+        # If point location, assume +/- 50 kbases on either side.
+        else:
+            width = 50*10**3
+            point = apply_si_suffix(location_str)
+            location = Just(point - width), Just(point + width)
+        return ChromosomalInterval(chromosome.removeprefix("chr"), *location)
 
     def make_query(interval: ChromosomalInterval) -> xapian.Query:
         # TODO: Convert the xapian index to use bases instead of megabases.