Code Duplication    Length = 40-40 lines in 2 locations

mandos/search/chembl/binding_search.py 1 location

@@ 32-71 (lines=40) @@
29
        return "activity"
30
31
32
class BindingSearch(_ActivitySearch[BindingHit]):
33
    """
34
    Search for ``activity`` of type "B".
35
    """
36
37
    @classmethod
38
    def allowed_assay_types(cls) -> Set[str]:
39
        return {"B"}
40
41
    def to_hit(
42
        self,
43
        lookup: str,
44
        compound: ChemblCompound,
45
        data: NestedDotDict,
46
        best_target: ChemblTargetGraph,
47
    ) -> Sequence[BindingHit]:
48
        # these must match the constructor of the Hit,
49
        # EXCEPT for object_id and object_name, which come from traversal
50
        from_super = self._extract(lookup, compound, data)
51
        hit = BindingHit(
52
            record_id=from_super.req_as("activity_id", str),
53
            origin_inchikey=lookup,
54
            matched_inchikey=compound.inchikey,
55
            compound_id=compound.chid,
56
            compound_name=compound.name,
57
            predicate="binds",
58
            object_id=best_target.chembl,
59
            object_name=best_target.name,
60
            search_key=self.key,
61
            search_class=self.search_class,
62
            data_source=self.data_source,
63
            exact_target_id=from_super.req_as("target_chembl_id", str),
64
            taxon_id=from_super.get("taxon_id"),
65
            taxon_name=from_super.get("taxon_name"),
66
            src_id=from_super.req_as("src_id", str),
67
            pchembl=from_super.req_as("pchembl_value", float),
68
            std_type=from_super.req_as("standard_type", str),
69
            standard_relation=from_super.req_as("standard_relation", str),
70
        )
71
        return [hit]
72
73
74
__all__ = ["BindingHit", "BindingSearch"]

mandos/search/chembl/functional_search.py 1 location

@@ 27-66 (lines=40) @@
24
    subcellular_region: Optional[str]
25
26
27
class FunctionalSearch(_ActivitySearch[FunctionalHit]):
28
    """
29
    Search for ``activity`` of type "F".
30
    """
31
32
    @classmethod
33
    def allowed_assay_types(cls) -> Set[str]:
34
        return {"F"}
35
36
    def to_hit(
37
        self,
38
        lookup: str,
39
        compound: ChemblCompound,
40
        data: NestedDotDict,
41
        best_target: ChemblTargetGraph,
42
    ) -> Sequence[FunctionalHit]:
43
        # these must match the constructor of the Hit,
44
        # EXCEPT for object_id and object_name, which come from traversal
45
        from_super = self._extract(lookup, compound, data)
46
        hit = FunctionalHit(
47
            record_id=from_super.req_as("activity_id", str),
48
            origin_inchikey=lookup,
49
            matched_inchikey=compound.inchikey,
50
            compound_id=compound.chid,
51
            compound_name=compound.name,
52
            predicate="functional activity",
53
            object_id=best_target.chembl,
54
            object_name=best_target.name,
55
            search_key=self.key,
56
            search_class=self.search_class,
57
            data_source=self.data_source,
58
            exact_target_id=from_super.req_as("target_chembl_id", str),
59
            taxon_id=from_super.get("taxon_id"),
60
            taxon_name=from_super.get("taxon_name"),
61
            src_id=from_super.req_as("src_id", str),
62
            tissue=from_super.get_as("tissue", str),
63
            cell_type=from_super.get_as("cell_type", str),
64
            subcellular_region=from_super.get("subcellular_region", str),
65
        )
66
        return [hit]
67
68
69
__all__ = ["FunctionalHit", "FunctionalSearch", "AssayType"]