Skip to content

Instantly share code, notes, and snippets.

@amonshiz
Created August 16, 2015 21:38
Show Gist options
  • Save amonshiz/6035382949be0d5da835 to your computer and use it in GitHub Desktop.
Save amonshiz/6035382949be0d5da835 to your computer and use it in GitHub Desktop.
Project Rosalind - Locating Restriction Sites 2
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