Skip to content

Commit

Permalink
Improve ancestry filter and use the server-side pagination for the Br…
Browse files Browse the repository at this point in the history
…owse Publications page as well
  • Loading branch information
ens-lgil committed Mar 13, 2024
1 parent 8eff925 commit fe53361
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 48 deletions.
64 changes: 47 additions & 17 deletions catalog/static/catalog/pgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,28 +429,29 @@ $(document).ready(function() {
$(sample_table_id).bootstrapTable('filterBy', {});

var stage = $("#ancestry_type_list option:selected").val();
var anc_eur_cb = 'anc_cb_EUR';
var anc_eur_cb_id = 'anc_cb_EUR';
var $anc_eur_cb = $('#'+anc_eur_cb_id);

// Single ancestry selection + show/hide European checkbox filter
var ind_anc = $("#ancestry_filter_ind option:selected").val();
if (ind_anc != '') {
// Hide European checkbox if European selected in the dropdown
if (ind_anc == anc_eur) {
var default_val = $('#'+anc_eur_cb).data('default');
$('#'+anc_eur_cb).prop('checked', default_val);
$('#'+anc_eur_cb).parent().hide();
var default_val = $anc_eur_cb.data('default');
$anc_eur_cb.prop('checked', default_val);
$anc_eur_cb.parent().hide();
}
anc_filter.push(ind_anc);
}
// Show European checkbox if European is not selected in the dropdown
if (ind_anc != anc_eur) {
$('#'+anc_eur_cb).parent().show();
$anc_eur_cb.parent().show();
}

// Fetch checkboxes selection
$(".ancestry_filter_cb").each(function () {
// Add filter when "European" checkbox is NOT checked
if ($(this).attr('id') == anc_eur_cb) {
if ($(this).attr('id') == anc_eur_cb_id) {
if (!$(this).prop('checked')) {
anc_filter.push('non-'+anc_eur);
}
Expand All @@ -464,8 +465,11 @@ $(document).ready(function() {


/** Filter the PGS Scores table **/
if (anc_filter_length != 0 || stage || trait_filter != '') {

if ((anc_filter_length != 0 && stage) || trait_filter != '') {
if (stage) {
anc_filter_length += 1;
}

if (trait_filter != '') {
anc_filter_length += 1;
Expand All @@ -485,24 +489,50 @@ $(document).ready(function() {
}

pgs_ids_list_link[scores_table_id] = [];

var data = $(scores_table_id).bootstrapTable('getData');
// Filter each row
$.each(data,function(i, row) {
var pass_filter = 0;
// Ancestry
if (anc_filter.length != 0 && stage) {
if (anc_filter.length != 0 || stage) {
var ancestry_html = $(row[ancestry_col]);
var anc_list = ancestry_html.attr('data-anc-'+stage);
if (!anc_list) {
return;
var stages_list = [stage];
if (stage == 'all') {
stages_list = ['gwas','dev','eval'];
}
anc_list = JSON.parse(anc_list);

for (var f in anc_filter) {
if (anc_list.includes(anc_filter[f])) {
pass_filter += 1;
var pass_anc_stage = 0;
var pass_anc_filter = 0;
for (var i=0; i<stages_list.length; i++) {
var data_stage = stages_list[i];
var anc_list = ancestry_html.attr('data-anc-'+data_stage);
// Has stage
if (anc_list) {
pass_anc_stage += 1;
anc_list = JSON.parse(anc_list);

// Check additional filters
if (anc_filter.length != 0) {
for (var f in anc_filter) {
if (anc_list.includes(anc_filter[f])) {
pass_anc_filter += 1;
}
}
}
}
// For "all" filters, allow missing value for the "dev" stage (but having data at thw gwas and eval stages)
else if (stage == 'all' && data_stage == 'dev' && ancestry_html.attr('data-anc-gwas') && ancestry_html.attr('data-anc-eval')) {
pass_anc_stage += 1;
for (var f in anc_filter) {
pass_anc_filter += 1;
}
}
}
if (pass_anc_filter == stages_list.length){
pass_filter += 1;
}
if (pass_anc_stage == stages_list.length){
pass_filter += 1;
}
}

// Traits
Expand Down
14 changes: 6 additions & 8 deletions catalog/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def ancestries_format(value, record, include_filter=False):
data_stage = {}
data_title = {}
anc_list = {}
anc_all_list = { 'dev_all': set(), 'all': set() }
anc_all_list = { 'dev_all': set(), 'any': set() }
multi_anc = 'multi'

# Fetch and store the data for each stage
Expand All @@ -84,7 +84,7 @@ def ancestries_format(value, record, include_filter=False):
# Add to the unique list of ancestries
anc_list[stage].add(anc)
# Add to the unique list of ALL ancestries
anc_all_list['all'].add(anc)
anc_all_list['any'].add(anc)
# Add to the unique list of DEV ancestries
if stage != 'eval':
anc_all_list['dev_all'].add(anc)
Expand All @@ -102,7 +102,7 @@ def ancestries_format(value, record, include_filter=False):
# Add to the unique list of ancestries
anc_list[stage].add(key)
# Add to the unique list of ALL ancestries
anc_all_list['all'].add(key)
anc_all_list['any'].add(key)
# Add to the unique list of DEV ancestries
if stage != 'eval':
anc_all_list['dev_all'].add(key)
Expand Down Expand Up @@ -285,10 +285,8 @@ class Browse_PublicationTable(tables.Table):
class Meta:
model = Publication
attrs = {
"data-show-columns" : "true",
"data-sort-name" : "id",
"data-page-size" : page_size,
"data-export-options" : '{"fileName": "pgs_publications_data"}'
"id": "publications_table",
"data-sort-name" : "id"
}
fields = [
'id',
Expand All @@ -301,7 +299,7 @@ class Meta:
'doi',
'PMID'
]
template_name = 'catalog/pgs_catalog_django_table.html'
template_name = 'catalog/pgs_catalog_django_tables2_browse.html'

def render_id(self, value):
return format_html('<a href="'+publication_path+'/{}">{}</a>', value, value)
Expand Down
15 changes: 14 additions & 1 deletion catalog/templates/catalog/browse/publications.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,20 @@
<div class="table-container">
<section>
<h2 class="pgs_facet_icon pgs_facet_3_icon icon icon-common">{{ view_name }}</h2>
{% render_table table %}

<form action="/browse/studies/" method="post" id="browse_form" name="browse_form">{% csrf_token %}
<div class="fixed-table-toolbar pgs_search_toolbar">
<div>
<input class="form-control search-input" type="search" aria-label="Search" placeholder="Search" autocomplete="off" name="browse_search" id="browse_search" {% if form_data.browse_search %}value="{{ form_data.browse_search }}"{% endif %}/>
</div>
<div>
<button type="button" class="btn btn-pgs pgs_no_icon_link" id="browse_search_btn" value="Submit">
<span class="fas fa-search"></span>
</button>
</div>
</div>
{% render_table table %}
</form>
</section>
</div>
{% endblock %}
8 changes: 5 additions & 3 deletions catalog/templates/catalog/includes/ancestry_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
<div class="filter_subheader mb-1">Individuals included in:</div>
{% if is_browse_score %}
<select id="browse_ancestry_type_list" name="browse_ancestry_type_list">
<option value="all" {% if form_data.browse_ancestry_type_list == 'all' %}selected{% endif %}>All Stages combined [G, D, E]</option>
<option value="any" {% if form_data.browse_ancestry_type_list == 'any' %}selected{% endif %}>Any Stage [G, D, E]</option>
<option value="all" {% if form_data.browse_ancestry_type_list == 'all' %}selected{% endif %}>All Stages combined [G + D + E]</option>
<option value="dev_all" {% if form_data.browse_ancestry_type_list == 'dev_all' %}selected{% endif %}>Development [G, D]</option>
<option value="gwas" {% if form_data.browse_ancestry_type_list == 'gwas' %}selected{% endif %}>&nbsp;&nbsp;- GWAS [G]</option>
<option value="dev" {% if form_data.browse_ancestry_type_list == 'dev' %}selected{% endif %}>&nbsp;&nbsp;- Score development [D]</option>
<option value="eval" {% if form_data.browse_ancestry_type_list == 'eval' %}selected{% endif %}>PGS Evaluation [E]</option>
</select>
{% else %}
<select id="ancestry_type_list">
<option value="all" selected>All Stages combined [G, D, E]</option>
<option value="any" selected>Any Stage [G, D, E]</option>
<option value="all">All Stages combined [G + D + E]</option>
<option value="dev_all">Development [G, D]</option>
<option value="gwas">&nbsp;&nbsp;- GWAS [G]</option>
<option value="dev">&nbsp;&nbsp;- Score development [D]</option>
Expand All @@ -45,7 +47,7 @@
<div id="{% if is_browse_score %}browse_{% endif %}ancestry_filter_list">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input {% if is_browse_score %}browse_{% endif %}ancestry_filter_cb" value="{% if is_browse_score %}browse_{% endif %}anc_cb_EUR" data-default="true" id="{% if is_browse_score %}browse_{% endif %}anc_cb_EUR" name="{% if is_browse_score %}browse_{% endif %}anc_cb_EUR" {% if form_data.browse_anc_cb_EUR or not form_data.browse_ancestry_type_list %}checked{% endif %}>
<label class="custom-control-label" for="{% if is_browse_score %}browse_{% endif %}anc_cb_EUR">Show European ancestry data</label><span class="info-icon-small" data-toggle="tooltip" data-placement="right" title="" data-original-title="This button can be used to hide PGS with any European ancestry data to only show scores with data from other non-European ancestry group. The button is selected by default, displaying all PGS."><i class="fas fa-info-circle"></i></span>
<label class="custom-control-label" for="{% if is_browse_score %}browse_{% endif %}anc_cb_EUR">Show European ancestry data</label><span class="info-icon-small" data-toggle="tooltip" data-placement="right" title="" data-original-title="This button can be used to hide PGS with any European ancestry data in the selected study stage(s) to only show scores with data from other non-European ancestry group. The button is selected by default, displaying all PGS."><i class="fas fa-info-circle"></i></span>
</div>
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input {% if is_browse_score %}browse_{% endif %}ancestry_filter_cb" value="MAO" data-default="false" id="{% if is_browse_score %}browse_{% endif %}anc_cb_multi" name="{% if is_browse_score %}browse_{% endif %}anc_cb_multi" {% if form_data.browse_anc_cb_multi %}checked{% endif %}>
Expand Down
Loading

0 comments on commit fe53361

Please sign in to comment.