Skip to content

Commit

Permalink
redirecting region search to data services
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Assis committed Jul 8, 2021
1 parent cee7c01 commit 8e22a5c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
18 changes: 18 additions & 0 deletions src/encoded/genomic_data_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
]
RNA_GET_EXPRESSIONS = '/expressions/bytes'
RNA_GET_AUTOCOMPLETE = '/autocomplete'
REGION_SEARCH = '/region-search'

# react component orders columns by "the position" in the hash map
RNA_GET_COLUMNS = {
Expand Down Expand Up @@ -262,3 +263,20 @@ def rna_get(self):
}

return response


def region_search(self, assembly, chromosome, start, end):
params = {
'assembly': assembly,
'chr': chromosome.replace('chr', ''),
'start': start,
'end': end
}

query_params = '&'.join([f'{k}={params[k]}' for k in params.keys()])

url = f'{self.path}{REGION_SEARCH}?{query_params}'

results = requests.get(url, timeout=3).json()

return results
27 changes: 12 additions & 15 deletions src/encoded/region_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import requests
from urllib.parse import urlencode

from encoded.genomic_data_service import GenomicDataService

import logging
import re

Expand Down Expand Up @@ -253,6 +255,9 @@ def region_search(context, request):
"""
Search files by region.
"""

data_service = GenomicDataService(context.registry, request)

types = request.registry[TYPES]
result = {
'@id': '/region-search/' + ('?' + request.query_string.split('&referrer')[0] if request.query_string else ''),
Expand Down Expand Up @@ -314,25 +319,17 @@ def region_search(context, request):
chr=chromosome, start=start, end=end
)

# Search for peaks for the coordinates we got
try:
# including inner hits is very slow
# figure out how to distinguish browser requests from .embed method requests
if 'peak_metadata' in request.query_string:
peak_query = get_peak_query(start, end, with_inner_hits=True, within_peaks=region_inside_peak_status)
else:
peak_query = get_peak_query(start, end, within_peaks=region_inside_peak_status)
peak_results = snp_es.search(body=peak_query,
index=chromosome.lower(),
doc_type=_GENOME_TO_ALIAS[assembly],
size=99999)
peak_results = data_service.region_search(_GENOME_TO_ALIAS[assembly], chromosome.lower(), start, end)
except Exception:
result['notification'] = 'Error during search'
return result

file_uuids = []
for hit in peak_results['hits']['hits']:
if hit['_id'] not in file_uuids:
file_uuids.append(hit['_id'])
for hit in peak_results['regions']:
region_uuid = hit['file_url'].split('/')[-1]
if region_uuid not in file_uuids:
file_uuids.append(region_uuid)
file_uuids = list(set(file_uuids))
result['notification'] = 'No results found'

Expand Down Expand Up @@ -363,7 +360,7 @@ def region_search(context, request):
result['@graph'] = list(format_results(request, es_results['hits']['hits']))
result['total'] = total = es_results['hits']['total']
result['facets'] = format_facets(es_results, _FACETS, used_filters, schemas, total, principals)
result['peaks'] = list(peak_results['hits']['hits'])
result['peaks'] = list(peak_results['regions'])
result['download_elements'] = get_peak_metadata_links(request)
if result['total'] > 0:
result['notification'] = 'Success'
Expand Down

0 comments on commit 8e22a5c

Please sign in to comment.