Skip to content

Commit

Permalink
issue #1159 - cohort per sample zygosity warnings, and return empty i…
Browse files Browse the repository at this point in the history
…f none selected
  • Loading branch information
davmlaw committed Dec 11, 2024
1 parent 735626e commit 91c2f1c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,54 @@
</style>
<script>
function checkIfAllChecked(toggle, array) {
var numChecked = 0;
let numChecked = 0;
array.each(function() { numChecked += $(this).is(":checked"); });
var allChecked = numChecked == array.length;
const allChecked = numChecked == array.length;
$(toggle).prop('checked', allChecked);
}


function checkZygConfigWarning() {
const zygosityTable = $(".zygosity-filter-table");
let samplesWithAllZyg = 0;
let samplesWithSomeZyg = 0;
$(".cohort-node-zygosity-filter", zygosityTable).each(function() {
let zygFilters = $(".zygosity_ref, .zygosity_het, .zygosity_hom, .zygosity_none", this);
let numZyg = $("input:checked", zygFilters).length;
if (numZyg) {
if (numZyg === 4) {
samplesWithAllZyg += 1;
} else {
samplesWithSomeZyg += 1;
}
}
});

if (samplesWithAllZyg || samplesWithSomeZyg) {
$("#zyg-config-no-samples-warning").hide();
if (samplesWithAllZyg && !samplesWithSomeZyg) {
$("#zyg-config-unintuitive-no-zyg-call-warning").show();
} else {
$("#zyg-config-unintuitive-no-zyg-call-warning").hide();
}

let showInGrid = $(".show_in_grid", zygosityTable);
if (!$("input:checked", showInGrid).length) {
$("#zyg-config-no-visible-samples-warning").show();
} else {
$("#zyg-config-no-visible-samples-warning").hide();
}


} else {
$("#zyg-config-no-samples-warning").show();
}
}

function checkboxSetup(addClickHandler) {
$(".toggle-row").each(function() {
var rowInputs = $("input[type=checkbox][class!='toggle-row']", $(this).parents("tr"));
checkIfAllChecked(this, rowInputs);
const rowInputs = $("input[type=checkbox][class!='toggle-row']", $(this).parents("tr"));
checkIfAllChecked(this, rowInputs);

if (addClickHandler) {
$(this).click(function() {
Expand All @@ -35,9 +73,9 @@
});

$(".toggle-column").each(function() {
var columnName = $(this).attr("column_name");
var columnInputs = $("input[type=checkbox]", "td." + columnName);
checkIfAllChecked(this, columnInputs);
const columnName = $(this).attr("column_name");
const columnInputs = $("input[type=checkbox]", "td." + columnName);
checkIfAllChecked(this, columnInputs);

if (addClickHandler) {
$(this).click(function() {
Expand All @@ -49,9 +87,11 @@

$(document).ready(function() {
checkboxSetup(true);

checkZygConfigWarning()

$("input[type=checkbox]", "table.zygosity-filter-table").click(function() {
checkboxSetup(false);
checkZygConfigWarning();
});
});
</script>
Expand Down Expand Up @@ -89,3 +129,17 @@
<td></td>
</tr>
</table>

<ul class="messages">
<li id="zyg-config-unintuitive-no-zyg-call-warning" class="warning hidden">
Warning: You have checked all zygosity calls (including "No Zygosity call in sample")
for all samples with any ticked.
This will return all variants in the cohort which may be unintuitive behaviour.
</li>
<li id="zyg-config-no-samples-warning" class="warning hidden">
Warning: No zygosity calls for any sample selected - no variants will be returned.
</li>
<li id="zyg-config-no-visible-samples-warning" class="warning hidden">
Warning: No samples will be shown in grid.
</li>
</ul>
4 changes: 4 additions & 0 deletions snpdb/models/models_cohort.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,10 @@ def get_zygosity_q(self, sample_zygosities: dict, sample_require_zygosity: dict
sample_require_zygosity = {sample : True/False} - defaults to True
exclude - invert query (not equals)
"""
if all([not v for v in sample_zygosities.values()]):
# nothing selected
q_none = Q(pk__isnull=True)
return q_none

if sample_require_zygosity is None:
sample_require_zygosity = {}
Expand Down

0 comments on commit 91c2f1c

Please sign in to comment.