Passed
Push — dependabot/pip/flake8-bugbear-... ( 16d864...b4f9fc )
by
unknown
01:45
created

TrialHit.predicate()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
import abc
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
Unused Code introduced by
The import abc seems to be unused.
Loading history...
2
import re
0 ignored issues
show
Unused Code introduced by
The import re seems to be unused.
Loading history...
3
from dataclasses import dataclass
4
from typing import Sequence, Set, Optional
5
6
from pocketutils.tools.common_tools import CommonTools
0 ignored issues
show
introduced by
Unable to import 'pocketutils.tools.common_tools'
Loading history...
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)
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
13
class TrialHit(PubchemHit):
14
    phase: float
15
    status: str
16
    interventions: str
17
18
19
class TrialSearch(PubchemSearch[TrialHit]):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
20
    """"""
21
22
    @property
23
    def data_source(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
24
        return "ClinicalTrials.gov"
25
26
    def __init__(
0 ignored issues
show
best-practice introduced by
Too many arguments (6/5)
Loading history...
27
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
28
        key: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
29
        api: PubchemApi,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
30
        min_phase: Optional[float],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
31
        statuses: Optional[Set[str]],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
32
        require_compound_as_intervention: bool,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
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]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
40
        data = self.api.fetch_data(inchikey)
41
        hits = []
42
        for dd in data.drug_and_medication_information.clinical_trials:
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...
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
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
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",
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (103/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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