-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgc.hs
More file actions
54 lines (39 loc) · 1.42 KB
/
Copy pathgc.hs
File metadata and controls
54 lines (39 loc) · 1.42 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
52
53
{-
Given: At most 10 DNA strings in FASTA format (of length at most 1 kbp each).
Return: The ID of the string having the highest GC-content,
followed by the GC-content of that string. Rosalind allows
for a default error of 0.001 in all decimal answers
unless otherwise stated;
please see the note on absolute error below.
-}
t = "AGC\nTATAG"
removeGC [] = []
removeGC (x:xs)
| x == 'G' || x == 'C' = [x] ++ removeGC xs
| otherwise = removeGC xs
contentGC s = (fromIntegral $ length $ removeGC s) / (fromIntegral $ length s)
formTuple [] = []
formTuple (x:y:xs) = [(x,contentGC y)] ++ formTuple (xs)
maxInTuple [] (curMaxStr, curMax) = (curMaxStr, curMax)
maxInTuple ((x,y):xs) (curMaxStr, curMax)
| y > curMax = maxInTuple xs (x,y)
| otherwise = maxInTuple xs (curMaxStr, curMax)
concGC [] = []
concGC (x:xs) = concTwo x $ head xs ++ concGC xs
concTwo s1 s2
| s1!!0 /= '>' && s2!!0 /= '>' = s1 ++ s2
| otherwise = []
splitStr [] = ""
splitStr [x] = [x]
splitStr [x,y] = [x,y]
splitStr (x:y:z:xs)
| x `elem` ['C','G','T','A'] && y == '\n' && z `elem` ['C','G','T','A'] = splitStr (x:z:xs)
| otherwise = [x] ++ splitStr (y:z:xs)
main = do
input <- readFile "rosalind_gc.txt"
let
s = splitStr input
tmp = formTuple $ lines s
(tmp', max) = maxInTuple tmp ("",0)
putStrLn $ [x | x<-tmp', x /= '>']
print $ 100 * max