Skip to content

module adabmDCA.input_loading

Shared, side-effect-free loading of alignments and sequence weights.


function load_alignment

load_alignment(
    source: 'AlignmentInput',
    config: 'AlignmentLoadConfig | None' = None,
    alphabet: 'str | None' = None,
    invalid_sequences: 'InvalidSequencePolicy | None' = None,
    remove_duplicates: 'bool | None' = None,
    expected_length: 'int | None' = None,
    format: 'AlignmentFormat | None' = None,
    alignment_index: 'int | None' = None,
    normalize_dots: 'bool | None' = None
) → Alignment

Parse, validate, filter, and deduplicate an alignment.

The alphabet is detected from standard DNA, RNA, or protein tokens by default; pass alphabet for ambiguous or custom alignments. Direct keyword options override the corresponding fields in config. The returned Alignment contains its selected encoding tokens and filtering provenance, so callers do not need a separate wrapper type.

Args:

  • source: Path, Alignment or sequences.
  • config: Loading policy; see AlignmentLoadConfig.
  • alphabet: Overrides config.alphabet.
  • invalid_sequences: Overrides config.invalid_sequences.
  • remove_duplicates: Overrides config.remove_duplicates.
  • expected_length: Overrides config.expected_length.
  • format: Overrides config.format.
  • alignment_index: Overrides config.alignment_index.
  • normalize_dots: Overrides config.normalize_dots.

Returns: The filtered Alignment, with tokens, encoded_sequences and the indices of the retained sequences.

Raises:

  • AlignmentLoadError: If the file cannot be read.
  • InputValidationError: If sequences are invalid under "error", the length is wrong, or no sequence remains.

Example:

alignment = load_alignment("family.fasta", invalid_sequences="drop")
alignment.tokens, alignment.num_sequences


function load_sequence_weights

load_sequence_weights(
    source: 'WeightInput | None',
    loaded_alignment: 'Alignment',
    no_reweighting: 'bool',
    clustering_seqid: 'float',
    device: 'device',
    dtype: 'dtype',
    allow_negative: 'bool' = False,
    require_positive_sum: 'bool' = True
) → Tensor

Load or calculate weights and align them with retained sequences.

allow_negative and require_positive_sum are intended for signed experimental adjustment vectors; ordinary statistical weights should keep their safe defaults.

Args:

  • source: Weights file (one number per line), sequence, array or tensor, or None to compute them. Their count may match the original or the retained sequences.
  • loaded_alignment: Alignment returned by load_alignment.
  • no_reweighting: Give every sequence weight 1 (source is ignored).
  • clustering_seqid: Computed weights: each sequence gets 1 / (number of sequences more than this identical to it), itself included.
  • device: Device of the returned tensor.
  • dtype: Precision of the returned tensor.
  • allow_negative: Accept negative weights.
  • require_positive_sum: Reject weights whose sum is not positive.

Returns: One weight per retained sequence.

Raises:

  • WeightLoadError: If the weights cannot be read, have the wrong count, or are not finite, negative, or sum to zero when disallowed.

class AlignmentLoadConfig

How load_alignment reads, validates and filters an alignment.

Attributes:

  • alphabet: "auto" (detect DNA, RNA or protein), a built-in name, or a custom token string.
  • invalid_sequences: "error" to reject, or "drop" to remove, sequences with tokens outside the alphabet.
  • remove_duplicates: Keep only the first copy of identical sequences.
  • expected_length: Required alignment length, or None.
  • format: "auto", "fasta" or "stockholm".
  • alignment_index: Alignment to read from a multi-alignment Stockholm file.
  • normalize_dots: Turn "." gaps into "-".

method __init__

__init__(
    alphabet: 'str' = 'auto',
    invalid_sequences: 'InvalidSequencePolicy' = 'error',
    remove_duplicates: 'bool' = False,
    expected_length: 'int | None' = None,
    format: 'AlignmentFormat' = 'auto',
    alignment_index: 'int | None' = None,
    normalize_dots: 'bool' = True
) → None

This file was automatically generated via lazydocs.