Anonymous user
Bioinformatics/Sequence mutation: Difference between revisions
m
→{{header|Haskell}}
(added Haskell) |
|||
Line 902:
</pre>
=={{header|Haskell}}==
<lang haskell>import
import Data.List (group, sort)
import Data.List.Split (chunksOf)
import System.Random (Random, randomR, random, newStdGen, randoms, getStdRandom)
Line 930 ⟶ 931:
toChar = head . show
fromChar c = read [c]
dropIndex i xs = take (pred i) xs <> drop i xs▼
insertIndex i e xs = take i xs <> [e] <> drop i xs▼
swapIndex i a xs = take (pred i) xs <> [a] <> drop i xs▼
chunkedDNASequence :: DNASequence -> [(Int, [DNABase])]
chunkedDNASequence = zip [50,100..] . chunksOf 50
baseCounts :: DNASequence -> [(DNABase, Int)]
Line 950 ⟶ 942:
mutateSequence :: DNASequence -> IO ((Mutation, Int), DNASequence)
mutateSequence
where
randomMutation = head . randoms <$> newStdGen▼
i <- randomIndex (length xs)
case m of
Swap -> randomDNA >>= \d -> pure ((Swap, i), swapIndex i d xs)
Insert -> randomDNA >>= \d -> pure ((Insert, i), insertIndex i d xs)
Delete -> pure ((Delete, i), dropIndex i xs)
where
▲ dropIndex i xs = take (pred i) xs <> drop i xs
▲ insertIndex i e xs = take i xs <> [e] <> drop i xs
randomIndex max = getStdRandom (randomR (1, max))▼
▲ swapIndex i a xs = take (pred i) xs <> [a] <> drop i xs
▲ randomIndex max = getStdRandom (randomR (1, max))
randomDNA = head . randoms <$> newStdGen
▲randomMutation = head . randoms <$> newStdGen
mutations :: Int -> DNASequence -> IO DNASequence
Line 1,028 ⟶ 1,017:
Total: 201
</pre>
=={{header|J}}==
<lang J>ACGT=: 'ACGT'
|