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

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