Created
February 10, 2015 02:09
-
-
Save amonshiz/11a34f1d5d4b51bf8b9a to your computer and use it in GitHub Desktop.
Finding a Motif in DNA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Bioinformatics.DNANucleotide ( | |
DNANucleotide (..), | |
charToDNANucleotide, | |
nucleotideComplement, | |
calculateGCContent, | |
findMotif | |
) where | |
import Data.Char | |
import Data.List | |
data DNANucleotide = A | C | G | T deriving(Show, Eq, Ord, Read) | |
charToDNANucleotide :: Char -> DNANucleotide | |
charToDNANucleotide c = read [toUpper c] :: DNANucleotide | |
nucleotideComplement :: DNANucleotide -> DNANucleotide | |
nucleotideComplement A = T | |
nucleotideComplement T = A | |
nucleotideComplement C = G | |
nucleotideComplement G = C | |
calculateGCContent :: [DNANucleotide] -> Double | |
calculateGCContent ns = | |
let gcs = filter (\n -> n == G || n == C) ns | |
in (fromIntegral $ length gcs) / (fromIntegral $ length ns) | |
findMotif :: [DNANucleotide] -> [DNANucleotide] -> [Int] | |
findMotif t = map (+1) . findIndices (isPrefixOf t) . tails |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qualified Bioinformatics.DNANucleotide as D | |
main = do | |
theDNAString <- getLine | |
theMotif <- getLine | |
putStrLn $ unwords . map show $ D.findMotif (map D.charToDNANucleotide theMotif) (map D.charToDNANucleotide theDNAString) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment