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; }
public ConsensusBuilder(IEnumerable <ISequence> sequences) { _sequences = sequences.ToList(); var firstElement = _sequences.First(); _sequenceLength = firstElement.Sequence.Length; _alphabet = firstElement.ActiveAlphabet; foreach (var sequence in _sequences) { if (sequence.Sequence.Length != _sequenceLength) { throw new ArgumentException("Sequences were not all of uniform length"); } if (_alphabet != sequence.ActiveAlphabet) { throw new ArgumentException("Sequences must all be of the same type"); } } char[] alphabetChars; switch (_alphabet) { case AlphabetType.StrictRna: case AlphabetType.AmbiguousRna: case AlphabetType.StrictDna: case AlphabetType.AmbiguousDna: { var symbols = AlphabetDataProvider.GetAllowedNucleotideSymbols(_alphabet).ToArray(); alphabetChars = new char[symbols.Length]; for (var i = 0; i < symbols.Length; i++) { alphabetChars[i] = (char)symbols[i]; } } break; case AlphabetType.ExtendedProtein: case AlphabetType.StandardProtein: { var symbols = AlphabetDataProvider.GetAllowedProteinSymbols(_alphabet).ToArray(); alphabetChars = new char[symbols.Length]; for (var i = 0; i < symbols.Length; i++) { alphabetChars[i] = (char)symbols[i]; } } break; default: throw new ArgumentException("Unknown alphabet type"); } _consensusMatrix = new Dictionary <char, int[]>(alphabetChars.Length); foreach (var character in alphabetChars) { _consensusMatrix.Add(character, new int[_sequenceLength]); } }