コード例 #1
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 amino acid.
        /// </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)
        {
            AminoAcid aa = item as AminoAcid;

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

            return(values.Contains(aa));
        }
コード例 #2
0
        /// <summary>
        /// Overrides Object Equals.
        /// Two amino acids 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)
        {
            AminoAcid other = obj as AminoAcid;

            if (other != null)
            {
                return(this.Symbol == other.Symbol);
            }
            else
            {
                return(false);
            }
        }
コード例 #3
0
        /// <summary>
        ///  Returns a new copy of the AminoAcid object.
        /// </summary>
        /// <returns>Clone of this amino acid</returns>
        public AminoAcid Clone()
        {
            AminoAcid amminoAcid = new AminoAcid();

            amminoAcid.val           = val;
            amminoAcid.symbol        = symbol;
            amminoAcid.extSymbol     = extSymbol;
            amminoAcid.Name          = name;
            amminoAcid.IsGap         = IsGap;
            amminoAcid.IsAmbiguous   = IsAmbiguous;
            amminoAcid.IsTermination = IsTermination;
            return(amminoAcid);
        }
コード例 #4
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
            AminoAcid aa = symbol as AminoAcid;

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

            if (symbol == Xxx)
            {
                // Return all unambiguous symbols
                return(new HashSet <ISequenceItem>(values.Where(AA => !AA.IsAmbiguous).Select(AA => (ISequenceItem)AA)));
            }
            else
            {
                if (ambiguousToBasicSymbolMap.ContainsKey(symbol))
                {
                    return(ambiguousToBasicSymbolMap[symbol]);
                }
                else
                {
                    // It is base / unambiguous character
                    return(new HashSet <ISequenceItem>()
                    {
                        symbol
                    });
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Find the consensus symbol for a set of amino acids
        /// </summary>
        /// <param name="symbols">Set of sequence items</param>
        /// <returns>Consensus amino acid</returns>
        public ISequenceItem GetConsensusSymbol(HashSet <ISequenceItem> symbols)
        {
            // Validate that all are valid protein symbols
            foreach (ISequenceItem sequenceItem in symbols)
            {
                AminoAcid aminoAcid = sequenceItem as AminoAcid;
                if (aminoAcid == null)
                {
                    throw new ArgumentException(Properties.Resource.ParameterContainsNullValue, "symbols");
                }

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

            if (symbols.Contains(Xxx))
            {
                return(Xxx);
            }

            // 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 (ISequenceItem aa in symbols)
                {
                    if (ambiguousToBasicSymbolMap.ContainsKey(aa))
                    {
                        baseSet.UnionWith(ambiguousToBasicSymbolMap[aa]);
                    }
                    else
                    {
                        // If not found in ambiguous map, it has to be base / unambiguous character
                        baseSet.Add(aa);
                    }
                }

                if (basicToAmbiguousSymbolMap.ContainsKey(baseSet))
                {
                    return(basicToAmbiguousSymbolMap[baseSet]);
                }
                else
                {
                    return(Xxx);
                }
            }
        }