Skip to content

Conversation

@AliAlimohammadi
Copy link
Contributor

Description

This PR adds the Smith-Waterman algorithm implementation to the dynamic programming module.

Algorithm Overview

The Smith-Waterman algorithm is a dynamic programming algorithm for determining similar regions between two sequences (nucleotide or protein sequences). It performs local sequence alignment and is particularly useful in bioinformatics.

Key Features:

  • Local alignment: Finds the best matching subsequence rather than aligning entire sequences
  • Dynamic programming: O(m×n) time complexity where m and n are sequence lengths
  • Configurable scoring: Supports custom match, mismatch, and gap penalties
  • Case-insensitive: Automatically handles uppercase and lowercase inputs

Implementation Details:

  • score_function: Calculates alignment scores for character pairs
  • smith_waterman: Builds the scoring matrix using dynamic programming
  • traceback: Reconstructs the optimal alignment from the scoring matrix

Testing

The implementation includes comprehensive tests:

  • ✅ Multiple test cases with different sequence pairs
  • ✅ Edge cases (empty sequences)
  • ✅ Case-insensitive matching
  • ✅ Traceback verification
  • ✅ Score function validation

All tests pass:

cargo test smith_waterman

Documentation

  • Detailed module-level documentation with algorithm overview
  • Function-level documentation with examples
  • References to original paper and Wikipedia

Checklist

  • Algorithm implementation is correct
  • All tests pass locally
  • Code follows Rust best practices
  • Documentation is comprehensive
  • No clippy warnings
  • Code is formatted with cargo fmt
  • Added to appropriate module (dynamic_programming)

References

@codecov-commenter
Copy link

codecov-commenter commented Dec 5, 2025

Codecov Report

❌ Patch coverage is 93.71069% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.46%. Comparing base (700fd3a) to head (7a849ee).

Files with missing lines Patch % Lines
src/dynamic_programming/smith_waterman.rs 93.71% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #960      +/-   ##
==========================================
- Coverage   95.48%   95.46%   -0.02%     
==========================================
  Files         335      336       +1     
  Lines       21797    21956     +159     
==========================================
+ Hits        20813    20961     +148     
- Misses        984      995      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AliAlimohammadi
Copy link
Contributor Author

@siriak, This is ready to merge.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an implementation of the Smith-Waterman algorithm for local sequence alignment to the dynamic programming module. The Smith-Waterman algorithm is a well-known bioinformatics algorithm for finding optimal local alignments between sequences using dynamic programming with O(m×n) time and space complexity.

Key Changes:

  • Implements Smith-Waterman algorithm with configurable scoring parameters (match, mismatch, gap penalties)
  • Provides traceback functionality to reconstruct optimal alignments from the scoring matrix
  • Includes comprehensive test coverage with multiple test cases
  • Case-insensitive sequence handling

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
src/dynamic_programming/smith_waterman.rs New implementation of Smith-Waterman algorithm with score matrix generation, traceback, and helper scoring function
src/dynamic_programming/mod.rs Module and public API declarations for smith_waterman functions
DIRECTORY.md Documentation entry for Smith-Waterman algorithm, maintaining alphabetical order

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the comments and address if they are relevant

Copy link
Contributor Author

@AliAlimohammadi AliAlimohammadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed.

@siriak siriak merged commit 1a27c6c into TheAlgorithms:master Dec 6, 2025
7 checks passed
@AliAlimohammadi AliAlimohammadi deleted the feat/smith-waterman-algorithm branch December 6, 2025 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants