简体   繁体   English

基因组处理服务器 - 方法返回 0,我不明白为什么 (java)

[英]Genome Processing Server - Method is returning 0 and I don't understand why (java)

For my assignment, I must calculate the best similarity score in a genome when compared to a sequence.对于我的作业,我必须计算与序列比较时基因组中的最佳相似度得分。 To determine the similarity score you must have the length of the sequence subtracted by the hamming distance all divided by the length of the sequence.要确定相似度分数,您必须将序列长度减去汉明距离,然后再除以序列长度。 The hamming distance is how many pieces of a substring of the genome does not equal the sequence.汉明距离是基因组的一个子串中有多少条不等于该序列。 For example GTTC and AGGT have a hamming distance of 4 because they don't equal each other at any point.例如,GTTC 和 AGGT 的汉明距离为 4,因为它们在任何一点都不相等。

If you were to give the method the genome="ATACGC" and the sequence="ACT" the best similarity score should be 0.67.如果您要为该方法提供基因组 =“ATACGC”和序列 =“ACT”,则最佳相似度得分应为 0.67。 But when I run my program it will only return 0. I am using an android app to interact with my genome processing server.但是当我运行我的程序时,它只会返回 0。我正在使用一个 android 应用程序与我的基因组处理服务器进行交互。 Thank you, if you can help me with this issue!!!谢谢,如果你能帮我解决这个问题!!!

Code to the method that is returning a 0-返回 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;
}

I think it is because your answer is being cast as an integer.我认为这是因为您的答案被转换为整数。 Here is how I arrived to the correct answer.这是我得出正确答案的方式。

Add this:添加这个:

Double len = sequence.length() * 1.0; 

Add it before the following line:将其添加到以下行之前:

similarity=(sequence.length()-hammingDistance)/sequence.length();

Then replace that line with this:然后用这个替换该行:

similarity=(sequence.length()-hammingDistance)/len;

That should give you the answer you're looking for.这应该给你你正在寻找的答案。

EDIT: fixed a line.编辑:固定一条线。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM