Ejemplo n.º 1
0
        public static double UnnormalisedSmithWatermanSimilarity(string source, string target)
        {
            double GapCost = DefaultGapCost;

            if (source == null || target == null)
            {
                return(DefaultMismatchScore);
            }
            int length = source.Length;
            int num2   = target.Length;

            if (length == 0)
            {
                return(num2);
            }
            if (num2 == 0)
            {
                return(length);
            }
            double[][] numArray = new double[length][];
            for (int i = 0; i < length; i++)
            {
                numArray[i] = new double[num2];
            }
            double num4 = 0.0;

            for (int j = 0; j < length; j++)
            {
                double thirdNumber = Get01Cost(source, j, target, 0);
                if (j == 0)
                {
                    numArray[0][0] = MathFunctions.MaxOf3(0.0, -GapCost, thirdNumber);
                }
                else
                {
                    numArray[j][0] = MathFunctions.MaxOf3(0.0, numArray[j - 1][0] - GapCost, thirdNumber);
                }
                if (numArray[j][0] > num4)
                {
                    num4 = numArray[j][0];
                }
            }

            for (int k = 0; k < num2; k++)
            {
                double num8 = Get01Cost(source, 0, target, k);
                if (k == 0)
                {
                    numArray[0][0] = MathFunctions.MaxOf3(0.0, -GapCost, num8);
                }
                else
                {
                    numArray[0][k] = MathFunctions.MaxOf3(0.0, numArray[0][k - 1] - GapCost, num8);
                }
                if (numArray[0][k] > num4)
                {
                    num4 = numArray[0][k];
                }
            }

            for (int m = 1; m < length; m++)
            {
                for (int n = 1; n < num2; n++)
                {
                    double num11 = Get01Cost(source, m, target, n);
                    numArray[m][n] = MathFunctions.MaxOf4(0.0, numArray[m - 1][n] - GapCost, numArray[m][n - 1] - GapCost, numArray[m - 1][n - 1] + num11);
                    if (numArray[m][n] > num4)
                    {
                        num4 = numArray[m][n];
                    }
                }
            }
            return(num4);
        } // end unnormallized
Ejemplo n.º 2
0
        public static double UnnormalisedSmithWatermanSimilarity(this string firstWord, string secondWord)
        {
            if (firstWord == null || secondWord == null)
            {
                return(0.0);
            }
            int length = firstWord.Length;
            int num2   = secondWord.Length;

            if (length == 0)
            {
                return(num2);
            }
            if (num2 == 0)
            {
                return(length);
            }
            double[][] numArray = new double[length][];
            for (int i = 0; i < length; i++)
            {
                numArray[i] = new double[num2];
            }
            double num4 = 0.0;

            for (int j = 0; j < length; j++)
            {
                double num6 = DCostFunction.GetCost(firstWord, j, secondWord, 0);
                if (j == 0)
                {
                    numArray[0][0] = Math.Max(0.0, num6);
                }
                else
                {
                    double num7 = 0.0;
                    int    num8 = j - _windowSize;
                    if (num8 < 1)
                    {
                        num8 = 1;
                    }
                    for (int n = num8; n < j; n++)
                    {
                        num7 = Math.Max(num7, numArray[j - n][0] - GGapFunction.GetCost(firstWord, j - n, j));
                    }
                    numArray[j][0] = MathFunctions.MaxOf3(0.0, num7, num6);
                }
                if (numArray[j][0] > num4)
                {
                    num4 = numArray[j][0];
                }
            }
            for (int k = 0; k < num2; k++)
            {
                double num11 = DCostFunction.GetCost(firstWord, 0, secondWord, k);
                if (k == 0)
                {
                    numArray[0][0] = Math.Max(0.0, num11);
                }
                else
                {
                    double num12 = 0.0;
                    int    num13 = k - _windowSize;
                    if (num13 < 1)
                    {
                        num13 = 1;
                    }
                    for (int num14 = num13; num14 < k; num14++)
                    {
                        num12 = Math.Max(num12, numArray[0][k - num14] - GGapFunction.GetCost(secondWord, k - num14, k));
                    }
                    numArray[0][k] = MathFunctions.MaxOf3(0.0, num12, num11);
                }
                if (numArray[0][k] > num4)
                {
                    num4 = numArray[0][k];
                }
            }
            for (int m = 1; m < length; m++)
            {
                for (int num16 = 1; num16 < num2; num16++)
                {
                    double num17 = DCostFunction.GetCost(firstWord, m, secondWord, num16);
                    double num18 = 0.0;
                    double num19 = 0.0;
                    int    num20 = m - _windowSize;
                    if (num20 < 1)
                    {
                        num20 = 1;
                    }
                    for (int num21 = num20; num21 < m; num21++)
                    {
                        num18 = Math.Max(num18, numArray[m - num21][num16] - GGapFunction.GetCost(firstWord, m - num21, m));
                    }
                    num20 = num16 - _windowSize;
                    if (num20 < 1)
                    {
                        num20 = 1;
                    }
                    for (int num22 = num20; num22 < num16; num22++)
                    {
                        num19 = Math.Max(num19, numArray[m][num16 - num22] - GGapFunction.GetCost(secondWord, num16 - num22, num16));
                    }
                    numArray[m][num16] = MathFunctions.MaxOf4(0.0, num18, num19, numArray[m - 1][num16 - 1] + num17);
                    if (numArray[m][num16] > num4)
                    {
                        num4 = numArray[m][num16];
                    }
                }
            }
            return(num4);
        }