对于我的作业,我必须计算基因组中与序列比较时的最佳相似性得分。要确定相似性分数,必须将序列的长度减去汉明距离,再除以序列的长度。汉明距离是基因组的一个子串的多少个片段不等于序列。例如,GTTC和AGGT的汉明距离为4,因为它们在任何一点都不相等。
如果要为该方法指定genome="ATACGC“和sequence="ACT”,则最佳相似性得分应为0.67。但是当我运行我的程序时,它将只返回0。我正在使用android应用程序与我的基因组处理服务器进行交互。谢谢你,如果你能帮我解决这个问题!
返回0的方法的代码-
public static String similarityScore(String genome, String sequence)
{
double bestSimilarity;
double similarity;
int i;
int j;
int hammingDistance;
String subString;
String miniSubString;
String subSequence;
String returnStr;
DecimalFormat df;
df=new DecimalFormat("#.##");
bestSimilarity=-1;
i=0;
//makes a substring of the genome so you can compare the substring to the sequence
//increments i by 1 each iteration to move down the string to make new substrings
while((i+sequence.length())<(genome.length()+1) && i<genome.length())
{
subString = genome.substring(i, i + sequence.length());
hammingDistance=0;
for (j=0;j<sequence.length();j++)
{
// these two lines make substrings of a single character
//to compare if they equal each other
miniSubString = subString.substring(j, j + 1);
subSequence = sequence.substring(j,j+1);
//if they dont equal each other increase hamming distance by 1
if(!miniSubString.equals(subSequence))
hammingDistance++;
}
//calculates hammingdistance, which is the
// (length of the sequence - the hamming distance) / the length of the sequence
similarity=(sequence.length()-hammingDistance)/sequence.length();
if (similarity>bestSimilarity)
bestSimilarity=similarity;
i++;
}
returnStr=df.format(bestSimilarity);
return returnStr;
}发布于 2019-12-03 04:14:40
我认为这是因为您的答案被转换为整数。这就是我是如何得到正确答案的。
添加以下内容:
Double len = sequence.length() * 1.0; 将其添加到以下行之前:
similarity=(sequence.length()-hammingDistance)/sequence.length();然后将该行替换为:
similarity=(sequence.length()-hammingDistance)/len;这应该会给你想要的答案。
编辑:固定一条线。
https://stackoverflow.com/questions/59145790
复制相似问题