1
|
|
|
import inspect |
|
|
|
|
2
|
|
|
|
3
|
|
|
import decorateme |
|
|
|
|
4
|
|
|
|
5
|
|
|
from mandos.model.apis.caching_pubchem_api import CachingPubchemApi |
6
|
|
|
from mandos.model.apis.chembl_api import ChemblApi |
7
|
|
|
from mandos.model.apis.chembl_scrape_api import ( |
8
|
|
|
CachingChemblScrapeApi, |
9
|
|
|
ChemblScrapeApi, |
10
|
|
|
QueryingChemblScrapeApi, |
11
|
|
|
) |
12
|
|
|
from mandos.model.apis.g2p_api import CachingG2pApi, G2pApi |
13
|
|
|
from mandos.model.apis.hmdb_api import CachingHmdbApi, HmdbApi, QueryingHmdbApi |
14
|
|
|
from mandos.model.apis.pubchem_api import PubchemApi |
15
|
|
|
from mandos.model.apis.pubchem_similarity_api import ( |
16
|
|
|
CachingPubchemSimilarityApi, |
17
|
|
|
QueryingPubchemSimilarityApi, |
18
|
|
|
) |
19
|
|
|
from mandos.model.apis.querying_pubchem_api import QueryingPubchemApi |
20
|
|
|
from mandos.model.apis.similarity_api import SimilarityApi |
21
|
|
|
from mandos.model.utils.setup import logger |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
@decorateme.auto_utils() |
|
|
|
|
25
|
|
|
class Apis: |
26
|
|
|
|
27
|
|
|
Pubchem: PubchemApi = None |
28
|
|
|
Chembl: ChemblApi = None |
29
|
|
|
ChemblScrape: ChemblScrapeApi = None |
30
|
|
|
G2p: G2pApi = None |
31
|
|
|
Hmdb: HmdbApi = None |
32
|
|
|
Similarity: SimilarityApi = None |
33
|
|
|
|
34
|
|
|
@classmethod |
35
|
|
|
def set( |
|
|
|
|
36
|
|
|
cls, |
|
|
|
|
37
|
|
|
*, |
|
|
|
|
38
|
|
|
chembl: ChemblApi, |
|
|
|
|
39
|
|
|
pubchem: PubchemApi, |
|
|
|
|
40
|
|
|
g2p: G2pApi, |
|
|
|
|
41
|
|
|
hmdb: HmdbApi, |
|
|
|
|
42
|
|
|
chembl_scrape: ChemblScrapeApi, |
|
|
|
|
43
|
|
|
similarity: SimilarityApi, |
|
|
|
|
44
|
|
|
) -> None: |
45
|
|
|
cls.Chembl = chembl |
46
|
|
|
cls.Pubchem = pubchem |
47
|
|
|
cls.G2p = g2p |
48
|
|
|
cls.Hmdb = hmdb |
49
|
|
|
cls.ChemblScrape = chembl_scrape |
50
|
|
|
cls.Similarity = similarity |
51
|
|
|
logger.debug("Set custom API singletons") |
52
|
|
|
cls.describe() |
53
|
|
|
|
54
|
|
|
@classmethod |
55
|
|
|
def set_default( |
|
|
|
|
56
|
|
|
cls, |
|
|
|
|
57
|
|
|
*, |
|
|
|
|
58
|
|
|
pubchem: bool = True, |
|
|
|
|
59
|
|
|
chembl: bool = True, |
|
|
|
|
60
|
|
|
hmdb: bool = True, |
|
|
|
|
61
|
|
|
g2p: bool = True, |
|
|
|
|
62
|
|
|
scrape: bool = True, |
|
|
|
|
63
|
|
|
similarity: bool = True, |
|
|
|
|
64
|
|
|
) -> None: |
65
|
|
|
if chembl: |
66
|
|
|
from chembl_webresource_client.new_client import new_client as _Chembl |
|
|
|
|
67
|
|
|
|
68
|
|
|
cls.Chembl = ChemblApi.wrap(_Chembl) |
69
|
|
|
if pubchem: |
70
|
|
|
cls.Pubchem = CachingPubchemApi(QueryingPubchemApi()) |
71
|
|
|
if hmdb: |
72
|
|
|
cls.Hmdb = CachingHmdbApi(QueryingHmdbApi()) |
73
|
|
|
if g2p: |
74
|
|
|
cls.G2p = CachingG2pApi() |
75
|
|
|
if scrape: |
76
|
|
|
cls.ChemblScrape = CachingChemblScrapeApi(QueryingChemblScrapeApi()) |
77
|
|
|
if similarity: |
78
|
|
|
cls.Similarity = CachingPubchemSimilarityApi(QueryingPubchemSimilarityApi()) |
79
|
|
|
logger.debug("Set default singletons") |
80
|
|
|
cls.describe() |
81
|
|
|
|
82
|
|
|
@classmethod |
83
|
|
|
def describe(cls) -> None: |
|
|
|
|
84
|
|
|
for v in [ |
|
|
|
|
85
|
|
|
f" {m} = {getattr(cls, m)}" |
|
|
|
|
86
|
|
|
for m in dir(cls) |
|
|
|
|
87
|
|
|
if m[0].isupper() and not inspect.ismethod(m) |
|
|
|
|
88
|
|
|
]: |
89
|
|
|
logger.debug(v) |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
__all__ = ["Apis"] |
93
|
|
|
|