togows.py 1.04 KB
Newer Older
1
2
import logging

3
4
from django.conf import settings

5
from dabeplech.togows import TogoWSEntryAPI
6
7
8
9
10
11
12
13
14
15
16
17


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):
18
        raise NotImplementedError("No source of information for %s from %s" % (self.function_id, self.source))
19
20
21
22
23
24

    def _get_kegg(self):
        """
        Get detailed information from KEGG orthology through Togows.
        """
        kegg_api = TogoWSEntryAPI("kegg-orthology")
25
26
27
28
29
30
        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
31
32

    def get_details(self):
33
        logger.info("Retrieving information from KEGG through togows")
34
        return getattr(self, f"_get_{self.source}", self._get_unknown_source)()