Commit 7fb4d79e authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion
Browse files

change name gene length to length

parent 65ee2b07
Pipeline #13610 failed with stages
in 1 minute and 37 seconds
import pandas as pd
import django_filters.rest_framework
from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
from rest_framework.viewsets import GenericViewSet
from rest_framework.viewsets import GenericViewSet, ModelViewSet
from rest_framework import mixins
from rest_framework import status
from rest_framework.decorators import action
......@@ -15,16 +16,14 @@ from metagenedb.apps.catalog.serializers import GeneSerializer
# Define global variable for API documentation
window_size_param = openapi.Parameter('window_size', in_=openapi.IN_QUERY, description='Size of the window.',
type=openapi.TYPE_INTEGER, default=10000)
gene_length_schema = openapi.Schema("pouet", {}, type={'hihi': 'haha'})
gene_length_response = openapi.Response('Get the distribution of gene length for a given window size', schema=gene_length_schema)
# gene_length_schema = openapi.Schema("pouet", {}, type={'hihi': 'haha'})
# gene_length_response = openapi.Response('Get the distribution of gene length for a given window size', schema=gene_length_schema)
class GeneViewSet(mixins.ListModelMixin,
mixins.RetrieveModelMixin,
GenericViewSet):
class GeneViewSet(ModelViewSet):
queryset = Gene.objects.all()
serializer_class = GeneSerializer
GENE_LENGTH_COL = 'gene_length'
GENE_LENGTH_COL = 'length'
def _count_windows(self, df, window_size=10000, window_col=GENE_LENGTH_COL):
"""
......@@ -48,10 +47,9 @@ class GeneViewSet(mixins.ListModelMixin,
@swagger_auto_schema(
manual_parameters=[window_size_param],
responses={
'200': gene_length_response,
# '200': gene_length_response,
'204': 'no content'
},
security=[],
operation_id='List of categories',
)
@action(methods=['get'], detail=False)
......
......@@ -6,7 +6,7 @@ from metagenedb.apps.catalog.models import Gene
@admin.register(Gene)
class GeneAdmin(admin.ModelAdmin):
list_display = ('gene_id', 'gene_length', 'get_functions', 'get_taxonomy')
list_display = ('gene_id', 'length', 'get_functions', 'get_taxonomy')
search_fields = ('gene_id',)
def get_functions(self, obj):
......
# Generated by Django 2.2.1 on 2019-08-07 13:20
# Generated by Django 2.2.1 on 2019-08-07 14:10
from django.db import migrations, models
......@@ -15,4 +15,9 @@ class Migration(migrations.Migration):
name='gene_length',
field=models.PositiveIntegerField(),
),
migrations.RenameField(
model_name='gene',
old_name='gene_length',
new_name='length',
),
]
......@@ -5,7 +5,7 @@ from .function import Function
class Gene(models.Model):
gene_id = models.CharField(max_length=100, unique=True, db_index=True)
gene_length = models.PositiveIntegerField()
length = models.PositiveIntegerField()
functions = models.ManyToManyField(Function)
taxonomy = models.ForeignKey(
'Taxonomy', related_name='genes',
......
......@@ -4,7 +4,7 @@ from metagenedb.apps.catalog.serializers import FunctionSerializer
class GeneSerializer(serializers.ModelSerializer):
functions = FunctionSerializer(many=True, read_only=True)
functions = FunctionSerializer(many=True, required=False)
taxonomy = serializers.SlugRelatedField(
queryset=Taxonomy.objects.all(),
slug_field='tax_id',
......@@ -13,4 +13,4 @@ class GeneSerializer(serializers.ModelSerializer):
class Meta:
model = Gene
fields = ('gene_id', 'gene_length', 'functions', 'taxonomy')
fields = ('gene_id', 'length', 'functions', 'taxonomy')
......@@ -106,7 +106,7 @@ REST_FRAMEWORK = {
# 'rest_framework.authentication.BasicAuthentication',
),
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 100
'PAGE_SIZE': 100,
}
......
......@@ -39,4 +39,5 @@ urlpatterns = [
path('admin/', admin.site.urls),
url(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
url(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
url(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
]
......@@ -41,7 +41,7 @@ http {
}
# backend urls
location ~ ^/(admin|api|swagger|static) {
location ~ ^/(admin|api|swagger|redoc|static) {
proxy_redirect off;
proxy_pass http://backend;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
......
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