mirror of
https://github.com/correl/elm.git
synced 2025-03-07 04:35:48 -10:00
refactor nucleotide-count
This commit is contained in:
parent
b013837af3
commit
0b9ffd8ca1
2 changed files with 40 additions and 10 deletions
|
@ -1,5 +1,6 @@
|
|||
module NucleotideCount (..) where
|
||||
|
||||
|
||||
version : Int
|
||||
version =
|
||||
2
|
||||
|
|
|
@ -3,18 +3,47 @@ module NucleotideCount (..) where
|
|||
import String
|
||||
|
||||
|
||||
version : Int
|
||||
version =
|
||||
2
|
||||
|
||||
|
||||
nucleotideCounts : String -> { a : Int, t : Int, c : Int, g : Int }
|
||||
type alias NucleotideCounts =
|
||||
{ a : Int
|
||||
, t : Int
|
||||
, c : Int
|
||||
, g : Int
|
||||
}
|
||||
|
||||
|
||||
init : NucleotideCounts
|
||||
init =
|
||||
{ a = 0
|
||||
, t = 0
|
||||
, c = 0
|
||||
, g = 0
|
||||
}
|
||||
|
||||
|
||||
update : Char -> NucleotideCounts -> NucleotideCounts
|
||||
update char counts =
|
||||
case char of
|
||||
'A' ->
|
||||
{ counts | a = counts.a + 1 }
|
||||
|
||||
'T' ->
|
||||
{ counts | t = counts.t + 1 }
|
||||
|
||||
'C' ->
|
||||
{ counts | c = counts.c + 1 }
|
||||
|
||||
'G' ->
|
||||
{ counts | g = counts.g + 1 }
|
||||
|
||||
_ ->
|
||||
counts
|
||||
|
||||
|
||||
nucleotideCounts : String -> NucleotideCounts
|
||||
nucleotideCounts sequence =
|
||||
let
|
||||
getCount n =
|
||||
String.filter (\c -> c == n) sequence |> String.length
|
||||
in
|
||||
{ a = getCount 'A'
|
||||
, t = getCount 'T'
|
||||
, c = getCount 'C'
|
||||
, g = getCount 'G'
|
||||
}
|
||||
String.foldl update init sequence
|
||||
|
|
Loading…
Add table
Reference in a new issue