Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Metagenomics
metagenedb
Commits
317bb154
Commit
317bb154
authored
Jun 17, 2020
by
Kenzo-Hugo Hillion
♻
Browse files
allow retrieving fasta file from gene list
parent
74c3f349
Pipeline
#32449
passed with stages
in 3 minutes and 25 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
backend/metagenedb/api/catalog/qparams_validators/gene.py
View file @
317bb154
...
...
@@ -14,3 +14,4 @@ class GeneQueryParams(PaginatedQueryParams):
tax_id
=
fields
.
Integer
()
function
=
fields
.
String
()
source
=
fields
.
String
()
fasta
=
fields
.
Boolean
()
backend/metagenedb/api/catalog/views/gene.py
View file @
317bb154
from
io
import
StringIO
from
django.http
import
HttpResponse
from
drf_yasg.utils
import
swagger_auto_schema
from
marshmallow.exceptions
import
ValidationError
from
rest_framework.response
import
Response
from
rest_framework.status
import
HTTP_422_UNPROCESSABLE_ENTITY
from
metagenedb.apps.catalog.models
import
Gene
from
metagenedb.api.catalog.filters
import
GeneFilter
...
...
@@ -18,8 +24,26 @@ class GeneViewSet(BulkViewSet):
@
swagger_auto_schema
(
tags
=
[
'Genes'
],
)
def
list
(
self
,
*
args
,
**
kwargs
):
return
super
().
list
(
*
args
,
**
kwargs
)
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
try
:
query_params
=
self
.
query_params_parser
().
load
(
request
.
query_params
)
except
ValidationError
as
validation_error
:
error_message
=
validation_error
.
normalized_messages
()
error_message
.
update
({
'allowed_query_params'
:
', '
.
join
(
self
.
query_params_parser
().
declared_fields
.
keys
())
})
return
Response
(
error_message
,
status
=
HTTP_422_UNPROCESSABLE_ENTITY
)
if
query_params
.
get
(
'fasta'
,
False
)
is
True
:
queryset
=
self
.
filter_queryset
(
self
.
get_queryset
())
fasta_file
=
StringIO
()
for
gene
in
queryset
.
iterator
():
fasta_file
.
write
(
gene
.
fasta
)
# generate the file
response
=
HttpResponse
(
fasta_file
.
getvalue
(),
content_type
=
'text/fasta'
)
filename
=
'metagenedb_sequences.fasta'
response
[
'Content-Disposition'
]
=
'attachment; filename=%s'
%
filename
return
response
return
super
().
list
(
request
,
*
args
,
**
kwargs
)
@
swagger_auto_schema
(
tags
=
[
'Genes'
],
...
...
backend/metagenedb/apps/catalog/models/gene.py
View file @
317bb154
...
...
@@ -28,6 +28,10 @@ class Gene(models.Model):
def
__str__
(
self
):
return
self
.
gene_id
@
property
def
fasta
(
self
):
return
f
">
{
self
.
gene_id
}
\n
{
self
.
sequence
}
\n
"
class
Meta
:
ordering
=
[
'-gene_id'
]
...
...
docker-compose.yaml
View file @
317bb154
...
...
@@ -21,7 +21,7 @@ services:
postgresql
:
container_name
:
postgresql
image
:
postgres:11.4-alpine
shm_size
:
'
2
gb'
shm_size
:
'
8
gb'
ports
:
-
"
5433:5432"
volumes
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment