{% extends "layouts/base.html" %}
{% from "macros/links.html" import omim_links %}
{% from "macros/gt_calls.html" import gt_call %}
{% from "macros/compounds.html" import compounds_table %}
{% from "macros/transcripts.html" import vep_transcripts %}
{% from "macros/genes.html" import gene_table %}
{% import "macros/comments.html" as comments_mod %}


{% block nav_left %}
  <li>
    <a href="{{ url_for('public.case', case_id=case_id) }}">{{ case_id }}</a>
  </li>

  <li>
    <a href="{{ url_for('variants.variants', case_id=case_id) }}">Variants</a>
  </li>
{% endblock %}

{% block container %}
  {# Overview #}
  <div class="row">
    <div class="col-md-6">
      <ul class="list-group">
        <li class="list-group-item">
          <span class="badge">{{ variant.index }}</span>
          Ranking
        </li>

        {% if variant.rank_score %}
          <li class="list-group-item">
            <span class="badge">{{ variant.rank_score }}</span>
            Rank score
          </li>
        {% endif %}

        {% if variant.cadd_score %}
          <li class="list-group-item">
            <span class="badge">
              {{ variant.cadd_score }}
            </span>
            CADD score
          </li>
        {% endif %}

        {% if variant.most_severe_consequence %}
          <li class="list-group-item">
            <span class="badge">{{ variant.most_severe_consequence }}</span>
            Most severe consequence
          </li>
        {% endif %}
      </ul>
    </div>

    <div class="col-md-6">

      <ul class="list-group">
        <li class="list-group-item">
          {% set variant_id = variant.variant_id|string %}
          {% if variant_id in case.suspect_dict %}
            <form action="{{ url_for('variants.delete_suspect', suspect_id=case.suspect_dict[variant_id].id) }}" method="POST">
              <button type="submit" class="btn btn-default btn-sm">
                Remove as suspect
              </button>
            </form>
          {% else %}
            <form action="{{ url_for('variants.suspects', case_id=case_id, variant_id=variant.variant_id) }}" method="POST">
              <button type="submit" class="btn btn-default btn-sm">
                Pin as suspect
              </button>
            </form>
          {% endif %}
        </li>

        <li class="list-group-item">
          Position
          <div class="pull-right">
            <a href=http://localhost:60151/goto?locus={{ variant.CHROM }}:{{ variant.POS }}>
              {{ variant.CHROM }}:{{ variant.POS }}
            </a>
            | {{ variant.REF }}
            <span class="glyphicon glyphicon-arrow-right"></span>
            {{ variant.ALT }}
          </div>
        </li>

        {% if variant.genes %}
          <li class="list-group-item overflow-auto">
            Genes (OMIM)
            <div class="pull-right">{{ omim_links(variant.genes) }}</div>
          </li>
        {% endif %}
      </ul>
    </div>
  </div>

  {# Genotype and frequency #}
  <div class="row">
    <div class="col-md-3">
      <div class="panel panel-default">
        <div class="panel-heading">Frequencies</div>

        <ul class="list-group">
          {% for frequency in variant.frequencies %}
            <li class="list-group-item">
              <span class="badge">
                {% if frequency.value %}
                  {{ frequency.value|round(4) }}
                {% else %}
                  —
                {% endif %}
              </span>
              {{ frequency.label }}
            </li>
          {% else %}
            <li class="list-group-item">No frequencies.</li>
          {% endfor %}
        </ul>
      </div>
    </div>

    <div class="col-md-6">{{ gt_call(case_id, variant.individuals) }}</div>

    <div class="col-md-3">
      <div class="panel panel-default">
        <div class="panel-heading">Inheritance models</div>
        <ul class="list-group">
          {% for model in variant.genetic_models %}
            <li class="list-group-item">
              {{ model }}
            </li>
          {% else %}
            <li class="list-group-item">N/A</li>
          {% endfor %}
        </ul>
      </div>
    </div>
  </div>

  {# External links #}
  <div class="row">
    <div class="col-md-6">
      <div class="panel panel-default">
        <div class="panel-heading">External links</div>
        <div class="panel-body">
          <div class="btn-group" role="group">
            <a class="btn btn-default" href="http://grch37.ensembl.org/Homo_sapiens/Location/View?db=core;r={{ variant.CHROM }}:{{ variant.start }}-{{ variant.stop }}" target="_blank">Ensembl</a>

            <a class="btn btn-default" href="http://genome.ucsc.edu/cgi-bin/hgTracks?db=hg19&position=chr{{ variant.CHROM }}:{{ variant.start }}-{{ variant.stop }}&dgv=pack&knownGene=pack&omimGene=pack" target="_blank">UCSC</a>

            <a class="btn btn-default" href="https://www.solvebio.com/variant/GRCh37-chr{{ variant.CHROM }}-{{ variant.start }}-{{ variant.stop }}-{{ variant.ALT }}" target="_blank">SolveBio</a>

            {% if variant.ID %}
              <a class="btn btn-default" href="http://snpedia.com/index.php/{{ variant.ID }}" target="_blank">SNPedia</a>
            {% endif %}

            <a class="btn btn-default" href="http://tools.genes.toronto.edu/" target="_blank">SPANR</a>
          </div>
        </div>
      </div>
    </div>

    <div class="col-md-6">
      {{ comments_mod.comments(case_id, comments, variant_id=variant.md5) }}
    </div>
  </div>

  {% if variant.genes %}
    <div class="row">
      <div class="col-md-12">{{ gene_table(variant.genes) }}</div>
    </div>
  {% endif %}

  {% if variant.transcripts %}
    <div class="row">
      <div class="col-md-12">{{ vep_transcripts(variant.transcripts) }}</div>
    </div>
  {% endif %}

  {% if variant.compounds %}
  <div class="row">
    <div class="col-md-12">{{ compounds_table(variant.compounds, case_id) }}</div>
  </div>
  {% endif %}
{% endblock %}

{% block js_bottom %}
  {{ super() }}
  <script type="text/javascript" charset="utf-8">
  $(document).ready(function(){
    $('#genes_list').DataTable({
      "paging":   true,
      "pageLength": 30,
      "searching": false,
      "info": false
    });
    $('#transcripts_list').DataTable({
      "paging":   true,
      "pageLength": 30,
      "searching": false,
      "info": false
    });
    $('#compounds_list').DataTable({
      "paging":   true,
      "pageLength": 30,
      "searching": false,
      "info": false
    });
  });
  </script>
{% endblock %}
