Skip to content

Commit

Permalink
issue #1104 - Samples per variant - option to hide ref variants
Browse files Browse the repository at this point in the history
  • Loading branch information
davmlaw committed Dec 6, 2024
1 parent a00a696 commit 494261c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
9 changes: 4 additions & 5 deletions snpdb/variant_sample_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,16 @@ def __init__(self, user, variant, genome_build: GenomeBuild):
visible_samples_qs = Sample.filter_for_user(user).filter(vcf__genome_build=self.genome_build)
self.user_sample_ids = set(visible_samples_qs.values_list("pk", flat=True))
self.num_user_samples = len(self.user_sample_ids)
self.visible_zygosity_counts = Counter()

locus_counter = defaultdict(Counter)
locus_patients = defaultdict(set)
num_observations = 0
self.visible_rows = []
for row in values_qs:
pk = row["variant"]
if zygosity := row.get("zygosity"):
locus_counter[pk][zygosity] += 1
else:
locus_counter[pk][Zygosity.UNKNOWN_ZYGOSITY] += 0 # Need an entry to make it show...

zygosity = row.get("zygosity", Zygosity.UNKNOWN_ZYGOSITY)
locus_counter[pk][zygosity] += 1
if patient := row.get("sample__patient"):
locus_patients[pk].add(patient)

Expand All @@ -49,6 +47,7 @@ def __init__(self, user, variant, genome_build: GenomeBuild):

if sample_id in self.user_sample_ids:
self.visible_rows.append(row)
self.visible_zygosity_counts[zygosity] += 1

has_hidden_samples = self.num_samples > self.num_user_samples
self.hidden_samples_details = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ <h3>Samples</h3>
{% if not vsi.hidden_samples_details or vsi.hidden_samples_details.num_visible_observations %}

<div id="genotype-grid-container">
<form id="genotype-grid-form">
<label>Ref ({{ vsi.visible_zygosity_counts.R }}):</label> <input checked type="checkbox" class="genotype-filter" data-field="zygosity" value="R"> <span class="separator">|</span>
<label>HET ({{ vsi.visible_zygosity_counts.E }}):</label> <input checked type="checkbox" class="genotype-filter" data-field="zygosity" value="E"> <span class="separator">|</span>
<label>HOM ({{ vsi.visible_zygosity_counts.O }}):</label> <input checked type="checkbox" class="genotype-filter" data-field="zygosity" value="O"> <span class="separator">|</span>
<label>unknown/? ({{ vsi.visible_zygosity_counts.U }}):</label> <input checked type="checkbox" class="genotype-filter" data-field="zygosity" value="U">
</form>

<table id="genotype-grid"></table>
<div id="genotype-grid-pager"></div>
</div>
Expand Down Expand Up @@ -191,9 +198,39 @@ <h3>Samples</h3>

}

function filterGenotypes() {
let genotypes = [];
console.log("filterGenotypes")
$(".genotype-filter").each(function() {
if ($(this).is(":checked")) {
genotypes.push($(this).attr("value"));
}
});
console.log(genotypes);

const filters = {
groupOp: "OR", // Match any of the conditions
rules: [
{
field: "zygosity",
op: "in",
data: genotypes
}
]
};

$("#genotype-grid").jqGrid("setGridParam", {
search: true,
postData: {
filters: JSON.stringify(filters)
}
}).trigger("reloadGrid");

}


$(document).ready(function() {
const visible_rows = {{ visible_rows | jsonify }};
const visible_rows = {{ vsi.visible_rows | jsonify }};
const ZYGOSITY_DICT = {
'O': 'HOM_ALT',
'E': 'HET',
Expand Down Expand Up @@ -243,6 +280,8 @@ <h3>Samples</h3>
pager: 'genotype-grid-pager',
});

$(".genotype-filter").change(filterGenotypes);

plotSampleAlleleFrequencies(visible_rows);
});

Expand Down Expand Up @@ -273,6 +312,10 @@ <h3>Phenotypes/OMIM</h3>
td.no-word-wrap {
white-space: normal !important;
}

.separator {
padding: 0 5 0 5;
}
</style>

{% load patient_graph_tags %}
Expand Down
1 change: 0 additions & 1 deletion variantopedia/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,6 @@ def variant_sample_information(request, variant_id, genome_build_name):
context = {
"variant": variant,
"vsi": vsi,
"visible_rows": vsi.visible_rows,
"other_loci_variants_by_multiallelic": other_loci_variants_by_multiallelic,
"has_samples_in_other_builds": Sample.objects.exclude(vcf__genome_build=genome_build).exists(),
}
Expand Down

0 comments on commit 494261c

Please sign in to comment.