Skip to content

Commit

Permalink
Allow filtering variant experiment by sample
Browse files Browse the repository at this point in the history
and use generic filter for filtering by related models with respect to
permissions
  • Loading branch information
gregorjerse committed Dec 5, 2024
1 parent da08199 commit eeb0a15
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 57 deletions.
14 changes: 10 additions & 4 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ All notable changes to this project are documented in this file.
This project adheres to `Semantic Versioning <http://semver.org/>`_.


==========
Unreleased
==========

Added
-----
- Add filtering ``Variant`` by ``VariantExperiment`` and ``VariantCall``
- Use generic permission filters when filtering variants by related models


===================
61.0.0 - 2024-11-21
===================
Expand All @@ -20,10 +30,6 @@ Changed
60.0.0 - 2024-11-19
===================

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

Changed
-------
- **BACKWARD INCOMPATIBLE:** Require Resolwe 41.x
Expand Down
90 changes: 41 additions & 49 deletions resolwe_bio/variants/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
"""

import django_filters as filters

from resolwe.flow.filters import (
DATETIME_LOOKUPS,
NUMBER_LOOKUPS,
RELATED_LOOKUPS,
TEXT_LOOKUPS,
CheckQueryParamsMixin,
BaseResolweFilter,
DataFilter,
FilterRelatedWithPermissions,
)

from resolwe_bio.variants.models import (
Expand All @@ -24,9 +24,42 @@
)


class VariantFilter(CheckQueryParamsMixin, filters.FilterSet):
class VariantCallFilter(BaseResolweFilter):
"""Filter the VariantCall objects endpoint."""

data = FilterRelatedWithPermissions(DataFilter)

class Meta:
"""Filter configuration."""

model = VariantCall
fields = {
"id": NUMBER_LOOKUPS,
"sample__slug": TEXT_LOOKUPS,
"sample": RELATED_LOOKUPS,
"variant": RELATED_LOOKUPS,
"variant__species": TEXT_LOOKUPS,
"variant__genome_assembly": TEXT_LOOKUPS,
"variant__chromosome": TEXT_LOOKUPS,
"variant__position": NUMBER_LOOKUPS,
"variant__reference": TEXT_LOOKUPS,
"variant__alternative": TEXT_LOOKUPS,
"experiment": RELATED_LOOKUPS,
"quality": NUMBER_LOOKUPS,
"depth": NUMBER_LOOKUPS,
"filter": TEXT_LOOKUPS,
"genotype": TEXT_LOOKUPS,
"genotype_quality": NUMBER_LOOKUPS,
"alternative_allele_depth": NUMBER_LOOKUPS,
"depth_norm_quality": NUMBER_LOOKUPS,
}


class VariantFilter(BaseResolweFilter):
"""Filter the Variant objects endpoint."""

variant_calls = FilterRelatedWithPermissions(VariantCallFilter)

class Meta:
"""Filter configuration."""

Expand All @@ -51,18 +84,6 @@ class Meta:
"annotation__clinical_significance": TEXT_LOOKUPS,
"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,
"variant_calls__alternative_allele_depth": NUMBER_LOOKUPS,
"variant_calls__depth_norm_quality": NUMBER_LOOKUPS,
}

@property
Expand All @@ -72,7 +93,7 @@ def qs(self):
return parent.distinct()


class VariantAnnotationFilter(CheckQueryParamsMixin, filters.FilterSet):
class VariantAnnotationFilter(BaseResolweFilter):
"""Filter the VariantAnnotation objects endpoint."""

class Meta:
Expand All @@ -94,40 +115,11 @@ class Meta:
}


class VariantCallFilter(CheckQueryParamsMixin, filters.FilterSet):
"""Filter the VariantCall objects endpoint."""

class Meta:
"""Filter configuration."""

model = VariantCall
fields = {
"id": NUMBER_LOOKUPS,
"sample__slug": TEXT_LOOKUPS,
"sample": RELATED_LOOKUPS,
"data__slug": TEXT_LOOKUPS,
"data": RELATED_LOOKUPS,
"variant": RELATED_LOOKUPS,
"variant__species": TEXT_LOOKUPS,
"variant__genome_assembly": TEXT_LOOKUPS,
"variant__chromosome": TEXT_LOOKUPS,
"variant__position": NUMBER_LOOKUPS,
"variant__reference": TEXT_LOOKUPS,
"variant__alternative": TEXT_LOOKUPS,
"experiment": RELATED_LOOKUPS,
"quality": NUMBER_LOOKUPS,
"depth": NUMBER_LOOKUPS,
"filter": TEXT_LOOKUPS,
"genotype": TEXT_LOOKUPS,
"genotype_quality": NUMBER_LOOKUPS,
"alternative_allele_depth": NUMBER_LOOKUPS,
"depth_norm_quality": NUMBER_LOOKUPS,
}


class VariantExperimentFilter(CheckQueryParamsMixin, filters.FilterSet):
class VariantExperimentFilter(BaseResolweFilter):
"""Filter the VariantExperiment objects endpoint."""

variant_calls = FilterRelatedWithPermissions(VariantCallFilter)

class Meta:
"""Filter configuration."""

Expand Down
Loading

0 comments on commit eeb0a15

Please sign in to comment.