コード例 #1
0
        /// <summary>
        /// Analyze the passed contig and store a consensus into its Consensus property.
        /// </summary>
        /// <param name="contig">Contig for which consensus is to be constructed</param>
        private void MakeConsensus(Contig contig)
        {
            List <byte> positionItems = new List <byte>(), consensusSequence = new List <byte>();

            // there's no simple way to pre-guess the length of the contig
            long position = 0;

            while (true)
            {
                // Initialization
                positionItems.Clear();

                // Add the sequences
                positionItems.AddRange(from aseq in contig.Sequences
                                       where position >= aseq.Position && position < aseq.Position + aseq.Sequence.Count
                                       let seqPos = aseq.IsReversed ? (aseq.Sequence.Count() - 1) - (position - aseq.Position) : position - aseq.Position
                                                    select aseq.IsComplemented ? aseq.Sequence.GetComplementedSequence()[seqPos] : aseq.Sequence[seqPos]);

                if (positionItems.Count == 0)
                {
                    // This means no sequences at this position. We're done
                    contig.Consensus = new Sequence(Alphabets.AmbiguousAlphabetMap[_sequenceAlphabet], consensusSequence.ToArray());
                    return;
                }

                consensusSequence.Add(ConsensusResolver.GetConsensus(positionItems.ToArray()));
                position++;
            }
        }
コード例 #2
0
        /// <summary>
        /// Analyze the given sequences and store a consensus into its Consensus property.
        /// </summary>
        /// <param name="referenceSequence">Reference sequence.</param>
        /// <param name="querySequence">Query sequence.</param>
        /// <returns>Consensus of sequences.</returns>
        protected ISequence MakeConsensus(
            ISequence referenceSequence,
            ISequence querySequence)
        {
            if (referenceSequence == null)
            {
                throw new ArgumentNullException("referenceSequence");
            }

            if (querySequence == null)
            {
                throw new ArgumentNullException("querySequence");
            }

            // For each pair of symbols (characters) in reference and query sequence
            // get the consensus symbol and append it.
            byte[] consensus = new byte[referenceSequence.Count];
            for (int index = 0; index < referenceSequence.Count; index++)
            {
                consensus[index] = ConsensusResolver.GetConsensus(
                    new byte[] { referenceSequence[index], querySequence[index] });
            }

            IAlphabet alphabet = Alphabets.AutoDetectAlphabet(consensus, 0, consensus.LongLength, referenceSequence.Alphabet);

            return(new Sequence(alphabet, consensus, false));
        }
コード例 #3
0
        /// <summary>
        /// Analyze the passed contig and store a consensus into its Consensus property.
        /// </summary>
        /// <param name="contig">Contig for which consensus is to be constructed</param>
        private void MakeConsensus(Contig contig)
        {
            List <byte> positionItems     = new List <byte>();
            List <byte> consensusSequence = new List <byte>();

            // there's no simple way to pre-guess the length of the contig
            long position = 0;

            while (true)
            {
                // Initializations
                positionItems.Clear();

                foreach (Contig.AssembledSequence aseq in contig.Sequences)
                {
                    if (position >= aseq.Position && position < aseq.Position + aseq.Sequence.Count)
                    {
                        long seqPos;
                        if (aseq.IsReversed)
                        {
                            seqPos = (aseq.Sequence.Count() - 1) - (position - aseq.Position);
                        }
                        else
                        {
                            seqPos = position - aseq.Position;
                        }

                        if (aseq.IsComplemented)
                        {
                            positionItems.Add(aseq.Sequence.GetComplementedSequence()[seqPos]);
                        }
                        else
                        {
                            positionItems.Add(aseq.Sequence[seqPos]);
                        }
                    }
                }

                if (positionItems.Count == 0)
                {
                    // This means no sequences at this position. We're done
                    contig.Consensus = new Sequence(Alphabets.AmbiguousAlphabetMap[_sequenceAlphabet], consensusSequence.ToArray());
                    return;
                }
                else
                {
                    consensusSequence.Add(ConsensusResolver.GetConsensus(positionItems.ToArray()));
                }

                position++;
            }
        }
コード例 #4
0
        /// <summary>
        /// Analyze the passed contig and store a consensus into its Consensus property.
        /// </summary>
        /// <param name="contig">Contig for which consensus is to be constructed</param>
        private void MakeConsensus(Contig contig)
        {
            Sequence             consensusSequence = new Sequence(_sequenceAlphabet);
            List <ISequenceItem> positionItems     = new List <ISequenceItem>();

            // there's no simple way to pre-guess the length of the contig
            int position = 0;

            while (true)
            {
                // Initializations
                positionItems.Clear();

                foreach (Contig.AssembledSequence aseq in contig.Sequences)
                {
                    if (position >= aseq.Position && position < aseq.Position + aseq.Sequence.Count)
                    {
                        int seqPos;
                        if (aseq.IsReversed)
                        {
                            seqPos = (aseq.Sequence.Count - 1) - (position - aseq.Position);
                        }
                        else
                        {
                            seqPos = position - aseq.Position;
                        }

                        if (aseq.IsComplemented)
                        {
                            positionItems.Add(aseq.Sequence.Complement[seqPos]);
                        }
                        else
                        {
                            positionItems.Add(aseq.Sequence[seqPos]);
                        }
                    }
                }

                if (positionItems.Count == 0)
                {
                    // This means no sequences at this position. We're done
                    contig.Consensus = consensusSequence;
                    return;
                }
                else
                {
                    consensusSequence.Add(ConsensusResolver.GetConsensus(positionItems));
                }

                position++;
            }
        }
コード例 #5
0
        /// <summary>
        /// Adds consensus to the alignment result.  At this point, it is a very simple algorithm
        /// which puts an ambiguity character where the two aligned sequences do not match.
        /// Uses X and N for protein and DNA/RNA alignments, respectively.
        /// </summary>
        /// <param name="alignment">
        /// Alignment to which to add the consensus.  This is the result returned by the main Align
        /// or AlignSimple method, which contains the aligned sequences but not yet a consensus sequence.
        /// </param>
        private void AddSimpleConsensusToResult(PairwiseAlignedSequence alignment)
        {
            ISequence seq0 = alignment.FirstSequence;
            ISequence seq1 = alignment.SecondSequence;

            byte[] consensus = new byte[seq0.Count];
            for (int i = 0; i < seq0.Count; i++)
            {
                consensus[i] = ConsensusResolver.GetConsensus(
                    new byte[] { seq0[i], seq1[i] });
            }

            IAlphabet consensusAlphabet = Alphabets.AutoDetectAlphabet(consensus, 0, consensus.GetLongLength(), seq0.Alphabet);

            alignment.Consensus = new Sequence(consensusAlphabet, consensus, false);
        }
コード例 #6
0
        /// <summary>
        /// Adds consensus to the alignment result.  At this point, it is a very simple algorithm
        /// which puts an ambiguity character where the two aligned sequences do not match.
        /// Uses X and N for protein and DNA/RNA alignments, respectively.
        /// </summary>
        /// <param name="alignment">
        /// Alignment to which to add the consensus.  This is the result returned by the main Align
        /// or AlignSimple method, which contains the aligned sequences but not yet a consensus sequence.
        /// </param>
        private void AddSimpleConsensusToResult(PairwiseAlignedSequence alignment)
        {
            ISequence seq0 = alignment.FirstSequence;
            ISequence seq1 = alignment.SecondSequence;

            Sequence consensus = new Sequence(seq0.Alphabet);

            for (int i = 0; i < seq0.Count; i++)
            {
                consensus.Add(
                    ConsensusResolver.GetConsensus(
                        new List <ISequenceItem>()
                {
                    seq0[i], seq1[i]
                }));
            }

            alignment.Consensus = consensus;
        }
コード例 #7
0
        /// <summary>
        /// Analyze the given seqquences and store a consensus into its Consensus property.
        /// </summary>
        /// <param name="referenceSequence">Reference sequence</param>
        /// <param name="querySequence">Query sequence</param>
        /// <returns>Consensus of sequences</returns>
        protected override ISequence MakeConsensus(
            ISequence referenceSequence,
            ISequence querySequence)
        {
            // For each pair of symbols (characters) in reference and query sequence
            // get the consensus symbol and append it.
            Sequence consensus = new Sequence(referenceSequence.Alphabet);

            for (int index = 0; index < referenceSequence.Count; index++)
            {
                consensus.Add(
                    ConsensusResolver.GetConsensus(
                        new List <ISequenceItem>()
                {
                    referenceSequence[index], querySequence[index]
                }));
            }

            return(consensus);
        }