-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrevp.hs
More file actions
34 lines (24 loc) · 944 Bytes
/
Copy pathrevp.hs
File metadata and controls
34 lines (24 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import Data.List (nub,tails)
import Fasta (parse, removeRosalind)
revComp = comp . reverse
comp [] = []
comp (x:xs)
| x == 'A' = ['T'] ++ comp xs
| x == 'T' = ['A'] ++ comp xs
| x == 'C' = ['G'] ++ comp xs
| x == 'G' = ['C'] ++ comp xs
| otherwise = [x] ++ comp xs
printM = mapM_ (putStrLn . (\(x,y) -> show x ++ " " ++ show y))
isPalindrom' s = s == revComp s
getPalindromes s =
concat $
map (\(x,y) -> map (\(a,b) -> (x,a)) y) $
filter (\(x,y) -> not . null $ y) $
map (\(x,y) -> (x, filter (\(x,y) -> y == True ) y)) $
zip [1..] $ map (zip [4..12]) $
map (\s -> map (isPalindrom') $ nub (map (\n -> take n s) [4..12])) cutt
where
t = tails s
cutt = take (length t - 4) t
main = readFile "rosalind_revp.txt" >>=
printM . getPalindromes . head . removeRosalind . parse . lines