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
from django.core.exceptions import ObjectDoesNotExist
from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
from rest_framework import status
......@@ -51,21 +50,6 @@ 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
from .togows import TogoWSEntry # noqa
import logging
import requests
from abc import ABC
from urllib.parse import urljoin
_LOGGER = logging.getLogger(__name__)
class MetageneDB(ABC):
BASE_URL = 'http://localhost/'
ROUTE = ''
'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)
return response.json()
def get(self, gene_id):
full_url = urljoin(self.url, gene_id)
response = requests.get(full_url)
return response.json()
def post(self, data):
response ="{self.url}", json=data, headers=self.HEADERS)
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)
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