From faba68fbfa096117d09d54928b1d55a2a676a60e Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Wed, 18 Jan 2023 17:16:08 +0000 Subject: search: Convert point locations to a +/- 50 kbase range. * gn3/api/search.py (parse_location_field): Convert point locations to a +/- 50 kbase range. --- gn3/api/search.py | 14 ++++++++++---- 1 file 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. -- cgit v1.2.3