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

GeneCoOccurrenceSearch._predicate()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
import abc
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
from dataclasses import dataclass
3
from typing import Sequence, TypeVar
4
5
from mandos.model.pubchem_api import PubchemApi
6
from mandos.model.pubchem_support.pubchem_data import PubchemData
7
from mandos.model.pubchem_support.pubchem_models import CoOccurrenceType
8
from mandos.search.pubchem import PubchemHit, PubchemSearch
9
10
11
@dataclass(frozen=True, order=True, repr=True)
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
12
class CoOccurrenceHit(PubchemHit, metaclass=abc.ABCMeta):
13
    score: int
14
    intersect_count: int
15
    query_count: int
16
    neighbor_count: int
17
18
19
@dataclass(frozen=True, order=True, repr=True)
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
20
class DiseaseCoOccurrenceHit(CoOccurrenceHit):
21
    """"""
22
23
24
@dataclass(frozen=True, order=True, repr=True)
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
25
class GeneCoOccurrenceHit(CoOccurrenceHit):
26
    """"""
27
28
29
@dataclass(frozen=True, order=True, repr=True)
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
30
class ChemicalCoOccurrenceHit(CoOccurrenceHit):
31
    """"""
32
33
34
H = TypeVar("H", bound=CoOccurrenceHit, covariant=True)
0 ignored issues
show
Coding Style Naming introduced by
Class name "H" doesn't conform to PascalCase naming style ('[^\\W\\da-z][^\\W_]+$' 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...
35
36
37
class CoOccurrenceSearch(PubchemSearch[H], metaclass=abc.ABCMeta):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
38
    """"""
39
40
    def __init__(self, key: str, api: PubchemApi, min_score: int, min_articles: int):
41
        super().__init__(key, api)
42
        self.min_score = min_score
43
        self.min_articles = min_articles
44
45
    @classmethod
46
    def cooccurrence_type(cls) -> CoOccurrenceType:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
47
        raise NotImplementedError()
48
49
    @property
50
    def data_source(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
51
        return "PubChem"
52
53
    def _predicate(self) -> str:
54
        raise NotImplementedError()
55
56
    def _query(self, data: PubchemData):
57
        raise NotImplementedError()
58
59
    def find(self, inchikey: str) -> Sequence[H]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
60
        data = self.api.fetch_data(inchikey)
61
        return [
62
            self.__class__.get_h()(
63
                record_id=None,
64
                compound_id=str(data.cid),
65
                inchikey=data.names_and_identifiers.inchikey,
66
                compound_name=data.name,
67
                predicate=self._predicate(),
68
                object_id=dd.neighbor_id,
69
                object_name=dd.neighbor_name,
70
                score=dd.score,
71
                intersect_count=dd.article_count,
72
                query_count=dd.query_article_count,
73
                neighbor_count=dd.neighbor_article_count,
74
                search_key=self.key,
75
                search_class=self.search_class,
76
                data_source=self.data_source,
77
            )
78
            for dd in data.literature.gene_cooccurrences
79
            if (
80
                dd.score >= self.min_score
81
                and dd.neighbor_article_count >= self.min_articles
82
                and dd.query_article_count >= self.min_articles
83
            )
84
        ]
85
86
87
class GeneCoOccurrenceSearch(CoOccurrenceSearch[GeneCoOccurrenceHit]):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
88
    @classmethod
89
    def cooccurrence_type(cls) -> CoOccurrenceType:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
90
        return CoOccurrenceType.gene
91
92
    def _predicate(self) -> str:
0 ignored issues
show
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...
93
        return "gene co-occurrence"
94
95
    def _query(self, data: PubchemData):
0 ignored issues
show
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...
96
        return data.literature.gene_cooccurrences
97
98
99
class ChemicalCoOccurrenceSearch(CoOccurrenceSearch[ChemicalCoOccurrenceHit]):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
100
    @classmethod
101
    def cooccurrence_type(cls) -> CoOccurrenceType:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
102
        return CoOccurrenceType.chemical
103
104
    def _predicate(self) -> str:
0 ignored issues
show
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...
105
        return "chemical co-occurrence"
106
107
    def _query(self, data: PubchemData):
0 ignored issues
show
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...
108
        return data.literature.chemical_cooccurrences
109
110
111
class DiseaseCoOccurrenceSearch(CoOccurrenceSearch[DiseaseCoOccurrenceHit]):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
112
    @classmethod
113
    def cooccurrence_type(cls) -> CoOccurrenceType:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
114
        return CoOccurrenceType.disease
115
116
    def _predicate(self) -> str:
0 ignored issues
show
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...
117
        return "disease co-occurrence"
118
119
    def _query(self, data: PubchemData):
0 ignored issues
show
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...
120
        return data.literature.disease_cooccurrences
121
122
123
__all__ = [
124
    "GeneCoOccurrenceHit",
125
    "GeneCoOccurrenceSearch",
126
    "ChemicalCoOccurrenceSearch",
127
    "ChemicalCoOccurrenceHit",
128
    "DiseaseCoOccurrenceSearch",
129
    "DiseaseCoOccurrenceHit",
130
    "CoOccurrenceSearch",
131
]
132