
{% macro disease_associated(variant) %}
  <div class="card panel-default">
    <div class="panel-heading" data-toggle='tooltip' title="Transcripts described as disease associated in the case default gene panels">Disease associated transcripts</div>
    <div class=card-body>
      <table class="table table-bordered table-hover table-sm">
        <tr>
          <td>
          {% set ns = namespace(gene='') %}
          {% for transcript in variant.disease_associated_transcripts %}
            {% set ns.gene = transcript.split(":")[0] != ns.gene %} <!-- is this a different gene? -->
            {% if ns.gene and loop.index > 1%}<!--new line-->
              <br><strong>{{transcript.split(":")[0]}}:</strong> &nbsp;<!--print gene -->
            {% elif ns.gene %} <!--first gene-->
              <strong>{{transcript.split(":")[0]}}:</strong> &nbsp;
            {% endif %}
            {{transcript.split(":")[1]}} &nbsp;<!-- print transcript-->
            {% set ns.gene = transcript.split(":")[0] %}
          {% else %}
            -
          {% endfor %}
          </td>
      </tr>
    </table>
  </div>
  </div>
{% endmacro %}

{% macro transcripts_overview(variant) %}
  <div class="card panel-default">
    <div data-toggle='tooltip' class="panel-heading" title="Displays all transcripts with RefSeq id. The complete list of transcripts is available below. One ensembl transcript can have multiple RefSeq ids. Blue color indicates that the ensembl transcript is mapped to a transcript that is primary according to HGNC">
      RefSeq transcripts</div>
    <div class=card-body>
      <table id="transcript_overview_table" class="table table-bordered table-hover table-sm">
        <thead class="thead-light">
          <tr>
            <th>Gene</th>
            <th>Refseq IDs</th>
            <th>ID</th>
            <th>HGVS Description</th>
            <th>Links</th>
          </tr>
        </thead>
        <tbody>
          {% for gene in variant.genes %}
            {% for transcript in gene.transcripts %}
              {% if "refseq_identifiers" in transcript or transcript.is_canonical %}
                <tr {% if transcript.is_primary %} class="bg-info-light" {% endif %}>
                  <td class="d-flex justify-content-between align-items-center"> <!-- gene symbol col-->
                    <a href="{{ url_for('genes.gene', hgnc_id=gene.hgnc_id) }}">
                      {{ gene.common.hgnc_symbol if gene.common else gene.hgnc_id }}
                    </a>
                  </td> <!-- end of gene symbol col-->
                  <td>
                    {% set decorated_txs = [] %}
                    {% for tx_id in transcript.refseq_identifiers %}
                      {% if tx_id.startswith('XM') and transcript.refseq_id != tx_id %} <!-- tx of minor importance -->
                        {% set decorated_tx = '<font class="text-muted font-italic">' + tx_id + '</font>' %}
                      {% else %}
                        {% set decorated_tx = tx_id %} <!-- tx with refseq ID -->
                      {% endif %}
                      {{ decorated_txs.append(decorated_tx)|default("", true) }}
                    {% endfor %}
                    {% if transcript.transcript_id.startswith('NM') and not decorated_txs %} <!-- VEP RefSeq annotation, use tx id as refseq ID -->
                      {{ decorated_txs.append(transcript.transcript_id)|default("", true) }}
                    {% endif %}
                    {{ decorated_txs|join(", ")|safe or '<font class="text-muted font-italic">Check complete list of transcripts</font>'|safe }}
                  </td> <!-- Refseq IDs -->
                  <td class="d-flex align-items-center">
                    <div> <!-- ID col-->
                      <span class="text"> {{ transcript.transcript_id }}</span>
                      {% if gene.common and transcript.refseq_id in gene.common.primary_transcripts %}
                        <a href="#" data-toggle="tooltip" title="hgnc primary"><span class="badge badge-primary" title="hgnc primary">P</span></a>
                      {% endif %}
                      {% if transcript.mane_select_transcript %}
                          <a href="#" data-toggle="tooltip" title="MANE Select"><span class="badge badge-success" title="MANE Select">M</span></a>
                      {% endif %}
                      {% if transcript.mane_plus_clinical_transcript %}
                          <a href="#" data-toggle="tooltip" title="MANE Plus Clinical"><span class="badge badge-success" title="MANE Plus Clinical">M+</span></a>
                      {% endif %}
                      {% if transcript.is_canonical %}
                        <a href="#" data-toggle="tooltip" title="vep canonical"><span class="badge badge-info" title="vep canonical">C</span></a>
                      {% endif %}
                    </div>
                  </td> <!-- end of ID col-->
                  <td title="{{ transcript.coding_sequence_name or '' }}"> <!-- >HGVS Description col -->
                    {{ (transcript.coding_sequence_name or '')|truncate(20, True) }}
                    <span class="text-muted float-right">
                      {{ (transcript.protein_sequence_name or '')|url_decode }}
                    </span>
                  </td>  <!-- end of HGVS Description col -->
                  <td class="text-center"> <!-- Links col -->
                    {% if transcript.varsome_link %}
                      <a href="{{ transcript.varsome_link }}" class="badge badge-secondary text-white" target="_blank"
                        data-toggle="tooltip" title="Varsome">V</a>
                    {% endif %}
                    {% if transcript.tp53_link %}
                      <a href="{{ transcript.tp53_link }}" class="badge badge-secondary text-white" target="_blank"
                        data-toggle="tooltip" title="MutanTP53">TP53</a>
                    {% endif %}
                    {% if transcript.cbioportal_link %}
                      <a href="{{ transcript.cbioportal_link }}" class="badge badge-secondary text-white" target="_blank"
                        data-toggle="tooltip" title="cBioPortal">CBP</a>
                    {% endif %}
                    {% if transcript.mycancergenome_link %}
                      <a href="{{ transcript.mycancergenome_link }}" class="badge badge-secondary text-white" target="_blank"
                        data-toggle="tooltip" title="MyCancerGenome">MCG</a>
                    {% endif %}
                  </td> <!-- end of Links col -->
                </tr>
              {% endif %} <!-- end of { if "refseq_identifiers" in  transcript } -->
            {% endfor %} <!-- end of { for transcript in gene.transcripts } loop -->
          {% endfor %} <!--end of { for gene in variant.genes } loop -->
        </tbody>
      </table>
    </div> <!-- end of card-body -->
  </div> <!-- end of card div -->
{% endmacro %}
