tests.model.test_targets_real_data   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 136
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 101
dl 0
loc 136
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A TestTargets.test_traverse_gabaa_up_and_down() 0 12 1
A TestTargets.test_traverse_gabaa_up() 0 10 1
A TestTargets.test_traverse_gabaa_up_mouse_2() 0 46 1
A TestTargets.test_traverse_gabaa_up_mouse() 0 41 1
1
from typing import Mapping
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
3
import pytest
0 ignored issues
show
introduced by
Unable to import 'pytest'
Loading history...
4
from chembl_webresource_client.new_client import new_client as Chembl
0 ignored issues
show
introduced by
Unable to import 'chembl_webresource_client.new_client'
Loading history...
5
6
from mandos.chembl_api import ChemblApi, ChemblEntrypoint
0 ignored issues
show
Unused Code introduced by
Unused ChemblApi imported from mandos.chembl_api
Loading history...
Unused Code introduced by
Unused ChemblEntrypoint imported from mandos.chembl_api
Loading history...
7
from mandos.model.targets import (
0 ignored issues
show
Unused Code introduced by
Unused Target imported from mandos.model.targets
Loading history...
8
    DagTarget,
9
    DagTargetLinkType,
10
    Target,
11
    TargetFactory,
12
    TargetRelationshipType,
13
    TargetType,
14
)
15
16
17
class TestTargets:
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
18
    def test_traverse_gabaa_up(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
19
        target = TargetFactory.find("CHEMBL2109243", Chembl)
20
        assert target.chembl == "CHEMBL2109243"
21
        link_types = DagTargetLinkType.cross(
22
            TargetType.protein_types(),
23
            {TargetRelationshipType.subset_of},
24
            TargetType.protein_types(),
25
        )
26
        accepted = target.traverse(link_types)
27
        assert {t.target.chembl for t in accepted} == {"CHEMBL2109243", "CHEMBL2093872"}
28
29
    def test_traverse_gabaa_up_mouse(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
30
        # a single protein
31
        # branches to GABA A channel complex group CHEMBL2094133
32
        # but also to complexes CHEMBL4296058 and CHEMBL4296059
33
        # weirdly, CHEMBL4296058 then joins up with CHEMBL2094133
34
        # but CHEMBL4296059 does not (it only joins through an OVERLAPS WITH rel)
35
        # so that one SHOULD be an "end" (which wouldn't be true in a real traversal strategy, hopefully)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (105/100).

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

Loading history...
36
        target = TargetFactory.find("CHEMBL3139", Chembl)
37
        assert target.chembl == "CHEMBL3139"
38
        link_types = DagTargetLinkType.cross(
39
            TargetType.protein_types(),
40
            {TargetRelationshipType.subset_of},
41
            TargetType.protein_types(),
42
        )
43
        accepted = target.traverse(link_types)
44
        vals: Mapping[str, DagTarget] = {a.target.chembl: a for a in accepted}
45
        assert {t.target.chembl for t in accepted} == {
46
            "CHEMBL2094133",
47
            "CHEMBL3139",
48
            "CHEMBL4296058",
49
            "CHEMBL4296059",
50
        }
51
        assert not vals["CHEMBL3139"].is_end
52
        assert vals["CHEMBL2094133"].is_end
53
        assert not vals["CHEMBL4296058"].is_end
54
        assert vals["CHEMBL4296059"].is_end
55
        assert vals["CHEMBL3139"].depth == 0
56
        assert vals["CHEMBL2094133"].depth == 1  # breadth-first!
57
        assert vals["CHEMBL2094133"].depth == 1
58
        assert vals["CHEMBL4296058"].depth == 1
59
        assert vals["CHEMBL3139"].link_type is None
60
        assert vals["CHEMBL2094133"].link_type == DagTargetLinkType(
61
            TargetType.single_protein,
62
            TargetRelationshipType.subset_of,
63
            TargetType.protein_complex_group,
64
        )
65
        assert vals["CHEMBL4296058"].link_type == DagTargetLinkType(
66
            TargetType.single_protein, TargetRelationshipType.subset_of, TargetType.protein_complex
67
        )
68
        assert vals["CHEMBL4296059"].link_type == DagTargetLinkType(
69
            TargetType.single_protein, TargetRelationshipType.subset_of, TargetType.protein_complex
70
        )
71
72
    def test_traverse_gabaa_up_mouse_2(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
73
        # this is about the same, but now we'll allow that OVERLAPS WITH rel
74
        # so we won't find them here
75
        target = TargetFactory.find("CHEMBL3139", Chembl)
76
        assert target.chembl == "CHEMBL3139"
77
        link_types = DagTargetLinkType.cross(
78
            TargetType.protein_types(),
79
            {TargetRelationshipType.subset_of},
80
            TargetType.protein_types(),
81
        )
82
        link_types.add(
83
            DagTargetLinkType(
84
                TargetType.protein_complex,
85
                TargetRelationshipType.overlaps_with,
86
                TargetType.protein_complex_group,
87
            )
88
        )
89
        accepted = target.traverse(link_types)
90
        vals: Mapping[str, DagTarget] = {a.target.chembl: a for a in accepted}
91
        assert {t.target.chembl for t in accepted} == {
92
            "CHEMBL2094133",
93
            "CHEMBL3139",
94
            "CHEMBL4296058",
95
            "CHEMBL4296059",
96
        }
97
        assert not vals["CHEMBL3139"].is_end
98
        assert vals["CHEMBL2094133"].is_end
99
        assert not vals["CHEMBL4296058"].is_end
100
        # here's the difference:
101
        # by adding the OVERLAPS WITH rel, it now knows it's not at the end
102
        assert not vals["CHEMBL4296059"].is_end
103
        assert vals["CHEMBL3139"].depth == 0
104
        assert vals["CHEMBL2094133"].depth == 1  # breadth-first!
105
        assert vals["CHEMBL2094133"].depth == 1
106
        assert vals["CHEMBL4296058"].depth == 1
107
        assert vals["CHEMBL3139"].link_type is None
108
        assert vals["CHEMBL2094133"].link_type == DagTargetLinkType(
109
            TargetType.single_protein,
110
            TargetRelationshipType.subset_of,
111
            TargetType.protein_complex_group,
112
        )
113
        assert vals["CHEMBL4296058"].link_type == DagTargetLinkType(
114
            TargetType.single_protein, TargetRelationshipType.subset_of, TargetType.protein_complex
115
        )
116
        assert vals["CHEMBL4296059"].link_type == DagTargetLinkType(
117
            TargetType.single_protein, TargetRelationshipType.subset_of, TargetType.protein_complex
118
        )
119
120
    def test_traverse_gabaa_up_and_down(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
121
        target = TargetFactory.find("CHEMBL2109243", Chembl)
122
        link_types = DagTargetLinkType.cross(
123
            TargetType.protein_types(),
124
            {TargetRelationshipType.subset_of, TargetRelationshipType.superset_of},
125
            TargetType.protein_types(),
126
        )
127
        accepted = target.traverse(link_types)
128
        # based on the docs I wrote, originally by looking thru the search results
129
        assert len(accepted) > 40
130
        assert len(accepted) < 60
131
        assert {"GABA" in t.target.name.upper() for t in accepted}
132
133
134
if __name__ == "__main__":
135
    pytest.main()
136