mirror of
https://github.com/correl/elm.git
synced 2024-11-15 19:19:31 +00:00
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:
commit
34b33d79d0
2 changed files with 13 additions and 15 deletions
|
@ -1,18 +1,16 @@
|
||||||
module NucleotideCount (..) where
|
module NucleotideCount (..) where
|
||||||
|
|
||||||
import String
|
import String
|
||||||
import List
|
|
||||||
|
|
||||||
|
|
||||||
nucleotideCounts : String -> List ( Char, Int )
|
nucleotideCounts : String -> { a : Int, t : Int, c : Int, g : Int }
|
||||||
nucleotideCounts sequence =
|
nucleotideCounts sequence =
|
||||||
[ (getCount 'A' sequence)
|
let
|
||||||
, (getCount 'T' sequence)
|
getCount n =
|
||||||
, (getCount 'C' sequence)
|
String.filter (\c -> c == n) sequence |> String.length
|
||||||
, (getCount 'G' sequence)
|
in
|
||||||
]
|
{ a = getCount 'A'
|
||||||
|
, t = getCount 'T'
|
||||||
|
, c = getCount 'C'
|
||||||
getCount : Char -> String -> ( Char, Int )
|
, g = getCount 'G'
|
||||||
getCount base sequence =
|
}
|
||||||
( base, (List.length (String.split (String.fromChar base) sequence)) - 1 )
|
|
||||||
|
|
|
@ -13,19 +13,19 @@ tests =
|
||||||
[ test
|
[ test
|
||||||
"empty dna strand has no nucleotides"
|
"empty dna strand has no nucleotides"
|
||||||
(assertEqual
|
(assertEqual
|
||||||
[ ( 'A', 0 ), ( 'T', 0 ), ( 'C', 0 ), ( 'G', 0 ) ]
|
{ a = 0, t = 0, c = 0, g = 0 }
|
||||||
(nucleotideCounts "")
|
(nucleotideCounts "")
|
||||||
)
|
)
|
||||||
, test
|
, test
|
||||||
"repetitive-sequence-has-only-guanosine"
|
"repetitive-sequence-has-only-guanosine"
|
||||||
(assertEqual
|
(assertEqual
|
||||||
[ ( 'A', 0 ), ( 'T', 0 ), ( 'C', 0 ), ( 'G', 8 ) ]
|
{ a = 0, t = 0, c = 0, g = 8 }
|
||||||
(nucleotideCounts "GGGGGGGG")
|
(nucleotideCounts "GGGGGGGG")
|
||||||
)
|
)
|
||||||
, test
|
, test
|
||||||
"counts all nucleotides"
|
"counts all nucleotides"
|
||||||
(assertEqual
|
(assertEqual
|
||||||
[ ( 'A', 20 ), ( 'T', 21 ), ( 'C', 12 ), ( 'G', 17 ) ]
|
{ a = 20, t = 21, c = 12, g = 17 }
|
||||||
(nucleotideCounts "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC")
|
(nucleotideCounts "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC")
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue