Skip to content

GenePopulation

A simple class to hold a tensor boolean 1D vector where 0 is meant to identify genes which are unaffected by a given TF and 1 is meant to identify genes which are affected by a given TF.

Source code in yeastdnnexplorer/probability_models/generate_data.py
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
class GenePopulation:
    """A simple class to hold a tensor boolean 1D vector where 0 is meant to identify
    genes which are unaffected by a given TF and 1 is meant to identify genes which are
    affected by a given TF."""

    def __init__(self, labels: torch.Tensor) -> None:
        """
        Constructor of GenePopulation.

        :param labels: This can be any 1D tensor of boolean values. But it is meant to
            be the output of `generate_gene_population()`
        :type labels: torch.Tensor
        :raises TypeError: If labels is not a tensor
        :raises ValueError: If labels is not a 1D tensor
        :raises TypeError: If labels is not a boolean tensor

        """
        if not isinstance(labels, torch.Tensor):
            raise TypeError("labels must be a tensor")
        if not labels.ndim == 1:
            raise ValueError("labels must be a 1D tensor")
        if not labels.dtype == torch.bool:
            raise TypeError("labels must be a boolean tensor")
        self.labels = labels

    def __repr__(self):
        return f"<GenePopulation size={len(self.labels)}>"

__init__(labels)

Constructor of GenePopulation.

Parameters:

Name Type Description Default
labels Tensor

This can be any 1D tensor of boolean values. But it is meant to be the output of generate_gene_population()

required

Raises:

Type Description
TypeError

If labels is not a tensor

ValueError

If labels is not a 1D tensor

TypeError

If labels is not a boolean tensor

Source code in yeastdnnexplorer/probability_models/generate_data.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def __init__(self, labels: torch.Tensor) -> None:
    """
    Constructor of GenePopulation.

    :param labels: This can be any 1D tensor of boolean values. But it is meant to
        be the output of `generate_gene_population()`
    :type labels: torch.Tensor
    :raises TypeError: If labels is not a tensor
    :raises ValueError: If labels is not a 1D tensor
    :raises TypeError: If labels is not a boolean tensor

    """
    if not isinstance(labels, torch.Tensor):
        raise TypeError("labels must be a tensor")
    if not labels.ndim == 1:
        raise ValueError("labels must be a 1D tensor")
    if not labels.dtype == torch.bool:
        raise TypeError("labels must be a boolean tensor")
    self.labels = labels