Skip to content

Commit

Permalink
Extend zygosity filters
Browse files Browse the repository at this point in the history
  • Loading branch information
landoskape committed Oct 26, 2023
1 parent 59d0512 commit 840f43e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions alyx/subjects/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,26 @@ def lookups(self, request, model_admin):
(None, 'All'),
('p', 'All positive'),
('h', 'All homo'),
('n', 'All negative'),
('e', 'All het')
)

def queryset(self, request, queryset):
if self.value() is None:
return queryset.all()
elif self.value() in ('p', 'h'):
elif self.value() in ('p', 'h', 'n', 'e'):
# Only keep subjects with a non-null geontype.
queryset = queryset.filter(genotype__isnull=False).distinct()
# Exclude subjects that have a specific zygosity/
d = dict(zygosity=0) if self.value() == 'p' else dict(zygosity__in=(0, 1, 3))
# Exclude subjects that have a specific zygosity
# See alyx/alyx/subjects/models.py - ZYGOSITY_TYPES for explanation
if self.value() == 'p':
d = dict(zygosity=0)
elif self.value() == 'h':
d = dict(zygosity__in=(0, 1, 3))
elif self.value() == 'n':
d = dict(zygosity__in=(1, 2, 3))
else:
d = dict(zygosity__in=(0, 2, 3))
nids = set([z.subject.id.hex for z in Zygosity.objects.filter(**d)])
return queryset.exclude(pk__in=nids)

Expand Down

0 comments on commit 840f43e

Please sign in to comment.