Skip to content
Snippets Groups Projects
Commit bf4feb29 authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion :recycle:
Browse files

use KEGGAPI instead of TOGOWS from dabeplech to retrieve KEGG details

parent 7f8fbe98
No related branches found
No related tags found
1 merge request!66replace TOGOWS by KEGGAPI from dabeplech
Pipeline #35410 passed
...@@ -14,11 +14,11 @@ class TestGetFunctionExternalInfo(TestCase): ...@@ -14,11 +14,11 @@ class TestGetFunctionExternalInfo(TestCase):
external_info_retriever.get_details() external_info_retriever.get_details()
def test_get_details_kegg(self): def test_get_details_kegg(self):
with mock.patch('metagenedb.common.utils.external_api.togows.TogoWSEntryAPI') as MockTogoWSEntryAPI: with mock.patch('metagenedb.common.utils.external_api.togows.KEGGAPI') as MockKEGGAPI:
MockTogoWSEntryAPI.return_value.get.return_value = [{"info": "some_info"}] MockKEGGAPI.return_value.get.return_value.dict.return_value = {"info": "some_info"}
test_url = "http://test.com/" test_url = "http://test.com/"
test_id = "test_kegg_id" test_id = "test_kegg_id"
MockTogoWSEntryAPI.return_value.url = test_url MockKEGGAPI.return_value.url = test_url
expected_dict = { expected_dict = {
'info': 'some_info', 'info': 'some_info',
settings.API_KEY_ADDITIONAL_INFO: { settings.API_KEY_ADDITIONAL_INFO: {
......
...@@ -2,7 +2,7 @@ import logging ...@@ -2,7 +2,7 @@ import logging
from django.conf import settings from django.conf import settings
from dabeplech.togows import TogoWSEntryAPI from dabeplech import KEGGAPI
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -21,8 +21,9 @@ class GetFunctionExternalInfo: ...@@ -21,8 +21,9 @@ class GetFunctionExternalInfo:
""" """
Get detailed information from KEGG orthology through Togows. Get detailed information from KEGG orthology through Togows.
""" """
kegg_api = TogoWSEntryAPI("kegg-orthology") logger.info("Retrieving information from KEGG API")
response = kegg_api.get(self.function_id)[0] kegg_api = KEGGAPI()
response = kegg_api.get(self.function_id).dict()
response[settings.API_KEY_ADDITIONAL_INFO] = { response[settings.API_KEY_ADDITIONAL_INFO] = {
'comment': f"Information retrieved from external source: {kegg_api.url}", 'comment': f"Information retrieved from external source: {kegg_api.url}",
'url': f"{kegg_api.url}{self.function_id}" 'url': f"{kegg_api.url}{self.function_id}"
...@@ -30,5 +31,4 @@ class GetFunctionExternalInfo: ...@@ -30,5 +31,4 @@ class GetFunctionExternalInfo:
return response return response
def get_details(self): def get_details(self):
logger.info("Retrieving information from KEGG through togows")
return getattr(self, f"_get_{self.source}", self._get_unknown_source)() return getattr(self, f"_get_{self.source}", self._get_unknown_source)()
...@@ -69,7 +69,6 @@ export default { ...@@ -69,7 +69,6 @@ export default {
this.buildPathways(response), this.buildPathways(response),
this.buildDiseases(response), this.buildDiseases(response),
this.buildModules(response), this.buildModules(response),
this.buildReferences(response),
]; ];
}, },
buildPathways(response) { buildPathways(response) {
...@@ -78,6 +77,7 @@ export default { ...@@ -78,6 +77,7 @@ export default {
icon: 'fas fa-bezier-curve', icon: 'fas fa-bezier-curve',
content: [], content: [],
}; };
if(response.data.pathways) {
Object.entries(response.data.pathways).forEach(([key, value]) => { Object.entries(response.data.pathways).forEach(([key, value]) => {
pathways.content.push( pathways.content.push(
{ {
...@@ -89,6 +89,7 @@ export default { ...@@ -89,6 +89,7 @@ export default {
}, },
); );
}); });
}
return pathways; return pathways;
}, },
buildModules(response) { buildModules(response) {
...@@ -97,6 +98,7 @@ export default { ...@@ -97,6 +98,7 @@ export default {
icon: 'fas fa-bezier-curve', icon: 'fas fa-bezier-curve',
content: [], content: [],
}; };
if(response.data.modules) {
Object.entries(response.data.modules).forEach(([key, value]) => { Object.entries(response.data.modules).forEach(([key, value]) => {
modules.content.push( modules.content.push(
{ {
...@@ -107,6 +109,7 @@ export default { ...@@ -107,6 +109,7 @@ export default {
}, },
); );
}); });
}
return modules; return modules;
}, },
buildDiseases(response) { buildDiseases(response) {
...@@ -115,6 +118,7 @@ export default { ...@@ -115,6 +118,7 @@ export default {
icon: 'fas fa-laptop-medical', icon: 'fas fa-laptop-medical',
content: [], content: [],
}; };
if(response.data.diseases) {
Object.entries(response.data.diseases).forEach(([key, value]) => { Object.entries(response.data.diseases).forEach(([key, value]) => {
diseases.content.push( diseases.content.push(
{ {
...@@ -124,6 +128,7 @@ export default { ...@@ -124,6 +128,7 @@ export default {
}, },
); );
}); });
}
return diseases; return diseases;
}, },
buildReferences(response) { buildReferences(response) {
...@@ -132,6 +137,7 @@ export default { ...@@ -132,6 +137,7 @@ export default {
icon: 'fas fa-book-open', icon: 'fas fa-book-open',
content: [], content: [],
}; };
if (response.data.references) {
for (let i = 0; i < response.data.references.length; i++) { for (let i = 0; i < response.data.references.length; i++) {
references.content.push( references.content.push(
{ {
...@@ -142,6 +148,7 @@ export default { ...@@ -142,6 +148,7 @@ export default {
}, },
); );
}; };
}
return references; return references;
}, },
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment