Commit 25dd11af authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion
Browse files

Merge branch '145-replace-togows-by-dabeplech' into 'dev'

replace TOGOWS by KEGGAPI from dabeplech

Closes #145

See merge request !66
parents 676fc92d 557a134f
Pipeline #35425 passed with stages
in 4 minutes and 6 seconds
from django.urls import path
from django.conf.urls import url, include
from django.conf.urls import include
from django.urls import re_path
from rest_framework.routers import DefaultRouter, DynamicRoute, Route
from metagenedb.api.catalog import views
......@@ -64,7 +65,7 @@ api_router.register(r'statistics', views.StatisticsViewSet, basename='statistics
urlpatterns = [
url(r'v1/', include((api_router.urls, 'v1'))),
re_path(r'v1/', include((api_router.urls, 'v1'))),
path('admin/', include(('metagenedb.api.catalog.admin_urls', 'admin'))),
path('celery-task-test/', test_task_view, name='celery-task-test'),
]
......@@ -14,11 +14,11 @@ class TestGetFunctionExternalInfo(TestCase):
external_info_retriever.get_details()
def test_get_details_kegg(self):
with mock.patch('metagenedb.common.utils.external_api.togows.TogoWSEntryAPI') as MockTogoWSEntryAPI:
MockTogoWSEntryAPI.return_value.get.return_value = [{"info": "some_info"}]
with mock.patch('metagenedb.common.utils.external_api.togows.KEGGAPI') as MockKEGGAPI:
MockKEGGAPI.return_value.get.return_value.dict.return_value = {"info": "some_info"}
test_url = "http://test.com/"
test_id = "test_kegg_id"
MockTogoWSEntryAPI.return_value.url = test_url
MockKEGGAPI.return_value.url = test_url
expected_dict = {
'info': 'some_info',
settings.API_KEY_ADDITIONAL_INFO: {
......
......@@ -2,7 +2,7 @@ import logging
from django.conf import settings
from dabeplech.togows import TogoWSEntryAPI
from dabeplech import KEGGAPI
logger = logging.getLogger(__name__)
......@@ -21,8 +21,9 @@ class GetFunctionExternalInfo:
"""
Get detailed information from KEGG orthology through Togows.
"""
kegg_api = TogoWSEntryAPI("kegg-orthology")
response = kegg_api.get(self.function_id)[0]
logger.info("Retrieving information from KEGG API")
kegg_api = KEGGAPI()
response = kegg_api.get(self.function_id).dict()
response[settings.API_KEY_ADDITIONAL_INFO] = {
'comment': f"Information retrieved from external source: {kegg_api.url}",
'url': f"{kegg_api.url}{self.function_id}"
......@@ -30,5 +31,4 @@ class GetFunctionExternalInfo:
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)()
from unittest import TestCase
import pandas as pd
from pandas.util.testing import assert_series_equal
from pandas.testing import assert_series_equal
from metagenedb.common.utils.df_operations import get_mask
......
......@@ -14,12 +14,11 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import include, path
from django.conf.urls import url
from django.urls import include, path, re_path
urlpatterns = [
path('api/', include(('metagenedb.api.urls', 'api'))),
path('admin/', admin.site.urls),
url(r'^ht/', include('health_check.urls')),
re_path(r'^ht/', include('health_check.urls')),
]
......@@ -5,6 +5,7 @@ services:
container_name: backend
build:
context: ./backend
image: metagenedb-backend
volumes:
- ./backend:/code
- django-static:/backend/public/static
......@@ -73,13 +74,13 @@ services:
celery:
container_name: celery
build:
context: ./backend
image: metagenedb-backend
volumes:
- ./backend:/code
depends_on:
- postgresql
- redis
- backend
command: bash -c 'manage.py watch_celery'
networks:
- main
......
......@@ -69,7 +69,6 @@ export default {
this.buildPathways(response),
this.buildDiseases(response),
this.buildModules(response),
this.buildReferences(response),
];
},
buildPathways(response) {
......@@ -78,17 +77,19 @@ export default {
icon: 'fas fa-bezier-curve',
content: [],
};
Object.entries(response.data.pathways).forEach(([key, value]) => {
pathways.content.push(
{
id: key,
name: value,
url: `https://www.genome.jp/kegg-bin/show_pathway?${key}+${this.keggId}`,
url_label: "Open in KEGG",
fetch: true,
},
);
});
if(response.data.pathways) {
Object.entries(response.data.pathways).forEach(([key, value]) => {
pathways.content.push(
{
id: key,
name: value,
url: `https://www.genome.jp/kegg-bin/show_pathway?${key}+${this.keggId}`,
url_label: "Open in KEGG",
fetch: true,
},
);
});
}
return pathways;
},
buildModules(response) {
......@@ -97,16 +98,18 @@ export default {
icon: 'fas fa-bezier-curve',
content: [],
};
Object.entries(response.data.modules).forEach(([key, value]) => {
modules.content.push(
{
id: key,
name: value,
url: `https://www.genome.jp/kegg-bin/show_module?${key}+${this.keggId}`,
url_label: "Open in KEGG"
},
);
});
if(response.data.modules) {
Object.entries(response.data.modules).forEach(([key, value]) => {
modules.content.push(
{
id: key,
name: value,
url: `https://www.genome.jp/kegg-bin/show_module?${key}+${this.keggId}`,
url_label: "Open in KEGG"
},
);
});
}
return modules;
},
buildDiseases(response) {
......@@ -115,15 +118,17 @@ export default {
icon: 'fas fa-laptop-medical',
content: [],
};
Object.entries(response.data.diseases).forEach(([key, value]) => {
diseases.content.push(
{
id: key,
name: value,
url: `https://www.genome.jp/dbget-bin/www_bget?ds:${key}`,
},
);
});
if(response.data.diseases) {
Object.entries(response.data.diseases).forEach(([key, value]) => {
diseases.content.push(
{
id: key,
name: value,
url: `https://www.genome.jp/dbget-bin/www_bget?ds:${key}`,
},
);
});
}
return diseases;
},
buildReferences(response) {
......@@ -132,16 +137,18 @@ export default {
icon: 'fas fa-book-open',
content: [],
};
for (let i = 0; i < response.data.references.length; i++) {
references.content.push(
{
id: response.data.references[i].title,
name: `${response.data.references[i].authors[0]} et al. ${response.data.references[i].journal}`,
url: `https://www.ncbi.nlm.nih.gov/pubmed/${response.data.references[i].pubmed}`,
url_label: "Open in Pubmed"
},
);
};
if (response.data.references) {
for (let i = 0; i < response.data.references.length; i++) {
references.content.push(
{
id: response.data.references[i].title,
name: `${response.data.references[i].authors[0]} et al. ${response.data.references[i].journal}`,
url: `https://www.ncbi.nlm.nih.gov/pubmed/${response.data.references[i].pubmed}`,
url_label: "Open in Pubmed"
},
);
};
}
return references;
},
},
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment