_javascript technique of JS DNA dynamic sequence ratio code

Source: Internet
Author: User
<title> Dynamic sequence Alignment </title> <script> function Pairaln (seq1, SEQ2) {//scoring scheme var MATCH = 1;//+ 1 for letters that match var mismatch =-1; -1 for letters that mismatch var GAP =-1; -1 for any gap//initialization var score=[[]]; var pointer=[[]]; Score[0][0] = 0; Pointer[0][0] = 0; var l1=seq1.length var l2=seq2.length for (var j = 1; j <= L1; j +) {Score[0][j] = GAP * J; POINTER[0][J] = 2; for (var i = 1; I <= L2; i++) {score[i]=[]; Pointer[i]=[]; SCORE[I][0] = GAP * i; Pointer[i][0] = 3; }//fill for (var i = 1; I <= L2; i++) {var letter2 = Seq2.charat (i-1); for (var j = 1; J <= L1 + +) {var diagonal_score, left_score, Up_score; Calculate Match score var letter1 = Seq1.charat (j-1); if (Letter1 = = letter2) {Diagonal_score = score[i-1][j-1] + MATCH; else {Diagonal_score = score[i-1][j-1] + mismatch; }//Calculate gap scores up_score = Score[i-1][j] + gap; Left_score = score[i][j-1] + GAP; Choose Best Score if (Diagonal_score >= up_score) {if (Diagonal_score >= left_score) {Score[i][j] = Diago Nal_score; POINTER[I][J] = 1; else {score[i][j] = Left_score; POINTER[I][J] = 2; } else {if (Up_score >= left_score) {score[i][j] = Up_score; POINTER[I][J] = 3; else {score[i][j] = Left_score; POINTER[I][J] = 2; }}//trace-back var align1 = []; var align2 = []; Start at the last cell of matrix var j = L1; var i = L2; while (1) {if (pointer[i][j] = = 0) break//ends at in the matrix if (pointer[i][j] = 1) {Align1[align1.lengt h] = Seq1.charat (j-1); Align2[align2.length] = Seq2.charat (i-1); i--; j--; } if (pointer[i][j] = = 2) {Align1[align1.length] = Seq1.charat (j-1); Align2[align2.length] = "-"; j--; } if (pointer[i][j] = = 3) {Align1[align1.length] = "-"; Align2[align2.length] = Seq2.charat (i-1); i--; } align1 = Align1.reverse (); ALIGN2 = Align2.reverse (); return "Sequence:<P> "+seq1+" <br> "+seq2+" <p> result:<table><tr><td> "+align1.join (" </td><td > ") +" </td></tr><tr><td> "+align2.join (" </td><td> ") +" </tr></ Table> "} document.write (Pairaln (' ctgggctgactga ', ' gactagctagactga ')) </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.