Skip to content

Relation classes

And

Bases: Relation

Class for representing the logical AND of multiple conditions Allows nesed conditions, i.e. And(1, Or(2, 3))

Source code in yeastdnnexplorer/probability_models/relation_classes.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class And(Relation):
    """Class for representing the logical AND of multiple conditions Allows nesed
    conditions, i.e. And(1, Or(2, 3))"""

    def __init__(self, *conditions):
        """
        :param conditions: List of conditions to be evaluated
        :type conditions: List[float | Relation]
        """
        self.conditions = conditions

    def evaluate(self, bound_vec):
        """
        Returns true if the And() condition evaluates to true Evaluates nested
        conditions as needed.

        :param bound_vec: Vector of TF indices (0 or 1) indicating which TFs are bound
            for the gene in question
        :type bound_vec: List[float]

        """
        if type(bound_vec) is not list or not all(
            isinstance(x, float) for x in bound_vec
        ):
            raise ValueError("bound_vec must be a list of floats")

        if not self.conditions:
            return True

        # Each condition can be an index or another Relation (And/Or)
        return all(
            c.evaluate(bound_vec) if isinstance(c, Relation) else bound_vec[c]
            for c in self.conditions
        )

    def __str__(self):
        return f"AND({', '.join(str(c) for c in self.conditions)})"

__init__(*conditions)

Parameters:

Name Type Description Default
conditions List[float | Relation]

List of conditions to be evaluated

()
Source code in yeastdnnexplorer/probability_models/relation_classes.py
12
13
14
15
16
17
def __init__(self, *conditions):
    """
    :param conditions: List of conditions to be evaluated
    :type conditions: List[float | Relation]
    """
    self.conditions = conditions

evaluate(bound_vec)

Returns true if the And() condition evaluates to true Evaluates nested conditions as needed.

Parameters:

Name Type Description Default
bound_vec List[float]

Vector of TF indices (0 or 1) indicating which TFs are bound for the gene in question

required
Source code in yeastdnnexplorer/probability_models/relation_classes.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
def evaluate(self, bound_vec):
    """
    Returns true if the And() condition evaluates to true Evaluates nested
    conditions as needed.

    :param bound_vec: Vector of TF indices (0 or 1) indicating which TFs are bound
        for the gene in question
    :type bound_vec: List[float]

    """
    if type(bound_vec) is not list or not all(
        isinstance(x, float) for x in bound_vec
    ):
        raise ValueError("bound_vec must be a list of floats")

    if not self.conditions:
        return True

    # Each condition can be an index or another Relation (And/Or)
    return all(
        c.evaluate(bound_vec) if isinstance(c, Relation) else bound_vec[c]
        for c in self.conditions
    )

Or

Bases: Relation

Source code in yeastdnnexplorer/probability_models/relation_classes.py
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
class Or(Relation):
    def __init__(self, *conditions):
        """
        :param conditions: List of conditions to be evaluated
        :type conditions: List[int | Relation]
        """
        self.conditions = conditions

    def evaluate(self, bound_vec):
        """
        Returns true if the Or() condition evaluates to true Evaluates nested conditions
        as needed.

        :param bound_vec: Vector of TF indices (0 or 1) indicating which TFs are bound
            for the gene in question
        :type bound_vec: List[int]

        """
        if type(bound_vec) is not list or not all(
            isinstance(x, float) for x in bound_vec
        ):
            raise ValueError("bound_vec must be a list of floats")

        if not self.conditions:
            return True

        # Each condition can be an index or another Relation (And/Or)
        return any(
            c.evaluate(bound_vec) if isinstance(c, Relation) else bound_vec[c]
            for c in self.conditions
        )

    def __str__(self):
        return f"OR({', '.join(str(c) for c in self.conditions)})"

__init__(*conditions)

Parameters:

Name Type Description Default
conditions List[int | Relation]

List of conditions to be evaluated

()
Source code in yeastdnnexplorer/probability_models/relation_classes.py
48
49
50
51
52
53
def __init__(self, *conditions):
    """
    :param conditions: List of conditions to be evaluated
    :type conditions: List[int | Relation]
    """
    self.conditions = conditions

evaluate(bound_vec)

Returns true if the Or() condition evaluates to true Evaluates nested conditions as needed.

Parameters:

Name Type Description Default
bound_vec List[int]

Vector of TF indices (0 or 1) indicating which TFs are bound for the gene in question

required
Source code in yeastdnnexplorer/probability_models/relation_classes.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def evaluate(self, bound_vec):
    """
    Returns true if the Or() condition evaluates to true Evaluates nested conditions
    as needed.

    :param bound_vec: Vector of TF indices (0 or 1) indicating which TFs are bound
        for the gene in question
    :type bound_vec: List[int]

    """
    if type(bound_vec) is not list or not all(
        isinstance(x, float) for x in bound_vec
    ):
        raise ValueError("bound_vec must be a list of floats")

    if not self.conditions:
        return True

    # Each condition can be an index or another Relation (And/Or)
    return any(
        c.evaluate(bound_vec) if isinstance(c, Relation) else bound_vec[c]
        for c in self.conditions
    )

Relation

Base class for relations between TF indices.

Source code in yeastdnnexplorer/probability_models/relation_classes.py
1
2
3
4
5
class Relation:
    """Base class for relations between TF indices."""

    def evaluate(self, bound_vec: list[int]):
        raise NotImplementedError