1
|
|
|
import abc |
|
|
|
|
2
|
|
|
import re |
|
|
|
|
3
|
|
|
from dataclasses import dataclass |
4
|
|
|
from typing import Sequence, Set, Optional |
5
|
|
|
|
6
|
|
|
from pocketutils.tools.common_tools import CommonTools |
|
|
|
|
7
|
|
|
|
8
|
|
|
from mandos.model.pubchem_api import PubchemApi |
9
|
|
|
from mandos.search.pubchem import PubchemHit, PubchemSearch |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
@dataclass(frozen=True, order=True, repr=True) |
|
|
|
|
13
|
|
|
class TrialHit(PubchemHit): |
14
|
|
|
phase: float |
15
|
|
|
status: str |
16
|
|
|
interventions: str |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
class TrialSearch(PubchemSearch[TrialHit]): |
|
|
|
|
20
|
|
|
"""""" |
21
|
|
|
|
22
|
|
|
@property |
23
|
|
|
def data_source(self) -> str: |
|
|
|
|
24
|
|
|
return "ClinicalTrials.gov" |
25
|
|
|
|
26
|
|
|
def __init__( |
|
|
|
|
27
|
|
|
self, |
|
|
|
|
28
|
|
|
key: str, |
|
|
|
|
29
|
|
|
api: PubchemApi, |
|
|
|
|
30
|
|
|
min_phase: Optional[float], |
|
|
|
|
31
|
|
|
statuses: Optional[Set[str]], |
|
|
|
|
32
|
|
|
require_compound_as_intervention: bool, |
|
|
|
|
33
|
|
|
): |
34
|
|
|
super().__init__(key, api) |
35
|
|
|
self.min_phase = min_phase |
36
|
|
|
self.statuses = statuses |
37
|
|
|
self.require_compound_as_intervention = require_compound_as_intervention |
38
|
|
|
|
39
|
|
|
def find(self, inchikey: str) -> Sequence[TrialHit]: |
|
|
|
|
40
|
|
|
data = self.api.fetch_data(inchikey) |
41
|
|
|
hits = [] |
42
|
|
|
for dd in data.drug_and_medication_information.clinical_trials: |
|
|
|
|
43
|
|
|
if self.min_phase is not None and dd.mapped_phase < self.min_phase: |
44
|
|
|
continue |
45
|
|
|
if self.statuses is not None and dd.mapped_status not in self.statuses: |
46
|
|
|
continue |
47
|
|
|
if self.require_compound_as_intervention and data.name not in { |
48
|
|
|
s.lower() for s in dd.interventions |
|
|
|
|
49
|
|
|
}: |
50
|
|
|
continue |
51
|
|
|
for did, condition in CommonTools.zip_list(dd.disease_ids, dd.conditions): |
52
|
|
|
hits.append( |
53
|
|
|
TrialHit( |
54
|
|
|
record_id=dd.ctid, |
55
|
|
|
compound_id=str(data.cid), |
56
|
|
|
origin_inchikey=inchikey, |
57
|
|
|
matched_inchikey=data.names_and_identifiers.inchikey, |
58
|
|
|
compound_name=data.name, |
59
|
|
|
predicate=f"was a {dd.mapped_status} {dd.mapped_phase} trial intervention for", |
|
|
|
|
60
|
|
|
object_id=did, |
61
|
|
|
object_name=condition, |
62
|
|
|
search_key=self.key, |
63
|
|
|
search_class=self.search_class, |
64
|
|
|
data_source=self.data_source, |
65
|
|
|
phase=dd.mapped_phase, |
66
|
|
|
status=dd.mapped_status, |
67
|
|
|
interventions=" || ".join(dd.interventions), |
68
|
|
|
) |
69
|
|
|
) |
70
|
|
|
return hits |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
__all__ = ["TrialHit", "TrialSearch"] |
74
|
|
|
|