Esempio n. 1
0
        public async Task PValueMainline()
        {
            SequenceMetadata item1 = await
                                     FastALookupCient.LookupByAccessionIdAsync("Q10574");

            SequenceMetadata item2 = await
                                     FastALookupCient.LookupByAccessionIdAsync("P15172");

            var localAlignmentImpl = new SmithWatermanImplementation(
                sequenceTomatch: item1,
                targetSequence:  item2,
                scoreProvider: new SimpleScoreProvider(),
                gapOpenPenality: 1);

            var pvalueCalculator = new PValueCalculator <SmithWatermanImplementation>
                                   (
                alignmentImpl: localAlignmentImpl,
                permutationLimit: 10
                                   );

            string result = await pvalueCalculator.CalculatePValueAsync();

            Assert.IsNotNull(result);

            Console.WriteLine("--Calculated P value--");
            Console.WriteLine(result);
        }
Esempio n. 2
0
        public async Task SmithWatermanP15172ToP17542WithBlosum62ScoringScheme()
        {
            SequenceMetadata item1 = await
                                     FastALookupCient.LookupByAccessionIdAsync("P10085");

            SequenceMetadata item2 = await
                                     FastALookupCient.LookupByAccessionIdAsync("P15172");

            var localAlignmentImpl = new SmithWatermanImplementation(
                sequenceTomatch: item1,
                targetSequence: item2,
                scoreProvider: new Blosum62ScoreProvider(),
                gapOpenPenality: 4);

            //var localAlignmentImpl = new SmithWatermanImplementation(
            //    sequenceTomatch: "KEVLAR",
            //    targetSequence: "KNIEVIL",
            //    scoreProvider: new Blosum62ScoreProvider(),
            //    gapOpenPenality: 4);

            AlignmentImplementationResults result
                = localAlignmentImpl.FindOptimalAlignment();

            Console.WriteLine("--Optimal Alignment--");
            Console.WriteLine(result.TargetSequenceAlignment);
            Console.WriteLine(result.SearchSequenceAlignment);

            Console.WriteLine("--Optimal Score--");
            Console.WriteLine(result.AlignmentScore);

            var pvalueCalculator = new PValueCalculator <SmithWatermanImplementation>
                                   (
                alignmentImpl: localAlignmentImpl,
                permutationLimit: 1
                                   );

            string pValue = await pvalueCalculator.CalculatePValueAsync();

            Assert.IsNotNull(result);

            Console.WriteLine("--Calculated P value--");
            Console.WriteLine(pValue);

            Console.WriteLine(result.PrettyPrint());
            Console.WriteLine(result.PrettyPrintScoreMatrix());
        }
Esempio n. 3
0
        public async Task ViterbiGCPatchTenRuns()
        {
            var gcPatchParameters  = new GCPatchParameters();
            SequenceMetadata item1 = await
                                     FastALookupCient.LookupByAccessionIdAsync("GCF_000091665.1_ASM9166v1_genomic");

            var viterbigcPatch           = new ViterbiImpl(gcPatchParameters, input: item1.Sequence);
            List <ViterbiResult> results = viterbigcPatch.ExecuteViterbiAndTrain(executionCount: 10);

            for (int i = 0; i < 9; i++)
            {
                Console.WriteLine("Iteration {0}", i + 1);
                Console.WriteLine("---------------------------------------------------------------------------");
                Console.WriteLine(results[i].PrettyPrint(interestedStateIndex: 1, numberOfHits: 5));
            }

            Console.WriteLine("Iteration {0}", 10);
            Console.WriteLine("---------------------------------------------------------------------------");
            Console.WriteLine(results[9].PrettyPrintAllHits(interestedStateIndex: 1));

            Assert.IsNotNull(results);
        }
Esempio n. 4
0
        public async Task SmithWatermanImplementationMainlineWithSimpleScoringScheme()
        {
            SequenceMetadata item1 = await
                                     FastALookupCient.LookupByAccessionIdAsync("Q10574");

            SequenceMetadata item2 = await
                                     FastALookupCient.LookupByAccessionIdAsync("P15172");

            var localAlignmentImpl = new SmithWatermanImplementation(
                sequenceTomatch: item1,
                targetSequence: item2,
                scoreProvider: new SimpleScoreProvider(),
                gapOpenPenality: 1);

            AlignmentImplementationResults result
                = localAlignmentImpl.FindOptimalAlignment();

            Console.WriteLine("--Optimal Alignment--");
            Console.WriteLine(result.TargetSequenceAlignment);
            Console.WriteLine(result.SearchSequenceAlignment);

            Console.WriteLine("--Optimal Score--");
            Console.WriteLine(result.AlignmentScore);

            Assert.AreEqual(expected: 19,
                            actual: result.AlignmentScore,
                            message: "Mismatching alignment scores");

            Assert.AreEqual(
                expected: "VE-IL-RNA-IRY-I-E-GL-QA-LL-RDQD",
                actual: result.TargetSequenceAlignment,
                message: "Mismatching target alignment sequence");

            Assert.AreEqual(
                expected: "-FE-TL-QMA-QKY-I-E-CL-SQ-IL-KQD",
                actual: result.SearchSequenceAlignment,
                message: "Mismatching target alignment sequence");
        }
Esempio n. 5
0
        public async Task ViterbiDiceRollTenRuns()
        {
            var diceRollParams     = new DiceRollParameters();
            SequenceMetadata item1 = await
                                     FastALookupCient.LookupByAccessionIdAsync("DiceRoll");

            var viterbiDiceRoll          = new ViterbiImpl(diceRollParams, input: item1.Sequence);
            List <ViterbiResult> results = viterbiDiceRoll.ExecuteViterbiAndTrain(executionCount: 10);

            for (int i = 0; i < 9; i++)
            {
                Console.WriteLine("Iteration {0}", i + 1);
                Console.WriteLine("---------------------------------------------------------------------------");
                Console.WriteLine(results[i].PrettyPrint(interestedStateIndex: 1, numberOfHits: 5));
                Console.WriteLine(results[i].StateTransitionRepresentaton);
            }

            Console.WriteLine("Iteration {0}", 10);
            Console.WriteLine("---------------------------------------------------------------------------");
            Console.WriteLine(results[9].PrettyPrintAllHits(interestedStateIndex: 1));
            Console.WriteLine(results[9].StateTransitionRepresentaton);

            Assert.IsNotNull(results);
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            string outputLocation      = @"c:\temp\output_jeeshn.txt";
            var    proteinAccessionIds = new string[]
            {
                "P15172",
                "P17542",
                "P10085",
                "P16075",
                "P13904",
                "Q90477",
                "Q8IU24",
                "P22816",
                "Q10574",
                "O95363"
            };

            // Input data for a simple sequence
            var item1 = new SequenceMetadata
            {
                AccessionId = "X1",
                Sequence    = "deadly"
            };

            var item2 = new SequenceMetadata
            {
                AccessionId = "X2",
                Sequence    = "ddgearlyk"
            };

            using (var fileStream = File.Open(outputLocation, FileMode.Create))
                using (var streamWriter = new StreamWriter(fileStream))
                {
                    // Run the local alignment .
                    var localAlignmentImpl = new SmithWatermanImplementation(
                        sequenceTomatch: item1,
                        targetSequence: item2,
                        scoreProvider: new Blosum62ScoreProvider(),
                        gapOpenPenality: 4);

                    AlignmentImplementationResults result
                        = localAlignmentImpl.FindOptimalAlignment();

                    // "Capture" output
                    WriteToConsoleAndFile(
                        String.Format("{0} vs {1}", item1.AccessionId, item2.AccessionId), streamWriter);
                    WriteToConsoleAndFile("Alignment Score", streamWriter);
                    WriteToConsoleAndFile(result.AlignmentScore.ToString(), streamWriter);

                    WriteToConsoleAndFile("Alignment", streamWriter);
                    WriteToConsoleAndFile(result.PrettyPrint(), streamWriter);

                    WriteToConsoleAndFile("Score Matrix", streamWriter);
                    WriteToConsoleAndFile(result.PrettyPrintScoreMatrix(), streamWriter);

                    // P-value calculation
                    var pvalueCalculator = new PValueCalculator <SmithWatermanImplementation>
                                           (
                        alignmentImpl: localAlignmentImpl,
                        permutationLimit: 999
                                           );

                    //Print p values
                    string pValue = pvalueCalculator.CalculatePValueAsync().Result;
                    WriteToConsoleAndFile("Empirical p-value", streamWriter);
                    WriteToConsoleAndFile(pValue, streamWriter);
                    WriteToConsoleAndFile(String.Empty, streamWriter);

                    int[,] scoreMatrix = new int[10, 10];

                    for (int i = 0; i < proteinAccessionIds.Length; i++)
                    {
                        for (int j = 0; j < proteinAccessionIds.Length; j++)
                        {
                            // no need to compare same sequences
                            if (i != j)
                            {
                                item1 = FastALookupCient.LookupByAccessionIdAsync(proteinAccessionIds[i]).Result;

                                item2 = FastALookupCient.LookupByAccessionIdAsync(proteinAccessionIds[j]).Result;

                                localAlignmentImpl = new SmithWatermanImplementation(
                                    sequenceTomatch: item1,
                                    targetSequence: item2,
                                    scoreProvider: new Blosum62ScoreProvider(),
                                    gapOpenPenality: 4);

                                result = localAlignmentImpl.FindOptimalAlignment();

                                // "Capture" output
                                WriteToConsoleAndFile(
                                    String.Format("{0} vs {1}", item1.AccessionId, item2.AccessionId), streamWriter);
                                WriteToConsoleAndFile("Alignment Score", streamWriter);
                                WriteToConsoleAndFile(result.AlignmentScore.ToString(), streamWriter);

                                WriteToConsoleAndFile("Alignment", streamWriter);
                                WriteToConsoleAndFile(result.PrettyPrint(), streamWriter);

                                scoreMatrix[i, j] = result.AlignmentScore;

                                if (item1.AccessionId == "P15172" &&
                                    (item2.AccessionId == "Q10574" || item2.AccessionId == "O95363"))
                                {
                                    pvalueCalculator = new PValueCalculator <SmithWatermanImplementation>
                                                       (
                                        alignmentImpl: localAlignmentImpl,
                                        permutationLimit: 999
                                                       );

                                    //Print p values
                                    pValue = pvalueCalculator.CalculatePValueAsync().Result;
                                    WriteToConsoleAndFile("Empirical p-value", streamWriter);
                                    WriteToConsoleAndFile(pValue, streamWriter);
                                    WriteToConsoleAndFile(String.Empty, streamWriter);
                                }
                            }
                        }
                    }

                    var stringBuilder = new StringBuilder();
                    for (int i = 0; i <= scoreMatrix.GetUpperBound(0); i++)
                    {
                        for (int j = 0; j <= scoreMatrix.GetUpperBound(1); j++)
                        {
                            if (j >= i)
                            {
                                stringBuilder.Append(scoreMatrix[i, j].ToString().PadRight(6, ' '));
                            }
                            else
                            {
                                stringBuilder.Append("0".PadRight(6, ' '));
                            }
                        }
                        stringBuilder.AppendLine();
                    }

                    WriteToConsoleAndFile("Protein scoring matrix", streamWriter);
                    WriteToConsoleAndFile(stringBuilder.ToString(), streamWriter);

                    streamWriter.Flush();
                    fileStream.Flush();
                }
            Console.ReadLine();
        }