Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filtering Variant by VariantCall and VariantExperiment #1395

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Unreleased

Added
-----
- Add filtering ``Variant`` by ``VariantExperiment`` and ``VariantCall``

Changed
-------
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
INSTALLED_APPS=(
"django.contrib.auth",
"django.contrib.contenttypes",
"resolwe.observers",
"resolwe.permissions",
"resolwe.flow",
"resolwe.observers",
"resolwe.storage",
"resolwe_bio",
),
Expand Down
4 changes: 3 additions & 1 deletion resolwe_bio/variants/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ class Meta:
"annotation__dbsnp_id": TEXT_LOOKUPS,
"annotation__clinvar_id": TEXT_LOOKUPS,
"annotation__data": RELATED_LOOKUPS,
"variant_calls": RELATED_LOOKUPS,
"variant_calls__quality": NUMBER_LOOKUPS,
"variant_calls__depth": NUMBER_LOOKUPS,
"variant_calls__sample__slug": TEXT_LOOKUPS,
"variant_calls__sample": RELATED_LOOKUPS,
"variant_calls__experiment": RELATED_LOOKUPS,
"variant_calls__filter": TEXT_LOOKUPS,
"variant_calls__genotype": TEXT_LOOKUPS,
"variant_calls__genotype_quality": NUMBER_LOOKUPS,
Expand Down Expand Up @@ -112,7 +114,7 @@ class Meta:
"variant__position": NUMBER_LOOKUPS,
"variant__reference": TEXT_LOOKUPS,
"variant__alternative": TEXT_LOOKUPS,
"experiment__id": NUMBER_LOOKUPS,
"experiment": RELATED_LOOKUPS,
"quality": NUMBER_LOOKUPS,
"depth": NUMBER_LOOKUPS,
"filter": TEXT_LOOKUPS,
Expand Down
27 changes: 23 additions & 4 deletions resolwe_bio/variants/tests/test_variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ def test_filter(self):
status_code=status.HTTP_400_BAD_REQUEST,
)

# Filter by sample.
request = APIRequestFactory().get(
"/variant", {"variant_calls__sample__in": [self.sample.pk]}
)
Expand Down Expand Up @@ -826,29 +827,47 @@ def test_filter(self):
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertCountEqual(response.data, expected)

# Filter by variant call
request = APIRequestFactory().get(
"/variant", {"variant_calls": self.calls[0].pk}
)
response = self.view(request)
expected = VariantSerializer(self.variants[:1], many=True).data
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertCountEqual(response.data, expected)

# Filter by experiment
request = APIRequestFactory().get(
"/variant", {"variant_calls__experiment": self.experiments[0].pk}
)
response = self.view(request)
expected = VariantSerializer(self.variants[:1], many=True).data
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertCountEqual(response.data, expected)

def test_filter_sample_by_variant(self):
client = APIClient()
path = reverse("resolwebio-api:entity-list")

# Anonymous user, no perms.
response = response = client.get(
path, {"variant_calls__variant": self.calls[0].pk}
path, {"variant_calls__variant": self.variants[0].pk}
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data, [])

# Contributor, no perms.
client.force_authenticate(user=self.contributor)
response = response = client.get(
path, {"variant_calls__variant": self.calls[0].pk}
path, {"variant_calls__variant": self.variants[0].pk}
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data, [])

# Permission granted.
self.sample.set_permission(Permission.VIEW, self.contributor)
response = response = client.get(
path, {"variant_calls__variant": self.calls[0].pk}
path, {"variant_calls__variant": self.variants[0].pk}
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
response.data[0].pop("current_user_permissions")
Expand Down Expand Up @@ -1225,7 +1244,7 @@ def test_filter(self):

# Filter by experiment id.
request = APIRequestFactory().get(
"/variantcall", {"experiment__id": self.experiments[0].id}
"/variantcall", {"experiment": self.experiments[0].id}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this in a separate commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have merged two commits together.

)
force_authenticate(request, self.contributor)
expected = VariantCallSerializer(self.calls[:1], many=True).data
Expand Down
Loading