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
db3f33e9
Commit
db3f33e9
authored
Nov 15, 2019
by
Kenzo-Hugo Hillion
♻
Browse files
add detailed option for function API
parent
eaa9d70a
Pipeline
#18285
passed with stages
in 2 minutes and 22 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
backend/metagenedb/api/catalog/views/function.py
View file @
db3f33e9
import
logging
from
rest_framework.response
import
Response
from
metagenedb.api.catalog.filters
import
FunctionFilter
from
metagenedb.apps.catalog.models
import
Function
from
metagenedb.apps.catalog.serializers
import
FunctionSerializer
from
metagenedb.common.utils.external_api.togows
import
GetFunctionExternalInfo
from
.bulk_viewset
import
BulkViewSet
logger
=
logging
.
getLogger
(
__name__
)
class
FunctionViewSet
(
BulkViewSet
):
queryset
=
Function
.
objects
.
all
()
serializer_class
=
FunctionSerializer
lookup_field
=
'function_id'
filterset_class
=
FunctionFilter
def
_get_external_info
(
self
,
db_data
):
detailed_info_retriever
=
GetFunctionExternalInfo
(
db_data
[
'function_id'
],
db_data
[
'source'
])
detailed_data
=
detailed_info_retriever
.
get_details
()
# @TODO check consistency?
return
detailed_data
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
instance
=
self
.
get_object
()
serializer
=
self
.
get_serializer
(
instance
)
return
Response
(
serializer
.
data
)
returned_data
=
serializer
.
data
if
request
.
query_params
.
get
(
'detailed'
,
None
):
returned_data
=
self
.
_get_external_info
(
returned_data
)
return
Response
(
returned_data
)
backend/metagenedb/api/catalog/views/test_function.py
0 → 100644
View file @
db3f33e9
backend/metagenedb/common/utils/external_api/test_togows.py
0 → 100644
View file @
db3f33e9
backend/metagenedb/common/utils/external_api/togows.py
View file @
db3f33e9
import
logging
from
django.conf
import
settings
from
bioapi.togows
import
TogoWSEntryAPI
...
...
@@ -21,7 +23,13 @@ class GetFunctionExternalInfo:
Get detailed information from KEGG orthology through Togows.
"""
kegg_api
=
TogoWSEntryAPI
(
"kegg-orthology"
)
return
kegg_api
.
get
(
self
.
function_id
)[
0
]
response
=
kegg_api
.
get
(
self
.
function_id
)[
0
]
response
[
settings
.
API_KEY_ADDITIONAL_INFO
]
=
{
'comment'
:
f
"Information retrieved from external source:
{
kegg_api
.
url
}
"
,
'url'
:
f
"
{
kegg_api
.
url
}{
self
.
function_id
}
"
}
return
response
def
get_details
(
self
):
logger
.
info
(
"Retrieving information from KEGG through togows"
)
return
getattr
(
self
,
f
"_get_
{
self
.
source
}
"
,
self
.
_get_unknown_source
)()
backend/metagenedb/settings/django.py
View file @
db3f33e9
...
...
@@ -146,3 +146,6 @@ STATIC_ROOT = public_root('static')
STATIC_URL
=
env
.
str
(
'STATIC_URL'
,
default
=
'/static/'
)
SECRET_KEY
=
env
.
str
(
'SECRET_KEY'
,
default
=
''
)
# -- key for API when additional information is added to the payload
API_KEY_ADDITIONAL_INFO
=
env
.
str
(
'API_KEY_ADDITIONAL_INFO'
,
default
=
'metagenedb_additional_info'
)
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