{% extends "base.html" %}

{% block content %}
  <div class="row">
    <div class="col-lg-6">
      <h3>Sequence Length Statistics</h3>
      <p>
        <a class="btn btn-default" href="descriptive_stats.tsv" target="_blank" rel="noopener noreferrer">
          Download sequence-length statistics as a TSV
        </a>
      </p>
      <table class="table table-striped" id="stats_table">
        <thead>
          <tr>
            <th>Sequence Count</th>
            <th>Min Length</th>
            <th>Max Length</th>
            <th>Mean Length</th>
            <th>Range</th>
            <th>Standard Deviation</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>{{ stats.count }}</td>
            <td>{{ stats.min | int }}</td>
            <td>{{ stats.max | int }}</td>
            <td>{{ stats.mean | round(2, 'common') }}</td>
            <td>{{ stats.range | int }}</td>
            <td>{{ stats.std | round(2, 'common') }}</td>
          </tr>
        </tbody>
      </table>
    </div>
    <div class="col-lg-6">
      <h3>Seven-Number Summary of Sequence Lengths</h3>
      <p>
        <a class="btn btn-default" href="seven_number_summary.tsv" target="_blank" rel="noopener noreferrer">
          Download seven-number summary as a TSV
        </a>
      </p>
      <table class="table table-striped" id="summary_table">
        <thead>
          <tr>
            <th>Percentile:</th>
            {% for percentile in stats.seven_num_summ_percentiles %}
            <th>{{ (percentile*100) | int }}%</th>
            {% endfor %}
          </tr>
        </thead>
        <tbody>
          <tr>
          <td>Length* (nts):</td>
          {% for value in stats.seven_num_summ_values %}
            <td>{{ value | int }}</td>
          {% endfor %}
          </tr>
        </tbody>
      </table>
    </div>
  </div>

  <div class="row">
    <div class="col-lg-6">
    </div>
    <div class="col-lg-6">
      <p>
        *Values rounded down to nearest whole number.
      </p>
    </div>
  </div>

  <div class="row">
    <div class="col-lg-12">
      <h3>Sequence Table</h3>
      <p>
        To BLAST a sequence against the NCBI nt database, click the
        sequence and then click the <i>View report</i>
        button on the resulting page.
      <p>
        <a class="btn btn-default" href="sequences.fasta" target="_blank" rel="noopener noreferrer">
          Download your sequences as a raw FASTA file
        </a>
      </p>
      <p>
        <i>Click on a Column header to sort the table.</i>
      </p>
      <table class="table table-striped table-hover" id="seq_table">
        <thead>
          <tr>
            <th>Feature ID</th>
            <th data-tsorter="numeric">Sequence</th>
            <th data-tsorter="link">Sequence Length</th>
            {% if taxonomy is defined %}
              {% for name in taxonomy.keys() %}
            <th data-tsorter="text">Taxon: {{name}}</th>
              {% endfor %}
            {% endif %}
            {% if metadata is defined %}
              {% for name in metadata.columns %}
            <th data-tsorter="text">{{ name }}</th>
              {% endfor %}
            {% endif %}
          </tr>
        </thead>
        <tbody>
        {% for sequence in display_sequences %}
          <tr>
            <td>{{ sequence }}</td>
            {% if sequence in data %}
            <td><samp><a target="_blank" href="{{ data[sequence].url }}" rel="noopener noreferrer">{{ data[sequence].seq }}</a></samp></td>
            <td>{{ data[sequence].len }}</td>
            {% else %}
            <td>-</td>
            <td>-</td>
            {% endif %}
            {% if taxonomy is defined %}
              {% for member in taxonomy.values() %}
                {% if sequence in member.index %}
            <td>{{ member.loc[sequence, "Taxon"] }}</td>
                {% else %}
            <td>-</td>
                {% endif %}
              {% endfor %}
            {% endif %}
            {% if metadata is defined %}
              {% if sequence in metadata.index %}
                {% for name in metadata.columns %}
            <td>{{ metadata.loc[sequence, name] }}</td>
                {% endfor %}
              {% else %}
                {%for name in metadata.columns %}
            <td>-</td>
                {% endfor %}
              {% endif %}
            {% endif %}
          </tr>
        {% endfor %}
        </tbody>
      </table>
    </div>
  </div>
  <script src="./js/tsorter.min.js" type="text/javascript"></script>
  <script type="text/javascript">
    function init() {
      var sorter = tsorter.create('seq_table');
    }

    window.onload = init;
  </script>
  <style media="screen">
    #seq_table th.descend:after{
      content: "\25B2";
    }
    #seq_table th.ascend:after{
      content: "\25BC";
    }
  </style>
{% endblock %}
