broadinstitute / seqr

web-based analysis tool for rare disease genomics
GNU Affero General Public License v3.0
176 stars 88 forks source link

KeyError: 'gene_consequences' #1376

Closed NLSVTN closed 4 years ago

NLSVTN commented 4 years ago

Describe the bug When we do variants search selecting Inheritance as 'Compound Heterozygous' and Pathogenicity as 'Clinvar -> Likely Benign' (for instance) then it crashes on the following line:

https://github.com/macarthur-lab/seqr/blob/2d0d81bedd199d0adcca812300a64306351d4cae/seqr/utils/elasticsearch/es_search.py#L740

Here is stack trace:

2020-07-16 15:53:29,678 ERROR:  Traceback (most recent call last):
  File "/seqr/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/seqr/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 23, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/seqr/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/seqr/views/apis/variant_search_api.py", line 75, in query_variants_handler
    variants, total_results = get_es_variants(results_model, sort=sort, page=page, num_results=per_page)
  File "/seqr/utils/elasticsearch/utils.py", line 126, in get_es_variants
    variant_results = es_search.search(**search_kwargs)
  File "/seqr/utils/elasticsearch/es_search.py", line 373, in search
    return self._execute_single_search(**search_kwargs)
  File "seqr/utils/elasticsearch/es_search.py", line 412, in _execute_single_search
    parsed_response = self._parse_response(response)
  File "/seqr/utils/elasticsearch/es_search.py", line 506, in _parse_response
    response_hits, response_total = self._parse_compound_het_response(response)
  File "/seqr/utils/elasticsearch/es_search.py", line 681, in _parse_compound_het_response
    self._filter_invalid_family_compound_hets(gene_id, family_compound_het_pairs, family_unaffected_individual_guids)
  File "/seqr/utils/elasticsearch/es_search.py", line 740, in _filter_invalid_family_compound_hets
    variant['gene_consequences'].get(gene_id, []) for variant in variants
KeyError: u'gene_consequences'

Screenshots

Screen Shot 2020-07-16 at 11 43 52 AM
NLSVTN commented 4 years ago

No Annotations were selected and that's the issue. No 'gene consequences' are added on the line:

https://github.com/macarthur-lab/seqr/blob/2d0d81bedd199d0adcca812300a64306351d4cae/seqr/utils/elasticsearch/es_search.py#L657

And then the code is trying to access it and it crashes it. Maybe need to add a better error handling here, provide user with the message that he needs to add Annotations.

hanars commented 4 years ago

Yes this appears to be a bug for compound het search with no annotation filtering, which should be handled better so I will fix it. However, this search is trying to find compound heterozygous variants where both hits are in clinvar as likely benign. I think it is very unlikely that that is what you were actually trying to search for. As a workaround until this is fixed, if you aren't really trying to restrict yourself ONLY to clinvar benign variants and instead are interested in variants with any predicted consequence, just select all the annotations instead of selecting none of them

hanars commented 4 years ago

This is fixed now, although I don't really recommend looking for compound hets with so little filtering