コード例 #1
0
        public void SimpleConsensusWithMakeConsensusMethod()
        {
            IOverlapDeNovoAssembly assembly = GetSequenceAssembly("consensus");

            string contigConsensus = utilityObj.xmlUtil.GetTextValue(Constants.AssemblyAlgorithmNodeName,
                                                                     Constants.ContigConsensusNode);
            double consensusThreshold = double.Parse(utilityObj.xmlUtil.GetTextValue(
                                                         Constants.AssemblyAlgorithmNodeName,
                                                         Constants.ConsensusThresholdNode), null);
            IAlphabet alphabet = Utility.GetAlphabet(utilityObj.xmlUtil.GetTextValue(
                                                         Constants.AssemblyAlgorithmNodeName,
                                                         Constants.AlphabetNameNode));
            // Read the contig from Contig method.
            Contig contigReadForConsensus = assembly.Contigs[0];

            contigReadForConsensus.Consensus = null;
            OverlapDeNovoAssembler simpleSeqAssembler = new OverlapDeNovoAssembler();

            simpleSeqAssembler.ConsensusResolver = new SimpleConsensusResolver(consensusThreshold);
            simpleSeqAssembler.MakeConsensus(alphabet, contigReadForConsensus);

            Assert.AreEqual(contigConsensus, new String(contigReadForConsensus.Consensus.Select(a => (char)a).ToArray()));

            // Log the required info.
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                   "SimpleConsensusMethod BVT : Consensus read is '{0}'.",
                                                   contigReadForConsensus.Consensus.ToString()));
            Console.WriteLine(string.Format((IFormatProvider)null,
                                            "SimpleConsensusMethod BVT : Consensus read is '{0}'.",
                                            contigReadForConsensus.Consensus.ToString()));
        }
コード例 #2
0
        /// <summary>
        ///     Validates the Sequence Assembler for all the general test cases.
        /// </summary>
        /// <param name="nodeName">Xml Node Name</param>
        /// <param name="additionalParameter">
        ///     Additional Parameter based
        ///     on which the validations are done.
        /// </param>
        /// <param name="isSeqAssemblyctr">True if Default contructor is validated or else false.</param>
        private void ValidateSequenceAssemblerGeneral(string nodeName,
                                                      AssemblyParameters additionalParameter, bool isSeqAssemblyctr)
        {
            // Get the parameters from Xml
            int matchScore = int.Parse(utilityObj.xmlUtil.GetTextValue(nodeName,
                                                                       Constants.MatchScoreNode), null);
            int mismatchScore = int.Parse(utilityObj.xmlUtil.GetTextValue(nodeName,
                                                                          Constants.MisMatchScoreNode), null);
            int gapCost = int.Parse(utilityObj.xmlUtil.GetTextValue(nodeName,
                                                                    Constants.GapCostNode), null);
            double mergeThreshold = double.Parse(utilityObj.xmlUtil.GetTextValue(nodeName,
                                                                                 Constants.MergeThresholdNode), null);
            double consensusThreshold = double.Parse(utilityObj.xmlUtil.GetTextValue(nodeName,
                                                                                     Constants.ConsensusThresholdNode),
                                                     null);

            string[] sequences = utilityObj.xmlUtil.GetTextValues(nodeName,
                                                                  Constants.SequencesNode);
            IAlphabet alphabet = Utility.GetAlphabet(utilityObj.xmlUtil.GetTextValue(nodeName,
                                                                                     Constants.AlphabetNameNode));
            string documentation = utilityObj.xmlUtil.GetTextValue(nodeName,
                                                                   Constants.DocumentaionNode);
            var info = new SerializationInfo(typeof(OverlapDeNovoAssembly),
                                             new FormatterConverter());
            var context = new StreamingContext(StreamingContextStates.All);

            var inputs = new List <ISequence>();

            switch (additionalParameter)
            {
            case AssemblyParameters.Consensus:
                for (int i = 0; i < sequences.Length; i++)
                {
                    // Logs the sequences
                    ApplicationLog.WriteLine(string.Format(null, "SimpleConsensusMethod P1 : Sequence '{0}' used is '{1}'.", i, sequences[i]));

                    var seq = new Sequence(alphabet, sequences[i]);
                    inputs.Add(seq);
                }
                break;

            default:
                for (int i = 0; i < sequences.Length; i++)
                {
                    // Logs the sequences
                    ApplicationLog.WriteLine(string.Format(null, "SequenceAssembly P1 : Sequence '{0}' used is '{1}'.", i, sequences[i]));
                    var seq = new Sequence(alphabet, sequences[i]);
                    inputs.Add(seq);
                }
                break;
            }

            // here is how the above sequences should align:
            // TATAAAGCGCCAA
            //         GCCAAAATTTAGGC
            //                   AGGCACCCGCGGTATT   <= reversed
            //
            // TATAAAGCGCCAAAATTTAGGCACCCGCGGTATT

            var assembler = new OverlapDeNovoAssembler
            {
                MergeThreshold   = mergeThreshold,
                OverlapAlgorithm = new PairwiseOverlapAligner()
            };

            switch (additionalParameter)
            {
            case AssemblyParameters.DiagonalSM:
                (assembler.OverlapAlgorithm).SimilarityMatrix =
                    new DiagonalSimilarityMatrix(matchScore, mismatchScore);
                break;

            case AssemblyParameters.SimilarityMatrix:
                string blosumFilePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.BlosumFilePathNode);
                (assembler.OverlapAlgorithm).SimilarityMatrix = new SimilarityMatrix(blosumFilePath);
                break;

            default:
                (assembler.OverlapAlgorithm).SimilarityMatrix = new DiagonalSimilarityMatrix(matchScore, mismatchScore);
                break;
            }

            (assembler.OverlapAlgorithm).GapOpenCost = gapCost;
            assembler.ConsensusResolver         = new SimpleConsensusResolver(consensusThreshold);
            assembler.AssumeStandardOrientation = false;

            // Assembles all the sequences.
            IOverlapDeNovoAssembly assembly = (IOverlapDeNovoAssembly)assembler.Assemble(inputs);

            // Set Documentation property.
            assembly.Documentation = documentation;

            // Get the parameters from Xml in general
            int    contigSequencesCount = int.Parse(utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ContigSequencesCountNode), null);
            string contigConsensus      = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ContigConsensusNode);

            switch (additionalParameter)
            {
            case AssemblyParameters.Consensus:
                // Read the contig from Contig method.
                Contig contigReadForConsensus = assembly.Contigs[0];
                contigReadForConsensus.Consensus = null;
                var simpleSeqAssembler = new OverlapDeNovoAssembler
                {
                    ConsensusResolver = new SimpleConsensusResolver(consensusThreshold)
                };
                simpleSeqAssembler.MakeConsensus(alphabet, contigReadForConsensus);

                // Log the required info.
                ApplicationLog.WriteLine(string.Format(null, "SimpleConsensusMethod BVT : Consensus read is '{0}'.", contigReadForConsensus.Consensus));
                Assert.AreEqual(contigConsensus, new String(contigReadForConsensus.Consensus.Select(a => (char)a).ToArray()));
                break;

            default:
                // Get the parameters from Xml for Assemble() method test cases.
                int unMergedCount = int.Parse(utilityObj.xmlUtil.GetTextValue(nodeName,
                                                                              Constants.UnMergedSequencesCountNode),
                                              null);
                int contigsCount = int.Parse(utilityObj.xmlUtil.GetTextValue(nodeName,
                                                                             Constants.ContigsCountNode), null);

                Assert.AreEqual(unMergedCount, assembly.UnmergedSequences.Count);
                Assert.AreEqual(contigsCount, assembly.Contigs.Count);
                Assert.AreEqual(documentation, assembly.Documentation);
                Contig contigRead = assembly.Contigs[0];

                // Logs the consensus
                ApplicationLog.WriteLine(string.Format(null, "SequenceAssembly BVT : Un Merged Sequences Count is '{0}'.", assembly.UnmergedSequences.Count));
                ApplicationLog.WriteLine(string.Format(null, "SequenceAssembly BVT : Contigs Count is '{0}'.", assembly.Contigs.Count));
                ApplicationLog.WriteLine(string.Format(null, "SequenceAssembly BVT : Contig Sequences Count is '{0}'.", contigRead.Sequences.Count));
                ApplicationLog.WriteLine(string.Format(null, "SequenceAssembly BVT : Consensus read is '{0}'.", contigRead.Consensus));

                Assert.AreEqual(contigConsensus, new String(contigRead.Consensus.Select(a => (char)a).ToArray()));
                Assert.AreEqual(contigSequencesCount, contigRead.Sequences.Count);
                break;
            }
        }
コード例 #3
0
        /// <summary>
        /// Validate Sequence Assembler Test cases based on additional parameter values
        /// </summary>
        /// <param name="additionalParameter">Addtional parameters</param>
        void ValidateSequenceAssemblerGeneral(string additionalParameter)
        {
            // Get the parameters from Xml
            int matchScore = int.Parse(_utilityObj._xmlUtil.GetTextValue(Constants.AssemblyAlgorithmNodeName,
                                                                         Constants.MatchScoreNode), null);
            int mismatchScore = int.Parse(_utilityObj._xmlUtil.GetTextValue(Constants.AssemblyAlgorithmNodeName,
                                                                            Constants.MisMatchScoreNode), null);
            int gapCost = int.Parse(_utilityObj._xmlUtil.GetTextValue(Constants.AssemblyAlgorithmNodeName,
                                                                      Constants.GapCostNode), null);
            double mergeThreshold = double.Parse(_utilityObj._xmlUtil.GetTextValue(
                                                     Constants.AssemblyAlgorithmNodeName,
                                                     Constants.MergeThresholdNode), null);
            double consensusThreshold = double.Parse(_utilityObj._xmlUtil.GetTextValue(
                                                         Constants.AssemblyAlgorithmNodeName,
                                                         Constants.ConsensusThresholdNode), null);
            string sequence1 = _utilityObj._xmlUtil.GetTextValue(Constants.AssemblyAlgorithmNodeName,
                                                                 Constants.SequenceNode1);
            string sequence2 = _utilityObj._xmlUtil.GetTextValue(Constants.AssemblyAlgorithmNodeName,
                                                                 Constants.SequenceNode2);
            string sequence3 = _utilityObj._xmlUtil.GetTextValue(Constants.AssemblyAlgorithmNodeName,
                                                                 Constants.SequenceNode3);
            IAlphabet alphabet = Utility.GetAlphabet(_utilityObj._xmlUtil.GetTextValue(
                                                         Constants.AssemblyAlgorithmNodeName,
                                                         Constants.AlphabetNameNode));
            MoleculeType molType = Utility.GetMoleculeType(_utilityObj._xmlUtil.GetTextValue(
                                                               Constants.AssemblyAlgorithmNodeName,
                                                               Constants.MoleculeTypeNode));

            // Log based on the test cases
            switch (additionalParameter)
            {
            case "consensus":
                // Logs the sequences
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "SimpleConsensusMethod BVT : Sequence 1 used is '{0}'.", sequence1));
                Console.WriteLine(string.Format((IFormatProvider)null,
                                                "SimpleConsensusMethod BVT : Sequence 1 used is '{0}'.", sequence1));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "SimpleConsensusMethod BVT : Sequence 2 used is '{0}'.", sequence2));
                Console.WriteLine(string.Format((IFormatProvider)null,
                                                "SimpleConsensusMethod BVT : Sequence 2 used is '{0}'.", sequence2));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "SimpleConsensusMethod BVT : Sequence 3 used is '{0}'.", sequence3));
                Console.WriteLine(string.Format((IFormatProvider)null,
                                                "SimpleConsensusMethod BVT : Sequence 3 used is '{0}'.", sequence3));
                break;

            default:
                // Logs the sequences
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "SequenceAssembly BVT : Sequence 1 used is '{0}'.", sequence1));
                Console.WriteLine(string.Format((IFormatProvider)null,
                                                "SequenceAssembly BVT : Sequence 1 used is '{0}'.", sequence1));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "SequenceAssembly BVT : Sequence 2 used is '{0}'.", sequence2));
                Console.WriteLine(string.Format((IFormatProvider)null,
                                                "SequenceAssembly BVT : Sequence 2 used is '{0}'.", sequence2));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "SequenceAssembly BVT : Sequence 3 used is '{0}'.", sequence3));
                Console.WriteLine(string.Format((IFormatProvider)null,
                                                "SequenceAssembly BVT : Sequence 3 used is '{0}'.", sequence3));
                break;
            }

            Sequence seq1 = new Sequence(alphabet, sequence1);
            Sequence seq2 = new Sequence(alphabet, sequence2);
            Sequence seq3 = new Sequence(alphabet, sequence3);

            // here is how the above sequences should align:
            // TATAAAGCGCCAA
            //         GCCAAAATTTAGGC
            //                   AGGCACCCGCGGTATT   <= reversed
            //
            // TATAAAGCGCCAAAATTTAGGCACCCGCGGTATT

            OverlapDeNovoAssembler assembler = new OverlapDeNovoAssembler();

            assembler.MergeThreshold   = mergeThreshold;
            assembler.OverlapAlgorithm = new PairwiseOverlapAligner();
            ((IPairwiseSequenceAligner)assembler.OverlapAlgorithm).SimilarityMatrix =
                new DiagonalSimilarityMatrix(matchScore, mismatchScore, molType);
            ((IPairwiseSequenceAligner)assembler.OverlapAlgorithm).GapOpenCost = gapCost;
            assembler.ConsensusResolver         = new SimpleConsensusResolver(consensusThreshold);
            assembler.AssumeStandardOrientation = false;

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

            inputs.Add(seq1);
            inputs.Add(seq2);
            inputs.Add(seq3);

            // Assembles all the sequences.
            IOverlapDeNovoAssembly assembly = (IOverlapDeNovoAssembly)assembler.Assemble(inputs);

            // Get the parameters from Xml in general
            int contigSequencesCount = int.Parse(_utilityObj._xmlUtil.GetTextValue(
                                                     Constants.AssemblyAlgorithmNodeName,
                                                     Constants.ContigSequencesCountNode), null);
            string contigConsensus = _utilityObj._xmlUtil.GetTextValue(Constants.AssemblyAlgorithmNodeName,
                                                                       Constants.ContigConsensusNode);

            switch (additionalParameter.ToLower(CultureInfo.CurrentCulture))
            {
            case "assemble":
                // Get the parameters from Xml for Assemble() method test cases.
                int unMergedCount = int.Parse(_utilityObj._xmlUtil.GetTextValue(
                                                  Constants.AssemblyAlgorithmNodeName,
                                                  Constants.UnMergedSequencesCountNode), null);
                int contigsCount = int.Parse(_utilityObj._xmlUtil.GetTextValue(
                                                 Constants.AssemblyAlgorithmNodeName,
                                                 Constants.ContigsCountNode), null);

                Assert.AreEqual(unMergedCount, assembly.UnmergedSequences.Count);
                Assert.AreEqual(contigsCount, assembly.Contigs.Count);
                Contig contigRead = assembly.Contigs[0];

                // Logs the concensus
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "SequenceAssembly BVT : Un Merged Sequences Count is '{0}'.",
                                                       assembly.UnmergedSequences.Count.ToString((IFormatProvider)null)));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "SequenceAssembly BVT : Contigs Count is '{0}'.",
                                                       assembly.Contigs.Count.ToString((IFormatProvider)null)));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "SequenceAssembly BVT : Contig Sequences Count is '{0}'.",
                                                       contigRead.Sequences.Count.ToString((IFormatProvider)null)));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "SequenceAssembly BVT : Consensus read is '{0}'.",
                                                       contigRead.Consensus.ToString()));
                Console.WriteLine(string.Format((IFormatProvider)null,
                                                "SequenceAssembly BVT : Consensus read is '{0}'.",
                                                contigRead.Consensus.ToString()));

                Assert.AreEqual(contigConsensus, contigRead.Consensus.ToString());
                Assert.AreEqual(contigSequencesCount, contigRead.Sequences.Count);
                break;

            case "contig":
                // Read the contig from Contig method.
                Contig contigsRead = assembly.Contigs[0];

                // Log the required info.
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "SequenceAssembly BVT : Consensus read is '{0}'.",
                                                       contigsRead.Consensus.ToString()));
                Console.WriteLine(string.Format((IFormatProvider)null,
                                                "SequenceAssembly BVT : Consensus read is '{0}'.",
                                                contigsRead.Consensus.ToString()));

                ApplicationLog.WriteLine("SequenceAssembly BVT : Successfully read the Contig.");
                Console.WriteLine("SequenceAssembly BVT : Successfully read the Contig.");

                Assert.AreEqual(contigConsensus, contigsRead.Consensus.ToString());
                Assert.AreEqual(contigSequencesCount, contigsRead.Sequences.Count);
                break;

            case "consensus":
                // Read the contig from Contig method.
                Contig contigReadForConsensus = assembly.Contigs[0];
                contigReadForConsensus.Consensus = null;
                OverlapDeNovoAssembler simpleSeqAssembler = new OverlapDeNovoAssembler();
                simpleSeqAssembler.ConsensusResolver = new SimpleConsensusResolver(consensusThreshold);
                simpleSeqAssembler.MakeConsensus(alphabet, contigReadForConsensus);

                // Log the required info.
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                                                       "SimpleConsensusMethod BVT : Consensus read is '{0}'.",
                                                       contigReadForConsensus.Consensus.ToString()));
                Console.WriteLine(string.Format((IFormatProvider)null,
                                                "SimpleConsensusMethod BVT : Consensus read is '{0}'.",
                                                contigReadForConsensus.Consensus.ToString()));
                Assert.AreEqual(contigConsensus, contigReadForConsensus.Consensus.ToString());
                break;

            default:
                break;
            }
        }