• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

java实现基因序列比较的示例代码

java 搞代码 4年前 (2022-01-05) 49次浏览 已收录 0个评论

这篇文章主要介绍了java实现基因序列比较的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

设计算法,计算两给定基因序列的相似程度。

人类基因由4种核苷酸,分别用字母ACTG表示。要求编写一个程序,按以下规则比较两个基因序列并确定它们的相似程度。即给出两个基因序列AGTGATG和GTTAG,它们有多相似呢?测量两个基因相似度的一种方法称为对齐。使用对齐方法可以在基因的适当位置加入空格,让两个基因的长度相等,然后根据基因的分值矩阵计算分数。

看了很多代码基本上都是用c++或者c写的,但是习惯性写java就用java实现一下

基本的思路就是,和背包问题差不多,实现还是模仿填表的形式去实现的

表达式:

  • s1 = result[i-1][j-1] + getScore(X[i], Y[j]) 这个是x,y序列使用坐标匹配
  • s2 = result[i-1][j] + getScore(X[i], ‘-‘) 这个是x序列匹配y的 ‘-‘
  • s3 = result[i][j-1] + getScore(‘-‘, Y[j]) 这个是y序列匹配x的 ‘-‘
  • result[i][j] = max(s1,s2,s3) 找出三个中最大的就是所求的值
 package algorithmClassSet.three; import java.util.HashMap; import java.util.Map; /** * s1 = result[i-1][j-1] + getScore(X[i], Y[j]) 这个是x,y序列使用坐标匹配 * s2 = result[i-1][j] + getScore(X[i], '-')  这个是x序列匹配y的 ‘-' * s3 = result[i][j-1] + getScore('-', Y[j]) 这个是y序列匹配x的 ‘-' * result[i][j] = max(s1,s2,s3)  找出三个中最大的就是所求的值 * m*n */ public class GeneSequenceComparison { public static v<mark style="color:transparent">来源gaodaimacom搞#^代%!码网</mark>oid main(String[] args) { dealIt(); } private static void dealIt() { String[] X = {"A", "G", "T", "G", "A", "T", "G"}; String[] Y = {"G", "T", "T", "A", "G"}; int m = X.length + 1; int n = Y.length + 1; int[][] result = new int[m][n]; for (int i = 1; i <m; i++) { result[i][0] = result[i - 1][0] + getScore(X[i - 1], "-"); } for (int j = 1; j <n; j++) { result[0][j] = result[0][j - 1] + getScore("-", Y[j - 1]); } for (int i = 1; i <m; i++) { for (int j = 1; j <n; j++) { int s1 = result[i - 1][j - 1] + getScore(X[i - 1], Y[j - 1]); int s2 = result[i - 1][j] + getScore(X[i - 1], "-"); int s3 = result[i][j - 1] + getScore("-", Y[j - 1]); int maxs = getMax(s1, s2, s3); result[i][j] = maxs; } } System.out.println("结果为:" + result[m - 1][n - 1]); for (int i = 0; i <m; i++) { for (int j = 0; j <n; j++) { System.out.print(result[i][j] + " "); } System.out.println(); } } private static int getMax(int s1, int s2, int s3) { int flag = s1; if (flag <s2) { flag = s2; } if (flag <s3) { flag = s3; } return flag; } //传入值获取分数 private static int getScore(String x, String y) { //x和y必须属于 ACGT- Map map = new HashMap(); map.put("A", 0); map.put("C", 1); map.put("G", 2); map.put("T", 3); map.put("-", 4); int[][] score = { {5, -1, -2, -1, -3}, {-1, 5, -3, -2, -4}, {-2, -3, 5, -2, -2}, {-1, -2, -2, 5, -1}, {-3, -4, -2, -1, -10000000}}; return score[map.get(x)][map.get(y)]; } }

以上就是java实现基因序列比较的示例代码的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:java实现基因序列比较的示例代码
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址