Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
metagenedb
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Metagenomics
metagenedb
Commits
0e823d06
Commit
0e823d06
authored
5 years ago
by
Kenzo-Hugo Hillion
♻️
Browse files
Options
Downloads
Patches
Plain Diff
create custom API documentation for gene_length endpoint
parent
7fb4d79e
No related branches found
No related tags found
2 merge requests
!59
Prod
,
!10
Generate Documentation for the backend API
Pipeline
#13632
failed
5 years ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
backend/metagenedb/api/catalog/views/gene.py
+39
-12
39 additions, 12 deletions
backend/metagenedb/api/catalog/views/gene.py
with
39 additions
and
12 deletions
backend/metagenedb/api/catalog/views/gene.py
+
39
−
12
View file @
0e823d06
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
,
ModelViewSet
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
from
rest_framework.permissions
import
IsAdminUser
from
rest_framework.response
import
Response
from
rest_framework.response
import
Response
from
rest_framework.viewsets
import
ModelViewSet
from
metagenedb.common.utils.df_operations
import
get_mask
from
metagenedb.common.utils.df_operations
import
get_mask
from
metagenedb.apps.catalog.models
import
Gene
from
metagenedb.apps.catalog.models
import
Gene
from
metagenedb.apps.catalog.serializers
import
GeneSerializer
from
metagenedb.apps.catalog.serializers
import
GeneSerializer
# Define global variable for API documentation
class
DocGeneLength
(
object
):
window_size_param
=
openapi
.
Parameter
(
'
window_size
'
,
in_
=
openapi
.
IN_QUERY
,
description
=
'
Size of the window.
'
,
"""
type
=
openapi
.
TYPE_INTEGER
,
default
=
10000
)
Define response for API documentation of gene length distribution method
# 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)
"
results
"
: {
"
counts
"
: [
0,
887,
],
"
labels
"
: [
"
0-9999
"
,
"
10000-19999
"
,
"
20000-29999
"
,
]
}
}
"""
window_size_param
=
openapi
.
Parameter
(
'
window_size
'
,
in_
=
openapi
.
IN_QUERY
,
description
=
'
Size of the window.
'
,
type
=
openapi
.
TYPE_INTEGER
,
default
=
10000
)
counts
=
openapi
.
Schema
(
type
=
"
array
"
,
items
=
openapi
.
Schema
(
type
=
"
int
"
),
description
=
"
Counts for every window_size
"
)
labels
=
openapi
.
Schema
(
type
=
"
array
"
,
items
=
openapi
.
Schema
(
type
=
"
char
"
),
description
=
"
Corresponding windows
"
)
results
=
openapi
.
Schema
(
type
=
"
object
"
,
properties
=
{
'
counts
'
:
counts
,
'
labels
'
:
labels
},
description
=
"
results of your request
"
)
gene_length_schema
=
openapi
.
Schema
(
type
=
"
object
"
,
properties
=
{
'
results
'
:
results
})
gene_length_response
=
openapi
.
Response
(
'
Get the distribution of gene length for a given window size
'
,
schema
=
gene_length_schema
)
class
GeneViewSet
(
ModelViewSet
):
class
GeneViewSet
(
ModelViewSet
):
...
@@ -25,6 +47,11 @@ class GeneViewSet(ModelViewSet):
...
@@ -25,6 +47,11 @@ class GeneViewSet(ModelViewSet):
serializer_class
=
GeneSerializer
serializer_class
=
GeneSerializer
GENE_LENGTH_COL
=
'
length
'
GENE_LENGTH_COL
=
'
length
'
def
get_permissions
(
self
):
if
self
.
action
==
'
create
'
:
self
.
permission_classes
=
[
IsAdminUser
,
]
return
super
(
self
.
__class__
,
self
).
get_permissions
()
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
...
@@ -45,12 +72,12 @@ class GeneViewSet(ModelViewSet):
...
@@ -45,12 +72,12 @@ class GeneViewSet(ModelViewSet):
}
}
@swagger_auto_schema
(
@swagger_auto_schema
(
manual_parameters
=
[
window_size_param
],
manual_parameters
=
[
DocGeneLength
.
window_size_param
],
responses
=
{
responses
=
{
#
'200': gene_length_response,
'
200
'
:
DocGeneLength
.
gene_length_response
,
'
204
'
:
'
no content
'
'
204
'
:
'
No genes on the catalog to build the distribution
'
},
},
operation_id
=
'
List of categories
'
,
operation_id
=
'
Gene length distribution
'
,
)
)
@action
(
methods
=
[
'
get
'
],
detail
=
False
)
@action
(
methods
=
[
'
get
'
],
detail
=
False
)
def
gene_length
(
self
,
request
,
window_size
=
10000
):
def
gene_length
(
self
,
request
,
window_size
=
10000
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment