为了解决DNA序列的拼接以及检错,特写一下算法
package my.dna; /** * * @author mabixiang * */ public class Util2 { public static void main(String[] args) { String a = "lkjhgfasd"; String b = "sd5sflk"; resemble(a,b); } public static void resemble(String one,String two){ char[] x = addStr(one,two).toCharArray(); char[] y = two.toCharArray(); int similar = 0; int maxi = 0; for(int i=0;i<x.length-y.length+1;i++){ int sim = 0; for(int j=0;j<y.length;j++){ if(y[j]==x[i+j]){ sim++; } } if(sim>similar){ similar=sim; maxi=i; } } System.out.println("相对于one,two重合偏移位:"+(maxi-y.length+1)); System.out.println("重合程度:"+((float)similar/y.length)); } public static String addStr(String one,String two){ StringBuffer sb = new StringBuffer(); for(int i=0;i<two.length()-1;i++){ sb.append(‘0‘); } String ss = sb.toString(); return ss+one+ss; } }
用于字符串拼接,字符串重合度以及偏移量算法,布布扣,bubuko.com
原文:http://blog.csdn.net/suifengerbi/article/details/25876197