aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2023-01-18 16:58:07 +0000
committerArun Isaac2023-01-18 16:58:07 +0000
commit411526a3d6fb3f52e9f2aca0eb394fefc6f53ead (patch)
treeda12c70e9e613690f94568bdfd099ccd5d322841
parent4cc328ef78c7b8108d7623fdd4fcae5294317f2e (diff)
downloadgenenetwork3-411526a3d6fb3f52e9f2aca0eb394fefc6f53ead.tar.gz
Pass species and species prefix as a single query argument.
* gn3/api/search.py (parse_location_field): Accept a single species query argument instead of separate species and species prefix arguments. (parse_query): Pass parse_location_field a single species query argument.
-rw-r--r--gn3/api/search.py15
1 files changed, 6 insertions, 9 deletions
diff --git a/gn3/api/search.py b/gn3/api/search.py
index 3cdee67..7f7a4ff 100644
--- a/gn3/api/search.py
+++ b/gn3/api/search.py
@@ -153,7 +153,7 @@ def apply_si_suffix(location: str) -> int:
return int(float(location[:-1])*10**suffixes.get(location[-1].lower(), 0))
-def parse_location_field(lifted_species: str, species_prefix: str, # pylint: disable=[too-many-arguments]
+def parse_location_field(species_query: xapian.Query,
chromosome_prefix: str, location_slot: int,
liftover_function: IntervalLiftoverFunction,
query: bytes) -> xapian.Query:
@@ -171,11 +171,11 @@ def parse_location_field(lifted_species: str, species_prefix: str, # pylint: dis
*[location.map(apply_si_suffix)
for location in parse_range(location)])
- def make_query(species: str, interval: ChromosomalInterval) -> xapian.Query:
+ def make_query(interval: ChromosomalInterval) -> xapian.Query:
# TODO: Convert the xapian index to use bases instead of megabases.
to_megabases = lambda x: str(float(x)/1e6)
return combine_queries(xapian.Query.OP_AND,
- xapian.Query(species_prefix + species),
+ species_query,
xapian.Query(chromosome_prefix + interval.chromosome),
xapian.NumberRangeProcessor(location_slot)
(interval.start.maybe("", to_megabases),
@@ -186,8 +186,7 @@ def parse_location_field(lifted_species: str, species_prefix: str, # pylint: dis
except ValueError:
return xapian.Query(xapian.Query.OP_INVALID)
return (liftover_function(interval)
- .maybe(xapian.Query.MatchNothing,
- partial(make_query, lifted_species)))
+ .maybe(xapian.Query.MatchNothing, make_query))
def parse_synteny_field(synteny_prefix: str, query: bytes) -> xapian.Query:
@@ -265,8 +264,7 @@ def parse_query(synteny_files_directory: Path, query: str):
"Mm": "mouse"}
for shorthand, species in species_shorthands.items():
field_processors = [partial(parse_location_field,
- species,
- species_prefix,
+ xapian.Query(species_prefix + species),
chromosome_prefix,
range_prefixes.index("mb"),
Just)]
@@ -280,8 +278,7 @@ def parse_query(synteny_files_directory: Path, query: str):
for lifted_species, chain_file in chain_files.items():
field_processors.append(
partial(parse_location_field,
- lifted_species,
- species_prefix,
+ xapian.Query(species_prefix + lifted_species),
chromosome_prefix,
range_prefixes.index("mb"),
partial(liftover_interval,