can't read "maxScore": no such variable
    while executing
"list $aligned_seq1 $aligned_seq2 $maxScore"
    (in namespace eval "::request" script line 144)
    invoked from within
"namespace eval ::request $script"
    ("::try" body line 12)

OUTPUT BUFFER:

# Smith-Waterman Algorithm Implementation for Protein Sequences with BLOSUM62 Matrix and Gap Penalties # Function to load BLOSUM62 matrix from a file proc loadBLOSUM62Matrix {} { set blosum62 [dict create] # Provide the path to your BLOSUM62 matrix file set matrix_file_path "/home/moumou/ordali2/etc/blosum62.dat" set file [open $matrix_file_path "r"] set header [gets $file] while {[string index $header 0] eq "#"} { set header [gets $file] } regsub -all { +} [string trim $header] " " Laa set Laa [split $Laa] while {[gets $file line] != -1} { set elements [regexp -all -inline {\S+} $line] set aa1 [lindex $elements 0] set scores [lrange $elements 1 end] foreach aa2 $Laa sco $scores { dict set blosum62 "$aa1$aa2" $sco } } close $file puts "[dict info $blosum62]" return $blosum62 } # Function to perform Smith-Waterman alignment with BLOSUM62 matrix and gap penalties proc smithWatermanProtein {seq1 seq2 gapOpen gapExtension} { set m [string length $seq1] set n [string length $seq2] set mp1 [expr {$m + 1}] set np1 [expr {$n + 1}] puts "seq1 $m" puts "seq2 $n" flush stdout # Initialize the scoring matrix and traceback matrix set scoreMatrix [lrepeat $mp1 [lrepeat $np1 0]] set tracebackMatrix [lrepeat $mp1 [lrepeat $np1 0]] # Initialize variables to store the maximum score and its position #set maxScore 0 set maxScore -99999 set maxi 0 set maxj 0 # Load BLOSUM62 matrix set blosum62Matrix [loadBLOSUM62Matrix] # Fill in the scoring matrix for {set i 1} {$i <= $m} {incr i} { for {set j 1} {$j <= $n} {incr j} { set diag [lindex $scoreMatrix $i-1 $j-1] set left [lindex $scoreMatrix $i $j-1] set up [lindex $scoreMatrix $i-1 $j] set aa1 [string index $seq1 $i-1] set aa2 [string index $seq2 $j-1] # Lookup BLOSUM62 score set matchScore [dict get $blosum62Matrix "$aa1$aa2"] puts "matchScore $aa1 $aa2 $matchScore" flush stdout # Calculate gap penalties set gapPenLeft [expr {$left - $gapExtension}] set gapPenUp [expr {$up - $gapExtension}] if {[lindex $tracebackMatrix $i $j] eq "left"} { set gapPenLeft [expr {$gapPenLeft - $gapOpen}] } elseif {[lindex $tracebackMatrix $i $j] eq "up"} { set gapPenUp [expr {$gapPenUp - $gapOpen}] } #set score [expr {[expr {$diag + $match_score}]} > [expr {$gapPenLeft > 0 ? $gapPenLeft : 0}] ? [expr {$diag + $match_score}] : 0}] #set score [expr {[expr {$score > $gapPenUp ? $score : $gapPenUp}] > 0 ? [expr {$score > $gapPenUp ? $score : $gapPenUp}] : 0}] lset scoreMatrix $i $j $score # Update the maximum score and its position if {$score > $maxScore} { set maxScore $score set maxi $i set maxj $j } # Update the traceback matrix if {$score == 0} { lset tracebackMatrix $i $j "none" } elseif {$score == $diag + $match_score} { lset tracebackMatrix $i $j "diag" } elseif {$score == $gapPenLeft} { lset tracebackMatrix $i $j "left" } elseif {$score == $gapPenUp} { lset tracebackMatrix $i $j "up" } } } # Traceback to find the aligned sequences set aligned_seq1 "" set aligned_seq2 "" while {0 && $maxi > 0 && $maxj > 0 && [lindex $scoreMatrix $maxi $maxj] > 0} { set current_score [lindex $scoreMatrix $maxi $maxj] set traceback [lindex $tracebackMatrix $maxi $maxj] set aa1 [string index $seq1 [expr {$maxi - 1}]] set aa2 [string index $seq2 [expr {$maxj - 1}]] switch $traceback { "diag" { append aligned_seq1 $aa1 append aligned_seq2 $aa2 incr maxi -1 incr maxj -1 } "left" { append aligned_seq1 "-" append aligned_seq2 $aa2 incr maxj -1 } "up" { append aligned_seq1 $aa1 append aligned_seq2 "-" incr maxi -1 } default { break } } } # Reverse the aligned sequences set aligned_seq1 [string reverse $aligned_seq1] set aligned_seq2 [string reverse $aligned_seq2] return [list $aligned_seq1 $aligned_seq2 $maxScore] } # Example usage set seq1 "ARNDC" set seq2 "AQEGH" set gapOpen 4 set gapExtension 2 set result [smithWatermanProtein $seq1 $seq2 $gapOpen $gapExtension] puts "Aligned Sequence 1: [lindex $result 0]" puts "Aligned Sequence 2: [lindex $result 1]" puts "Alignment Score: [lindex $result 2]"