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
0120036a
Commit
0120036a
authored
Nov 14, 2019
by
Kenzo-Hugo Hillion
♻
Browse files
replace endpoint by class to call different external APIs
parent
9d65ac11
Changes
7
Hide whitespace changes
Inline
Side-by-side
backend/metagenedb/api/catalog/views/function.py
View file @
0120036a
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
get_kegg
from
.bulk_viewset
import
BulkViewSet
...
...
@@ -10,3 +13,8 @@ class FunctionViewSet(BulkViewSet):
serializer_class
=
FunctionSerializer
lookup_field
=
'function_id'
filterset_class
=
FunctionFilter
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
instance
=
self
.
get_object
()
serializer
=
self
.
get_serializer
(
instance
)
return
Response
(
serializer
.
data
)
backend/metagenedb/api/external/urls.py
deleted
100644 → 0
View file @
9d65ac11
from
django.urls
import
path
from
metagenedb.api.external.views
import
KeggInfoTogows
urlpatterns
=
[
path
(
r
'togows/<kegg_id>'
,
KeggInfoTogows
.
as_view
(),
name
=
'kegg-info'
),
]
backend/metagenedb/api/external/views/__init__.py
deleted
100644 → 0
View file @
9d65ac11
from
.togows
import
KeggInfoTogows
# noqa
backend/metagenedb/api/external/views/togows.py
deleted
100644 → 0
View file @
9d65ac11
from
bioapi.togows
import
TogoWSEntryAPI
from
requests.exceptions
import
HTTPError
from
rest_framework.views
import
APIView
from
rest_framework.response
import
Response
from
rest_framework.status
import
(
HTTP_200_OK
,
HTTP_404_NOT_FOUND
)
class
KeggInfoTogows
(
APIView
):
"""
Obtain detailed information about KEGG orthology entry.
"""
def
get
(
self
,
request
,
kegg_id
=
None
):
"""
Return a list of all users.
"""
kegg_api
=
TogoWSEntryAPI
(
"kegg-orthology"
)
try
:
content
=
kegg_api
.
get
(
kegg_id
)[
0
]
status
=
HTTP_200_OK
except
HTTPError
as
http_err
:
content
=
[{
'error'
:
str
(
http_err
)}]
status
=
HTTP_404_NOT_FOUND
return
Response
(
content
,
status
=
status
)
backend/metagenedb/api/urls.py
View file @
0120036a
...
...
@@ -3,6 +3,5 @@ from django.urls import include, path
urlpatterns
=
[
path
(
'auth/'
,
include
((
'metagenedb.api.accounts.urls'
,
'auth'
))),
path
(
'catalog/'
,
include
((
'metagenedb.api.catalog.urls'
,
'catalog'
))),
path
(
'external/'
,
include
((
'metagenedb.api.external.urls'
,
'external'
)))
path
(
'catalog/'
,
include
((
'metagenedb.api.catalog.urls'
,
'catalog'
)))
]
backend/metagenedb/
api
/external/__init__.py
→
backend/metagenedb/
common/utils
/external
_api
/__init__.py
View file @
0120036a
File moved
backend/metagenedb/common/utils/external_api/togows.py
0 → 100644
View file @
0120036a
import
logging
from
bioapi.togows
import
TogoWSEntryAPI
logger
=
logging
.
getLogger
(
__name__
)
class
GetFunctionExternalInfo
:
def
__init__
(
self
,
function_id
,
source
):
self
.
function_id
=
function_id
self
.
source
=
source
def
_get_unknown_source
(
self
):
logger
.
warning
(
"No source of information for %s from %s"
%
(
self
.
function_id
,
self
.
source
))
return
{}
def
_get_kegg
(
self
):
"""
Get detailed information from KEGG orthology through Togows.
"""
kegg_api
=
TogoWSEntryAPI
(
"kegg-orthology"
)
return
kegg_api
.
get
(
self
.
function_id
)[
0
]
def
get_details
(
self
):
return
getattr
(
self
,
f
"_get_
{
self
.
source
}
"
,
self
.
_get_unknown_source
)()
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