Skip to content
Snippets Groups Projects
Commit 7fb4d79e authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion :recycle:
Browse files

change name gene length to length

parent 65ee2b07
No related branches found
No related tags found
2 merge requests!59Prod,!10Generate Documentation for the backend API
Pipeline #13610 failed
import pandas as pd import pandas as pd
import django_filters.rest_framework
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.viewsets import GenericViewSet from rest_framework.viewsets import GenericViewSet, ModelViewSet
from rest_framework import mixins from rest_framework import mixins
from rest_framework import status from rest_framework import status
from rest_framework.decorators import action from rest_framework.decorators import action
...@@ -15,16 +16,14 @@ from metagenedb.apps.catalog.serializers import GeneSerializer ...@@ -15,16 +16,14 @@ from metagenedb.apps.catalog.serializers import GeneSerializer
# Define global variable for API documentation # Define global variable for API documentation
window_size_param = openapi.Parameter('window_size', in_=openapi.IN_QUERY, description='Size of the window.', window_size_param = openapi.Parameter('window_size', in_=openapi.IN_QUERY, description='Size of the window.',
type=openapi.TYPE_INTEGER, default=10000) type=openapi.TYPE_INTEGER, default=10000)
gene_length_schema = openapi.Schema("pouet", {}, type={'hihi': 'haha'}) # 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_response = openapi.Response('Get the distribution of gene length for a given window size', schema=gene_length_schema)
class GeneViewSet(mixins.ListModelMixin, class GeneViewSet(ModelViewSet):
mixins.RetrieveModelMixin,
GenericViewSet):
queryset = Gene.objects.all() queryset = Gene.objects.all()
serializer_class = GeneSerializer 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): def _count_windows(self, df, window_size=10000, window_col=GENE_LENGTH_COL):
""" """
...@@ -48,10 +47,9 @@ class GeneViewSet(mixins.ListModelMixin, ...@@ -48,10 +47,9 @@ class GeneViewSet(mixins.ListModelMixin,
@swagger_auto_schema( @swagger_auto_schema(
manual_parameters=[window_size_param], manual_parameters=[window_size_param],
responses={ responses={
'200': gene_length_response, # '200': gene_length_response,
'204': 'no content' '204': 'no content'
}, },
security=[],
operation_id='List of categories', operation_id='List of categories',
) )
@action(methods=['get'], detail=False) @action(methods=['get'], detail=False)
......
...@@ -6,7 +6,7 @@ from metagenedb.apps.catalog.models import Gene ...@@ -6,7 +6,7 @@ from metagenedb.apps.catalog.models import Gene
@admin.register(Gene) @admin.register(Gene)
class GeneAdmin(admin.ModelAdmin): 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',) search_fields = ('gene_id',)
def get_functions(self, obj): 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 from django.db import migrations, models
...@@ -15,4 +15,9 @@ class Migration(migrations.Migration): ...@@ -15,4 +15,9 @@ class Migration(migrations.Migration):
name='gene_length', name='gene_length',
field=models.PositiveIntegerField(), field=models.PositiveIntegerField(),
), ),
migrations.RenameField(
model_name='gene',
old_name='gene_length',
new_name='length',
),
] ]
...@@ -5,7 +5,7 @@ from .function import Function ...@@ -5,7 +5,7 @@ from .function import Function
class Gene(models.Model): class Gene(models.Model):
gene_id = models.CharField(max_length=100, unique=True, db_index=True) gene_id = models.CharField(max_length=100, unique=True, db_index=True)
gene_length = models.PositiveIntegerField() length = models.PositiveIntegerField()
functions = models.ManyToManyField(Function) functions = models.ManyToManyField(Function)
taxonomy = models.ForeignKey( taxonomy = models.ForeignKey(
'Taxonomy', related_name='genes', 'Taxonomy', related_name='genes',
......
...@@ -4,7 +4,7 @@ from metagenedb.apps.catalog.serializers import FunctionSerializer ...@@ -4,7 +4,7 @@ from metagenedb.apps.catalog.serializers import FunctionSerializer
class GeneSerializer(serializers.ModelSerializer): class GeneSerializer(serializers.ModelSerializer):
functions = FunctionSerializer(many=True, read_only=True) functions = FunctionSerializer(many=True, required=False)
taxonomy = serializers.SlugRelatedField( taxonomy = serializers.SlugRelatedField(
queryset=Taxonomy.objects.all(), queryset=Taxonomy.objects.all(),
slug_field='tax_id', slug_field='tax_id',
...@@ -13,4 +13,4 @@ class GeneSerializer(serializers.ModelSerializer): ...@@ -13,4 +13,4 @@ class GeneSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Gene model = Gene
fields = ('gene_id', 'gene_length', 'functions', 'taxonomy') fields = ('gene_id', 'length', 'functions', 'taxonomy')
...@@ -106,7 +106,7 @@ REST_FRAMEWORK = { ...@@ -106,7 +106,7 @@ REST_FRAMEWORK = {
# 'rest_framework.authentication.BasicAuthentication', # 'rest_framework.authentication.BasicAuthentication',
), ),
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 100 'PAGE_SIZE': 100,
} }
......
...@@ -39,4 +39,5 @@ urlpatterns = [ ...@@ -39,4 +39,5 @@ urlpatterns = [
path('admin/', admin.site.urls), 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(?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'^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 { ...@@ -41,7 +41,7 @@ http {
} }
# backend urls # backend urls
location ~ ^/(admin|api|swagger|static) { location ~ ^/(admin|api|swagger|redoc|static) {
proxy_redirect off; proxy_redirect off;
proxy_pass http://backend; proxy_pass http://backend;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment