mirror of
https://github.com/correl/elm.git
synced 2024-11-15 19:19:31 +00:00
Convert nucleotide-counts to use a record rather than a List (Char, Int)
This commit is contained in:
parent
ad55c22ccd
commit
a8eca4050e
2 changed files with 13 additions and 15 deletions
|
@ -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'
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
)
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue