Пример #1
0
        protected void VerifyAndInitializeNucleotides(string rawNucleotides)
        {
            if (String.IsNullOrWhiteSpace(rawNucleotides))
            {
                throw new ArgumentException("Empty nucleotide sequence!");
            }

            SymbolCounts = new Dictionary <Nucleotide, long>(AllowedSymbols.Count);
            foreach (var basePair in AllowedSymbols)
            {
                SymbolCounts.Add(basePair, 0);
            }

            foreach (var nucleotide in rawNucleotides)
            {
                var typedNucleotide = (Nucleotide)Char.ToUpperInvariant(nucleotide);

                if (!AllowedSymbols.Contains(typedNucleotide))
                {
                    throw new ArgumentException(nucleotide + " is not a recognized nucleotide");
                }

                SymbolCounts[typedNucleotide]++;
            }
        }
Пример #2
0
 public long AminoCount(AminoAcid aminoAcid)
 {
     if (!AllowedSymbols.Contains(aminoAcid))
     {
         throw new ArgumentException(String.Format(_invalidAminoAcidCharacter, aminoAcid, _proteinAlphabet));
     }
     return(_aminoCounts[aminoAcid]);
 }
Пример #3
0
        public virtual long NucleotideCount(Nucleotide nucleotide)
        {
            if (!AllowedSymbols.Contains(nucleotide))
            {
                throw new ArgumentException(String.Format(InvalidNucleotideForAlphabetType, nucleotide, ActiveAlphabet));
            }

            return(!SymbolCounts.ContainsKey(nucleotide) ? 0 : SymbolCounts[nucleotide]);
        }
Пример #4
0
        public ProteinSequence(string rawSequence, AlphabetType desiredProteinAlphabet, GeneticCode geneticCode = GeneticCode.Standard)
        {
            switch (desiredProteinAlphabet)
            {
            case AlphabetType.ExtendedProtein:
                break;

            case AlphabetType.StandardProtein:
                break;

            default:
                throw new ArgumentException(String.Format(ProteinAlphabet.InvalidProteinAlphabet, desiredProteinAlphabet));
            }

            _proteinAlphabet = new ProteinAlphabet(desiredProteinAlphabet, geneticCode);
            ActiveAlphabet   = desiredProteinAlphabet;
            AllowedSymbols   = AlphabetDataProvider.GetAllowedProteinSymbols(ActiveAlphabet);

            _aminoCounts = new Dictionary <AminoAcid, long>(AllowedSymbols.Count);
            foreach (var symbol in AllowedSymbols)
            {
                _aminoCounts.Add(symbol, 0);
            }

            var trimmedRaw = rawSequence.Trim();

            foreach (var aminoCharacter in trimmedRaw)
            {
                var typedAmino = (AminoAcid)Char.ToUpperInvariant(aminoCharacter);
                if (!AllowedSymbols.Contains(typedAmino))
                {
                    throw new ArgumentException(String.Format(_invalidAminoAcidCharacter, aminoCharacter, _proteinAlphabet));
                }
                _aminoCounts[typedAmino]++;
            }
            Sequence = trimmedRaw;
        }