public static long CalculateHammingDistance(NucleotideSequence a, NucleotideSequence b) { if (a.Sequence.Length != b.Sequence.Length) { throw new ArgumentException("Sequences are of unequal length!"); } if (a.ActiveAlphabet != b.ActiveAlphabet) { throw new ArgumentException("Sequences are not using the same nucleotide alphabet!"); } if (a.GetType() != b.GetType()) { throw new ArgumentException(String.Format("Sequence types do not match. ({0} vs {1})", a.GetType(), b.GetType())); } return(a.Sequence.Where((t, i) => t != b.Sequence[i]).Count()); }
internal ProteinSequence(NucleotideSequence seq) { if (seq.ActiveAlphabet == AlphabetType.StrictDna || seq.ActiveAlphabet == AlphabetType.StrictRna) { if (seq.Sequence.Length % 3 != 0) { throw new ArgumentException("Sequence length is not evenly divisible by three, which means it cannot be translated because you are using a strict nucleotide alphabet"); } } AlphabetType alphabet; var allowedSymbols = new HashSet <AminoAcid> { AminoAcid.Stop, AminoAcid.Gap }; switch (seq.ActiveAlphabet) { case AlphabetType.AmbiguousDna: alphabet = AlphabetType.ExtendedProtein; allowedSymbols.UnionWith(AlphabetDataProvider.ExtendedProtein); break; case AlphabetType.AmbiguousRna: alphabet = AlphabetType.ExtendedProtein; allowedSymbols.UnionWith(AlphabetDataProvider.ExtendedProtein); break; default: alphabet = AlphabetType.StandardProtein; allowedSymbols.UnionWith(AlphabetDataProvider.StandardProtein); break; } var translationTable = new Dictionary <string, AminoAcid>(AlphabetDataProvider.GetTranslationTable(seq.GeneticCode, seq.ActiveAlphabet)); //string safeSequence, AlphabetType alphabet, GeneticCode geneticCode, Dictionary<Nucleotide, long> symbolCounts ActiveAlphabet = seq.ActiveAlphabet; _proteinAlphabet = new ProteinAlphabet(alphabet, seq.GeneticCode); var proteinBlob = Translate(seq.Sequence, translationTable); Sequence = proteinBlob.Sequence; _aminoCounts = proteinBlob.AminoCounts; }
public virtual long CalculateHammingDistance(NucleotideSequence comparisonSequence) { return(CalculateHammingDistance(this, comparisonSequence)); }