Commit 197b32bd authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion
Browse files

start class to contact metagenedb api

parent 77df3e6f
import pandas as pd import pandas as pd
from django.core.exceptions import ObjectDoesNotExist
from drf_yasg import openapi from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema from drf_yasg.utils import swagger_auto_schema
from rest_framework import status from rest_framework import status
...@@ -51,21 +50,6 @@ class GeneViewSet(ModelViewSet): ...@@ -51,21 +50,6 @@ class GeneViewSet(ModelViewSet):
def get_permissions(self): def get_permissions(self):
return super(self.__class__, self).get_permissions() 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(data=request.data)
try:
gene_obj = self.queryset.get(gene_id=request.data.get('gene_id'))
serializer = self.get_serializer(gene_obj, data=request.data)
except ObjectDoesNotExist:
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
self.perform_create(serializer)
headers = self.get_success_headers(serializer.data)
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
def _count_windows(self, df, window_size=10000, window_col=GENE_LENGTH_COL): 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 Count how many line of the df belong to each windows defined by the window_size for the window_col
......
from .togows import TogoWSEntry # noqa
import logging
import requests
from abc import ABC
from urllib.parse import urljoin
logging.basicConfig(level=logging.INFO)
_LOGGER = logging.getLogger(__name__)
class MetageneDB(ABC):
BASE_URL = 'http://localhost/'
ROUTE = ''
HEADERS = {
'Content-type': 'application/json',
'Accept': '*/*'
}
def __init__(self, base_url=BASE_URL):
self.url = urljoin(base_url, self.ROUTE)
class MetageneDBCatalogGene(MetageneDB):
ROUTE = 'api/catalog/v1/genes/'
def get_genes(self):
response = requests.get(self.url)
response.raise_for_status()
return response.json()
def get(self, gene_id):
full_url = urljoin(self.url, gene_id)
response = requests.get(full_url)
response.raise_for_status()
return response.json()
def post(self, data):
response = requests.post(f"{self.url}", json=data, headers=self.HEADERS)
response.raise_for_status()
return response.json()
def put(self, gene_id, data):
full_url = urljoin(self.url, gene_id)
response = requests.put(f"{full_url}/", json=data, headers=self.HEADERS)
response.raise_for_status()
return response.json()
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