Advertisement
Yurry

Simple bioinformatics in REPL

Oct 7th, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. GHCi, version 7.0.4: http://www.haskell.org/ghc/  :? for help
  2. Loading package ghc-prim ... linking ... done.
  3. Loading package integer-gmp ... linking ... done.
  4. Loading package base ... linking ... done.
  5. Loading package ffi-1.0 ... linking ... done.
  6. ghci> --Distribution of genotypes in the second generation
  7. ghci> let split _ [] = []; split n xs = (take n xs):split (drop n xs)
  8.  
  9. <interactive>:1:47:
  10.     Couldn't match expected type `[[a0]]'
  11.                 with actual type `[a0] -> [[a0]]'
  12.    In the return type of a call of `split'
  13.     In the second argument of `(:)', namely `split (drop n xs)'
  14.     In the expression: (take n xs) : split (drop n xs)
  15. ghci> let split _ [] = []; split n xs = (take n xs):split n (drop n xs)
  16. ghci> split 2 "aabbb"
  17. ["aa","bb","b"]
  18. ghci> :{
  19. Prelude| let variants f m = variants' (split 2 f) (split 2 m) where
  20. Prelude|     variants' [] [] = []
  21. Prelude|     variants' (f:fs) (m:ms) = [[fa, ma]:rest | fa <- f, ma <- m, rest <- variants' fs ms]
  22. Prelude|     variants' _ _ = error "Parents have different genomes size"
  23. Prelude| :}
  24. ghci> variants "Aa" "Aa"
  25. []
  26. ghci> split 2 "Aa"
  27. ["Aa"]
  28. ghci> :t variants
  29. variants :: [t] -> [t] -> [[[t]]]
  30. ghci> :{
  31. Prelude| let variants f m = variants' (split 2 f) (split 2 m) where
  32. Prelude|     variants' [] [] = []
  33. Prelude|     variants' (f:fs) (m:ms) = [[fa, ma] ++ rest | fa <- f, ma <- m, rest <- variants' fs ms]
  34. Prelude| :}
  35. ghci> :t variants
  36. variants :: [a] -> [a] -> [[a]]
  37. ghci> variants "Aa" "Aa"
  38. []
  39. ghci> :{
  40. Prelude| let variants f m = variants' (split 2 f) (split 2 m) where
  41. Prelude|     variants' [] [] = [[]]
  42. Prelude|     variants' (f:fs) (m:ms) = [[fa, ma] ++ rest | fa <- f, ma <- m, rest <- variants' fs ms]
  43. Prelude| :}
  44. ghci> variants "Aa" "Aa"
  45. ["AA","Aa","aA","aa"]
  46. ghci> variants "AaBb" "AaBb"
  47. ["AABB","AABb","AAbB","AAbb","AaBB","AaBb","AabB","Aabb","aABB","aABb","aAbB","aAbb","aaBB","aaBb","aabB","aabb"]
  48. ghci> import Data.List
  49. ghci> import Data.Sort
  50.  
  51. <no location info>:
  52.    Could not find module `Data.Sort':
  53.       Use -v to see a list of the files searched for.
  54. ghci> import Data.Ratio
  55. ghci> let distribution(\group -> (head group, length group % length f)) . group . sort . map sort . variants
  56.  
  57. <interactive>:1:103: parse error (possibly incorrect indentation)
  58. ghci> let distribution = map (\group -> (head group, length group % length f)) . group . sort . map sort . variants
  59.  
  60. <interactive>:1:70: Not in scope: `f'
  61. ghci> let distribution f m = map (\group -> (head group, length group % length f)) . group . sort . map sort $ variants f m
  62. ghci> let distribution f m = map (\group -> (head group, length group % length f ^ 2)) . group . sort . map sort $ variants f m
  63. ghci> distribution "Aa" "Aa"
  64. [("AA",1 % 4),("Aa",1 % 2),("aa",1 % 4)]
  65. ghci> distribution "AaBb" "AaBb"
  66. [("AABB",1 % 16),("AABb",1 % 8),("AAbb",1 % 16),("ABBa",1 % 8),("ABab",1 % 4),("Aabb",1 % 8),("BBaa",1 % 16),("Baab",1 % 8),("aabb",1 % 16)]
  67. ghci> import Data.Monoid
  68. ghci> import Data.Char
  69. ghci> let compAllel = comparing toLower <+> compare
  70.  
  71. <interactive>:1:17: Not in scope: `comparing'
  72.  
  73. <interactive>:1:35: Not in scope: `<+>'
  74. ghci> import Data.Ord
  75. ghci> let compAllel = comparing toLower `mappend` compare
  76. ghci> zipWith2 compAllel "AABBaabb" "ababABAB"
  77.  
  78. <interactive>:1:1: Not in scope: `zipWith2'
  79. ghci> zipWith compAllel "AABBaabb" "ababABAB"
  80. [LT,LT,GT,LT,GT,LT,GT,GT]
  81. ghci> sortBy compAllel "BaBAaABaABa"
  82. "AAAaaaaBBBB"
  83. ghci> let distribution f m = map (\group -> (head group, length group % 2 ^ length f)) . group . sort . map (sortBy compAllel) $ variants f m
  84. ghci> distribution "AaBb" "AaBb"
  85. [("AABB",1 % 16),("AABb",1 % 8),("AAbb",1 % 16),("AaBB",1 % 8),("AaBb",1 % 4),("Aabb",1 % 8),("aaBB",1 % 16),("aaBb",1 % 8),("aabb",1 % 16)]
  86. ghci>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement