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

use KEGGAPI instead of TOGOWS from dabeplech to retrieve KEGG details

parent 7f8fbe98
Pipeline #35410 passed with stages
in 3 minutes and 12 seconds
......@@ -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)()
......@@ -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