Passed
Push — main ( 9ff912...d08a4e )
by Douglas
03:54
created

CgiSearch.find()   A

Complexity

Conditions 1

Size

Total Lines 17
Code Lines 16

Duplication

Lines 17
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 16
nop 2
dl 17
loc 17
rs 9.6
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.pubchem_api import PubchemApi
5
from mandos.search.pubchem import PubchemHit, PubchemSearch
6
7
8
@dataclass(frozen=True, order=True, repr=True)
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
9
class DgiHit(PubchemHit):
10
    """"""
11
12
13
@dataclass(frozen=True, order=True, repr=True)
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
14
class CgiHit(PubchemHit):
15
    """"""
16
17
18 View Code Duplication
class DgiSearch(PubchemSearch[DgiHit]):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Documentation introduced by
Empty class docstring
Loading history...
19
    """"""
20
21
    def __init__(self, key: str, api: PubchemApi):
0 ignored issues
show
introduced by
Useless super delegation in method '__init__'
Loading history...
22
        super().__init__(key, api)
23
24
    @property
25
    def data_source(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
26
        return "The Drug Gene Interaction Database (DGIdb)"
27
28
    def find(self, inchikey: str) -> Sequence[DgiHit]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
29
        data = self.api.fetch_data(inchikey)
30
        return [
31
            DgiHit(
32
                record_id=None,
33
                origin_inchikey=inchikey,
34
                matched_inchikey=data.names_and_identifiers.inchikey,
35
                compound_id=str(data.cid),
36
                compound_name=data.name,
37
                predicate=f"interacts with gene (drug)",
0 ignored issues
show
introduced by
Using an f-string that does not have any interpolated variables
Loading history...
38
                object_id=dd.gene_claim_id,
39
                object_name=dd.gene_name,
40
                search_key=self.key,
41
                search_class=self.search_class,
42
                data_source=self.data_source,
43
            )
44
            for dd in data.biomolecular_interactions_and_pathways.drug_gene_interactions
45
        ]
46
47
48 View Code Duplication
class CgiSearch(PubchemSearch[CgiHit]):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Documentation introduced by
Empty class docstring
Loading history...
49
    """"""
50
51
    def __init__(self, key: str, api: PubchemApi):
0 ignored issues
show
introduced by
Useless super delegation in method '__init__'
Loading history...
52
        super().__init__(key, api)
53
54
    @property
55
    def data_source(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
56
        return "The Drug Gene Interaction Database (DGIdb)"
57
58
    def find(self, inchikey: str) -> Sequence[DgiHit]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
59
        data = self.api.fetch_data(inchikey)
60
        return [
61
            DgiHit(
62
                record_id=None,
63
                origin_inchikey=inchikey,
64
                matched_inchikey=data.names_and_identifiers.inchikey,
65
                compound_id=str(data.cid),
66
                compound_name=data.name,
67
                predicate=f"interacts with gene (compound)",
0 ignored issues
show
introduced by
Using an f-string that does not have any interpolated variables
Loading history...
68
                object_id=dd.gene_name,
69
                object_name=dd.gene_name,
70
                search_key=self.key,
71
                search_class=self.search_class,
72
                data_source=self.data_source,
73
            )
74
            for dd in data.biomolecular_interactions_and_pathways.compound_gene_interactions
75
        ]
76
77
78
__all__ = ["DgiHit", "DgiSearch", "CgiHit", "CgiSearch"]
79