<!DOCTYPE html>


<html>
    <head>

        {% load static %}
        {% load custom_tags %}
        {% load crispy_forms_tags %}
        <script type="text/javascript" id="js">
            $(document).ready(function() {
            // call the tablesorter plugin
            $("table").tablesorter({
            // change the default sorting order from 'asc' to 'desc'
            sortInitialOrder: 1
            });
            });
        </script>
        <script type="text/javascript">
            jQuery(document).ready(function ($) {
                $('#tabs_main').tab();
            });
        </script>
        <script type="text/javascript">
            jQuery(document).ready(function ($) {
                $('#tabs1').tab();
            });
        </script>


        {% include "chlamdb/header.html" %}

    </head>


    <div class="container-fluid" id="main_container">
      <div class="row">
        <div id="wrapper">
            <div id="page-content-wrapper">
              <div class="row">
                <div class="col-lg-12">
                   {% include "chlamdb/menu.html" %}
                   {% include "chlamdb/extract_nav_tabs_template.html" with type="EC" active_tab="det" %}

                     <div id="extract_form">

                        <div class="panel panel-success" style="width:80% ; top: 200px; margin: 10px 10px 10px 10px">
                            <div class="panel-heading" style="width:100%">
                                <h3 class="panel-title">Help</h3>
                            </div>
                            <p style="margin: 10px 10px 10px 10px; line-height: 160%;">Get list of EC numbers shared between genomes selected in panel A and absent in genomes of panel B. EC based on PRIAM prediction and not Kegg Oorthologs data. Kegg data will replace PRIAM in the near future.<br>
                            Reference: one of the genome in panel A can be chosen as reference for display the result EC list on a circular map of the genome. Click on "show on circular map" to generate the circos map. Corresponding locus are highlighted in pink. <br>
                            Missing data: if more than one panel A genome (include) is selected, possibility to tolerate missing data in 1 up to 10 genomes (in order to get EC present in at least x out of the y genomes selected in panel A).</p>
                        </div>

                        <form action="{% url "extract_EC" %}" method="post">
                            {% csrf_token %}
                            {% crispy form %}
                        </form>

                    </div>



                    {% if wrong_n_missing%}

                    <div class="panel panel-warning" style="width:500px ; top: 200px; margin: 10px 10px 10px 10px">
                        <div class="panel-heading" style="width:100%">
                            <h3 class="panel-title">Help</h3>
                        </div>
                        <p style="margin: 10px 10px 10px 10px">You cannot set a number of missing data bigger than the number of included genomes</p>
                    </div>

                    {% elif no_match%}

                    <div class="panel panel-warning" style="width:500px ; top: 200px; margin: 10px 10px 10px 10px">
                        <div class="panel-heading" style="width:100%">
                            <h3 class="panel-title"></h3>
                        </div>
                        <p style="margin: 10px 10px 10px 10px">No match</p>
                    </div>

                    {% endif %}

                    {% if envoi_extract %}

                        <ul id="tabs" class="nav nav-tabs" data-tabs="tabs">
                            <li class="active"><a href="#red" data-toggle="tab">EC list</a></li>
                            <li><a href="#orange" data-toggle="tab">Phylogenetic profile</a></li>
                            <li><a href="#tab2" data-toggle="tab">Locus list reference</a></li>
                        </ul>

                        <div id="my-tab-content" class="tab-content">

                            <div class="tab-pane active" id="red">


                                <div id="export_bouttons_groups">
                                    <a download="biodb_extract.xls" href="#" onclick="return ExcellentExport.excel(this, 'table_groups', 'search');" class="btn btn-success">Export to Excel</a>

                                    <a download="biodb_extract.csv" href="#" onclick="return ExcellentExport.csv(this, 'table_groups');" class="btn btn-success">Export to CSV</a>
                                    <a href="{% url 'circos_main' %}{{circos_url}}" class="btn btn-success">Show on circular map (takes some time)</a>

                                    <br/>
                                </div>

                                <p>Number of EC: {{ sum_group }} </p>

                                <table class="sortable" id="table_groups">

                                    <thead>
                                        <tr>
                                        <th></th>
                                        <th id="entete_locus">EC number</th>
                                        <th>Description</th>
                                            <th>KEGG Map</th>
                                            <th>Pathway Category</th>
                                            <th>Pathway description</th>
                                            <th>present in (/{{include|length}} included genomes)</th>
                                            <th>freq complete database (/{{max_n}} genomes)</th>
                                        </tr>
                                    </thead>

                                    {% for value in match_groups_data %}
                                        <tr>
                                            <td>{{value.0}}</td>
                                            <td><a href="{% url 'fam' value.1 'EC' %}">{{value.1}}</a></td>
                                            {% for value_2 in value.2 %}
                                            <td>{{value_2}}</td>
                                            {% endfor %}
                                            <td>{{value.3}}</td>
                                            <td>{{value.4}}</td>
                                        </tr>
                                    {% endfor %}

                                </table>


                            </div>
                            <div class="tab-pane" id="orange">
                                <object type="image/svg+xml" data="{% static asset_path %}" id="cog_tree"></object>
                            </div>



                            <div class="tab-pane" id="tab2">

                                <h3> Locus annotation </h3>
                                <div id="export_bouttons_groups">
                                    <a download="biodb_extract.xls" href="#" onclick="return ExcellentExport.excel(this, 'cog_table', 'search');" class="btn btn-success">Export to Excel</a>
                                    <a href="{% url 'get_fasta' %}{{fasta_url_ref}}" class="btn btn-success">Download fasta</a>
                                    <a download="biodb_extract.csv" href="#" onclick="return ExcellentExport.csv(this, 'cog_table');" class="btn btn-success">Export to CSV</a>
                                    <a href="{% url 'circos_main' %}{{circos_url}}" class="btn btn-success">Show on circular map (takes some time)</a>

                                    <br/>
                                </div>
                                <table id="cog_table" class="sortable">
                                    <thead>
                                        <tr>
                                            <th></th>
                                            <th id="entete_locus">Orthogroup</th>
                                            <th id="entete_locus">Locus</th>
                                            <th style="width:10px">C</th>
                                            <th style="width:70px">COGn</th>
                                            <th style="width:55px">KO</th>
                                            <th style="width:260px">Pathways</th>
                                            <th style="width:230px">Modules</th>
                                            <th style="width:230px">Interpro</th>
                                            <th id="entete_gene">Gene</th>
                                            <th id="entete_n">nH</th>
                                            <th id="entete_n">nG</th>
                                            <th id="entete_n">TM</th>
                                            <th id="entete_n">SP</th>
                                            <th id="entete_product">Product</th>


                                        </tr>
                                    </thead>
                                    <tbody>

                                        {%for values in locus2annot%}
                                        <tr>
                                            <td>{{values.0}}</td>
                                            <td>{{values.1}}</td>
                                            <td><a href="{% url 'locusx' values.2 True %}" target="_top">{{values.2}}</a></td>
                                            <td><a href="http://www.ncbi.nlm.nih.gov/protein/{{values.3}}" target="_top">{{locus_tag2cog_catego|keyvalue:values.2}}</a></td>
                                            {% with locus_tag2cog_name|keyvalue:values.2 as name %}
                                                {% if name == '-' %}
                                                    <td>{{locus_tag2cog_name|keyvalue:values.2}}</td>
                                                {% else %}
                                                    <td><a href="{% url "fam" name 'cog'%}" target="_top">{{locus_tag2cog_name|keyvalue:values.2}}</a></td>
                                                {% endif %}
                                            {%endwith%}
                                            {% with locus_tag2ko|keyvalue:values.2 as oneko %}
                                                {% if oneko == '-' %}
                                                    <td>{{locus_tag2ko|keyvalue:values.2}}</td>
                                                    <td>-</td>
                                                    <td>-</td>
                                                {% else %}
                                                    <td><a href="{% url "fam" oneko 'ko'%}" target="_top">{{locus_tag2ko|keyvalue:values.2}}</a></td>
                                                    {% with ko2ko_pathways|keyvalue:oneko as name %}
                                                        {% if name == '-' %}
                                                            <td>-</td>
                                                        {% else %}
                                                            <td>{{name|safe}}</td>
                                                        {% endif %}
                                                    {%endwith%}
                                                    {% with ko2ko_modules|keyvalue:oneko as name %}
                                                        {% if name == '-' %}
                                                            <td>-</td>
                                                        {% else %}
                                                            <td>{{name|safe}}</td>
                                                        {% endif %}
                                                    {%endwith%}
                                                {% endif %}


                                            {%endwith%}
                                            {% with locus2interpro|keyvalue:values.2 as interpro_data %}
                                            <td>
                                                {% for one_interpro in interpro_data %}
                                                {% if one_interpro.0 != '-' %}
                                                    <a href="{% url 'fam' one_interpro.0 'interpro' %}" target="_top">{{one_interpro.0}}</a> /
                                                {%else%}
                                                    {{one_interpro.0}}
                                                {%endif%}
                                                    {{one_interpro.1}} </br>
                                                {% endfor %}
                                                {%endwith%}
                                            </td>
                                            <td>{{values.7}}</td>
                                            <td>{{values.8}}</td>
                                            <td>{{values.9}}</td>
                                            <td>{{values.10}}</td>
                                            <td>{{values.11}}</td>
                                            <td>{{values.12}}</td>

                                        </tr>

                                        {%endfor%}
                                    </tbody>
                                </table>



                            </div>








                        </div>
                    {% endif %}
                </div>
            </div>
          </div>
        </div>
      </div>
    </div>


    <div id="footer">

    </div>

              <script type="text/javascript" id="js2">
                $(document).ready(function() {

                    var x=document.getElementById("id_reference");
                    for (var i = 0; i < x.options.length; i++) {
                        $("#id_reference").children("option[value^=" + x.options[i].value + "]").hide()
                    }

                    $("#id_orthologs_in").change(function() {
                        document.getElementById("id_reference").selectedIndex=0;
                        var x=document.getElementById("id_orthologs_in");
                        for (var i = 0; i < x.options.length; i++) {
                            if(x.options[i].selected ==true){

                            $("#id_reference").children("option[value^=" + x.options[i].value + "]").show()
                            }else{
                            $("#id_reference").children("option[value^=" + x.options[i].value + "]").hide()

                            }
                            }
                    })

                })
          </script>



    </body>
    {% include "chlamdb/style_menu.html" %}
    <style>

    #div_id_checkbox_single_copy{
      display: none;
    }
</html>
