Skip to content

module adabmDCA.io


function load_chains

load_chains(
    fname: str,
    tokens: str,
    load_weights: bool = False,
    device: device = device(type='cpu'),
    dtype: dtype = torch.float32
) → Tuple[Tensor, ]

Loads the sequences from a fasta file and returns the one-hot encoded version. If the sequences are weighted, the log-weights are also returned. If the sequences are not weighted, the log-weights are set to 0.

Args:

  • fname (str): Path to the file containing the sequences.
  • tokens (str): "protein", "dna", "rna" or another string with the alphabet to be used.
  • load_weights (bool, optional): If True, the log-weights are loaded and returned. Defaults to False.
  • device (torch.device, optional): Device where to store the sequences. Defaults to "cpu".
  • dtype (torch.dtype, optional): Data type of the sequences. Defaults to torch.float32

Return: - Tuple[torch.Tensor, ...]: One-hot encoded sequences and log-weights if load_weights is True.


function save_chains

save_chains(
    fname: str,
    chains: Union[list, ndarray, Tensor],
    tokens: str,
    log_weights: Optional[Tensor, ndarray] = None
) → None

Saves the chains in a fasta file.

Args:

  • fname (str): Path to the file where to save the chains.
  • chains (Union[list, np.ndarray, torch.Tensor]): Iterable with sequences in string, categorical or one-hot encoded format.
  • tokens (str): "protein", "dna", "rna" or another string with the alphabet to be used.
  • log_weights (Union[torch.Tensor, np.ndarray, None], optional): Log-weights of the chains. Defaults to None.

function load_params

load_params(
    fname: str,
    tokens: str,
    device: device,
    dtype: dtype = torch.float32
) → Dict[str, Tensor]

Import the parameters of the model from a text file.

Args:

  • fname (str): Path of the file that stores the parameters.
  • tokens (str): "protein", "dna", "rna" or another string with a compatible alphabet to be used.
  • device (torch.device): Device where to store the parameters.
  • dtype (torch.dtype): Data type of the parameters. Defaults to torch.float32.

Returns:

  • Dict[str, torch.Tensor]: Parameters of the model. - "bias": Tensor of shape (L, q) - local biases. - "coupling_matrix": Tensor of shape (L, q, L, q) - coupling matrix.

function load_params_old

load_params_old(
    fname: str,
    tokens: str,
    device: device,
    dtype: dtype = torch.float32
) → Dict[str, Tensor]

Import the parameters of the model from a file.

Args:

  • fname (str): Path of the file that stores the parameters.
  • tokens (str): "protein", "dna", "rna" or another string with a compatible alphabet to be used.
  • device (torch.device): Device where to store the parameters.
  • dtype (torch.dtype): Data type of the parameters. Defaults to torch.float32.

Returns:

  • Dict[str, torch.Tensor]: Parameters of the model. - "bias": Tensor of shape (L, q) - local biases. - "coupling_matrix": Tensor of shape (L, q, L, q) - coupling matrix.

function save_params

save_params(
    fname: str,
    params: Dict[str, Tensor],
    tokens: str,
    mask: Optional[Tensor] = None
) → None

Saves the parameters of the model in a file.

Args:

  • fname (str): Path to the file where to save the parameters.
  • params (Dict[str, torch.Tensor]): Parameters of the model. - "bias": Tensor of shape (L, q) - local biases. - "coupling_matrix": Tensor of shape (L, q, L, q) - coupling matrix.
  • tokens (str): "protein", "dna", "rna" or another string with a compatible alphabet to be used.
  • mask (Optional[torch.Tensor]): Tensor of shape (L, q, L, q) - Mask of the coupling matrix that determines which are the non-zero entries. If None, the lower-triangular part of the coupling matrix is masked. Defaults to None.

function load_params_oldformat

load_params_oldformat(
    fname: str,
    device: device,
    dtype: dtype = torch.float32
) → Dict[str, Tensor]

Import the parameters of the model from a file. Assumes the old DCA format.

Args:

  • fname (str): Path of the file that stores the parameters.
  • device (torch.device): Device where to store the parameters.
  • dtype (torch.dtype): Data type of the parameters. Defaults to torch.float32.

Returns:

  • Dict[str, torch.Tensor]: Parameters of the model. - "bias": Tensor of shape (L, q) - local biases. - "coupling_matrix": Tensor of shape (L, q, L, q) - coupling matrix.

function save_params_oldformat

save_params_oldformat(
    fname: str,
    params: Dict[str, Tensor],
    mask: Optional[Tensor] = None
) → None

Saves the parameters of the model in a file. Assumes the old DCA format.

Args:

  • fname (str): Path to the file where to save the parameters.
  • params (Dict[str, torch.Tensor]): Parameters of the model. - "bias": Tensor of shape (L, q) - local biases. - "coupling_matrix": Tensor of shape (L, q, L, q) - coupling matrix.
  • mask (Optional[torch.Tensor]): Tensor of shape (L, q, L, q) - Mask of the coupling matrix that determines which are the non-zero entries. If None, the lower-triangular part of the coupling matrix is masked. Defaults to None.

This file was automatically generated via lazydocs.