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