1
|
|
|
import abc |
|
|
|
|
2
|
|
|
from dataclasses import dataclass |
3
|
|
|
from typing import Sequence, Set, Optional |
|
|
|
|
4
|
|
|
|
5
|
|
|
from pocketutils.tools.common_tools import CommonTools |
|
|
|
|
6
|
|
|
|
7
|
|
|
from mandos.model.pubchem_api import PubchemApi |
8
|
|
|
from mandos.model.pubchem_support.pubchem_models import ClinicalTrialsGovUtils |
|
|
|
|
9
|
|
|
from mandos.search.pubchem import PubchemHit, PubchemSearch |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
@dataclass(frozen=True, order=True, repr=True) |
|
|
|
|
13
|
|
|
class ComputedPropertyHit(PubchemHit): |
14
|
|
|
pass |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
class ComputedPropertySearch(PubchemSearch[ComputedPropertyHit]): |
|
|
|
|
18
|
|
|
"""""" |
19
|
|
|
|
20
|
|
|
def __init__(self, key: str, api: PubchemApi, descriptors: Set[str], source: str): |
21
|
|
|
super().__init__(key, api) |
22
|
|
|
self.api = api |
23
|
|
|
self.descriptors = descriptors |
24
|
|
|
self.source = source |
25
|
|
|
|
26
|
|
|
@property |
27
|
|
|
def data_source(self) -> str: |
|
|
|
|
28
|
|
|
return self.source |
29
|
|
|
|
30
|
|
|
def find(self, inchikey: str) -> Sequence[ComputedPropertyHit]: |
|
|
|
|
31
|
|
|
data = self.api.fetch_data(inchikey) |
32
|
|
|
results = [] |
33
|
|
|
# we're really not going to have a case where there are two keys -- |
34
|
|
|
# one with different capitalization or punctuation |
35
|
|
|
descriptors = {self._standardize_key(s) for s in self.descriptors} |
36
|
|
|
for dd in data.chemical_and_physical_properties.computed: |
|
|
|
|
37
|
|
|
if self._standardize_key(dd.key) in descriptors: |
38
|
|
|
results.append( |
39
|
|
|
ComputedPropertyHit( |
40
|
|
|
record_id=None, |
41
|
|
|
compound_id=str(data.cid), |
42
|
|
|
origin_inchikey=inchikey, |
43
|
|
|
matched_inchikey=data.names_and_identifiers.inchikey, |
44
|
|
|
compound_name=data.name, |
45
|
|
|
predicate="has " + dd.key.lower(), |
46
|
|
|
object_id=dd.value, |
47
|
|
|
object_name=dd.value, |
48
|
|
|
search_key=self.key, |
49
|
|
|
search_class=self.search_class, |
50
|
|
|
data_source=self.data_source, |
51
|
|
|
) |
52
|
|
|
) |
53
|
|
|
return results |
54
|
|
|
|
55
|
|
|
def _standardize_key(self, key: str) -> str: |
|
|
|
|
56
|
|
|
return key.replace(" ", "").replace("-", "").replace("_", "").replace(".", "").lower() |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
__all__ = ["ComputedPropertyHit", "ComputedPropertySearch"] |
60
|
|
|
|