Commit 8bfe6c63 authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion
Browse files

add filter on presence absence of tax and functions

parent a2e8a22c
Pipeline #19067 passed with stages
in 2 minutes and 19 seconds
from .function import FunctionFilter # noqa
from .gene import GeneFilter # noqa
from .taxonomy import TaxonomyFilter # noqa
from django_filters import rest_framework as filters
from metagenedb.apps.catalog.models import Gene
class GeneFilter(filters.FilterSet):
no_taxonomy = filters.BooleanFilter(field_name='taxonomy', lookup_expr="isnull")
no_functions = filters.BooleanFilter(field_name='functions', lookup_expr="isnull")
class Meta:
model = Gene
fields = ['taxonomy', 'functions']
from marshmallow import Schema, fields
from metagenedb.common.django_default.qparams_validators import PaginatedQueryParams
class GeneLengthQueryParams(Schema):
window_size = fields.Integer()
stop_at = fields.Integer()
class GeneQueryParams(PaginatedQueryParams):
no_taxonomy = fields.Boolean()
no_functions = fields.Boolean()
......@@ -2,13 +2,13 @@ from django_pandas.io import read_frame
from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
from marshmallow.exceptions import ValidationError
from rest_framework import filters
from rest_framework.decorators import action
from rest_framework.response import Response
from rest_framework.status import HTTP_204_NO_CONTENT, HTTP_422_UNPROCESSABLE_ENTITY
from metagenedb.apps.catalog.models import Gene
from metagenedb.api.catalog.qparams_validators.gene import GeneLengthQueryParams
from metagenedb.api.catalog.filters import GeneFilter
from metagenedb.api.catalog.qparams_validators.gene import GeneLengthQueryParams, GeneQueryParams
from metagenedb.apps.catalog.serializers import GeneSerializer
from metagenedb.common.utils.df_operations import get_mask
......@@ -46,11 +46,12 @@ class DocGeneLength(object):
class GeneViewSet(BulkViewSet):
search_fields = ['gene_name']
filter_backends = (filters.SearchFilter,)
queryset = Gene.objects.select_related('taxonomy').prefetch_related('functions').all()
serializer_class = GeneSerializer
filterset_class = GeneFilter
query_params_parser = GeneQueryParams
lookup_field = 'gene_id'
GENE_LENGTH_COL = 'length'
DEFAULT_WINDOW_SIZE = 1000
DEFAULT_STOP_AT = 10000
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment