예제 #1
0
        /// <summary>
        /// This method is considered as main execute method which defines the
        /// step by step algorithm. Drived class flows the defined flow by this
        /// method. Store generated MUMs in properties MUMs, SortedMUMs.
        /// Alignment first finds MUMs for all the query sequence, and then
        /// runs pairwise algorithm on gaps to produce alignments.
        /// </summary>
        /// <param name="referenceSequence">reference sequence</param>
        /// <param name="querySequenceList">list of input sequences</param>
        /// <returns>A list of sequence alignments</returns>
        private IList <IPairwiseSequenceAlignment> AlignmentWithAccumulatedMUMs(
            ISequence referenceSequence,
            IList <ISequence> querySequenceList)
        {
            // Get MUMs
            _mums      = new Dictionary <ISequence, IList <MaxUniqueMatch> >();
            _finalMums = new Dictionary <ISequence, IList <MaxUniqueMatch> >();

            if (Validate(referenceSequence, querySequenceList))
            {
                IList <MaxUniqueMatch> mumList;

                // Step1 : building suffix trees using reference sequence
                ISuffixTree suffixTree = BuildSuffixTree(referenceSequence);

                // On each query sequence aligned with reference sequence
                foreach (ISequence sequence in querySequenceList)
                {
                    if (sequence.Equals(referenceSequence))
                    {
                        continue;
                    }

                    // Step2 : streaming process is performed with the query sequence
                    mumList = Streaming(suffixTree, referenceSequence, sequence, LengthOfMUM);
                    _mums.Add(sequence, mumList);

                    // Step3(a) : sorted mum list based on reference sequence
                    mumList = SortMum(mumList);

                    if (mumList.Count > 0)
                    {
                        // Step3(b) : LIS using greedy cover algorithm
                        mumList = CollectLongestIncreasingSubsequence(mumList);
                    }
                    else
                    {
                        mumList = null;
                    }

                    _finalMums.Add(sequence, mumList);
                }
            }

            IList <IPairwiseSequenceAlignment> results   = new List <IPairwiseSequenceAlignment>();
            IPairwiseSequenceAlignment         alignment = null;

            if (MUMs != null && FinalMUMs != null)
            {
                // Getting refernce sequence
                _referenceSequence = referenceSequence;

                // On each query sequence aligned with reference sequence
                foreach (var finalMum in FinalMUMs)
                {
                    var sequence = finalMum.Key;
                    _mumList      = MUMs[sequence];
                    _finalMumList = finalMum.Value;

                    alignment = new PairwiseSequenceAlignment(referenceSequence, sequence);

                    if (_mumList.Count > 0)
                    {
                        if (_finalMumList.Count > 0)
                        {
                            // Step 4 : get all the gaps in each sequence and call
                            // pairwise alignment
                            alignment.PairwiseAlignedSequences.Add(ProcessGaps(referenceSequence, sequence));
                        }

                        results.Add(alignment);
                    }
                    else
                    {
                        IList <IPairwiseSequenceAlignment> sequenceAlignment = RunPairWise(
                            referenceSequence,
                            sequence);

                        foreach (IPairwiseSequenceAlignment pairwiseAlignment in sequenceAlignment)
                        {
                            results.Add(pairwiseAlignment);
                        }
                    }
                }
            }

            return(results);
        }
예제 #2
0
        /// <summary>
        /// This method is considered as main execute method which defines the
        /// step by step algorithm. Drived class flows the defined flow by this
        /// method.
        /// </summary>
        /// <param name="referenceSequenceList">reference sequence</param>
        /// <param name="querySequenceList">list of input sequences</param>
        /// <returns>A list of sequence alignment</returns>
        private IList <IPairwiseSequenceAlignment> Alignment(
            IList <ISequence> referenceSequenceList,
            IList <ISequence> querySequenceList)
        {
            // Initializations
            if (referenceSequenceList.Count > 0)
            {
                if (ConsensusResolver == null)
                {
                    ConsensusResolver = new SimpleConsensusResolver(referenceSequenceList[0].Alphabet);
                }
                else
                {
                    ConsensusResolver.SequenceAlphabet = referenceSequenceList[0].Alphabet;
                }
            }

            IList <IPairwiseSequenceAlignment> results           = new List <IPairwiseSequenceAlignment>();
            IPairwiseSequenceAlignment         sequenceAlignment = null;
            IList <DeltaAlignment>             deltaAlignments   = null;
            IList <PairwiseAlignedSequence>    alignments        = null;
            ISequence referenceSequence = null;

            // Validate the input
            Validate(referenceSequenceList, querySequenceList);

            // Step:1 concat all the sequences into one sequence
            if (referenceSequenceList.Count > 1)
            {
                referenceSequence = ConcatSequence(referenceSequenceList);
            }
            else
            {
                referenceSequence = referenceSequenceList[0];
            }

            // Getting refernce sequence
            _referenceSequence = referenceSequence;

            // Step2 : building suffix trees using reference sequence
            _suffixTree = BuildSuffixTree(_referenceSequence);

            // On each query sequence aligned with reference sequence
            foreach (ISequence sequence in querySequenceList)
            {
                if (sequence.Equals(referenceSequence))
                {
                    continue;
                }

                sequenceAlignment = new PairwiseSequenceAlignment(referenceSequence, sequence);

                // Step3 : streaming process is performed with the query sequence
                _mumList = Streaming(_suffixTree, sequence, LengthOfMUM);

                if (_mumList.Count > 0)
                {
                    // Step 5 : Get the list of Clusters
                    _clusterList = GetClusters(_mumList);

                    // Step 7: Process Clusters and get delta
                    deltaAlignments = ProcessCluster(
                        referenceSequenceList,
                        _clusterList);

                    // Step 8: Convert delta alignments to sequence alignments
                    alignments = ConvertDeltaToAlignment(deltaAlignments);

                    if (alignments.Count > 0)
                    {
                        foreach (PairwiseAlignedSequence align in alignments)
                        {
                            // Calculate the score of alignment
                            align.Score = CalculateScore(
                                align.FirstSequence,
                                align.SecondSequence);

                            // Make Consensus
                            align.Consensus = MakeConsensus(
                                align.FirstSequence,
                                align.SecondSequence);

                            sequenceAlignment.PairwiseAlignedSequences.Add(align);
                        }
                    }
                }

                results.Add(sequenceAlignment);
            }

            return(results);
        }
예제 #3
0
        /// <summary>
        /// This method is considered as main execute method which defines the
        /// step by step algorithm. Drived class flows the defined flow by this
        /// method. Does not store MUMs, processes MUMs and gaps to find
        /// alignment directly.
        /// </summary>
        /// <param name="referenceSequence">reference sequence</param>
        /// <param name="querySequenceList">list of input sequences</param>
        /// <returns>A list of sequence alignments</returns>
        private IList <IPairwiseSequenceAlignment> AlignmentWithoutAccumulatedMUMs(
            ISequence referenceSequence,
            IList <ISequence> querySequenceList)
        {
            IList <IPairwiseSequenceAlignment> results   = new List <IPairwiseSequenceAlignment>();
            IPairwiseSequenceAlignment         alignment = null;

            if (Validate(referenceSequence, querySequenceList))
            {
                // Safety check for public methods to ensure that null
                // inputs are handled.
                if (referenceSequence == null || querySequenceList == null)
                {
                    return(null);
                }

                // Getting refernce sequence
                _referenceSequence = referenceSequence;

                // Step1 : building suffix trees using reference sequence
                _suffixTree = BuildSuffixTree(_referenceSequence);

                // On each query sequence aligned with reference sequence
                foreach (ISequence sequence in querySequenceList)
                {
                    if (sequence.Equals(referenceSequence))
                    {
                        continue;
                    }

                    alignment = new PairwiseSequenceAlignment(referenceSequence, sequence);

                    // Step2 : streaming process is performed with the query sequence
                    _mumList = Streaming(_suffixTree, referenceSequence, sequence, LengthOfMUM);

                    // Step3(a) : sorted mum list based on reference sequence
                    _sortedMumList = SortMum(_mumList);

                    if (_sortedMumList.Count > 0)
                    {
                        // Step3(b) : LIS using greedy cover algorithm
                        _finalMumList = CollectLongestIncreasingSubsequence(_sortedMumList);

                        if (_finalMumList.Count > 0)
                        {
                            // Step 4 : get all the gaps in each sequence and call
                            // pairwise alignment
                            alignment.PairwiseAlignedSequences.Add(ProcessGaps(referenceSequence, sequence));
                        }

                        results.Add(alignment);
                    }
                    else
                    {
                        IList <IPairwiseSequenceAlignment> sequenceAlignment = RunPairWise(
                            referenceSequence,
                            sequence);

                        foreach (IPairwiseSequenceAlignment pairwiseAlignment in sequenceAlignment)
                        {
                            results.Add(pairwiseAlignment);
                        }
                    }
                }
            }

            return(results);
        }