Merge pull request #51 from tgecho/nucleotide-count-records

Convert nucleotide-counts to use a record rather than a `List (Char, Int)`
This commit is contained in:
Lew Parker 2016-03-26 12:29:04 -06:00
commit 34b33d79d0
2 changed files with 13 additions and 15 deletions

View file

@ -1,18 +1,16 @@
module NucleotideCount (..) where
import String
import List
nucleotideCounts : String -> List ( Char, Int )
nucleotideCounts : String -> { a : Int, t : Int, c : Int, g : Int }
nucleotideCounts sequence =
[ (getCount 'A' sequence)
, (getCount 'T' sequence)
, (getCount 'C' sequence)
, (getCount 'G' sequence)
]
getCount : Char -> String -> ( Char, Int )
getCount base sequence =
( base, (List.length (String.split (String.fromChar base) sequence)) - 1 )
let
getCount n =
String.filter (\c -> c == n) sequence |> String.length
in
{ a = getCount 'A'
, t = getCount 'T'
, c = getCount 'C'
, g = getCount 'G'
}

View file

@ -13,19 +13,19 @@ tests =
[ test
"empty dna strand has no nucleotides"
(assertEqual
[ ( 'A', 0 ), ( 'T', 0 ), ( 'C', 0 ), ( 'G', 0 ) ]
{ a = 0, t = 0, c = 0, g = 0 }
(nucleotideCounts "")
)
, test
"repetitive-sequence-has-only-guanosine"
(assertEqual
[ ( 'A', 0 ), ( 'T', 0 ), ( 'C', 0 ), ( 'G', 8 ) ]
{ a = 0, t = 0, c = 0, g = 8 }
(nucleotideCounts "GGGGGGGG")
)
, test
"counts all nucleotides"
(assertEqual
[ ( 'A', 20 ), ( 'T', 21 ), ( 'C', 12 ), ( 'G', 17 ) ]
{ a = 20, t = 21, c = 12, g = 17 }
(nucleotideCounts "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC")
)
]