mirror of
https://github.com/correl/elm.git
synced 2025-03-07 20:53:30 -10:00
Merge pull request #63 from lukewestby/nucleotide-update
refactor nucleotide-count
This commit is contained in:
commit
f52d27184c
2 changed files with 40 additions and 10 deletions
|
@ -1,5 +1,6 @@
|
||||||
module NucleotideCount (..) where
|
module NucleotideCount (..) where
|
||||||
|
|
||||||
|
|
||||||
|
version : Int
|
||||||
version =
|
version =
|
||||||
2
|
2
|
||||||
|
|
|
@ -3,18 +3,47 @@ module NucleotideCount (..) where
|
||||||
import String
|
import String
|
||||||
|
|
||||||
|
|
||||||
|
version : Int
|
||||||
version =
|
version =
|
||||||
2
|
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 =
|
nucleotideCounts sequence =
|
||||||
let
|
String.foldl update init sequence
|
||||||
getCount n =
|
|
||||||
String.filter (\c -> c == n) sequence |> String.length
|
|
||||||
in
|
|
||||||
{ a = getCount 'A'
|
|
||||||
, t = getCount 'T'
|
|
||||||
, c = getCount 'C'
|
|
||||||
, g = getCount 'G'
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue