对于我的任务,与序列相比,我必须计算出基因组中的最佳相似性得分。要确定相似性得分,您必须将序列的长度减去汉明距离,再除以序列的长度。汉明距离是基因组子串中有多少个片段不等于序列。例如,GTTC和AGGT的汉明距离为4,因为它们在任何一点都不相等。
如果要为该方法提供基因组=“ ATACGC”和序列=“ 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;
}
答案 0 :(得分:0)
我认为这是因为您的答案被强制转换为整数。这是我到达正确答案的方式。
添加此内容:
Double len = sequence.length() * 1.0;
在以下行之前添加它:
similarity=(sequence.length()-hammingDistance)/sequence.length();
然后用以下内容替换该行:
similarity=(sequence.length()-hammingDistance)/len;
这应该为您提供所需的答案。
编辑:修正了一行。