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

mandos.search.pubchem.bioactivity_search   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 61
dl 0
loc 77
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A BioactivitySearch.data_source() 0 3 1
A BioactivitySearch.find() 0 6 2
A BioactivitySearch.process() 0 19 1
A BioactivitySearch.__init__() 0 17 1
1
from dataclasses import dataclass
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
from typing import Sequence, Optional, Set
3
4
from mandos.model.pubchem_api import PubchemApi
5
from mandos.model.pubchem_support.pubchem_data import PubchemData
6
from mandos.model.pubchem_support.pubchem_models import Activity, AssayType, Bioactivity
7
from mandos.search.pubchem import PubchemHit, PubchemSearch
8
9
10
@dataclass(frozen=True, order=True, repr=True)
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
11
class BioactivityHit(PubchemHit):
12
    """"""
13
14
    activity: str
15
    confirmatory: bool
16
    micromolar: float
17
    relation: str
18
    compound_name_in_assay: str
19
    referrer: str
20
21
22
class BioactivitySearch(PubchemSearch[BioactivityHit]):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
23
    """"""
24
25
    def __init__(
0 ignored issues
show
best-practice introduced by
Too many arguments (9/5)
Loading history...
26
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
27
        key: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
28
        api: PubchemApi,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
29
        answers: Set[Activity],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
30
        assay_types: Set[AssayType],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
31
        min_micromolar: Optional[float],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
32
        max_micromolar: Optional[float],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
33
        relations: Set[str],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
34
        compound_name_must_match: bool,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
35
    ):
36
        super().__init__(key, api)
37
        self.answers = answers
38
        self.assay_types = assay_types
39
        self.min_micromolar, self.max_micromolar = min_micromolar, max_micromolar
40
        self.relations = relations
41
        self.compound_name_must_match = compound_name_must_match
42
43
    @property
44
    def data_source(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
45
        return "PubChem"
46
47
    def find(self, inchikey: str) -> Sequence[BioactivityHit]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
48
        data = self.api.fetch_data(inchikey)
49
        results = []
50
        for dd in data.biological_test_results.bioactivity:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "dd" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
51
            results.append(self.process(inchikey, data, dd))
52
        return results
53
54
    def process(self, inchikey: str, data: PubchemData, dd: Bioactivity) -> BioactivityHit:
0 ignored issues
show
Coding Style Naming introduced by
Argument name "dd" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
introduced by
Missing function or method docstring
Loading history...
55
        return BioactivityHit(
56
            record_id=None,
57
            origin_inchikey=inchikey,
58
            matched_inchikey=data.names_and_identifiers.inchikey,
59
            compound_id=str(data.cid),
60
            compound_name=data.name,
61
            predicate=f"bioactivity",
0 ignored issues
show
introduced by
Using an f-string that does not have any interpolated variables
Loading history...
62
            object_id=dd.gene_id,
63
            object_name=dd.target_name,
64
            search_key=self.key,
65
            search_class=self.search_class,
66
            data_source=self.data_source + " : " + dd.assay_ref,
67
            activity=dd.activity.name.lower(),
68
            confirmatory=dd.assay_type is AssayType.confirmatory,
69
            micromolar=dd.activity_value,
70
            relation=dd.activity_name,
71
            compound_name_in_assay=dd.compound_name,
72
            referrer=dd.assay_ref,
73
        )
74
75
76
__all__ = ["BioactivityHit", "BioactivitySearch"]
77