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

DataValidityComment.resolve()   B

Complexity

Conditions 6

Size

Total Lines 16
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 15
nop 2
dl 0
loc 16
rs 8.6666
c 0
b 0
f 0
1
from __future__ import annotations
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
import enum
3
from dataclasses import dataclass
4
from typing import Set, Union
5
6
from mandos.model import CleverEnum, CompoundNotFoundError
7
8
9
class ChemblCompoundLookupError(CompoundNotFoundError):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
10
    """ """
11
12
13
class ActivityRelation(CleverEnum):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
14
    lt = enum.auto()
15
    gt = enum.auto()
16
    le = enum.auto()
17
    ge = enum.auto()
18
    eq = enum.auto()
19
    approx = enum.auto()
20
21
    @classmethod
22
    def of(cls, name: Union[int, str]) -> CleverEnum:
0 ignored issues
show
Bug introduced by
Parameters differ from overridden 'of' method
Loading history...
23
        return super().of(
24
            {
25
                "<": "lt",
26
                ">": "gt",
27
                "=": "eq",
28
                "~": "approx",
29
                "<=": "le",
30
                ">=": "ge",
31
            }.get(name, name)
32
        )
33
34
35
class DataValidityComment(CleverEnum):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
36
    potential_missing_data = enum.auto()
37
    potential_transcription_error = enum.auto()
38
    potential_author_error = enum.auto()
39
    manually_validated = enum.auto()
40
    outside_typical_range = enum.auto()
41
    non_standard_unit_for_type = enum.auto()
42
    author_confirmed_error = enum.auto()
43
44
    @classmethod
45
    def resolve(cls, st: str) -> Set[DataValidityComment]:
0 ignored issues
show
Coding Style Naming introduced by
Argument name "st" 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...
46
        found = set()
47
        for s in st.lower().split(","):
0 ignored issues
show
Coding Style Naming introduced by
Variable name "s" 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...
48
            s = s.strip()
0 ignored issues
show
Coding Style Naming introduced by
Variable name "s" 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...
49
            if s == "@all":
50
                return set(cls)
51
            if s == "@negative":
52
                match = DataValidityComment.negative_comments()
53
            elif s == "@positive":
54
                match = DataValidityComment.positive_comments()
55
            else:
56
                match = {DataValidityComment.of(s)}
57
            for m in match:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "m" 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...
58
                found.add(m)
59
        return found
60
61
    @property
62
    def is_positive(self) -> bool:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
63
        return self in DataValidityComment.positive_comments()
64
65
    @property
66
    def is_negative(self) -> bool:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
67
        return self in DataValidityComment.negative_comments()
68
69
    @classmethod
70
    def positive_comments(cls) -> Set[DataValidityComment]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
71
        return {DataValidityComment.manually_validated}
72
73
    @classmethod
74
    def negative_comments(cls) -> Set[DataValidityComment]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
75
        return {
76
            DataValidityComment.potential_missing_data,
77
            DataValidityComment.potential_transcription_error,
78
            DataValidityComment.potential_author_error,
79
            DataValidityComment.outside_typical_range,
80
            DataValidityComment.non_standard_unit_for_type,
81
            DataValidityComment.author_confirmed_error,
82
        }
83
84
85
@dataclass(frozen=True, order=True, repr=True)
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
86
class ChemblCompound:
87
    """ """
88
89
    chid: str
90
    inchikey: str
91
    name: str
92
93
94
class AssayType(enum.Enum):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
95
    binding = enum.auto()
96
    functional = enum.auto()
97
    adme = enum.auto()
98
    physicochemical = enum.auto()
99
100
    @property
101
    def character(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
102
        return {
103
            AssayType.binding: "B",
104
            AssayType.functional: "F",
105
            AssayType.adme: "A",
106
            AssayType.physicochemical: "P",
107
        }[self]
108
109
110
__all__ = [
111
    "ChemblCompound",
112
    "ChemblCompoundLookupError",
113
    "DataValidityComment",
114
    "ActivityRelation",
115
    "AssayType",
116
]
117