Commit 77df3e6f authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion
Browse files

add upsert method to genes API

parent 3997c0ad
import pandas as pd
from django.core.exceptions import ObjectDoesNotExist
from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
from rest_framework import status
......@@ -50,6 +51,21 @@ class GeneViewSet(ModelViewSet):
def get_permissions(self):
return super(self.__class__, self).get_permissions()
def create(self, request, *args, **kwargs):
Overload create to behave like an upsert method.
serializer = self.get_serializer(
gene_obj = self.queryset.get('gene_id'))
serializer = self.get_serializer(gene_obj,
except ObjectDoesNotExist:
serializer = self.get_serializer(
headers = self.get_success_headers(
return Response(, status=status.HTTP_201_CREATED, headers=headers)
def _count_windows(self, df, window_size=10000, window_col=GENE_LENGTH_COL):
Count how many line of the df belong to each windows defined by the window_size for the window_col
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