简体   繁体   中英

dynamic programming filling matrix in sequence alignment

hello guys i have 2d char array opt[][] and i have 2 sequence in my arrays like in example

 `opt[0][0]=A        
  opt[0][1]=T
  opt[0][2]=G
  opt[0][3]=A`   

I suggest you read these articles.

http://en.wikipedia.org/wiki/Smith%E2%80%93Waterman_algorithm
http://en.wikipedia.org/wiki/Needleman%E2%80%93Wunsch_algorithm

The implementation in any language is pretty trivial.

And if you need information about dynamic programming in general,
either Google for it yourself, or check these two links.

http://en.wikipedia.org/wiki/Dynamic_programming
https://www.topcoder.com/tc?d1=tutorials&d2=dynProg&module=Static

Below you have a javascript implementation that computes the score matrix for global alignment. The entire alignment process was described in " Paul A. Gagniuc. Algorithms in Bioinformatics: Theory and Implementation. John Wiley & Sons, Hoboken, NJ, USA, 2021, ISBN: 9781119697961. " and is available here:

https://github.com/gagniuc/Local-sequence-alignment-in-JS

or here:

https://bcs.wiley.com/he-bcs/Books?action=index&itemId=1119697964&bcsId=12108

 // Variable statement var Match = +2; var Mismatch = -1; var gap = -2; var s0 = 'AGCCCTCCAGGACAGGCT'; var s1 = 'GAAATGATCCGGAA'; var m = []; var s = []; // Matrix initialization and completion s[0] = [] = s0.split(''); s[1] = [] = s1.split(''); var n_0 = s[0].length + 1; var n_1 = s[1].length + 1; for(var i=0; i<=n_0; i++) { m[i]=[]; for(var j=0; j<=n_1; j++) { m[i][j]=0; if (i==1 && j>1) {m[i][j]=m[i][j-1]+gap;} if (j==1 && i>1) {m[i][j]=m[i-1][j]+gap;} if (i>1) {m[i][0]=s[0][i-2];} if (j>1) {m[0][j]=s[1][j-2];} if(i>1 && j>1){ var A = m[i-1][j-1] + f(m[i][0],m[0][j]); //'\\ var B = m[i-1][j] + gap; //'- var C = m[i][j-1] + gap; //'| m[i][j] = Math.max(A, B, C); } } } document.write('Score matrix:'+SMC(m)); // Matching function function f(a1, a2) { if(a1 === a2){return Match;} else {return Mismatch;} } // SHOW MATRIX CONTENT function SMC(m) { var r = "<table border=1>"; for(var i=0; i<m.length; i++) { r += "<tr>"; for(var j=0; j<m[i].length; j++){ r += "<td>"+m[i][j]+"</td>"; } r += "</tr>"; } r += "</table>"; return r; }
 body { padding: 1rem; font-family: monospace; font-size: 18px; font-style: normal; font-variant: normal; line-height: 20px; }

得分矩阵

There are a few implementations with short source codes that you may be interested in. For instance in Visual Basic:

https://github.com/gagniuc/Visual-Sequence-Alignment-in-VB6

https://github.com/gagniuc/Simple-sequence-alignment-in-VB6

Or in Javascript:

https://github.com/Gagniuc/Local-sequence-alignment-in-JS

Or an application in the browser that can help you understand the score matrix a little bit better:

https://github.com/gagniuc/Jupiter-Bioinformatics-V1

Live: https://gagniuc.github.io/Jupiter-Bioinformatics-V1/

在此处输入图像描述

References

Paul A. Gagniuc. Algorithms in Bioinformatics: Theory and Implementation. John Wiley & Sons, Hoboken, NJ, USA, 2021, ISBN: 9781119697961.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM