1234567891011121314151617181920212223242526 |
- module NucleotideCount
-
- let isValidNucleotide nucleotide =
- nucleotide = 'A'
- || nucleotide = 'C'
- || nucleotide = 'G'
- || nucleotide = 'T'
-
- let validInput (strand: string) =
- String.collect (fun c -> if isValidNucleotide c then string (c) else "") strand = strand
-
- let nucleotideCounts (strand: string): Option<Map<char, int>> =
- if validInput strand then
- let mutable counts =
- Map.empty.Add('A', 0).Add('C', 0).Add('G', 0).Add('T', 0)
-
- Seq.iter (fun c ->
- if counts.ContainsKey c then
- let current = counts.Item c
- counts <- counts.Remove(c)
- counts <- counts.Add(c, current + 1)
- else
- counts <- counts.Add(c, 1)) strand
- Some(counts)
- else
- None
|