Skip to content

Fine-Mapping Plan

gentropy.dataset.fine_mapping.FineMappingRoute

Bases: StrEnum

Enum representing the route of the fine-mapping method.

Source code in src/gentropy/dataset/fine_mapping.py
20
21
22
23
24
class FineMappingRoute(StrEnum):
    """Enum representing the route of the fine-mapping method."""

    MULTI_SUSIE_ROUTE = "multi_susie_route"
    """Route for multi-SuSiE fine-mapping methods."""

MULTI_SUSIE_ROUTE = 'multi_susie_route' class-attribute instance-attribute

Route for multi-SuSiE fine-mapping methods.

gentropy.dataset.fine_mapping.FineMappingPlanner dataclass

Bases: Dataset

Class representing a planner for fine-mapping methods.

Examples:

data = [("run1", "study1", "multi_susie_route", [("constraint1", True), ("constraint2", False)]), ... ("run2", "study2", "multi_susie_route", [("constraint2", False),])] df = spark.createDataFrame(data, schema=FineMappingPlanner.get_schema()) from gentropy.dataset.fine_mapping import FineMappingPlanner planner = FineMappingPlanner(df) assert isinstance(planner, FineMappingPlanner) planner.df.show(truncate=False) +-----+-------+-----------------+-------------------------------------------+ |runId|studyId|route |constraints | +-----+-------+-----------------+-------------------------------------------+ |run1 |study1 |multi_susie_route|[{constraint1, true}, {constraint2, false}]| |run2 |study2 |multi_susie_route|[{constraint2, false}] | +-----+-------+-----------------+-------------------------------------------+

Source code in src/gentropy/dataset/fine_mapping.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
class FineMappingPlanner(Dataset):
    """Class representing a planner for fine-mapping methods.

    Examples:
    ---
    >>> data = [("run1", "study1", "multi_susie_route", [("constraint1", True), ("constraint2", False)]),
    ...         ("run2", "study2", "multi_susie_route", [("constraint2", False),])]
    >>> df = spark.createDataFrame(data, schema=FineMappingPlanner.get_schema())
    >>> from gentropy.dataset.fine_mapping import FineMappingPlanner
    >>> planner = FineMappingPlanner(df)
    >>> assert isinstance(planner, FineMappingPlanner)
    >>> planner.df.show(truncate=False)
    +-----+-------+-----------------+-------------------------------------------+
    |runId|studyId|route            |constraints                                |
    +-----+-------+-----------------+-------------------------------------------+
    |run1 |study1 |multi_susie_route|[{constraint1, true}, {constraint2, false}]|
    |run2 |study2 |multi_susie_route|[{constraint2, false}]                     |
    +-----+-------+-----------------+-------------------------------------------+
    <BLANKLINE>
    """

    @classmethod
    def get_schema(cls) -> t.StructType:
        """Get the schema of the planner.

        Returns:
            t.StructType: The schema of the planner.
        """
        return t.StructType(
            [
                t.StructField("runId", t.StringType(), nullable=True),
                t.StructField("studyId", t.StringType(), nullable=False),
                t.StructField("route", t.StringType(), nullable=False),
                t.StructField(
                    "constraints",
                    t.ArrayType(
                        t.StructType(
                            [
                                t.StructField("name", t.StringType(), nullable=False),
                                t.StructField("value", t.BooleanType(), nullable=False),
                            ]
                        )
                    ),
                    nullable=False,
                ),
            ]
        )

    def __add__(self, other: FineMappingPlanner) -> FineMappingPlanner:
        """Combine two FineMappingPlanner datasets.

        The combined dataset is unique per (studyId, route), not per studyId alone: a
        study eligible for more than one fine-mapping route (e.g. both MultiSuSiE and
        SuSiE-inf) legitimately appears once per eligible route. Callers must not assume
        studyId is unique across the combined output.

        Args:
            other (FineMappingPlanner): Another FineMappingPlanner dataset to combine with.

        Returns:
            FineMappingPlanner: A new FineMappingPlanner dataset containing the combined data.
        """
        combined_df = self.df.unionByName(other.df)
        return FineMappingPlanner(combined_df)

get_schema() -> t.StructType classmethod

Get the schema of the planner.

Returns:

Type Description
StructType

t.StructType: The schema of the planner.

Source code in src/gentropy/dataset/fine_mapping.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
@classmethod
def get_schema(cls) -> t.StructType:
    """Get the schema of the planner.

    Returns:
        t.StructType: The schema of the planner.
    """
    return t.StructType(
        [
            t.StructField("runId", t.StringType(), nullable=True),
            t.StructField("studyId", t.StringType(), nullable=False),
            t.StructField("route", t.StringType(), nullable=False),
            t.StructField(
                "constraints",
                t.ArrayType(
                    t.StructType(
                        [
                            t.StructField("name", t.StringType(), nullable=False),
                            t.StructField("value", t.BooleanType(), nullable=False),
                        ]
                    )
                ),
                nullable=False,
            ),
        ]
    )