Exemple #1
0
        /// <summary>
        /// Find the set of symbols that is represented by input symbol
        /// </summary>
        /// <param name="symbol">Symbol to look up</param>
        /// <returns>Set of symbols</returns>
        public HashSet <ISequenceItem> GetBasicSymbols(ISequenceItem symbol)
        {
            if (symbol == null)
            {
                throw new ArgumentNullException("symbol");
            }

            // Validate input symbol
            Nucleotide n = symbol as Nucleotide;

            if (n == null || !values.Contains(n))
            {
                throw new ArgumentException(string.Format(
                                                CultureInfo.CurrentCulture, Properties.Resource.INVALID_SYMBOL, symbol.Symbol, Name));
            }

            if (ambiguousToBasicSymbolMap.ContainsKey(symbol))
            {
                return(ambiguousToBasicSymbolMap[symbol]);
            }
            else
            {
                // It is base / unambiguous character
                return(new HashSet <ISequenceItem>()
                {
                    symbol
                });
            }
        }
Exemple #2
0
        /// <summary>
        /// Find the consensus nucleotide for a set of nucleotides
        /// </summary>
        /// <param name="symbols">Set of sequence items</param>
        /// <returns>Consensus nucleotide</returns>
        public ISequenceItem GetConsensusSymbol(HashSet <ISequenceItem> symbols)
        {
            // Validate that all are valid RNA symbols
            foreach (ISequenceItem sequenceItem in symbols)
            {
                Nucleotide nucleotide = sequenceItem as Nucleotide;

                if (sequenceItem == null)
                {
                    throw new ArgumentException(Properties.Resource.ParameterContainsNullValue, "symbols");
                }

                if (nucleotide == null)
                {
                    throw new ArgumentException(Properties.Resource.AllItemMustBeNucleotide, "symbols");
                }

                if (!values.Contains(nucleotide))
                {
                    throw new ArgumentException(string.Format(
                                                    CultureInfo.CurrentCulture, Properties.Resource.INVALID_SYMBOL, sequenceItem.Symbol, Name));
                }
            }

            // Remove all gap symbols
            symbols.ExceptWith(gapItems);

            if (symbols.Count == 0)
            {
                // All are gap characters, return default 'Gap'
                return(DefaultGap);
            }
            else if (symbols.Count == 1)
            {
                return(symbols.First());
            }
            else
            {
                HashSet <ISequenceItem> baseSet = new HashSet <ISequenceItem>();
                foreach (Nucleotide n in symbols)
                {
                    if (ambiguousToBasicSymbolMap.ContainsKey(n))
                    {
                        baseSet.UnionWith(ambiguousToBasicSymbolMap[n]);
                    }
                    else
                    {
                        // If not found in ambiguous map, it has to be base / unambiguous character
                        baseSet.Add(n);
                    }
                }

                return(basicToAmbiguousSymbolMap[baseSet]);
            }
        }
Exemple #3
0
        /// <summary>
        /// Indication of whether or not an ISequenceItem is in the alphabet. This is
        /// a simple lookup and will only match exactly with items of this alphabet. It
        /// will not compare items from other alphabets that match the same nucleotide.
        /// </summary>
        /// <param name="item">Item whose presence is to be checked</param>
        /// <returns>True if this contains input item</returns>
        public bool Contains(ISequenceItem item)
        {
            Nucleotide nucleo = item as Nucleotide;

            if (nucleo == null)
            {
                return(false);
            }

            return(values.Contains(nucleo));
        }
Exemple #4
0
        /// <summary>
        /// Returns a new copy of the Nucleotide object.
        /// </summary>
        /// <returns>Clone of this nucleotide</returns>
        public virtual Nucleotide Clone()
        {
            Nucleotide nucleotide = new Nucleotide();

            nucleotide.val         = val;
            nucleotide.symbol      = symbol;
            nucleotide.Name        = name;
            nucleotide.IsGap       = IsGap;
            nucleotide.IsAmbiguous = IsAmbiguous;
            return(nucleotide);
        }
Exemple #5
0
        /// <summary>
        /// Overrides Object Equals.
        /// Two nucleotides are judged equal, if they have the same symbol
        /// </summary>
        /// <param name="obj">Object to be compared with</param>
        /// <returns>True if equal</returns>
        public override bool Equals(object obj)
        {
            Nucleotide other = obj as Nucleotide;

            if (other != null)
            {
                return(this.Symbol == other.Symbol);
            }
            else
            {
                return(false);
            }
        }
Exemple #6
0
        /// <summary>
        /// Transcribes a DNA sequence into the corresponding sequence on
        /// the other strand, then reverses it so that the new sequence has
        /// the same orientation as the original (in the 3'-to-5' sense). The length
        /// of the resulting sequence will equal the length of the source
        /// sequence. Gap and ambiguous characters will also be transcribed.
        ///
        /// For example:
        ///
        /// Sequence dna = new Sequence(Alphabets.DNA, "TACCGC");
        /// Sequence otherStrand = Complementarity.ReverseComplement(dna);
        ///
        /// otherStrand.ToString() would produce "GCGGTA"
        /// </summary>
        /// <param name="dnaSource">The input sequence.</param>
        /// <returns>A new complementary sequence.</returns>
        public static ISequence ReverseComplement(ISequence dnaSource)
        {
            if (dnaSource.Alphabet != Alphabets.DNA)
            {
                string message = "ReverseComplement is only supported for DNA sequence.";
                Trace.Report(message);
                throw new NotSupportedException(message);
            }
            Sequence result = new Sequence(Alphabets.DNA);

            result.IsReadOnly = false;
            result.ID         = "Reverse Complement: " + dnaSource.ID;
            result.DisplayID  = "Reverse Complement: " + dnaSource.DisplayID;

            for (int iSymbol = dnaSource.Count - 1; iSymbol >= 0; --iSymbol)
            {
                Nucleotide n = (Nucleotide)dnaSource[iSymbol];
                result.Add(GetDnaComplement(n));
            }
            result.IsReadOnly = true;
            return(result);
        }
Exemple #7
0
 /// <summary>
 /// Returns the complement of an RNA nucleotide. This also
 /// respects ambiguous characters in the RNA alphabet.
 /// </summary>
 public static Nucleotide GetRnaComplement(Nucleotide rnaSource)
 {
     return(rnaToComplement[rnaSource]);
 }
Exemple #8
0
 /// <summary>
 /// Returns the complement of a DNA nucleotide. This also
 /// respects ambiguous characters in the DNA alphabet.
 /// </summary>
 public static Nucleotide GetDnaComplement(Nucleotide dnaSource)
 {
     return(dnaToComplement[dnaSource]);
 }