From 76716ddcdf58fb5c9391e3743d40f88d8a634143 Mon Sep 17 00:00:00 2001 From: SOLOMON JOHNSON Date: Thu, 26 Jun 2025 15:41:26 +0530 Subject: [PATCH 1/4] Create code.js Created Smith-Waterman algorithm's code file --- Dynamic Programming/Smith-Waterman/code.js | 103 +++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 Dynamic Programming/Smith-Waterman/code.js diff --git a/Dynamic Programming/Smith-Waterman/code.js b/Dynamic Programming/Smith-Waterman/code.js new file mode 100644 index 00000000..7e2311a6 --- /dev/null +++ b/Dynamic Programming/Smith-Waterman/code.js @@ -0,0 +1,103 @@ +// import visualization libraries { +const { Array2DTracer, Layout, LogTracer, Tracer, VerticalLayout } = require('algorithm-visualizer'); +// } + +// define tracer variables { +const array2dTracer = new Array2DTracer('Scoring Matrix'); // Renamed for clarity +const logTracer = new LogTracer('Logs'); // Renamed for clarity +// } + +function smithWatermanLogic(seq1, seq2) { + // Define scoring parameters + const matchScore = 2; + const mismatchScore = -1; + const gapPenalty = -1; + + // Create a scoring matrix + const lenSeq1 = seq1.length; + const lenSeq2 = seq2.length; + + // Initialize a 2D array (matrix) with zeros + const scoreMatrix = Array(lenSeq1 + 1).fill(0).map(() => Array(lenSeq2 + 1).fill(0)); + + // Prepare the matrix for display + const rowLabels = [''].concat(Array.from(seq1)); // e.g., ['', 'G', 'G', 'C', 'A', 'T'] + const colLabels = [''].concat(Array.from(seq2)); // e.g., ['', 'G', 'G', 'C', 'A'] + + array2dTracer.set(scoreMatrix, rowLabels, colLabels); // Use array2dTracer here + logTracer.print('Smith-Waterman Algorithm Visualization Started.'); // Use logTracer here + Tracer.delay(); + + let maxScore = 0; // Track the maximum score found + + // Fill the scoring matrix + for (let i = 1; i <= lenSeq1; i++) { + for (let j = 1; j <= lenSeq2; j++) { + // Determine score for match/mismatch + const score = (seq1[i - 1] === seq2[j - 1]) ? matchScore : mismatchScore; + + // Calculate scores from three possible paths: diagonal, up, left + const diagonalScore = scoreMatrix[i - 1][j - 1] + score; + const upScore = scoreMatrix[i - 1][j] + gapPenalty; + const leftScore = scoreMatrix[i][j - 1] + gapPenalty; + + // The Smith-Waterman algorithm ensures scores never drop below zero + // by taking the maximum of 0 and the calculated path scores. + const currentCellScore = Math.max(0, diagonalScore, upScore, leftScore); + + // Update the score matrix cell + scoreMatrix[i][j] = currentCellScore; + + // --- Visualization steps for the current cell --- + + // Highlight the current cell being processed + array2dTracer.patch(i, j, currentCellScore); + logTracer.print(`\n Processing cell [${i}, ${j}] (seq1: ${seq1[i-1] || '-'}, seq2: ${seq2[j-1] || '-'})`); + Tracer.delay(); + + // Briefly highlight the contributing cells for context + array2dTracer.select(i - 1, j - 1); // Diagonal + array2dTracer.select(i - 1, j); // Up + array2dTracer.select(i, j - 1); // Left + logTracer.print(`\n Scores from paths: Diagonal (${diagonalScore}), Up (${upScore}), Left (${leftScore})`); + Tracer.delay(); + + // Deselect the contributing cells + array2dTracer.deselect(i - 1, j - 1); + array2dTracer.deselect(i - 1, j); + array2dTracer.deselect(i, j - 1); + + // Update the matrix tracer with the final value for the cell + array2dTracer.depatch(i, j); // Remove patch after calculation + array2dTracer.set(scoreMatrix, rowLabels, colLabels); // Re-render the matrix with updated value + logTracer.print(`\n Cell [${i}, ${j}] updated to: ${currentCellScore}`); + Tracer.delay(); + + // Update the maximum score found so far + if (currentCellScore > maxScore) { + maxScore = currentCellScore; + logTracer.print(`\n New maximum score found: ${maxScore} at [${i}, ${j}]`); + Tracer.delay(); + } + } + } + + logTracer.print(`\n Algorithm finished. Final maximum score: ${maxScore}`); + Tracer.delay(); + + return maxScore; +} + + +(function main() { + // visualize { + Layout.setRoot(new VerticalLayout([array2dTracer, logTracer])); + // } + + // Define input sequences + const seq1 = "GGCAT"; + const seq2 = "GGCA"; + + // Call the Smith-Waterman logic + smithWatermanLogic(seq1, seq2); +})(); From b8d637498c5d7da185469ef42a2fff64a86876c4 Mon Sep 17 00:00:00 2001 From: SOLOMON JOHNSON Date: Thu, 26 Jun 2025 15:43:28 +0530 Subject: [PATCH 2/4] Create README.md Created Smith-Waterman algorithm's README file --- Dynamic Programming/Smith-Waterman/README.md | 135 +++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 Dynamic Programming/Smith-Waterman/README.md diff --git a/Dynamic Programming/Smith-Waterman/README.md b/Dynamic Programming/Smith-Waterman/README.md new file mode 100644 index 00000000..336ffd10 --- /dev/null +++ b/Dynamic Programming/Smith-Waterman/README.md @@ -0,0 +1,135 @@ +# **Smith-Waterman Algorithm** + +This guide will help you understand the Smith-Waterman algorithm, a key tool used to find similarities in biological sequences like DNA. + +## **What is the Smith-Waterman Algorithm?** + +Imagine you have two long strings of letters (like DNA sequences). The Smith-Waterman algorithm is a smart way to find the *most similar little pieces* within those two strings. It's like finding a matching phrase in two different books, even if the books are mostly about different things. + +This is super useful in biology to find: + +* **Local Alignments:** It doesn't try to match the entire sequence from start to finish. Instead, it looks for the best "local" matches, which are short, highly similar segments. +* **Key Patterns:** It helps identify important common patterns (like genes or protein parts) that might be hidden within larger, less similar sequences. + +## **How Does It Work?** + +The algorithm works in two main parts: + +### **Part 1: Building a Score Grid** + +We create a grid (or matrix) to score every possible way the sequences could line up. + +1. **The Empty Grid:** + +\* We start with an empty grid. The first row and column are always filled with zeros. Think of these zeros as a "fresh start" button – if a match isn't going well, the algorithm can always reset to zero and look for a new, better match elsewhere. + +2. **Filling the Grid (One Box at a Time):** + +\* For each empty box in the grid, we look at three neighbors: the box above, the box to the left, and the box diagonally up-left. +\* We then calculate four possible scores for the current box: +\* Matching/Mismatching: Take the score from the diagonal box, and add points if the letters match (e.g., 'A' and 'A') or subtract points if they don't match (e.g., 'A' and 'G'). +\* Gap in Sequence 1: Take the score from the box above, and subtract points because we're inserting a "gap" in the first sequence. +\* Gap in Sequence 2: Take the score from the box to the left, and subtract points because we're inserting a "gap" in the second sequence. +\* Reset to Zero: If all the scores above are negative, we simply set the current box's score to 0\. This is how the algorithm finds "local" similarities – it essentially ignores bad matches and looks for new good ones. + +The score for the current box is the highest of these four possibilities. +As we fill the grid, we also keep track of the absolute highest score we find anywhere in the entire grid. This highest score tells us how good our best local match is. + +**The Score Formula for Each Box (H(i,j)):** +H(i,j)=max of⎩⎨⎧​Score from diagonal+Match/Mismatch ScoreScore from above+Gap PenaltyScore from left+Gap Penalty0​ + +### **Part 2: Tracing Back to Find the Best Match** + +Once the entire grid is filled, we find the actual similar segments: + +1. **Find the Highest Score:** We locate the box in the grid that holds the single highest score. This is where our best local match ends. +2. **Follow the Path Back:** From that highest-scoring box, we work backward, moving to the box that gave it its value (diagonal for a match, up for a gap, or left for a gap). +3. **Stop at Zero:** We keep tracing back until we hit a box with a score of 0\. This 0 marks the beginning of our best local match. +4. **Rebuild the Match:** As we trace back, we collect the letters from both sequences to reconstruct the highly similar segments. + +## **Example Walkthrough** + +**Our Sequences:** + +* Seq1 \= "GA" +* Seq2 \= "G" + +**Our Scoring Rules:** + +* Matching letters: Add 2 points +* Mismatching letters: Subtract 1 point +* Adding a gap: Subtract 1 point + +### **Step 1: Set Up the Empty Grid** + +Our grid will be (2+1)×(1+1)=3×2. We fill the first row and column with 0s. + +| | \- | G | +| :---- | :---- | :---- | +| \- | 0 | 0 | +| G | 0 | | +| A | 0 | | + +*Highest score so far:* 0 + +### **Step 2: Fill the Grid Boxes** + +Let's calculate each box's score: + +* **Box at (G, G) (Cell** (1,1)**):** + * This compares G from Seq1 with G from Seq2. They match + * Score options: + * From diagonal (0) \+ Match (2) \= 2 + * From above (0) \+ Gap (-1) \= −1 + * From left (0) \+ Gap (-1) \= −1 + * Reset to zero: 0 + * H(1,1)=max(0,2,−1,−1)=2 + +| | \- | G | +| :---- | :---- | :---- | +| \- | 0 | 0 | +| G | 0 | 2 | +| A | 0 | | + +*Highest score so far:* 2 + +* **Box at (A, G) (Cell** (2,1)**):** + * This compares A from Seq1 with G from Seq2. They mismatch + * Score options: + * From diagonal (0) \+ Mismatch (-1) \= −1 + * From above (2) \+ Gap (-1) \= 1 + * From left (0) \+ Gap (-1) \= −1 + * Reset to zero: 0 + * H(2,1)=max(0,−1,1,−1)=1 + +| | \- | G | +| :---- | :---- | :---- | +| \- | 0 | 0 | +| G | 0 | 2 | +| A | 0 | 1 | + +*Highest score so far:* 2 *(still the* 2 *from the previous box)* + +### **Final Score Grid:** + +| | \- | G | +| :---- | :---- | :---- | +| \- | 0 | 0 | +| G | 0 | 2 | +| A | 0 | 1 | + +The highest score in the grid is 2, found at the box for G in Seq1 and G in Seq2. + +### **Step 3: Tracing Back (What's the Match?)** + +* We start at the box with score 2 (Cell (1,1)). +* It got its score from the diagonal 0 (Cell (0,0)) because G matched G. +* Since we hit a 0, we stop + +Our best local match is: +G +G + +**With a score of 2\.** + +This example shows how the Smith-Waterman algorithm builds the score grid to find the most similar local segments between two sequences. From f9c9537d642157a52e580ce35b0d3e26046e07c3 Mon Sep 17 00:00:00 2001 From: SOLOMON JOHNSON Date: Thu, 26 Jun 2025 15:44:37 +0530 Subject: [PATCH 3/4] formula SS --- .../Screenshot from 2025-06-26 15-31-10.png | Bin 0 -> 20015 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Dynamic Programming/Smith-Waterman/Screenshot from 2025-06-26 15-31-10.png diff --git a/Dynamic Programming/Smith-Waterman/Screenshot from 2025-06-26 15-31-10.png b/Dynamic Programming/Smith-Waterman/Screenshot from 2025-06-26 15-31-10.png new file mode 100644 index 0000000000000000000000000000000000000000..c8213f22d43a4abbbfac263e680b2dda384b0ec7 GIT binary patch literal 20015 zcmc$`WmJ`I^u~D<3&9ozNdZB+yHvWnL6Gk57NomDN?Jg=LBOE9ySuw3W}o*zvu4(s znKd(?=KbJ%qzm$aFgZr=UBM^uO!a{s92*gb;cwIz~pl2o!u{F~rpr@s0BA{hpXP{%Jqa~0M@77y) zMj!|f!hG-L91=H^?B$*dKl|lQN#Lp3ebWc!Inkf^((m^$5!Ua1CmzJ#Mkf{MWmv(H zqI<2`?Ma%&@a?TW;wQr_)^Eg*8GJON4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H 4/4] Update README.md updated the formula --- Dynamic Programming/Smith-Waterman/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dynamic Programming/Smith-Waterman/README.md b/Dynamic Programming/Smith-Waterman/README.md index 336ffd10..3d210fce 100644 --- a/Dynamic Programming/Smith-Waterman/README.md +++ b/Dynamic Programming/Smith-Waterman/README.md @@ -36,7 +36,7 @@ The score for the current box is the highest of these four possibilities. As we fill the grid, we also keep track of the absolute highest score we find anywhere in the entire grid. This highest score tells us how good our best local match is. **The Score Formula for Each Box (H(i,j)):** -H(i,j)=max of⎩⎨⎧​Score from diagonal+Match/Mismatch ScoreScore from above+Gap PenaltyScore from left+Gap Penalty0​ +![formula](https://github.com/deathstalkr/algorithms/blob/Smith-Waterman/Dynamic%20Programming/Smith-Waterman/Screenshot%20from%202025-06-26%2015-31-10.png?raw=true) ### **Part 2: Tracing Back to Find the Best Match**