-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
739 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
User | ||
BaseModel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
yeastregulatorydb/regulatory_data/api/filters/RankResponseFilter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import django_filters | ||
|
||
from ...models import RankResponse | ||
|
||
|
||
class RankResponseFilter(django_filters.FilterSet): | ||
id = django_filters.NumberFilter() | ||
pk = django_filters.NumberFilter() | ||
promotersetsig_id = django_filters.NumberFilter(field_name="promotersetsig__id") | ||
binding_source = django_filters.CharFilter( | ||
field_name="promotersetsig__binding__source__name", lookup_expr="iexact" | ||
) | ||
expression_id = django_filters.NumberFilter(field_name="expression__id") | ||
expression_source = django_filters.CharFilter(field_name="expression__source__name", lookup_expr="iexact") | ||
regulator_locus_tag = django_filters.CharFilter( | ||
field_name="expression__regulator__locus_tag", lookup_expr="iexact" | ||
) | ||
regulator_symbol = django_filters.CharFilter(field_name="expression__regulator__symbol", lookup_expr="iexact") | ||
expression_effect_threshold = django_filters.NumberFilter() | ||
expression_pvalue_threshold = django_filters.NumberFilter() | ||
normalized = django_filters.BooleanFilter() | ||
|
||
class Meta: | ||
model = RankResponse | ||
fields = [ | ||
"id", | ||
"pk", | ||
"promotersetsig_id", | ||
"binding_source", | ||
"expression_id", | ||
"expression_source", | ||
"regulator_locus_tag", | ||
"regulator_symbol", | ||
"expression_effect_threshold", | ||
"expression_pvalue_threshold", | ||
"normalized", | ||
] |
6 changes: 1 addition & 5 deletions
6
yeastregulatorydb/regulatory_data/api/serializers/PromoterSetSigSerializer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
yeastregulatorydb/regulatory_data/api/serializers/RankResponseSerializer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from rest_framework import serializers | ||
|
||
from ...models import RankResponse | ||
from .mixins.CustomValidateMixin import CustomValidateMixin | ||
from .mixins.FileValidationMixin import FileValidationMixin | ||
|
||
|
||
class RankResponseSerializer(CustomValidateMixin, FileValidationMixin, serializers.ModelSerializer): | ||
uploader = serializers.ReadOnlyField(source="uploader.username") | ||
modifier = serializers.CharField(source="uploader.username", required=False) | ||
|
||
class Meta: | ||
model = RankResponse | ||
fields = "__all__" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
yeastregulatorydb/regulatory_data/api/views/RankResponseViewSet.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import tempfile | ||
|
||
import pandas as pd | ||
from django.http import HttpResponse | ||
from django_filters.rest_framework import DjangoFilterBackend | ||
from rest_framework import status, viewsets | ||
from rest_framework.authentication import SessionAuthentication, TokenAuthentication | ||
from rest_framework.decorators import action | ||
from rest_framework.permissions import IsAuthenticated | ||
from rest_framework.response import Response | ||
|
||
from ...models import RankResponse | ||
from ...utils.extract_file_from_storage import extract_file_from_storage | ||
from ..filters.RankResponseFilter import RankResponseFilter | ||
from ..serializers.RankResponseSerializer import RankResponseSerializer | ||
from .mixins.UpdateModifiedMixin import UpdateModifiedMixin | ||
|
||
|
||
class RankResponseViewSet(UpdateModifiedMixin, viewsets.ModelViewSet): | ||
""" | ||
A viewset for viewing and editing RankResponse instances. | ||
""" | ||
|
||
queryset = RankResponse.objects.all() | ||
authentication_classes = [SessionAuthentication, TokenAuthentication] | ||
permission_classes = [IsAuthenticated] | ||
serializer_class = RankResponseSerializer | ||
filter_backends = [DjangoFilterBackend] | ||
filterset_class = RankResponseFilter | ||
|
||
@action(detail=False, methods=["get"]) | ||
def summary(self, request, *args, **kwargs): | ||
if "rank_response_id" not in request.query_params: | ||
return Response({"error": "rank_response_id must be specified"}, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
filtered_queryset = self.filter_queryset(self.get_queryset()) | ||
if len(filtered_queryset) != 1: | ||
return Response( | ||
{ | ||
"error": "rank_response_summary returned multiple matches to your query. There should only be 1. " | ||
"Contact our admin -- this message shouldn't appear -- but in the meantime, " | ||
"re-submit with only the `rank_response_id` as a paramater" | ||
}, | ||
status=status.HTTP_400_BAD_REQUEST, | ||
) | ||
with tempfile.TemporaryDirectory() as tmpdir: | ||
for rank_response_record in filtered_queryset: | ||
# Iterate over the filtered queryset | ||
filepath = extract_file_from_storage(rank_response_record.file, tmpdir) | ||
df = pd.read_csv(filepath, compression="gzip") | ||
|
||
with tempfile.NamedTemporaryFile(suffix=".gz") as tmpfile: | ||
df.to_csv(tmpfile.name, compression="gzip", index=False) | ||
tmpfile.seek(0) | ||
response = HttpResponse(tmpfile, content_type="application/gzip") | ||
response["Content-Disposition"] = "attachment; filename=rank_response_summary.csvgz" | ||
return response |
Oops, something went wrong.