-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcons.hs
More file actions
52 lines (42 loc) · 1.57 KB
/
Copy pathcons.hs
File metadata and controls
52 lines (42 loc) · 1.57 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{-
Given: A collection of at most 10 DNA strings of equal length
(at most 1 kbp) in FASTA format.
Return: A consensus string and profile matrix for the collection.
(If several possible consensus strings exist,
then you may return any one of them.)
-}
import Fasta (splitStr, formTuple)
removeRosalind [] = []
removeRosalind ((x,y):xs) = [y] ++ removeRosalind xs
makeProfile c a = foldl (addTwoCounts) (head tmp) (tail tmp)
where tmp = map (countChar c) a
countChar c [] = []
countChar c (s:str)
| c == s = [1] ++ countChar c str
| otherwise = [0] ++ countChar c str
addTwoCounts [] [] = []
addTwoCounts (a:aa) (b:bb) = [a+b] ++ addTwoCounts aa bb
formStr c n = [c] ++ ": " ++ (unwords . map show $ n)
outPut c input = formStr c (makeProfile c input)
findMax [] [] [] [] = []
findMax (a:aa) (c:cc) (g:gg) (t:tt)
| a>=c && a>=g && a>=t = ['A'] ++ findMax aa cc gg tt
| c>=a && c>=g && c>=t = ['C'] ++ findMax aa cc gg tt
| g>=a && g>=c && g>=t = ['G'] ++ findMax aa cc gg tt
| t>=a && t>=c && t>=g = ['T'] ++ findMax aa cc gg tt
| otherwise = " " ++ findMax aa cc gg tt
main = do
input <- readFile "rosalind_cons.txt"
let
s = splitStr input
tmp = formTuple $ lines s
tmp'= removeRosalind tmp
a = makeProfile 'A' tmp'
c = makeProfile 'C' tmp'
g = makeProfile 'G' tmp'
t = makeProfile 'T' tmp'
putStrLn $ findMax a c g t
putStrLn $ outPut 'A' tmp'
putStrLn $ outPut 'C' tmp'
putStrLn $ outPut 'G' tmp'
putStrLn $ outPut 'T' tmp'