示例#1
0
 /// <summary>
 /// Default constructor
 /// </summary>
 protected PairwiseSequenceAligner()
 {
     SimilarityMatrix  = new DiagonalSimilarityMatrix(2, -2);
     GapOpenCost       = -8;
     GapExtensionCost  = -1;
     IncludeScoreTable = false;
 }
示例#2
0
        public void PairwiseOverlapProteinSeqWithZeroOverlap()
        {
            Sequence         sequence1     = new Sequence(Alphabets.Protein, "ACDEF");
            Sequence         sequence2     = new Sequence(Alphabets.Protein, "TUVWY");
            SimilarityMatrix sm            = new DiagonalSimilarityMatrix(5, -5);
            int gapPenalty                 = -10;
            PairwiseOverlapAligner overlap = new PairwiseOverlapAligner();

            overlap.SimilarityMatrix = sm;
            overlap.GapOpenCost      = gapPenalty;
            overlap.GapExtensionCost = -1;
            IList <IPairwiseSequenceAlignment> result = overlap.Align(sequence1, sequence2);

            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "{0}, Simple; Matrix {1}; GapOpenCost {2}", overlap.Name, overlap.SimilarityMatrix.Name, overlap.GapOpenCost));
            foreach (IPairwiseSequenceAlignment sequenceResult in result)
            {
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "score {0}", sequenceResult.PairwiseAlignedSequences[0].Score));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "input 0     {0}", sequenceResult.FirstSequence.ToString()));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "input 1     {0}", sequenceResult.SecondSequence.ToString()));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "result 0    {0}", sequenceResult.PairwiseAlignedSequences[0].FirstSequence.ToString()));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "result 1    {0}", sequenceResult.PairwiseAlignedSequences[0].SecondSequence.ToString()));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "consesus    {0}", sequenceResult.PairwiseAlignedSequences[0].Consensus.ToString()));
            }

            IList <IPairwiseSequenceAlignment> expectedOutput = new List <IPairwiseSequenceAlignment>();

            Assert.IsTrue(CompareAlignment(result, expectedOutput));
        }
示例#3
0
        public void SmithWatermanAlignerMultipleAlignments2()
        {
            Sequence         sequence1 = new Sequence(Alphabets.DNA, "AAAAGGGGGGCCCC");
            Sequence         sequence2 = new Sequence(Alphabets.DNA, "AAAATTTTTTTCCCC");
            SimilarityMatrix sm        = new DiagonalSimilarityMatrix(5, -4);
            int gapPenalty             = -10;
            SmithWatermanAligner sw    = new SmithWatermanAligner();

            sw.SimilarityMatrix = sm;
            sw.GapOpenCost      = gapPenalty;
            IList <IPairwiseSequenceAlignment> result = sw.AlignSimple(sequence1, sequence2);

            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "{0}, Simple; Matrix {1}; GapOpenCost {2}", sw.Name, sw.SimilarityMatrix.Name, sw.GapOpenCost));
            foreach (IPairwiseSequenceAlignment sequenceResult in result)
            {
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "score {0}", sequenceResult.PairwiseAlignedSequences[0].Score));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "input 0     {0}", sequenceResult.FirstSequence.ToString()));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "input 1     {0}", sequenceResult.SecondSequence.ToString()));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "result 0    {0}", sequenceResult.PairwiseAlignedSequences[0].FirstSequence.ToString()));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "result 1    {0}", sequenceResult.PairwiseAlignedSequences[0].SecondSequence.ToString()));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "consesus    {0}", sequenceResult.PairwiseAlignedSequences[0].Consensus.ToString()));
            }

            IList <IPairwiseSequenceAlignment> expectedOutput = new List <IPairwiseSequenceAlignment>();
            IPairwiseSequenceAlignment         align          = new PairwiseSequenceAlignment(sequence1, sequence2);

            // First alignment
            PairwiseAlignedSequence alignedSeq = new PairwiseAlignedSequence();

            alignedSeq.FirstSequence  = new Sequence(Alphabets.DNA, "AAAA");
            alignedSeq.SecondSequence = new Sequence(Alphabets.DNA, "AAAA");
            alignedSeq.Consensus      = new Sequence(Alphabets.DNA, "AAAA");
            alignedSeq.Score          = 20;
            alignedSeq.FirstOffset    = 0;
            alignedSeq.SecondOffset   = 0;
            align.PairwiseAlignedSequences.Add(alignedSeq);

            // Second alignment
            alignedSeq = new PairwiseAlignedSequence();
            alignedSeq.FirstSequence  = new Sequence(Alphabets.DNA, "CCCC");
            alignedSeq.SecondSequence = new Sequence(Alphabets.DNA, "CCCC");
            alignedSeq.Consensus      = new Sequence(Alphabets.DNA, "CCCC");
            alignedSeq.Score          = 20;
            alignedSeq.FirstOffset    = 1;
            alignedSeq.SecondOffset   = 0;
            align.PairwiseAlignedSequences.Add(alignedSeq);

            expectedOutput.Add(align);
            Assert.IsTrue(CompareAlignment(result, expectedOutput));
        }
示例#4
0
        public void NeedlemanWunschDnaSeqSimpleGap()
        {
            Sequence         sequence1 = new Sequence(Alphabets.DNA, "GAATTCAGTTA");
            Sequence         sequence2 = new Sequence(Alphabets.DNA, "GGATCGA");
            SimilarityMatrix sm        = new DiagonalSimilarityMatrix(2, -1);
            int gapPenalty             = -2;
            NeedlemanWunschAligner nw  = new NeedlemanWunschAligner();

            nw.SimilarityMatrix = sm;
            nw.GapOpenCost      = gapPenalty;

            IList <IPairwiseSequenceAlignment> result = nw.AlignSimple(sequence1, sequence2);

            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "{0}, Simple; Matrix {1}; GapOpenCost {2}", nw.Name, nw.SimilarityMatrix.Name, nw.GapOpenCost));
            ApplicationLog.WriteLine(string.Format(
                                         (IFormatProvider)null, "score {0}", result[0].PairwiseAlignedSequences[0].Score));
            ApplicationLog.WriteLine(string.Format(
                                         (IFormatProvider)null, "input 0     {0}", result[0].FirstSequence.ToString()));
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "input 1     {0}", result[0].SecondSequence.ToString()));
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "result 0    {0}", result[0].PairwiseAlignedSequences[0].FirstSequence.ToString()));
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "result 1    {0}", result[0].PairwiseAlignedSequences[0].SecondSequence.ToString()));
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "consesus    {0}", result[0].PairwiseAlignedSequences[0].Consensus));

            IList <IPairwiseSequenceAlignment> expectedOutput = new List <IPairwiseSequenceAlignment>();
            IPairwiseSequenceAlignment         align          = new PairwiseSequenceAlignment();
            PairwiseAlignedSequence            alignedSeq     = new PairwiseAlignedSequence();

            alignedSeq.FirstSequence  = new Sequence(Alphabets.DNA, "GAATTCAGTTA");
            alignedSeq.SecondSequence = new Sequence(Alphabets.DNA, "GGA-TC-G--A");
            alignedSeq.Consensus      = new Sequence(AmbiguousDnaAlphabet.Instance, "GRATTCAGTTA");
            alignedSeq.Score          = 3;
            alignedSeq.FirstOffset    = 0;
            alignedSeq.SecondOffset   = 0;
            align.PairwiseAlignedSequences.Add(alignedSeq);
            expectedOutput.Add(align);
            Assert.IsTrue(CompareAlignment(result, expectedOutput));
        }
示例#5
0
        public void TestMUMmer3MultipleMumWithCustomMatrix()
        {
            string reference = "ATGCGCATCCCCTT";
            string search    = "GCGCCCCCTA";

            Sequence referenceSeq = null;
            Sequence searchSeq    = null;

            referenceSeq = new Sequence(Alphabets.DNA, reference);
            searchSeq    = new Sequence(Alphabets.DNA, search);

            List <ISequence> searchSeqs = new List <ISequence>();

            searchSeqs.Add(searchSeq);

            int[,] customMatrix = new int[256, 256];

            customMatrix[(byte)'A', (byte)'A'] = 3;
            customMatrix[(byte)'A', (byte)'T'] = -2;
            customMatrix[(byte)'A', (byte)'G'] = -2;
            customMatrix[(byte)'A', (byte)'c'] = -2;

            customMatrix[(byte)'G', (byte)'G'] = 3;
            customMatrix[(byte)'G', (byte)'A'] = -2;
            customMatrix[(byte)'G', (byte)'T'] = -2;
            customMatrix[(byte)'G', (byte)'C'] = -2;

            customMatrix[(byte)'T', (byte)'T'] = 3;
            customMatrix[(byte)'T', (byte)'A'] = -2;
            customMatrix[(byte)'T', (byte)'G'] = -2;
            customMatrix[(byte)'T', (byte)'C'] = -2;

            customMatrix[(byte)'C', (byte)'C'] = 3;
            customMatrix[(byte)'C', (byte)'T'] = -2;
            customMatrix[(byte)'C', (byte)'A'] = -2;
            customMatrix[(byte)'C', (byte)'G'] = -2;

            DiagonalSimilarityMatrix matrix = new DiagonalSimilarityMatrix(3, -2);

            int gapOpenCost = -6;

            MUMmerAligner mummer = new MUMmerAligner();

            mummer.LengthOfMUM       = 4;
            mummer.PairWiseAlgorithm = new NeedlemanWunschAligner();
            mummer.SimilarityMatrix  = matrix;
            mummer.GapOpenCost       = gapOpenCost;
            mummer.GapExtensionCost  = -2;

            IList <IPairwiseSequenceAlignment> result = mummer.AlignSimple(referenceSeq, searchSeqs);

            // Check if output is not null
            Assert.AreNotEqual(null, result);

            IList <IPairwiseSequenceAlignment> expectedOutput = new List <IPairwiseSequenceAlignment>();
            IPairwiseSequenceAlignment         align          = new PairwiseSequenceAlignment();
            PairwiseAlignedSequence            alignedSeq     = new PairwiseAlignedSequence();

            alignedSeq.FirstSequence  = new Sequence(Alphabets.DNA, "ATGCGCATCCCCTT");
            alignedSeq.SecondSequence = new Sequence(Alphabets.DNA, "--GCGC--CCCCTA");
            alignedSeq.Consensus      = new Sequence(AmbiguousDnaAlphabet.Instance, "ATGCGCATCCCCTW");
            alignedSeq.Score          = 1;
            alignedSeq.FirstOffset    = 0;
            alignedSeq.SecondOffset   = 2;
            align.PairwiseAlignedSequences.Add(alignedSeq);
            expectedOutput.Add(align);
            Assert.IsTrue(CompareAlignment(result, expectedOutput));
        }
示例#6
0
        public void SimilarityMatrixMultiTest()
        {
            string filename = @"testdata\SimilarityMatrices\SampleCustomMatrix.txt";

            Assert.IsTrue(File.Exists(filename));

            SimilarityMatrix blosum50   = new SimilarityMatrix(SimilarityMatrix.StandardSimilarityMatrix.Blosum50);
            SimilarityMatrix fromFile   = new SimilarityMatrix(filename);
            SimilarityMatrix fromReader = null;

            using (TextReader reader = new StreamReader(filename))
            {
                fromReader = new SimilarityMatrix(reader);
            }
            // Custom matrix, clone BLOSUM50 and see if it works.
            int[][]          customMatrixInput = (int[][])blosum50.Matrix.Clone();
            string           symbolMap         = "ARNDCQEGHILKMFPSTWYVBJZX*";
            SimilarityMatrix custom            = new SimilarityMatrix(customMatrixInput, symbolMap, "custom matrix, should be BLOSUM50", MoleculeType.Protein);


            int[][] matrix       = blosum50.Matrix;
            int[][] matrixFile   = fromFile.Matrix;
            int[][] matrixReader = fromReader.Matrix;
            int[][] matrixCustom = custom.Matrix;

            int i, j;
            int iLength = matrix.GetLength(0);
            int jLength = matrix[0].GetLength(0);

            Assert.AreEqual(iLength, matrixFile.GetLength(0));
            Assert.AreEqual(jLength, matrixFile[0].GetLength(0));
            Assert.AreEqual(iLength, matrixReader.GetLength(0));
            Assert.AreEqual(jLength, matrixReader[0].GetLength(0));
            Assert.AreEqual(iLength, matrixCustom.GetLength(0));
            Assert.AreEqual(jLength, matrixCustom[0].GetLength(0));

            for (i = 0; i < iLength; i++)
            {
                for (j = 0; j < jLength; j++)
                {
                    int blosum50Value = blosum50.Matrix[i][j];
                    Assert.AreEqual(blosum50Value, matrixFile[i][j]);
                    Assert.AreEqual(blosum50Value, matrixReader[i][j]);
                    Assert.AreEqual(blosum50Value, matrixCustom[i][j]);
                }
            }

            // Diagonal
            int matchValue               = 10;
            int mismatchValue            = -5;
            DiagonalSimilarityMatrix dsm = new DiagonalSimilarityMatrix(matchValue, mismatchValue, MoleculeType.Protein);

            // There is no real matrix here, just a function that returns matchValue for i==j and otherwise mismatchValue.
            // Run it 25x25
            for (i = 0; i < 25; i++)
            {
                for (j = 0; j < 25; j++)
                {
                    if (i == j)
                    {
                        Assert.AreEqual(matchValue, dsm[i, j]);
                    }
                    else
                    {
                        Assert.AreEqual(mismatchValue, dsm[i, j]);
                    }
                }
            }
        }