Created
August 16, 2015 21:38
-
-
Save amonshiz/6035382949be0d5da835 to your computer and use it in GitHub Desktop.
Project Rosalind - Locating Restriction Sites 2
This file contains 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 Bioinformatics.DNANucleotide (DNANucleotide (..), | |
charToDNANucleotide) | |
import Bioinformatics.Utilities (getLines, reverseComplement) | |
import Data.List (sort) | |
type PotentialSite = (Int, Int) | |
slice :: PotentialSite -> [a] -> [a] | |
slice (b, l) xs = take l $ drop b xs | |
buildIndices :: [a] -> [PotentialSite] | |
buildIndices xs = sort [(b, l) | l <- [4,6..12], b <- [0..length xs - l]] | |
isRevPalindrome :: [DNANucleotide] -> Bool | |
isRevPalindrome xs = | |
xs == reverseComplement xs | |
buildSites :: [DNANucleotide] -> [PotentialSite] | |
buildSites xs = | |
let possibleIndices = buildIndices xs | |
in filter (\ps -> isRevPalindrome $ slice ps xs) possibleIndices | |
main :: IO () | |
main = do | |
dnaString <- getLines "" | |
let dna = map charToDNANucleotide $ init dnaString | |
sites = buildSites dna | |
resWords = map (\(b,l) -> unwords [show (b+1), show l]) sites | |
resLines = unlines resWords | |
putStr resLines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment