Passed
Push — main ( ddff4b...7b3fbc )
by Douglas
04:33
created

G2pInteractionSearch.find()   A

Complexity

Conditions 2

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
from dataclasses import dataclass
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
from typing import Sequence
3
4
from mandos.model.apis.g2p_data import G2pData, G2pInteraction
5
6
from mandos.search.g2p import G2pSearch, G2pHit
7
8
9
@dataclass(frozen=True, order=True, repr=True)
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
10
class G2pInteractionHit(G2pHit):
11
    """ """
12
13
    action: str
14
    selective: str
15
    primary: str
16
    endogenous: str
17
    species: str
18
    affinity: float
19
    measurement: str
20
21
22
class G2pInteractionSearch(G2pSearch[G2pInteractionHit]):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
23
    """ """
24
25
    @property
26
    def data_source(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
27
        return "G2P :: interactions"
28
29
    def find(self, inchikey: str) -> Sequence[G2pInteractionHit]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
30
        ligand = self.api.fetch(inchikey)
31
        results = []
32
        for inter in ligand.interactions:
33
            results.append(self.process(inchikey, ligand, inter))
34
        return results
35
36
    def process(self, inchikey: str, ligand: G2pData, inter: G2pInteraction) -> G2pInteractionHit:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
37
        return self._create_hit(
38
            c_origin=inchikey,
39
            c_matched=ligand.inchikey,
40
            c_id=str(ligand.g2pid),
41
            c_name=ligand.name,
42
            predicate=f"interaction:{inter.action}",
43
            statement=f"{inter.action} at",
44
            object_id=inter.target_id,
45
            object_name=inter.target,
46
            action=inter.action,
47
            affinity=inter.affinity_median,
48
            measurement=inter.affinity_units,
49
            species=inter.target_species,
50
            primary=str(inter.primary_target),
51
            selective=str(inter.selectivity),
52
            endogenous=str(inter.endogenous),
53
        )
54
55
56
__all__ = ["G2pInteractionHit", "G2pInteractionSearch"]
57