<commit_before>{% extends "base.html" %}
{% block title %}Search Results{% endblock %}
{% block css %}
    <link rel="stylesheet" type="text/css" href="{{ url_for('css', filename='DataTables/css/jquery.dataTables.css') }}" />
    <link rel="stylesheet" type="text/css" href="{{ url_for('css', filename='fontawesome/css/font-awesome.min.css') }}" />
    <link rel="stylesheet" type="text/css" href="{{ url_for('js', filename='DataTablesExtensions/buttonStyles/css/buttons.dataTables.min.css') }}">
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css">
    <link rel="stylesheet" type="text/css" href="/static/new/css/show_trait.css" />
    <link rel="stylesheet" type="text/css" href="static/new/css/trait_list.css" />
{% endblock %}
{% block content %}
<!-- Start of body -->
    <div style="padding-left: 10px;">
        <input type="hidden" name="uc_id" id="uc_id" value="{{ uc_id }}">

        <div style="padding-top: 10px; padding-bottom: 10px; font-size: 16px;">
        <!-- Need to customize text more for other types of searches -->

        <p><b>Search Results:</b> We searched <a href="http://genenetwork.org/webqtl/main.py?FormID=sharinginfo&{% if dataset.accession_id != 'None' %}GN_AccessionId={{ dataset.accession_id }}{% else %}InfoPageName={{ dataset.name }}{% endif %}">{{ dataset.fullname }}</a>
           to find all records
                {% if go_term is not none %}
                with <u>Gene Ontology ID</u> <strong>GO:{{ go_term }}</strong>.
                {% else %}
                {% for word in search_terms %}
                    {% if word.key|lower == "rif" %}
                    with <u>GeneRIF</u> containing <strong>{{ word.search_term[0] }}</strong>{% if loop.last %}.{% else %} and {% endif %}
                    {% elif word.key|lower == "go" %}
                    with <u>Gene Ontology ID</u> <strong>{{ word.search_term[0] }}</strong>{% if loop.last %}.{% else %} and {% endif %}
                    {% elif word.key|lower == "wiki" %}
                    with <u>GeneWiki</u> containing <strong>{{ word.search_term[0] }}</strong>{% if loop.last %}.{% else %} and {% endif %}
                    {% elif word.key|lower == "mean" %}
                    with <u>MEAN</u> between <strong>{{ word.search_term[0] }}</strong> and <strong>{{ word.search_term[1] }}</strong>{% if loop.last %}.{% else %} and {% endif %}
                    {% elif word.key|lower == "range" %}
                    with <u>RANGE</u> between <strong>{{ word.search_term[0] }}</strong> and <strong>{{ word.search_term[1] }}</strong>{% if loop.last %}.{% else %} and {% endif %}
                    {% elif word.key|lower == "lrs" or word.key|lower == "lod" or word.key|lower == "translrs" or word.key|lower == "cislrs" or word.key|lower == "translod" or word.key|lower == "cislod" %}
                    {% if word.search_term|length == 1 %}
                    with {% if word.key|lower == "translrs" %}trans{% elif word.key|lower == "cislrs" %}cis{% endif %}LRS {% if word.separator == ">" %} greater than {% elif word.separator == "<" %} less than {% elif word.separator == ">=" %} greater than or equal to {% elif word.separator == "<=" %} less than or equal to {% endif %} <strong>{{ word.search_term[0] }}</strong>{% if loop.last %}.{% else %} and {% endif %}
                    {% elif word.search_term|length == 2 %}
                    with <u>{{ word.key|upper }}</u> between <strong>{{ word.search_term[0] }}</strong> and <strong>{{ word.search_term[1] }}</strong>{% if loop.last %}.{% else %} and {% endif %}
                    {% elif word.search_term|length == 3 %}
                    with <u>{{ word.key|upper }}</u> between <strong>{{ word.search_term[0] }}</strong> and <strong>{{ word.search_term[1] }}</strong> on chromosome <strong>{{ word.search_term[2] }}</strong>{% if loop.last %}.{% else %} and {% endif %}
                    {% elif word.search_term|length == 5 %}
                    with <u>{{ word.key|upper }}</u> between <strong>{{ word.search_term[0] }}</strong> and <strong>{{ word.search_term[1] }}</strong> on chromosome <strong>{{ word.search_term[2] }}</strong> between <strong>{{ word.search_term[3] }}</strong> and <strong>{{ word.search_term[4] }}</strong> Mb{% if loop.last %}.{% else %} and {% endif %}
                    {% endif %}
                    {% elif word.key|lower == "position" or word.key|lower == "mb" %}
                    with <u>target genes</u> on chromosome <strong>{% if (word.search_term[0]|lower).split('chr')|length > 1 %}{{ (word.search_term[0]|lower).split('chr')[1] }}{% else %}{{ word.search_term[0] }}{% endif %}</strong> between <strong>{{ word.search_term[1] }}</strong> and <strong>{{ word.search_term[2] }}</strong> Mb{% if loop.last %}.{% else %} and {% endif %}
                    {% else %}
                    {% if word.search_term[0] == "*" %} in the dataset.{% else %}{% if loop.first %}that match:<br>{% endif %}<b>{{ word.search_term[0] }}</b>{% if loop.last %}{% else %} and {% endif %}{% endif %}
                    {% endif %}
                {% endfor %}
                {% endif %}
                <br>
                A total of {{ results|count }} records were found.
        </p>

        {% if go_term is not none %}
        <p><b>The associated genes include:</b><br><br>{% for word in search_terms %}{{ word.search_term[0] }}{% endfor %}</p>
        {% endif %}

        <!--<p>To study a record click on its ID below, and to view the whole description {% if dataset.type == "Publish" %}or list of authors {% endif %} hover over the table cell. Check records below and click Add button to add to selection.</p>-->

        <!--<hr style="height: 1px; background-color: #A9A9A9;">-->

        </div>
        {% if too_many_results %}
        <p>Your search generated over 50000 results. Please modify your search to generate 50000 or fewer matches.</p>
        {% else %}
        <div style="min-width: 950px;">
          <form id="trait_submission_form" target="_blank" action="/corr_matrix" method="post">
            <input type="hidden" name="tool_used" value="" />
            <input type="hidden" name="form_url" value="" />
            <input type="hidden" name="trait_list" id="trait_list" value= "
            {% for this_trait in trait_list %}
                {{ this_trait.name }}:{{ this_trait.dataset }},
            {% endfor %}" >

            {% include 'tool_buttons.html' %}

          </form>
        </div>

        <div>
          <br />
          <form id="export_form" method="POST" action="/export_traits_csv" style="display: inline;">
            <div style="min-width: 950px;">
              <input type="hidden" name="headers" id="headers" value="{% for field in header_fields %}{{ field }},{% endfor %}">
              <input type="hidden" name="search_string" id="search_string" value="{{ original_search_string }}">
              <input type="hidden" name="database_name" id="database_name" value="{{ dataset.fullname }}">
              <input type="hidden" name="file_name" id="file_name" value="search_results">
              <input type="hidden" name="filter_term" id="filter_term" value="None">
              {% if dataset.accession_id is defined %}
              <input type="hidden" name="accession_id" id="accession_id" value="{{ dataset.accession_id }}">
              {% endif %}
              <input type="hidden" name="export_data" id="export_data" value="">
              <button class="btn btn-default" id="select_all" type="button"><span class="glyphicon glyphicon-ok"></span> Select</button>
              <button class="btn btn-default" id="invert" type="button"><span class="glyphicon glyphicon-adjust"></span> Invert</button>
              <button class="btn btn-success" id="add" type="button" disabled><span class="glyphicon glyphicon-plus-sign"></span> Add</button>
              <button class="btn btn-default" id="export_traits">Download <span class="glyphicon glyphicon-download"></span></button>
              <input type="text" id="searchbox" class="form-control" style="width: 200px; display: inline;" placeholder="Search This Table For ...">
              <input type="text" id="select_top" class="form-control" style="width: 200px; display: inline;" placeholder="Select Top ...">
              <button class="btn btn-default" id="deselect_all" type="button"><span class="glyphicon glyphicon-remove"></span> Deselect</button>
            </div>
          </form>
          {% if dataset.type != 'Geno' %}
          <div class="show-hide-container">
            <b>Show/Hide Columns:</b>
            <br>
            {% if dataset.type == 'ProbeSet' %}
            <button class="toggle-vis" data-column="3">Symbol</button>
            <button class="toggle-vis" data-column="4">Description</button>
            <button class="toggle-vis" data-column="5">Location</button>
            <button class="toggle-vis" data-column="6">Mean</button>
            <button class="toggle-vis" data-column="7">Peak LOD</button>
            <button class="toggle-vis" data-column="8">Peak Location</button>
            <button class="toggle-vis" data-column="9">Effect Size</button>
            {% elif dataset.type == 'Publish' %}
            <button class="toggle-vis" data-column="3">Description</button>
            <button class="toggle-vis" data-column="4">Mean</button>
            <button class="toggle-vis" data-column="5">Authors</button>
            <button class="toggle-vis" data-column="6">Year</button>
            <button class="toggle-vis" data-column="7">Peak LOD</button>
            <button class="toggle-vis" data-column="8">Peak Location</button>
            <button class="toggle-vis" data-column="9">Effect Size</button>
            {% endif %}
          </div>
          {% endif %}
          <div id="table_container" {% if dataset.type == 'ProbeSet' or dataset.type == 'Publish' %}style="min-width: 1500px; max-width:100%;"{% endif %}>
            <table class="table-hover table-striped cell-border" id='trait_table' style="float: left; width: {% if dataset.type == 'Geno' %}380px{% else %}100%{% endif %};">
                <tbody>
                 <td colspan="100%" align="center"><br><b><font size="15">Loading...</font></b><br></td>
                </tbody>
            </table>
          </div>
        </div>
        {% endif %}
    </div>

    <div id="myModal"></div>

<!-- End of body -->

{% endblock %}

{% block js %}
    <script language="javascript" type="text/javascript" src="{{ url_for('js', filename='js_alt/md5.min.js') }}"></script>

    <script language="javascript" type="text/javascript" src="{{ url_for('js', filename='DataTables/js/jquery.dataTables.min.js') }}"></script>
    <script language="javascript" type="text/javascript" src="{{ url_for('js', filename='DataTablesExtensions/scroller/js/dataTables.scroller.min.js') }}"></script>
    <script language="javascript" type="text/javascript" src="{{ url_for('js', filename='jszip/jszip.min.js') }}"></script>
    <script language="javascript" type="text/javascript" src="{{ url_for('js', filename='DataTablesExtensions/plugins/sorting/natural.js') }}"></script>
    <script language="javascript" type="text/javascript" src="{{ url_for('js', filename='DataTablesExtensions/buttons/js/dataTables.buttons.min.js') }}"></script>
    <script language="javascript" type="text/javascript" src="{{ url_for('js', filename='DataTablesExtensions/buttons/js/buttons.colVis.min.js') }}"></script>
    <script language="javascript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/js/all.min.js"></script>

    <script language="javascript" type="text/javascript" src="/static/new/javascript/search_results.js"></script>

    <script type='text/javascript'>
        var trait_list = {{ trait_list|safe }};
    </script>

    <script type="text/javascript" charset="utf-8">
        $(document).ready( function () {

            var getParams = function(url) {
                let parser = document.createElement('a');
                parser.href = url;
                let params = parser.search.substring(1);
                if(params.length > 0) {
                    return ('?'+params);
                }
                return params;
            };
            
            $('#trait_table tr').click(function(event) {
                if (event.target.type !== 'checkbox') {
                    $(':checkbox', this).trigger('click');
                }
            });

            //ZS: Need to make sort by symbol, also need to make sure blank symbol fields at the bottom and symbols starting with numbers below letters
            trait_table = $('#trait_table').DataTable( {
                'drawCallback': function( settings ) {
                      $('#trait_table tr').off().on("click", function(event) {
                        if (event.target.type !== 'checkbox' && event.target.tagName.toLowerCase() !== 'a') {
                          var obj =$(this).find('input');
                          obj.prop('checked', !obj.is(':checked'));
                        }
                        if ($(this).hasClass("selected")){
                          $(this).removeClass("selected")
                        } else {
                          $(this).addClass("selected")
                        }
                        change_buttons()
                      });
                },
                'createdRow': function ( row, data, index ) {
                    $('td', row).eq(0).attr("style", "text-align: center; padding: 0px 10px 2px 10px;");
                    $('td', row).eq(1).attr("align", "right");
                    $('td', row).eq(1).attr('data-export', index+1);
                    $('td', row).eq(2).attr('data-export', $('td', row).eq(2).text());
                    {% if dataset.type == 'ProbeSet' %}
                    $('td', row).eq(3).attr('title', $('td', row).eq(3).text());
                    $('td', row).eq(3).attr('data-export', $('td', row).eq(3).text());
                    if ($('td', row).eq(3).text().length > 20) {
                        $('td', row).eq(3).text($('td', row).eq(3).text().substring(0, 20));
                        $('td', row).eq(3).text($('td', row).eq(3).text() + '...')
                    }
                    $('td', row).eq(4).attr('title', $('td', row).eq(4).text());
                    $('td', row).eq(4).attr('data-export', $('td', row).eq(4).text());
                    $('td', row).slice(5,10).attr("align", "right");
                    $('td', row).eq(5).attr('data-export', $('td', row).eq(5).text());
                    $('td', row).eq(6).attr('data-export', $('td', row).eq(6).text());
                    $('td', row).eq(7).attr('data-export', $('td', row).eq(7).text());
                    $('td', row).eq(8).attr('data-export', $('td', row).eq(8).text());
                    $('td', row).eq(9).attr('data-export', $('td', row).eq(9).text());
                    {% elif dataset.type == 'Publish' %}
                    $('td', row).eq(3).attr('title', $('td', row).eq(3).text());
                    $('td', row).eq(3).attr('data-export', $('td', row).eq(3).text());
                    $('td', row).eq(4).attr('title', $('td', row).eq(4).text());
                    $('td', row).eq(4).attr('data-export', $('td', row).eq(4).text());
                    $('td', row).eq(4).attr('align', 'right');
                    $('td', row).slice(6,10).attr("align", "right");
                    $('td', row).eq(5).attr('data-export', $('td', row).eq(5).text());
                    $('td', row).eq(6).attr('data-export', $('td', row).eq(6).text());
                    $('td', row).eq(7).attr('data-export', $('td', row).eq(7).text());
                    $('td', row).eq(8).attr('data-export', $('td', row).eq(8).text());
                    $('td', row).eq(9).attr('data-export', $('td', row).eq(8).text());
                    {% elif dataset.type == 'Geno' %}
                    $('td', row).eq(3).attr('data-export', $('td', row).eq(3).text());
                    {% endif %}
                },
                'data': trait_list,
                'columns': [
                    {
                      'data': null,
                      'width': "25px",
                      'orderDataType': "dom-checkbox",
                      'orderable': false,
                      'render': function(data, type, row, meta) {
                        return '<input type="checkbox" name="searchResult" class="checkbox trait_checkbox" value="' + data.hmac + '">'
                      }
                    },
                    {
                      'title': "Index",
                      'type': "natural",
                      'width': "30px",
                      'data': "index"
                    },
                    {
                      'title': "Record",
                      'type': "natural-minus-na",
                      'data': null,
                      'width': "60px",
                      'render': function(data, type, row, meta) {
                        return '<a target="_blank" href="/show_trait?trait_id=' + data.name + '&dataset=' + data.dataset + '">' + data.display_name + '</a>'
                      }
                    }{% if dataset.type == 'ProbeSet' %},
                    {
                      'title': "Symbol",
                      'type': "natural",
                      'width': "120px",
                      'data': "symbol"
                    },
                    {
                      'title': "Description",
                      'type': "natural",
                      'data': null,
                      'render': function(data, type, row, meta) {
                        try {
                          return decodeURIComponent(escape(data.description))
                        } catch(err){
                          return escape(data.description)
                        }
                      }
                    },
                    {
                      'title': "<div style='text-align: right;'>Location</div>",
                      'type': "natural-minus-na",
                      'width': "125px",
                      'data': "location"
                    },
                    {
                      'title': "<div style='text-align: right;'>Mean</div>",
                      'type': "natural-minus-na",
                      'width': "30px",
                      'data': "mean",
                      'orderSequence': [ "desc", "asc"]
                    },
                    {
                      'title': "<div style='text-align: right;'>Peak <a href=\"{{ url_for('glossary_blueprint.glossary') }}#LRS\" target=\"_blank\" style=\"color: white;\">&nbsp;<i class=\"fa fa-info-circle\" aria-hidden=\"true\"></i></a></div><div style='text-align: right;'>LOD&ensp;&emsp;</div>",
                      'type': "natural-minus-na",
                      'data': "lod_score",
                      'width': "60px",
                      'orderSequence': [ "desc", "asc"]
                    },
                    {
                      'title': "<div style='text-align: right;'>Peak Location</div>",
                      'type': "natural-minus-na",
                      'width': "125px",
                      'data': "lrs_location"
                    },
                    {
                      'title': "<div style='text-align: right;'>Effect <a href=\"{{ url_for('glossary_blueprint.glossary') }}#A\" target=\"_blank\" style=\"color: white;\">&nbsp;<i class=\"fa fa-info-circle\" aria-hidden=\"true\"></i></a></div><div style='text-align: right;'>Size&ensp;&emsp;</div>",
                      'type': "natural-minus-na",
                      'data': "additive",
                      'width': "60px",
                      'orderSequence': [ "desc", "asc"]
                    }{% elif dataset.type == 'Publish' %},
                    {
                      'title': "Description",
                      'type': "natural",
                      'width': "500px",
                      'data': null,
                      'render': function(data, type, row, meta) {
			                  try {
                            return decodeURIComponent(escape(data.description))
			                  } catch(err){
			                      return data.description
                        }
                      }
                    },
                    {
                      'title': "<div style='text-align: right;'>Mean</div>",
                      'type': "natural-minus-na",
                      'width': "30px",
                      'data': "mean",
                      'orderSequence': [ "desc", "asc"]
                    },
                    {
                      'title': "Authors",
                      'type': "natural",
                      'width': "300px",
                      'data': null,
                      'render': function(data, type, row, meta) {
                        author_list = data.authors.split(",")
                        if (author_list.length >= 6) {
                          author_string = author_list.slice(0, 6).join(",") + ", et al."
                        } else{
                          author_string = data.authors
                        }
                        return author_string
                      }
                    },
                    {
                      'title': "<div style='text-align: right;'>Year</div>",
                      'type': "natural-minus-na",
                      'data': null,
                      'width': "25px",
                      'render': function(data, type, row, meta) {
                        if (data.pubmed_id != "N/A"){
                          return '<a href="' + data.pubmed_link + '">' + data.pubmed_text + '</a>'
                        } else {
                          return data.pubmed_text
                        }
                      },
                      'orderSequence': [ "desc", "asc"]
                    },
                    {
                      'title': "<div style='text-align: right;'>Peak <a href=\"{{ url_for('glossary_blueprint.glossary') }}#LRS\" target=\"_blank\" style=\"color: white;\">&nbsp;<i class=\"fa fa-info-circle\" aria-hidden=\"true\"></i></a></div><div style='text-align: right;'>LOD&ensp;&emsp;</div>",
                      'type': "natural-minus-na",
                      'data': "lod_score",
                      'width': "60px",
                      'orderSequence': [ "desc", "asc"]
                    },
                    {
                      'title': "<div style='text-align: right;'>Peak Location</div>",
                      'type': "natural-minus-na",
                      'width': "120px",
                      'data': "lrs_location"
                    },
                    {
                      'title': "<div style='text-align: right;'>Effect <a href=\"{{ url_for('glossary_blueprint.glossary') }}#A\" target=\"_blank\" style=\"color: white;\">&nbsp;<i class=\"fa fa-info-circle\" aria-hidden=\"true\"></i></a></div><div style='text-align: right;'>Size&ensp;&emsp;</div>",
                      'type': "natural-minus-na",
                      'width': "60px",
                      'data': "additive",
                      'orderSequence': [ "desc", "asc"]
                    }{% elif dataset.type == 'Geno' %},
                    {
                      'title': "<div style='text-align: right;'>Location</div>",
                      'type': "natural-minus-na",
                      'width': "120px",
                      'data': "location"
                    }{% endif %}
                ],
                "order": [[1, "asc" ]],
                'sDom': "iti",
                "autoWidth": true,
                "bSortClasses": false,
                "scrollY": "100vh",
                "scroller":  true,
                "scrollCollapse": true
            } );
            
            trait_table.draw(); //ZS: This makes the table adjust its height properly on initial load

            $('.toggle-vis').on( 'click', function (e) {
              e.preventDefault();

              // Get the column API object
              var column = trait_table.column( $(this).attr('data-column') );

              // Toggle the visibility
              column.visible( ! column.visible() );

              if (column.visible()){
                $(this).removeClass("active");
              } else {
                $(this).addClass("active");
              }
            } );
<commit_msg>Disabled Scroller for search results when there are fewer than 20 results (in order to avoid strange behavior when there are only a handful of rows)<commit_after>{% extends "base.html" %}
{% block title %}Search Results{% endblock %}
{% block css %}
    <link rel="stylesheet" type="text/css" href="{{ url_for('css', filename='DataTables/css/jquery.dataTables.css') }}" />
    <link rel="stylesheet" type="text/css" href="{{ url_for('css', filename='fontawesome/css/font-awesome.min.css') }}" />
    <link rel="stylesheet" type="text/css" href="{{ url_for('js', filename='DataTablesExtensions/buttonStyles/css/buttons.dataTables.min.css') }}">
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css">
    <link rel="stylesheet" type="text/css" href="/static/new/css/show_trait.css" />
    <link rel="stylesheet" type="text/css" href="static/new/css/trait_list.css" />
{% endblock %}
{% block content %}
<!-- Start of body -->
    <div style="padding-left: 10px;">
        <input type="hidden" name="uc_id" id="uc_id" value="{{ uc_id }}">

        <div style="padding-top: 10px; padding-bottom: 10px; font-size: 16px;">
        <!-- Need to customize text more for other types of searches -->

        <p><b>Search Results:</b> We searched <a href="http://genenetwork.org/webqtl/main.py?FormID=sharinginfo&{% if dataset.accession_id != 'None' %}GN_AccessionId={{ dataset.accession_id }}{% else %}InfoPageName={{ dataset.name }}{% endif %}">{{ dataset.fullname }}</a>
           to find all records
                {% if go_term is not none %}
                with <u>Gene Ontology ID</u> <strong>GO:{{ go_term }}</strong>.
                {% else %}
                {% for word in search_terms %}
                    {% if word.key|lower == "rif" %}
                    with <u>GeneRIF</u> containing <strong>{{ word.search_term[0] }}</strong>{% if loop.last %}.{% else %} and {% endif %}
                    {% elif word.key|lower == "go" %}
                    with <u>Gene Ontology ID</u> <strong>{{ word.search_term[0] }}</strong>{% if loop.last %}.{% else %} and {% endif %}
                    {% elif word.key|lower == "wiki" %}
                    with <u>GeneWiki</u> containing <strong>{{ word.search_term[0] }}</strong>{% if loop.last %}.{% else %} and {% endif %}
                    {% elif word.key|lower == "mean" %}
                    with <u>MEAN</u> between <strong>{{ word.search_term[0] }}</strong> and <strong>{{ word.search_term[1] }}</strong>{% if loop.last %}.{% else %} and {% endif %}
                    {% elif word.key|lower == "range" %}
                    with <u>RANGE</u> between <strong>{{ word.search_term[0] }}</strong> and <strong>{{ word.search_term[1] }}</strong>{% if loop.last %}.{% else %} and {% endif %}
                    {% elif word.key|lower == "lrs" or word.key|lower == "lod" or word.key|lower == "translrs" or word.key|lower == "cislrs" or word.key|lower == "translod" or word.key|lower == "cislod" %}
                    {% if word.search_term|length == 1 %}
                    with {% if word.key|lower == "translrs" %}trans{% elif word.key|lower == "cislrs" %}cis{% endif %}LRS {% if word.separator == ">" %} greater than {% elif word.separator == "<" %} less than {% elif word.separator == ">=" %} greater than or equal to {% elif word.separator == "<=" %} less than or equal to {% endif %} <strong>{{ word.search_term[0] }}</strong>{% if loop.last %}.{% else %} and {% endif %}
                    {% elif word.search_term|length == 2 %}
                    with <u>{{ word.key|upper }}</u> between <strong>{{ word.search_term[0] }}</strong> and <strong>{{ word.search_term[1] }}</strong>{% if loop.last %}.{% else %} and {% endif %}
                    {% elif word.search_term|length == 3 %}
                    with <u>{{ word.key|upper }}</u> between <strong>{{ word.search_term[0] }}</strong> and <strong>{{ word.search_term[1] }}</strong> on chromosome <strong>{{ word.search_term[2] }}</strong>{% if loop.last %}.{% else %} and {% endif %}
                    {% elif word.search_term|length == 5 %}
                    with <u>{{ word.key|upper }}</u> between <strong>{{ word.search_term[0] }}</strong> and <strong>{{ word.search_term[1] }}</strong> on chromosome <strong>{{ word.search_term[2] }}</strong> between <strong>{{ word.search_term[3] }}</strong> and <strong>{{ word.search_term[4] }}</strong> Mb{% if loop.last %}.{% else %} and {% endif %}
                    {% endif %}
                    {% elif word.key|lower == "position" or word.key|lower == "mb" %}
                    with <u>target genes</u> on chromosome <strong>{% if (word.search_term[0]|lower).split('chr')|length > 1 %}{{ (word.search_term[0]|lower).split('chr')[1] }}{% else %}{{ word.search_term[0] }}{% endif %}</strong> between <strong>{{ word.search_term[1] }}</strong> and <strong>{{ word.search_term[2] }}</strong> Mb{% if loop.last %}.{% else %} and {% endif %}
                    {% else %}
                    {% if word.search_term[0] == "*" %} in the dataset.{% else %}{% if loop.first %}that match:<br>{% endif %}<b>{{ word.search_term[0] }}</b>{% if loop.last %}{% else %} and {% endif %}{% endif %}
                    {% endif %}
                {% endfor %}
                {% endif %}
                <br>
                A total of {{ results|count }} records were found.
        </p>

        {% if go_term is not none %}
        <p><b>The associated genes include:</b><br><br>{% for word in search_terms %}{{ word.search_term[0] }}{% endfor %}</p>
        {% endif %}

        <!--<p>To study a record click on its ID below, and to view the whole description {% if dataset.type == "Publish" %}or list of authors {% endif %} hover over the table cell. Check records below and click Add button to add to selection.</p>-->

        <!--<hr style="height: 1px; background-color: #A9A9A9;">-->

        </div>
        {% if too_many_results %}
        <p>Your search generated over 50000 results. Please modify your search to generate 50000 or fewer matches.</p>
        {% else %}
        <div style="min-width: 950px;">
          <form id="trait_submission_form" target="_blank" action="/corr_matrix" method="post">
            <input type="hidden" name="tool_used" value="" />
            <input type="hidden" name="form_url" value="" />
            <input type="hidden" name="trait_list" id="trait_list" value= "
            {% for this_trait in trait_list %}
                {{ this_trait.name }}:{{ this_trait.dataset }},
            {% endfor %}" >

            {% include 'tool_buttons.html' %}

          </form>
        </div>

        <div>
          <br />
          <form id="export_form" method="POST" action="/export_traits_csv" style="display: inline;">
            <div style="min-width: 950px;">
              <input type="hidden" name="headers" id="headers" value="{% for field in header_fields %}{{ field }},{% endfor %}">
              <input type="hidden" name="search_string" id="search_string" value="{{ original_search_string }}">
              <input type="hidden" name="database_name" id="database_name" value="{{ dataset.fullname }}">
              <input type="hidden" name="file_name" id="file_name" value="search_results">
              <input type="hidden" name="filter_term" id="filter_term" value="None">
              {% if dataset.accession_id is defined %}
              <input type="hidden" name="accession_id" id="accession_id" value="{{ dataset.accession_id }}">
              {% endif %}
              <input type="hidden" name="export_data" id="export_data" value="">
              <button class="btn btn-default" id="select_all" type="button"><span class="glyphicon glyphicon-ok"></span> Select</button>
              <button class="btn btn-default" id="invert" type="button"><span class="glyphicon glyphicon-adjust"></span> Invert</button>
              <button class="btn btn-success" id="add" type="button" disabled><span class="glyphicon glyphicon-plus-sign"></span> Add</button>
              <button class="btn btn-default" id="export_traits">Download <span class="glyphicon glyphicon-download"></span></button>
              <input type="text" id="searchbox" class="form-control" style="width: 200px; display: inline;" placeholder="Search This Table For ...">
              <input type="text" id="select_top" class="form-control" style="width: 200px; display: inline;" placeholder="Select Top ...">
              <button class="btn btn-default" id="deselect_all" type="button"><span class="glyphicon glyphicon-remove"></span> Deselect</button>
            </div>
          </form>
          {% if dataset.type != 'Geno' %}
          <div class="show-hide-container">
            <b>Show/Hide Columns:</b>
            <br>
            {% if dataset.type == 'ProbeSet' %}
            <button class="toggle-vis" data-column="3">Symbol</button>
            <button class="toggle-vis" data-column="4">Description</button>
            <button class="toggle-vis" data-column="5">Location</button>
            <button class="toggle-vis" data-column="6">Mean</button>
            <button class="toggle-vis" data-column="7">Peak LOD</button>
            <button class="toggle-vis" data-column="8">Peak Location</button>
            <button class="toggle-vis" data-column="9">Effect Size</button>
            {% elif dataset.type == 'Publish' %}
            <button class="toggle-vis" data-column="3">Description</button>
            <button class="toggle-vis" data-column="4">Mean</button>
            <button class="toggle-vis" data-column="5">Authors</button>
            <button class="toggle-vis" data-column="6">Year</button>
            <button class="toggle-vis" data-column="7">Peak LOD</button>
            <button class="toggle-vis" data-column="8">Peak Location</button>
            <button class="toggle-vis" data-column="9">Effect Size</button>
            {% endif %}
          </div>
          {% endif %}
          <div id="table_container" {% if dataset.type == 'ProbeSet' or dataset.type == 'Publish' %}style="min-width: 1500px; max-width:100%;"{% endif %}>
            <table class="table-hover table-striped cell-border" id='trait_table' style="float: left; width: {% if dataset.type == 'Geno' %}380px{% else %}100%{% endif %};">
                <tbody>
                 <td colspan="100%" align="center"><br><b><font size="15">Loading...</font></b><br></td>
                </tbody>
            </table>
          </div>
        </div>
        {% endif %}
    </div>

    <div id="myModal"></div>

<!-- End of body -->

{% endblock %}

{% block js %}
    <script language="javascript" type="text/javascript" src="{{ url_for('js', filename='js_alt/md5.min.js') }}"></script>

    <script language="javascript" type="text/javascript" src="{{ url_for('js', filename='DataTables/js/jquery.dataTables.min.js') }}"></script>
    <script language="javascript" type="text/javascript" src="{{ url_for('js', filename='DataTablesExtensions/scroller/js/dataTables.scroller.min.js') }}"></script>
    <script language="javascript" type="text/javascript" src="{{ url_for('js', filename='jszip/jszip.min.js') }}"></script>
    <script language="javascript" type="text/javascript" src="{{ url_for('js', filename='DataTablesExtensions/plugins/sorting/natural.js') }}"></script>
    <script language="javascript" type="text/javascript" src="{{ url_for('js', filename='DataTablesExtensions/buttons/js/dataTables.buttons.min.js') }}"></script>
    <script language="javascript" type="text/javascript" src="{{ url_for('js', filename='DataTablesExtensions/buttons/js/buttons.colVis.min.js') }}"></script>
    <script language="javascript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/js/all.min.js"></script>

    <script language="javascript" type="text/javascript" src="/static/new/javascript/search_results.js"></script>

    <script type='text/javascript'>
        var trait_list = {{ trait_list|safe }};
    </script>

    <script type="text/javascript" charset="utf-8">
        $(document).ready( function () {

            var getParams = function(url) {
                let parser = document.createElement('a');
                parser.href = url;
                let params = parser.search.substring(1);
                if(params.length > 0) {
                    return ('?'+params);
                }
                return params;
            };
            
            $('#trait_table tr').click(function(event) {
                if (event.target.type !== 'checkbox') {
                    $(':checkbox', this).trigger('click');
                }
            });

            //ZS: Need to make sort by symbol, also need to make sure blank symbol fields at the bottom and symbols starting with numbers below letters
            trait_table = $('#trait_table').DataTable( {
                'drawCallback': function( settings ) {
                      $('#trait_table tr').off().on("click", function(event) {
                        if (event.target.type !== 'checkbox' && event.target.tagName.toLowerCase() !== 'a') {
                          var obj =$(this).find('input');
                          obj.prop('checked', !obj.is(':checked'));
                        }
                        if ($(this).hasClass("selected")){
                          $(this).removeClass("selected")
                        } else {
                          $(this).addClass("selected")
                        }
                        change_buttons()
                      });
                },
                'createdRow': function ( row, data, index ) {
                    $('td', row).eq(0).attr("style", "text-align: center; padding: 0px 10px 2px 10px;");
                    $('td', row).eq(1).attr("align", "right");
                    $('td', row).eq(1).attr('data-export', index+1);
                    $('td', row).eq(2).attr('data-export', $('td', row).eq(2).text());
                    {% if dataset.type == 'ProbeSet' %}
                    $('td', row).eq(3).attr('title', $('td', row).eq(3).text());
                    $('td', row).eq(3).attr('data-export', $('td', row).eq(3).text());
                    if ($('td', row).eq(3).text().length > 20) {
                        $('td', row).eq(3).text($('td', row).eq(3).text().substring(0, 20));
                        $('td', row).eq(3).text($('td', row).eq(3).text() + '...')
                    }
                    $('td', row).eq(4).attr('title', $('td', row).eq(4).text());
                    $('td', row).eq(4).attr('data-export', $('td', row).eq(4).text());
                    $('td', row).slice(5,10).attr("align", "right");
                    $('td', row).eq(5).attr('data-export', $('td', row).eq(5).text());
                    $('td', row).eq(6).attr('data-export', $('td', row).eq(6).text());
                    $('td', row).eq(7).attr('data-export', $('td', row).eq(7).text());
                    $('td', row).eq(8).attr('data-export', $('td', row).eq(8).text());
                    $('td', row).eq(9).attr('data-export', $('td', row).eq(9).text());
                    {% elif dataset.type == 'Publish' %}
                    $('td', row).eq(3).attr('title', $('td', row).eq(3).text());
                    $('td', row).eq(3).attr('data-export', $('td', row).eq(3).text());
                    $('td', row).eq(4).attr('title', $('td', row).eq(4).text());
                    $('td', row).eq(4).attr('data-export', $('td', row).eq(4).text());
                    $('td', row).eq(4).attr('align', 'right');
                    $('td', row).slice(6,10).attr("align", "right");
                    $('td', row).eq(5).attr('data-export', $('td', row).eq(5).text());
                    $('td', row).eq(6).attr('data-export', $('td', row).eq(6).text());
                    $('td', row).eq(7).attr('data-export', $('td', row).eq(7).text());
                    $('td', row).eq(8).attr('data-export', $('td', row).eq(8).text());
                    $('td', row).eq(9).attr('data-export', $('td', row).eq(8).text());
                    {% elif dataset.type == 'Geno' %}
                    $('td', row).eq(3).attr('data-export', $('td', row).eq(3).text());
                    {% endif %}
                },
                'data': trait_list,
                'columns': [
                    {
                      'data': null,
                      'width': "25px",
                      'orderDataType': "dom-checkbox",
                      'orderable': false,
                      'render': function(data, type, row, meta) {
                        return '<input type="checkbox" name="searchResult" class="checkbox trait_checkbox" value="' + data.hmac + '">'
                      }
                    },
                    {
                      'title': "Index",
                      'type': "natural",
                      'width': "30px",
                      'data': "index"
                    },
                    {
                      'title': "Record",
                      'type': "natural-minus-na",
                      'data': null,
                      'width': "60px",
                      'render': function(data, type, row, meta) {
                        return '<a target="_blank" href="/show_trait?trait_id=' + data.name + '&dataset=' + data.dataset + '">' + data.display_name + '</a>'
                      }
                    }{% if dataset.type == 'ProbeSet' %},
                    {
                      'title': "Symbol",
                      'type': "natural",
                      'width': "120px",
                      'data': "symbol"
                    },
                    {
                      'title': "Description",
                      'type': "natural",
                      'data': null,
                      'render': function(data, type, row, meta) {
                        try {
                          return decodeURIComponent(escape(data.description))
                        } catch(err){
                          return escape(data.description)
                        }
                      }
                    },
                    {
                      'title': "<div style='text-align: right;'>Location</div>",
                      'type': "natural-minus-na",
                      'width': "125px",
                      'data': "location"
                    },
                    {
                      'title': "<div style='text-align: right;'>Mean</div>",
                      'type': "natural-minus-na",
                      'width': "30px",
                      'data': "mean",
                      'orderSequence': [ "desc", "asc"]
                    },
                    {
                      'title': "<div style='text-align: right;'>Peak <a href=\"{{ url_for('glossary_blueprint.glossary') }}#LRS\" target=\"_blank\" style=\"color: white;\">&nbsp;<i class=\"fa fa-info-circle\" aria-hidden=\"true\"></i></a></div><div style='text-align: right;'>LOD&ensp;&emsp;</div>",
                      'type': "natural-minus-na",
                      'data': "lod_score",
                      'width': "60px",
                      'orderSequence': [ "desc", "asc"]
                    },
                    {
                      'title': "<div style='text-align: right;'>Peak Location</div>",
                      'type': "natural-minus-na",
                      'width': "125px",
                      'data': "lrs_location"
                    },
                    {
                      'title': "<div style='text-align: right;'>Effect <a href=\"{{ url_for('glossary_blueprint.glossary') }}#A\" target=\"_blank\" style=\"color: white;\">&nbsp;<i class=\"fa fa-info-circle\" aria-hidden=\"true\"></i></a></div><div style='text-align: right;'>Size&ensp;&emsp;</div>",
                      'type': "natural-minus-na",
                      'data': "additive",
                      'width': "60px",
                      'orderSequence': [ "desc", "asc"]
                    }{% elif dataset.type == 'Publish' %},
                    {
                      'title': "Description",
                      'type': "natural",
                      'width': "500px",
                      'data': null,
                      'render': function(data, type, row, meta) {
			                  try {
                            return decodeURIComponent(escape(data.description))
			                  } catch(err){
			                      return data.description
                        }
                      }
                    },
                    {
                      'title': "<div style='text-align: right;'>Mean</div>",
                      'type': "natural-minus-na",
                      'width': "30px",
                      'data': "mean",
                      'orderSequence': [ "desc", "asc"]
                    },
                    {
                      'title': "Authors",
                      'type': "natural",
                      'width': "300px",
                      'data': null,
                      'render': function(data, type, row, meta) {
                        author_list = data.authors.split(",")
                        if (author_list.length >= 6) {
                          author_string = author_list.slice(0, 6).join(",") + ", et al."
                        } else{
                          author_string = data.authors
                        }
                        return author_string
                      }
                    },
                    {
                      'title': "<div style='text-align: right;'>Year</div>",
                      'type': "natural-minus-na",
                      'data': null,
                      'width': "25px",
                      'render': function(data, type, row, meta) {
                        if (data.pubmed_id != "N/A"){
                          return '<a href="' + data.pubmed_link + '">' + data.pubmed_text + '</a>'
                        } else {
                          return data.pubmed_text
                        }
                      },
                      'orderSequence': [ "desc", "asc"]
                    },
                    {
                      'title': "<div style='text-align: right;'>Peak <a href=\"{{ url_for('glossary_blueprint.glossary') }}#LRS\" target=\"_blank\" style=\"color: white;\">&nbsp;<i class=\"fa fa-info-circle\" aria-hidden=\"true\"></i></a></div><div style='text-align: right;'>LOD&ensp;&emsp;</div>",
                      'type': "natural-minus-na",
                      'data': "lod_score",
                      'width': "60px",
                      'orderSequence': [ "desc", "asc"]
                    },
                    {
                      'title': "<div style='text-align: right;'>Peak Location</div>",
                      'type': "natural-minus-na",
                      'width': "120px",
                      'data': "lrs_location"
                    },
                    {
                      'title': "<div style='text-align: right;'>Effect <a href=\"{{ url_for('glossary_blueprint.glossary') }}#A\" target=\"_blank\" style=\"color: white;\">&nbsp;<i class=\"fa fa-info-circle\" aria-hidden=\"true\"></i></a></div><div style='text-align: right;'>Size&ensp;&emsp;</div>",
                      'type': "natural-minus-na",
                      'width': "60px",
                      'data': "additive",
                      'orderSequence': [ "desc", "asc"]
                    }{% elif dataset.type == 'Geno' %},
                    {
                      'title': "<div style='text-align: right;'>Location</div>",
                      'type': "natural-minus-na",
                      'width': "120px",
                      'data': "location"
                    }{% endif %}
                ],
                "order": [[1, "asc" ]],
                'sDom': "iti",
                "autoWidth": true,
                "bSortClasses": false,
                {% if trait_list|length > 20 %}
                "scrollY": "100vh",
                "scroller":  true,
                "scrollCollapse": true
                {% endif %}
            } );

            trait_table.draw(); //ZS: This makes the table adjust its height properly on initial load

            $('.toggle-vis').on( 'click', function (e) {
              e.preventDefault();

              // Get the column API object
              var column = trait_table.column( $(this).attr('data-column') );

              // Toggle the visibility
              column.visible( ! column.visible() );

              if (column.visible()){
                $(this).removeClass("active");
              } else {
                $(this).addClass("active");
              }
            } );

{'fraction_non_alphanumeric': 0.18842247662890949, 'fraction_numerical': 0.00916671714418398, 'mean_word_length': 1.705117701676771, 'pattern_counts': {'":': 12, '<': 537, '<?xml version=': 0, '>': 546, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5389421', 'n_tokens_mistral': 14680, 'n_tokens_neox': 13368, 'n_words': 2837}