Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions seq_smith/_seq_smith.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ class Alignment:

@final
class AlignmentFragment:
def __init__(
self,
fragment_type: FragmentType,
sa_start: int,
sb_start: int,
length: int,
) -> None: ...
@property
def fragment_type(self) -> FragmentType: ...
@fragment_type.setter
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,9 +676,10 @@ fn _local_global_align_core(params: AlignmentParams) -> PyResult<Alignment> {
let mut max_col = 0;

for row in 0..params.sb_len {
data.prev_score[row] = std::i32::MIN;
let score = params.gap_cost(row as i32 + 1);
data.prev_score[row] = score;
data.hgap_pos[row] = -1;
data.hgap_score[row] = std::i32::MIN;
data.hgap_score[row] = score.saturating_add(params.gap_open);
}

for col in 0..params.sa_len {
Expand Down
22 changes: 22 additions & 0 deletions tests/test_seq_smith.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from conftest import AlignmentData

from seq_smith import (
AlignmentFragment,
FragmentType,
encode,
format_alignment_ascii,
generate_cigar,
Expand Down Expand Up @@ -454,3 +456,23 @@ def test_generate_cigar_with_deletion(common_data: AlignmentData) -> None:
alignment = global_align(seqa, seqb, common_data.score_matrix, common_data.gap_open, common_data.gap_extend)
cigar = generate_cigar(alignment)
assert cigar == "1M1D" # AC vs A-, so A matches, then C is a deletion in seqB (query)


def test_local_global_align_overhangs() -> None:
# Sequence B (Global) has overhanging tails
# sequence A: CCCC
# sequence B: AAACCCCAAA
# Expected: A aligns to central C's, B has leading/trailing gaps.
seqa = encode("CCCC", "ACGT")
seqb = encode("AAACCCCAAA", "ACGT")
sm = make_score_matrix("ACGT", match_score=2, mismatch_score=-2)
aln = local_global_align(seqa, seqb, sm, gap_open=-3, gap_extend=-1)

expected_fragments = [
AlignmentFragment(FragmentType.AGap, 0, 0, 3),
AlignmentFragment(FragmentType.Match, 0, 3, 4),
AlignmentFragment(FragmentType.AGap, 4, 7, 3),
]
assert aln.fragments == expected_fragments

assert aln.score == -2
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading