You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

31 lines
727 B

using System;
using System.Collections.Generic;
using System.Linq;
public class NucleotideCount
{
private string _seq;
private char[] keys = new[] {'A', 'C', 'G', 'T'};
public NucleotideCount(string sequence)
{
_seq = sequence;
if (_seq.Any(c => !keys.Contains(c))) throw new InvalidNucleotideException();
}
private int CountOne(char key)
=> _seq.Count(c => c == key);
public IDictionary<char, int> NucleotideCounts
{
get
{
var c = new Dictionary<char, int>();
foreach (var key in keys)
c.Add(key, CountOne(key));
return c;
}
}
}
public class InvalidNucleotideException : Exception { }