Skip to content

Commit

Permalink
issue #1152 - classify from tag - get cohort genotype query to work a…
Browse files Browse the repository at this point in the history
…cross common/uncommon and autocomplete to work
  • Loading branch information
davmlaw committed Sep 4, 2024
1 parent f704b0a commit 87cf5a9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
9 changes: 0 additions & 9 deletions analysis/forms/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,6 @@ def save(self, commit=True):
return obj


class InputSamplesForm(forms.Form):
sample = forms.ModelChoiceField(queryset=Sample.objects.none(), required=True)

def __init__(self, *args, **kwargs):
samples = kwargs.pop("samples")
super().__init__(*args, **kwargs)
self.fields['sample'].queryset = Sample.objects.filter(pk__in=[sample.pk for sample in samples])


class VCFLocusFilterForm(forms.Form):

def __init__(self, *args, **kwargs):
Expand Down
6 changes: 4 additions & 2 deletions analysis/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from analysis import forms
from analysis.analysis_templates import populate_analysis_from_template_run
from analysis.exceptions import NonFatalNodeError, NodeOutOfDateException
from analysis.forms import SelectGridColumnForm, UserTrioWizardForm, VCFLocusFilterForm, InputSamplesForm, \
from analysis.forms import SelectGridColumnForm, UserTrioWizardForm, VCFLocusFilterForm, \
AnalysisChoiceForm, AnalysisTemplateTypeChoiceForm, AnalysisTemplateVersionForm, AnalysisTemplateForm
from analysis.graphs.column_boxplot_graph import ColumnBoxplotGraph
from analysis.grids import VariantGrid
Expand All @@ -55,6 +55,7 @@
from library.utils import full_class_name, defaultdict_to_dict
from library.utils.database_utils import run_sql, queryset_to_sql
from pedigree.models import Pedigree
from snpdb.forms import SampleChoiceForm
from snpdb.graphs import graphcache
from snpdb.models import UserSettings, Sample, \
Cohort, CohortSample, ImportStatus, VCF, get_igv_data, Trio, Variant, GenomeBuild
Expand Down Expand Up @@ -944,8 +945,9 @@ def _get_sample_form(self):
samples = self.variant_tag.analysis.get_samples()

if samples:
form = InputSamplesForm(samples=samples)
form = SampleChoiceForm()
form.fields['sample'].required = False
form.fields['sample'].queryset = Sample.objects.filter(pk__in=[s.pk for s in samples])
else:
form = super()._get_sample_form()
return form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,15 @@ <h3>Create Classification Record for {{ variant }}</h3>

{% labelled label="Sample" %}
<div class='value'>
{{ variant_sample_autocomplete_form.sample }} <span id='zygosity'></span>
{{ variant_sample_autocomplete_form.media }}
<div id='no-sample-link' class='hidden'>
<a href="javascript:allowNoSample()">My sample isn't here</a>
</div>
<div id='no-sample-text' class='hidden'>
<p>Please find or upload the sample if you have it, as it allows us to link classifications together, and auto-fill fields.
<p>Please remember to set the SampleID field in the classification form manually.
</div>
{{ variant_sample_autocomplete_form.sample }} <span id='zygosity'></span>
{{ variant_sample_autocomplete_form.media }}
<div id='no-sample-link' class='hidden'>
<a href="javascript:allowNoSample()">My sample isn't here</a>
</div>
<div id='no-sample-text' class='hidden'>
<p>Please find or upload the sample if you have it, as it allows us to link classifications together, and auto-fill fields.
<p>Please remember to set the SampleID field in the classification form manually.
</div>
</div>
{% endlabelled %}

Expand Down
10 changes: 8 additions & 2 deletions snpdb/models/models_vcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,16 @@ def cohort_genotype_collection(self):
return self.vcf.cohort.cohort_genotype_collection

def get_genotype(self, variant: Variant) -> 'SampleGenotype':
from snpdb.models import CohortGenotype

cgc = self.cohort_genotype_collection
collections = [cgc]
if cgc.common_collection:
collections.append(cgc.common_collection)
try:
cg = self.cohort_genotype_collection.cohortgenotype_set.get(variant=variant)
cg = CohortGenotype.objects.filter(collection__in=collections).get(variant=variant)
sample_genotype = cg.get_sample_genotype(self)
except ObjectDoesNotExist:
except CohortGenotype.DoesNotExist:
sample_genotype = None
return sample_genotype

Expand Down

0 comments on commit 87cf5a9

Please sign in to comment.