Anonymous user
Bioinformatics/Sequence mutation: Difference between revisions
m
→{{header|Haskell}}
Line 910:
data DNABase = A | C | G | T deriving (Show, Read, Eq, Ord, Enum, Bounded)
type DNASequence = [DNABase]
data Result = Result Mutation Int [DNABase]
instance Random DNABase where
Line 938 ⟶ 940:
newSequence n = take n . randoms <$> newStdGen
mutateSequence :: DNASequence -> IO (
mutateSequence [] = fail "empty dna sequence"
mutateSequence ds = mutate ds =<< randomMutation
where
Line 945 ⟶ 947:
mutate xs m = do
i <- randomIndex (length xs)
case m of
Swap -> randomDNA >>= \d -> pure (
Insert -> randomDNA >>= \d -> pure (
Delete -> pure (
where
dropElement i xs = take (pred i) xs <> drop i xs
Line 959 ⟶ 961:
mutate 0 s = pure s
mutate n s = do
(Result m i b, ms) <- mutateSequence s
case m of
Swap -> printf "%6s @ %-3d : %s -> %s \n" m i (head b) (last b)
_ -> printf "%6s @ %-3d : %s\n" m i (head b)
mutate (pred n) ms
Line 968 ⟶ 972:
putStrLn "\nInitial Sequence:" >> showSequence ds
putStrLn "\nBase Counts:" >> showBaseCounts ds
showSumBaseCounts ds
ms <- mutate 10 ds
putStrLn "\nMutated Sequence:" >> showSequence ms
putStrLn "\nBase Counts:" >> showBaseCounts ms
showSumBaseCounts ms
where
showSequence = mapM_ (uncurry (printf "%3d: %s\n")) . chunkedDNASequence
showBaseCounts = mapM_ (uncurry (printf "%s: %3d\n")) . baseCounts
showSumBaseCounts xs = putStrLn (replicate 6 '-') >> printf "Σ: %d\n\n" (length xs)</lang>
{{out}}
<pre>Initial Sequence:
50: CCGGCGAACTGGTAGGTCTTTAATTATGCGGCCGCGATCGCGACACAGGT
100: GCAGGAGGAAAATAGGCCCCCGTTCTGGGCAGCCTGATTGCACACTCCCG
150: ATACCAGACGTGTGGCGGCTTTTTCGCAAGATCTTACCAAACATTAAGAT
200: TCGAAATACCAACTGTCGAAAGCAGAACGTGAATGTACCACCCGGATGCG
Base Counts:
A:
C: 53
G:
T:
------
Insert @
Insert @
Insert @
Swap @
Insert @
Delete @ 9 : C
Swap @
▲Delete @ 134
Insert @
Swap @ 102 : C -> T
Mutated Sequence:
50: CCGGCGAATGGTCGGTCTTTAATTATGGCGGCCGCGATCGCGGACACAGG
100: TGCAGGAGGAAAAATAGGCCCCCGTTCTGGGCAGCCTGAATTGCACACTC
150: CTGATACCCAGACGTGTGGCGGCTTTTTCGCAAGACTTACCAAACATTAA
200: GATTCGAAATACCAACTGTCGAAAGCAGAACGTGAGTGTACCACCCGGAT
250:
Base Counts:
A:
C:
G:
T:
------
Σ: 203</pre>
=={{header|J}}==
|