smftools.tools.sequence_alignment#

Functions

align_sequences_with_mismatches(seq1, seq2)

Globally align two sequences and return mismatch positions/bases.

Classes

AlignmentMismatch(event, seq1_pos, ...)

Record a mismatch or gap between two aligned sequences.

class smftools.tools.sequence_alignment.AlignmentMismatch(event, seq1_pos, seq1_base, seq2_pos, seq2_base)#

Bases: object

Record a mismatch or gap between two aligned sequences.

event: Literal['substitution', 'insertion', 'deletion']#
seq1_pos: int | None#
seq1_base: str | None#
seq2_pos: int | None#
seq2_base: str | None#
smftools.tools.sequence_alignment.align_sequences_with_mismatches(seq1, seq2, match_score=1, mismatch_score=-1, gap_score=-1, ignore_n=True)#

Globally align two sequences and return mismatch positions/bases.

The alignment uses a simple Needleman-Wunsch dynamic programming approach with configurable scores. Mismatch reporting is based on the aligned sequences and returns 0-based coordinates in each sequence. Gap events are represented with a None coordinate for the gapped sequence.

Parameters:
  • seq1 (str) -- First sequence (treated as reference for positions).

  • seq2 (str) -- Second sequence.

  • match_score (int (default: 1)) -- Score for matching bases.

  • mismatch_score (int (default: -1)) -- Score for mismatching bases.

  • gap_score (int (default: -1)) -- Score for introducing a gap.

  • ignore_n (bool (default: True)) -- Whether to ignore mismatches involving the base N.

Return type:

tuple[str, str, list[AlignmentMismatch]]

Returns:

Tuple of (aligned_seq1, aligned_seq2, mismatches).