Skip to content

Commit

Permalink
remove ability to not define the entire region; avoid exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
talavis committed Mar 27, 2019
1 parent 4edde8d commit b517459
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 30 deletions.
24 changes: 5 additions & 19 deletions backend/modules/browser/browser_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,28 +126,15 @@ def get(self, dataset:str, region:str, ds_version:str=None):
Returns:
dict: information about the region and the genes found there
"""
region = region.split('-')

chrom = region[0]
start = None
stop = None

try:
if len(region) > 1:
start = int(region[1])
if len(region) > 2:
stop = int(region[2])

chrom, start, stop = region.split('-')
start = int(start)
stop = int(stop)
except ValueError:
logging.error('GetRegion: unable to parse region ({})'.format(region))
self.send_error(status_code=400)
self.set_user_msg('Unable to parse region', 'error')
self.send_error(status_code=400, reason='Unable to parse region')
return

if not start:
start = 0
if not stop:
stop = start
ret = {'region':{'chrom': chrom,
'start': start,
'stop': stop,
Expand Down Expand Up @@ -245,8 +232,7 @@ def get(self, dataset:str, variant:str, ds_version:str=None):

if not variant:
logging.error('Variant not found ({})'.format(orig_variant))
self.send_error(status_code=404)
self.set_user_msg('Variant not found', 'error')
self.send_error(status_code=404, reason='Variant not found')
return

# Just get the information we need
Expand Down
10 changes: 0 additions & 10 deletions backend/modules/browser/tests/test_browser_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,6 @@ def test_get_region():
'geneName': 'PPARA'}]}}
assert region == expected

region_def = '22'
response = requests.get('{}/api/datasets/{}/browser/region/{}'.format(BASE_URL, dataset, region_def))
region = json.loads(response.text)
assert region == {'region': {'chrom': '22', 'start': 0, 'stop': 20}}

region_def = '22-1000'
response = requests.get('{}/api/datasets/{}/browser/region/{}'.format(BASE_URL, dataset, region_def))
region = json.loads(response.text)
assert region == {'region': {'chrom': '22', 'start': 980, 'stop': 1020}}

region_def = '22-16364870-16366200'
response = requests.get('{}/api/datasets/{}/browser/region/{}'.format(BASE_URL, dataset, region_def))
region = json.loads(response.text)
Expand Down
9 changes: 8 additions & 1 deletion backend/modules/browser/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,14 @@ def get_variant_list(dataset:str, datatype:str, item:str, ds_version:str=None):
if datatype == 'gene':
variants = lookups.get_variants_in_gene(dataset, item, ds_version)
elif datatype == 'region':
chrom, start, stop = item.split('-')
try:
chrom, start, stop = item.split('-')
start = int(start)
stop = int(stop)
except ValueError:
self.send_error(status_code=400, reason='Unable to parse region')
return

if is_region_too_large(start, stop):
return {'variants': [], 'headers': [], 'region_too_large': True}
variants = lookups.get_variants_in_region(dataset, chrom, start, stop, ds_version)
Expand Down

0 comments on commit b517459

Please sign in to comment.