module adabmDCA.dataset
Global Variables
- CPU_DEVICE
class DatasetDCA
Encoded alignment with sequence weights, as a PyTorch dataset.
Build one with from_alignment. Items are (sequence, weight) pairs of encoded sequences.
Attributes:
names: Sequence names.data: Encoded sequences, shape(M, L), integer states.weights: Weight of each sequence.tokens: Ordered alphabet.
method __init__
__init__(*args: Any, **kwargs: Any) → None
classmethod from_alignment
from_alignment(
alignment: str | Path | Alignment,
weights: str | Path | Sequence[float] | ndarray | Tensor | None = None,
load_config: AlignmentLoadConfig | None = None,
clustering_th: float = 0.8,
no_reweighting: bool = False,
device: device = device(type='cpu'),
dtype: dtype = torch.float32,
allow_signed_weights: bool = False
) → DatasetDCA
Load an alignment and its weights into a dataset.
An Alignment already returned by load_alignment is reused when load_config is omitted, preserving its filtering provenance. Pass load_config to apply a new loading policy.
Args:
alignment: Path,Alignmentor sequences.weights: Sequence weights (file, array or tensor), orNoneto compute them.load_config: Loading policy; seeAlignmentLoadConfig.clustering_th: Identity threshold of the computed weights.no_reweighting: Give every sequence weight 1.device: Device of the tensors.dtype: Precision of the weights and one-hot encodings.allow_signed_weights: Accept negative weights (experimental reintegration).
Returns:
A DatasetDCA.
Example:
dataset = DatasetDCA.from_alignment("family.fasta", load_config=AlignmentLoadConfig(alphabet="rna"))
fi, fij = dataset.get_frequencies(pseudocount=1 / dataset.get_effective_size())
method get_effective_size
get_effective_size() → float
Returns the effective size (Meff) of the dataset.
Returns:
float: Sum of the sequence weights.
method get_frequencies
get_frequencies(
pseudocount: float = 0.0,
batch_size: int = 10000
) → tuple[Tensor, Tensor]
Computes the single-site and two-site frequencies of the dataset. When there are too many sequences, computing the frequencies directly from the one-hot encoding can be memory-intensive. Therefore, we compute the frequencies using batched operations.
Args:
pseudocount(float, optional): Pseudocount to be added to the frequencies. Defaults to 0.0.batch_size(int, optional): Batch size to use when computing the frequencies. Defaults to 10000.
Returns:
Tuple[torch.Tensor, torch.Tensor]: Single-site frequencies fi of shape (L, q) and two-site frequencies fij of shape (L, q, L, q).
method get_num_residues
get_num_residues() → int
Returns the number of residues (L) in the multi-sequence alignment.
Returns:
int: Length of the MSA.
method get_num_states
get_num_states() → int
Returns the number of states (q) in the alphabet.
Returns:
int: Number of states.
method shuffle
shuffle() → None
Shuffles the dataset.
method to_one_hot
to_one_hot() → Tensor
Converts the dataset to one-hot encoding.
Returns:
torch.Tensor: One-hot encoded dataset of shape (M, L, q).
This file was automatically generated via lazydocs.