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

Allow filtering variant experiment by sample #1399

Merged
merged 3 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
2 changes: 1 addition & 1 deletion resolwe_bio/processes/import_data/geneset.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

def parse_geneset_file(geneset_file, warning):
"""Parse geneset file."""
with open(geneset_file, "rU") as handle:
with open(geneset_file, "r") as handle:
# skip empty lines
genes = [str(line.strip()) for line in handle if line.strip()]
geneset = sorted(set(genes))
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
Loading