Beispiel #1
0
        public void TestStartNoGapAlgorithm(string matrix, string X, string Y, Func <int, double> penaltyFunc, double evaluation, string resultX, string resultY)
        {
            var similarityMatrix = new SimilarityMatrix(matrix);

            var withGapPenalty = new WithGapPenalty(similarityMatrix, penaltyFunc);
            var tuple          = withGapPenalty.StartNoGapAlgorithm(X, Y);

            Assert.AreEqual(evaluation, tuple.Item1);
            Assert.AreEqual(resultX, tuple.Item2.Item1);
            Assert.AreEqual(resultY, tuple.Item2.Item2);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var arguments = args.Where(x => !x.StartsWith("-")).ToArray();
            var options   = args.Where(x => x.StartsWith("-")).ToArray();

            // Display help message and quit program.
            if (options.Any(x => x == "--help"))
            {
                Console.WriteLine("Syntax:\n");
                Console.WriteLine("   SequencesAlignment [<matrixFilePath>] [<sequencesFilePath>] [--nogappenalty]");
                return;
            }

            // Resolve path to file with matrix from arguments or ask user for the path.
            string matrixFilePath = arguments.ElementAtOrDefault(0);

            if (matrixFilePath == null)
            {
                Console.WriteLine("Path to file with similarity matrix:");
                matrixFilePath = Console.ReadLine();
            }

            FileUtils fu = new FileUtils();

            string           matrixFileContent = fu.ReadContentFromFile(matrixFilePath);
            SimilarityMatrix similarityMatrix  = new SimilarityMatrix(matrixFileContent);

            // Resolve path to file with sequences from arguments or ask user for two sequences.
            string sequencesFilePath = arguments.ElementAtOrDefault(1);
            string sequence1;
            string sequence2;

            if (sequencesFilePath == null)
            {
                Console.WriteLine("First sequences:");
                sequence1 = Console.ReadLine();

                Console.WriteLine("Second sequences:");
                sequence2 = Console.ReadLine();
            }
            else
            {
                string[] sequences = fu.ReadSequencesFromFile(sequencesFilePath);
                sequence1 = sequences[0];
                sequence2 = sequences[1];
            }

            similarityMatrix.CheckSequenceCorrectness(sequence1);
            similarityMatrix.CheckSequenceCorrectness(sequence2);

            // Check whether user provided the --nogappenalty option.
            bool isOptionB = options.Any(x => x == "--nogappenalty");

            if (isOptionB)
            {
                Hirschberg h          = new Hirschberg(similarityMatrix);
                var        results    = h.StartAlgorithm(sequence1, sequence2);
                double     evaluation = similarityMatrix.Evaluate(results.Item1, results.Item2);
                Console.WriteLine(results.Item1);
                Console.WriteLine(results.Item2);
                Console.WriteLine("Evaluation: " + evaluation);
            }
            else
            {
                WithGapPenalty p       = new WithGapPenalty(similarityMatrix, x => x + 2);
                var            results = p.StartNoGapAlgorithm(sequence1, sequence2);
                Console.WriteLine(results.Item2.Item1);
                Console.WriteLine(results.Item2.Item2);
                Console.WriteLine("Evaluation: " + results.Item1);
            }
        }