1
|
|
|
from __future__ import annotations |
|
|
|
|
2
|
|
|
|
3
|
|
|
import logging |
4
|
|
|
from dataclasses import dataclass |
5
|
|
|
from typing import Sequence |
6
|
|
|
|
7
|
|
|
from pocketutils.core.dot_dict import NestedDotDict |
|
|
|
|
8
|
|
|
|
9
|
|
|
from mandos.model import AbstractHit, ChemblCompound, Search |
10
|
|
|
|
11
|
|
|
logger = logging.getLogger("mandos") |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
@dataclass(frozen=True, order=True, repr=True) |
15
|
|
|
class IndicationHit(AbstractHit): |
16
|
|
|
""" |
17
|
|
|
An indication with a MESH term. |
18
|
|
|
""" |
19
|
|
|
|
20
|
|
|
max_phase: int |
21
|
|
|
|
22
|
|
|
@property |
23
|
|
|
def predicate(self) -> str: |
24
|
|
|
return f"phase-{self.max_phase} indication" |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
class IndicationSearch(Search[IndicationHit]): |
|
|
|
|
28
|
|
|
"""""" |
29
|
|
|
|
30
|
|
|
def find(self, lookup: str) -> Sequence[IndicationHit]: |
31
|
|
|
""" |
32
|
|
|
|
33
|
|
|
Args: |
34
|
|
|
lookup: |
35
|
|
|
|
36
|
|
|
Returns: |
37
|
|
|
|
38
|
|
|
""" |
39
|
|
|
# 'atc_classifications': ['S01HA01', 'N01BC01', 'R02AD03', 'S02DA02'] |
40
|
|
|
# 'indication_class': 'Anesthetic (topical)' |
41
|
|
|
ch = self.get_compound_dot_dict(lookup) |
|
|
|
|
42
|
|
|
compound = self.compound_dot_dict_to_obj(ch) |
43
|
|
|
inds = self.api.drug_indication.filter(parent_molecule_chembl_id=compound.chid) |
44
|
|
|
hits = [] |
45
|
|
|
for ind in inds: |
46
|
|
|
if ind.req_as("max_phase_for_ind", int) >= self.config.min_phase: |
47
|
|
|
hits.append(self.process(lookup, compound, ind)) |
48
|
|
|
return hits |
49
|
|
|
|
50
|
|
|
def process( |
|
|
|
|
51
|
|
|
self, lookup: str, compound: ChemblCompound, indication: NestedDotDict |
|
|
|
|
52
|
|
|
) -> IndicationHit: |
53
|
|
|
""" |
54
|
|
|
|
55
|
|
|
Args: |
56
|
|
|
lookup: |
57
|
|
|
compound: |
58
|
|
|
indication: |
59
|
|
|
|
60
|
|
|
Returns: |
61
|
|
|
|
62
|
|
|
""" |
63
|
|
|
return IndicationHit( |
64
|
|
|
indication.req_as("drugind_id", str), |
65
|
|
|
compound.chid, |
66
|
|
|
compound.inchikey, |
67
|
|
|
lookup, |
68
|
|
|
compound.name, |
69
|
|
|
object_id=indication.req_as("mesh_id", str), |
70
|
|
|
object_name=indication.req_as("mesh_heading", str).strip("\n"), |
71
|
|
|
max_phase=indication.req_as("max_phase_for_ind", int), |
72
|
|
|
) |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
__all__ = ["IndicationHit", "IndicationSearch"] |
76
|
|
|
|