Repository: Clinical-Genomics/scout

Issue:
SV frequency filter
- [x] add filter boxes for filter frequencies of interest (e.g. ClinGen NGI, array, SweGen)
- [x] clinical filter settings update for structural variants
- [x] clickable coordinates for start end of structural variant to enable view the edges of large variants


Discussion:

Patch:
diff --git a/scout/adapter/mongo/query.py b/scout/adapter/mongo/query.py
index 3ec4fe991..914733acc 100644
--- a/scout/adapter/mongo/query.py
+++ b/scout/adapter/mongo/query.py
@@ -12,6 +12,7 @@ class QueryHandler(object):
                 'genetic_models': list,
                 'thousand_genomes_frequency': float,
                 'exac_frequency': float,
+                'clingen_ngi': int,
                 'cadd_score': float,
                 'cadd_inclusive": boolean,
                 'genetic_models': list(str),
@@ -24,6 +25,7 @@ class QueryHandler(object):
                 'chrom': str,
                 'start': int,
                 'end': int,
+                'svtype': list,
                 'gene_panels': list(str),
             }
 
@@ -144,6 +146,14 @@ class QueryHandler(object):
                 ]
             })
 
+        if query.get('clingen_ngi') is not None:
+            mongo_query_minor.append({
+                '$or': [
+                    {'clingen_ngi': {'$exists': False}},
+                    {'clingen_ngi': {'$lt': query['clingen_ngi'] + 1}},
+                ]
+            })
+
         if query.get('cadd_score') is not None:
             cadd = query['cadd_score']
             cadd_query = {'cadd_score': {'$gt': float(cadd)}}
diff --git a/scout/server/blueprints/variants/forms.py b/scout/server/blueprints/variants/forms.py
index bab4716d7..407cbe9d7 100644
--- a/scout/server/blueprints/variants/forms.py
+++ b/scout/server/blueprints/variants/forms.py
@@ -90,3 +90,4 @@ class SvFiltersForm(FlaskForm):
     svtype = SelectMultipleField('SVType', choices=SV_TYPE_CHOICES)
 
     thousand_genomes_frequency = BetterDecimalField('1000 Genomes', places=2)
+    clingen_ngi = IntegerField('ClinGen NGI obs')
diff --git a/scout/server/blueprints/variants/templates/variants/sv-variant.html b/scout/server/blueprints/variants/templates/variants/sv-variant.html
index e4e54740a..249c9cb4b 100644
--- a/scout/server/blueprints/variants/templates/variants/sv-variant.html
+++ b/scout/server/blueprints/variants/templates/variants/sv-variant.html
@@ -93,8 +93,11 @@
           Position
           <div class="pull-right">
             <a class="md-label" href="{{ url_for('pileup.viewer', bam=case.bam_files, bai=case.bai_files, sample=case.sample_names, contig=variant.chromosome, start=(variant.position - 50), stop=(variant.end + 50), vcf=case.vcf_files.vcf_sv) }}" target="_blank">
-              Alignment: {{ variant.chromosome }}:{{ variant.position }}-{{ variant.end }}
-            </a>
+              Alignment: {{ variant.chromosome }}
+            </a>:
+            <a class="md-label" href="{{ url_for('pileup.viewer', bam=case.bam_files, bai=case.bai_files, sample=case.sample_names, contig=variant.chromosome, start=(variant.position - 500), stop=(variant.position + 500), vcf=case.vcf_files.vcf_sv) }}" target="_blank">
+{{ variant.position }}</a> -
+            <a class="md-label" href="{{ url_for('pileup.viewer', bam=case.bam_files, bai=case.bai_files, sample=case.sample_names, contig=variant.chromosome, start=(variant.end - 500), stop=(variant.end + 500), vcf=case.vcf_files.vcf_sv) }}" target="_blank">{{ variant.end }}</a>
           </div>
         </li>
 	      <li class="list-group-item">
diff --git a/scout/server/blueprints/variants/templates/variants/sv-variants.html b/scout/server/blueprints/variants/templates/variants/sv-variants.html
index 4a20b3618..5c4674b10 100644
--- a/scout/server/blueprints/variants/templates/variants/sv-variants.html
+++ b/scout/server/blueprints/variants/templates/variants/sv-variants.html
@@ -152,6 +152,8 @@
           {{ form.thousand_genomes_frequency(class="form-control") }}
         </div>
         <div class="col-xs-3">
+	  {{ form.clingen_ngi.label(class="control-label") }}
+	  {{ form.clingen_ngi(class="form-control") }}
         </div>
         <div class="col-xs-3">
           {{ form.svtype.label(class="control-label") }}
@@ -177,6 +179,7 @@
                           functional_annotations=severe_so_terms,
                           region_annotations=['exonic', 'splicing'],
                           thousand_genomes_frequency=institute.frequency_cutoff,
+			  clingen_ngi=15,
 			  size=100,
                           gene_panels=form.data.get('gene_panels')) }}"
                  class="btn btn-default form-control">
@@ -258,7 +261,11 @@
         <div>{{ annotation }}</div>
       {% endfor %}
     </td>
-    <td>{{ variant.thousand_genomes_frequency|human_decimal if variant.thousand_genomes_frequency }}</td>
+    <td>
+      {% if variant.thousand_genomes_frequency %}
+        {{ variant.thousand_genomes_frequency|human_decimal }}
+      {% endif %}
+    </td>
     <td>
       <div class="flex">
         <div>


Test patch:
diff --git a/tests/adapter/test_query.py b/tests/adapter/test_query.py
index d6c424276..bad5131af 100644
--- a/tests/adapter/test_query.py
+++ b/tests/adapter/test_query.py
@@ -195,6 +195,22 @@ def test_build_chrom(adapter):
 
     assert mongo_query['chromosome'] == chrom
 
+
+def test_build_ngi_sv(adapter):
+    case_id = 'cust000'
+    count = 1
+    query = {'clingen_ngi': count}
+    
+    mongo_query = adapter.build_query(case_id, query=query)
+    assert  mongo_query['$and'] == [
+        {
+            '$or':[
+                {'clingen_ngi': {'$exists': False}},
+                {'clingen_ngi': {'$lt': query['clingen_ngi'] + 1}}
+            ]
+        }
+    ]
+
 def test_build_range(adapter):
     case_id = 'cust000'
     chrom = '1'