js DNA动态序列比对代码

时间:2024-04-16 10:41:26 

<title>动态序列比对</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; j++) { 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] = diagonal_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 last cell of matrix var j = l1; var i = l2; while (1) { if(pointer[i][j] == 0)break // ends at first cell of matrix if (pointer[i][j] == 1) { align1[align1.length] = 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 "序列:<p>"+seq1+"<br>"+seq2+"<p>比对结果:<table><tr><td>"+align1.join("</td><td>")+"</td></tr><tr><td>"+align2.join("</td><td>")+"</tr></table>" } document.write(pairaln('CTGGGCTGACTGA', 'GACTAGCTAGACTGA')) </script>
标签:DNA,动态序列
0
投稿

猜你喜欢

  • SQL数据库十四种案例介绍

    2024-01-14 14:50:42
  • vue+Element实现登录随机验证码

    2024-05-29 22:48:34
  • python3.7+selenium模拟淘宝登录功能的实现

    2022-03-05 01:26:27
  • mysql 日期和时间格式转换实现语句

    2024-01-22 22:58:38
  • 用注解编写创建表的SQL语句

    2024-01-14 01:51:11
  • sql索引失效的情况以及超详细解决方法

    2024-01-21 09:25:30
  • python跨文件使用全局变量的实现

    2023-11-27 00:16:40
  • 一个ASP.NET的MYSQL的数据库操作类自己封装的

    2024-01-17 16:43:21
  • 利用python Selenium实现自动登陆京东签到领金币功能

    2021-11-09 12:00:33
  • 为MySQL创建高性能索引

    2024-01-19 09:22:32
  • 设计哲学与跨界

    2009-08-18 12:25:00
  • SQL分页查询存储过程代码分享

    2024-01-12 23:51:04
  • python概率计算器实例分析

    2021-01-16 05:34:52
  • numpy之sum()的使用及说明

    2023-12-12 00:31:16
  • 利用windows任务计划实现oracle的定期备份

    2009-08-31 12:24:00
  • Python 通过微信控制实现app定位发送到个人服务器再转发微信服务器接收位置信息

    2023-02-15 16:49:10
  • Python使用贪婪算法解决问题

    2022-04-13 10:23:14
  • python使用yield压平嵌套字典的超简单方法

    2023-08-28 03:20:00
  • Python使用PyAudio制作录音工具的实现代码

    2023-09-07 22:36:46
  • 详解Go语言中单链表的使用

    2024-02-01 11:55:03
  • asp之家 网络编程 m.aspxhome.com