packages feed

BiobaseVienna 0.0.2.1 → 0.0.2.3

raw patch · 11 files changed

+364/−26 lines, 11 filesdep +directory

Dependencies added: directory

Files

Biobase/Vienna.hs view
@@ -1,6 +1,8 @@ {-# LANGUAGE NoMonomorphismRestriction #-}  -- | Turner energy data as used in the ViennaRNA package.+--+-- TODO should use energy type for tables, not int!  module Biobase.Vienna where @@ -9,6 +11,8 @@ import Data.Ix.Tuple import Data.PrimitiveArray.Ix import Data.PrimitiveArray+import Biobase.Types.Partition+import Biobase.Types.Energy  import Biobase.RNA import Biobase.Turner.Tables@@ -18,8 +22,12 @@  -- Type for Vienna Tables -type ViennaEnergySet = (Temperature, ViennaTables, ViennaTables)-type ViennaTables = Turner2004 ViennaPair Nucleotide Int+-- type ViennaEnergySet = (Temperature, ViennaTables, ViennaTables)++type ViennaIntTables = Turner2004 ViennaPair Nucleotide Int+type ViennaEnergyTables = Turner2004 ViennaPair Nucleotide Energy+type ViennaPartitionTables = Turner2004 ViennaPair Nucleotide Partition+ type Temperature = Double  @@ -28,7 +36,7 @@ -- are commented out. Activate them in BiobaseTurner before doing the same -- here! -emptyTables :: ViennaTables+emptyTables :: ViennaIntTables emptyTables = Turner2004   --stack   { stack = emptyIV
Biobase/Vienna/Default.hs view
@@ -14,7 +14,7 @@ import Biobase.Vienna.Import.ViennaPar import Biobase.Turner.Tables import Biobase.Vienna-+import Biobase.Types.Energy   @@ -23,4 +23,5 @@  -- Turner entropy and enthalpy tables. -turner2004GH = importPar $ B.unpack defaultPars+turner2004GH = (dmap Energy ta,dmap Energy tb) where+  (ta,tb) = importPar $ B.unpack defaultPars
+ Biobase/Vienna/Export/ViennaC.hs view
@@ -0,0 +1,264 @@+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TemplateHaskell #-}++-- | Exports the Vienna energy tables as a number of C files (one .c file, a+-- number .h files). For this reason, files are written into a target+-- directory!++module Biobase.Vienna.Export.ViennaC+  ( export+  ) where++import Prelude hiding (pi)+import Text.Printf+import System.Directory+import Data.List.Split+import Data.List+import qualified Data.Map as M+import Data.FileEmbed+import qualified Data.ByteString.Char8 as B++import Biobase.Turner.Tables+import Biobase.Vienna+import Data.PrimitiveArray+import Biobase.RNA++import Biobase.Vienna.Default++(g,h) = turner2004GH++++type Directory = FilePath++-- | Export the files required for default values in the ViennaRNA 2.0 C+-- package.++export :: ViennaIntTables -> ViennaIntTables -> Directory -> IO ()+export trnrG trnrH target = mapM_ (\f -> f trnrG trnrH target) [exportC, export11, export21, export22]++++-- | Export the main C file++exportC :: ViennaIntTables -> ViennaIntTables -> Directory -> IO ()+exportC trnrG trnrH target = writeFile (target ++ "/energy_par.c") out where+  out = unlines [ B.unpack $(embedFile "templates/cheader") , xs, stck, lps, mms, dngls, tris, tets, hexs,includes]+  xs = unlines+        [ pd "lxc37" $ largeLoop trnrG+        , pi "ML_intern37" $ multiHelix trnrG+        , pi "ML_interndH" $ multiHelix trnrH+        , pi "ML_closing37" $ multiOffset trnrG+        , pi "ML_closingdH" $ multiOffset trnrH+        , pi "ML_BASE37" $ multiNuc trnrG+        , pi "ML_BASEdH" $ multiNuc trnrH+        , pi "MAX_NINIO" $ maxNinio trnrG+        , pi "ninio37" $ ninio trnrG+        , pi "niniodH" $ ninio trnrH+        , pi "TerminalAU37" $ termAU trnrG+        , pi "TerminalAUdH" $ termAU trnrH+        , pi "DuplexInit37" $ intermolecularInit trnrG+        , pi "DuplexInitdH" $ intermolecularInit trnrH+        , pi "TripleC37" 100+        , pi "TripleCdH" 1860+        , pi "MultipleCA37" 30+        , pi "MultipleCAdH" 340+        , pi "MultipleCB37" 160+        , pi "MultipleCBdH" 760+        ]+  stck = unlines+          [ "PUBLIC int stack37[NBPAIRS+1][NBPAIRS+1] ="+          , (block2 8 . toList $ stack trnrG)+          , "PUBLIC int stackdH[NBPAIRS+1][NBPAIRS+1] ="+          , (block2 8 . toList $ stack trnrH)+          ]+  lps = unlines+          [ "PUBLIC int hairpin37[31] = {" ++ (concat . intersperse "," . map printNum . toList $ hairpinL trnrG) ++ "};"+          , "PUBLIC int hairpindH[31] = {" ++ (concat . intersperse "," . map printNum . toList $ hairpinL trnrH) ++ "};"+          , "PUBLIC int bulge37[31] = {" ++ (concat . intersperse "," . map printNum . toList $ bulgeL trnrG) ++ "};"+          , "PUBLIC int bulgedH[31] = {" ++ (concat . intersperse "," . map printNum . toList $ bulgeL trnrH) ++ "};"+          , "PUBLIC int internal_loop37[31] = {" ++ (concat . intersperse "," . map printNum . toList $ iloopL trnrG) ++ "};"+          , "PUBLIC int internal_loopdH[31] = {" ++ (concat . intersperse "," . map printNum . toList $ iloopL trnrH) ++ "};"+          ]+  mms = unlines+          [ writeMM "I" iloopMM trnrG trnrH+          , writeMM "H" hairpinMM trnrG trnrH+          , writeMM "M" multiMM trnrG trnrH+          , writeMM "1nI" iloop1xnMM trnrG trnrH+          , writeMM "23I" iloop2x3MM trnrG trnrH+          , writeMM "Ext" extMM trnrG trnrH+          ]+  dngls = unlines+            [ "PUBLIC int dangle3_37[NBPAIRS+1][5] ="+            , block2 5 . toList $ dangle3 trnrG+            , "PUBLIC int dangle3_dH[NBPAIRS+1][5] ="+            , block2 5 . toList $ dangle3 trnrH+            , "PUBLIC int dangle5_37[NBPAIRS+1][5] ="+            , block2 5 . toList $ dangle5 trnrG+            , "PUBLIC int dangle5_dH[NBPAIRS+1][5] ="+            , block2 5 . toList $ dangle5 trnrH+            ]+  t3 = getLookup 3 trnrG trnrH+  t4 = getLookup 4 trnrG trnrH+  t6 = getLookup 6 trnrG trnrH+  tris = writeTabbed 3 "Triloop" t3+  tets = writeTabbed 4 "Tetraloop" t4+  hexs = writeTabbed 6 "Hexaloop" t6++  includes = unlines $ map ((++ "\"") . ("#include \""++))+    [ "intl11.h"+    , "intl11dH.h"+    , "intl21.h"+    , "intl21dH.h"+    , "intl22.h"+    , "intl22dH.h"+    ]++++-- | Export iloops 1x1++export11 :: ViennaIntTables -> ViennaIntTables -> Directory -> IO ()+export11 trnrG trnrH target = writeFile (target ++ "/intl11.h") outG >> writeFile (target ++ "/intl11dH.h") outH where+  outG = unlines+    [ "PUBLIC int int11_37[NBPAIRS+1][NBPAIRS+1][5][5] ="+    , (block4 8 5 5 . toList $ iloop1x1 trnrG)+    ]+  outH = unlines+    [ "PUBLIC int int11_dH[NBPAIRS+1][NBPAIRS+1][5][5] ="+    , (block4 8 5 5 . toList $ iloop1x1 trnrH)+    ]++++-- | Export iloops 2x1++export21 :: ViennaIntTables -> ViennaIntTables -> Directory -> IO ()+export21 trnrG trnrH target = writeFile (target ++ "/intl21.h") outG >> writeFile (target ++ "/intl21dH.h") outH where+  outG = unlines+    [ "PUBLIC int int21_37[NBPAIRS+1][NBPAIRS+1][5][5][5] ="+    , (block5 8 5 5 5 . toList $ iloop1x2 trnrG)+    ]+  outH = unlines+    [ "PUBLIC int int21_dH[NBPAIRS+1][NBPAIRS+1][5][5][5] ="+    , (block5 8 5 5 5 . toList $ iloop1x2 trnrH)+    ]++++-- | Export iloops 2x2++export22 :: ViennaIntTables -> ViennaIntTables -> Directory -> IO ()+export22 trnrG trnrH target =  writeFile (target ++ "/intl22.h") outG >> writeFile (target ++ "/intl22dH.h") outH where+  outG = unlines+    [ "PUBLIC int int22_37[NBPAIRS+1][NBPAIRS+1][5][5][5][5] ="+    , (block6 8 5 5 5 5 . toList $ iloop2x2 trnrG)+    ]+  outH = unlines+    [ "PUBLIC int int22_dH[NBPAIRS+1][NBPAIRS+1][5][5][5][5] ="+    , (block6 8 5 5 5 5 . toList $ iloop2x2 trnrH)+    ]++++-- * Helper functions++writeTabbed (ksize :: Int) key (ns,gs,hs) =  unlines+          [ printf "PUBLIC char %ss[%d] =" key ((ksize+3)*40+1)+          , ns+          , ";"+          ] ++ printf "PUBLIC int %s37[40] = " key ++ gs ++ ";\n"+          ++ printf "PUBLIC int %sdH[40] = " key ++ hs ++ ";\n"++getLookup k trnrG trnrH = (nsF,gs,hs) where+  nsF = concat $ intersperse "\n" $ map ((++ " \"") . ("  \"" ++) . map nucleotideToChar) ns+  ns = filter ((==(k+2)) . length) . M.keys $ hairpinLookup trnrG+  gs = lkup trnrG+  hs = lkup trnrH+  lkup tbl = ("{"++) . (++"}") . concat . intersperse "," $ map (printNum . (hairpinLookup tbl M.!)) ns++writeMM typ fun trnrG trnrH = unlines+          [ printf "PUBLIC int mismatch%s37[NBPAIRS+1][5][5] =" typ+          , block3 5 5 . toList $ fun trnrG+          , printf "PUBLIC int mismatch%sdH[NBPAIRS+1][5][5] =" typ+          , block3 5 5 . toList $ fun trnrH+          ]++block2 s2 xs+  = (++ "};")+  . ("{" ++)+  . concat+  . intersperse "\n,"+  . map ((++ "}") . ("{" ++) . concat . intersperse ",")+  . splitEvery s2+  $ map printNum xs++block3 s2 s3 xs+  = (++ "};")+  . ("{" ++)+  . concat+  . intersperse "\n,"+  . map ((++ "}") . ("{" ++) . concat . intersperse ",")+  . splitEvery s2+  . map ((++ "}\n ") . ("{" ++) . concat . intersperse ",")+  . splitEvery s3+  $ map printNum xs++block4 s2 s3 s4 xs+  = (++ "};")+  . ("{" ++)+  . concat+  . intersperse "\n,"+  . map ((++ "}") . ("{" ++) . concat . intersperse ",")+  . splitEvery s2+  . map ((++ "}\n ") . ("{" ++) . concat . intersperse ",")+  . splitEvery s3+  . map ((++ "}\n  ") . ("{" ++) . concat . intersperse ",")+  . splitEvery s4+  $ map printNum xs++block5 s2 s3 s4 s5 xs+  = (++ "};")+  . ("{" ++)+  . concat+  . intersperse "\n,"+  . map ((++ "}") . ("{" ++) . concat . intersperse ",")+  . splitEvery s2+  . map ((++ "}\n ") . ("{" ++) . concat . intersperse ",")+  . splitEvery s3+  . map ((++ "}\n  ") . ("{" ++) . concat . intersperse ",")+  . splitEvery s4+  . map ((++ "}\n   ") . ("{" ++) . concat . intersperse ",")+  . splitEvery s5+  $ map printNum xs++block6 s2 s3 s4 s5 s6 xs+  = (++ "};")+  . ("{" ++)+  . concat+  . intersperse "\n,"+  . map ((++ "}") . ("{" ++) . concat . intersperse ",")+  . splitEvery s2+  . map ((++ "}\n ") . ("{" ++) . concat . intersperse ",")+  . splitEvery s3+  . map ((++ "}\n  ") . ("{" ++) . concat . intersperse ",")+  . splitEvery s4+  . map ((++ "}\n   ") . ("{" ++) . concat . intersperse ",")+  . splitEvery s5+  . map ((++ "}\n    ") . ("{" ++) . concat . intersperse ",")+  . splitEvery s6+  $ map printNum xs+++pd :: String -> Double -> String+pd k v = printf "PUBLIC double %s=%f;" k v++pi :: String -> Int -> String+pi k v = printf "PUBLIC int %s=%d;" k v++printNum :: Int -> String+printNum n+  | n >= maxN = "   INF"+  | otherwise = printf "%6d" n+  where+    maxN = 10000
Biobase/Vienna/Export/ViennaPar.hs view
@@ -21,7 +21,7 @@   -export :: ViennaTables -> ViennaTables -> String+export :: ViennaIntTables -> ViennaIntTables -> String export trnr trnrH = hdr ++ blocks ++ mlps ++ ninios ++ misc ++ triloops ++ tetra ++ hexa ++ "\n#END" where   hdr = "## RNAfold parameter file v2.0\n\n"   mlps = printf "# ML_params\n%7d %7d %7d %7d %7d %7d\n\n"
Biobase/Vienna/Import/Turner.hs view
@@ -20,7 +20,7 @@ import Biobase.Vienna -- | Convert from Turner keys to Vienna keys and all values from Double to Int -fromTurner :: TurnerTables -> ViennaTables+fromTurner :: TurnerTables -> ViennaIntTables fromTurner Turner2004{..} = Turner2004   { stack = convert pp stack   , dangle3 = convert pb dangle3@@ -43,7 +43,7 @@   , multiNuc = f2i multiNuc   , multiHelix = f2i multiHelix   , extMM = convert pbb extMM-  , largeLoop = largeLoop+  , largeLoop = largeLoop * 100 -- scale to decacals   , termAU = f2i termAU   , intermolecularInit = f2i intermolecularInit   }
Biobase/Vienna/Import/ViennaPar.hs view
@@ -25,7 +25,7 @@  -- | Imports Vienna tables from a given string. -importPar :: String -> (ViennaTables,ViennaTables)+importPar :: String -> (ViennaIntTables,ViennaIntTables) importPar s   | Right _  <- p = foldr updateTables (trnr,trnrH) bs   | Left err <- p = error $ show err@@ -38,7 +38,7 @@  -- | Apply all parsed blocks to a Turner2004 structure. -updateTable :: Block -> ViennaTables -> ViennaTables+updateTable :: Block -> ViennaIntTables -> ViennaIntTables updateTable Block{..} trnr -- @Turner2004{..}   | bhdr =? "stack" = trnr{stack = fromAssocs minBound maxBound z $ zip pp ints}   | bhdr =? "dangle3" = trnr{dangle3 = fromAssocs minBound maxBound z $ zip pb ints}@@ -90,7 +90,7 @@ ppbbbb = [(p1,p2,b1,b2,b3,b4) | p1<-cguaP,p2<-cguaP,b1<-acgu,b2<-acgu,b3<-acgu,b4<-acgu] z = eInf -- xs is the block header name, ys the constant string-xs =? ys = xs == ys || xs == ys++"enthalpies" -- and $ zipWith (==) xs ys+xs =? ys = xs == ys || xs == ys++"_enthalpies" -- and $ zipWith (==) xs ys s2ns = map charToNucleotide  -- * Simple parser for the vienna 2.0 format.
Biobase/Vienna/Modification/NonStandard.hs view
@@ -14,6 +14,7 @@ import Biobase.Turner.Tables import Data.Ix.Tuple import Biobase.Constants+import Biobase.Types.Energy  import Data.PrimitiveArray @@ -23,7 +24,7 @@  changeTable f tbl = fromAssocs l u z . map (f tbl) $ assocs tbl where   (l,u) = bounds tbl-  z = eInf+  z = Energy eInf   @@ -33,7 +34,7 @@  fPPBBBBmax tbl (k@(p1,p2,b1,b2,b3,b4),v)   | p1==vpNP || p2==vpNP = (k,v) -- don't do anything-  | otherwise = (k,maximum+  | otherwise = (k,maximum'     [ tbl ! (p1n,p2n,b1n,b2n,b3n,b4n)     | p1n <- genKeyP p1     , p2n <- genKeyP p2@@ -45,7 +46,7 @@  fPPBBBmax tbl (k@(p1,p2,b1,b2,b3),v)   | p1==vpNP || p2==vpNP = (k,v)-  | otherwise = (k,maximum+  | otherwise = (k,maximum'     [ tbl ! (p1n,p2n,b1n,b2n,b3n)     | p1n <- genKeyP p1     , p2n <- genKeyP p2@@ -56,7 +57,7 @@  fPPBBmax tbl (k@(p1,p2,b1,b2),v)   | p1==vpNP || p2==vpNP = (k,v)-  | otherwise = (k,maximum+  | otherwise = (k,maximum'     [ tbl ! (p1n,p2n,b1n,b2n)     | p1n <- genKeyP p1     , p2n <- genKeyP p2@@ -66,7 +67,7 @@  fPPmax tbl (k@(p1,p2),v)   | p1==vpNP || p2==vpNP = (k,v)-  | otherwise = (k,maximum+  | otherwise = (k,maximum'     [ tbl ! (p1n,p2n)     | p1n <- genKeyP p1     , p2n <- genKeyP p2@@ -74,7 +75,7 @@  fPBBmax tbl (k@(p1,b1,b2),v)   | p1==vpNP = (k,v)-  | otherwise = (k,maximum+  | otherwise = (k,maximum'     [ tbl ! (p1n,b1n,b2n)     | p1n <- genKeyP p1     , b1n <- genKeyB b1@@ -83,12 +84,13 @@  fPBmax tbl (k@(p1,b1),v)   | p1==vpNP = (k,v)-  | otherwise = (k,maximum+  | otherwise = (k,maximum'     [ tbl ! (p1n,b1n)     | p1n <- genKeyP p1     , b1n <- genKeyB b1     ]) +maximum' = Energy . maximum . map unEnergy   -- * Generate keys. If the key is of the non-standard kind, then we go fishing,@@ -102,7 +104,7 @@ -- | The max operation applied to all relevant tables. (This serves as a -- pointer, which tables to manipulate). -nonStandardMax :: ViennaTables -> ViennaTables+nonStandardMax :: ViennaEnergyTables -> ViennaEnergyTables nonStandardMax tbl = tbl   { iloop1x1   = changeTable fPPBBmax   $ iloop1x1 tbl   , iloop1x2   = changeTable fPPBBBmax  $ iloop1x2 tbl
+ Biobase/Vienna/Modification/Partition.hs view
@@ -0,0 +1,51 @@++-- | Small module for converting Vienna energy tables to partition function+-- value tables.+--+-- Temperature scaling should happen on the level of energy tables, followed by+-- conversion here.+--+-- TODO after the switch to the Energy type, change too, the partitionTables+-- generation++module Biobase.Vienna.Modification.Partition+  ( partitionTables+  ) where++import Biobase.Types.Partition+import Biobase.Types.Energy+import Biobase.Turner.Tables+import Biobase.Vienna+import Biobase.Constants+++-- Testing++{-+import Biobase.Vienna.Default+import Data.PrimitiveArray+import Debug.Trace.Tools+import Biobase.RNA+import Biobase.Types.Ring++(g,h) = turner2004GH++-- x = toList $ stack $ partitionTables 37 g+x = {- toList $ -} (stack $ partitionTables 37 g) ! (vpGC,vpGC)+-}++-- | Create partition tables out of normal energy tables. Note that these+-- values are not normalized. An additional term 1/Z(1/kt) would be required+-- which is missing until we are done calculating the partition function.+--+-- All energy contributions are rescaled from dekacals back to kcal/mol.+--+-- We explicitly set all probabilities =0 where the energy is >= eMax.++partitionTables :: Temperature -> ViennaEnergyTables -> ViennaPartitionTables+partitionTables tempe trnr = dmap f trnr where+  kt = (tempe + kelvinC0) * gasconst+  -- convert energy into probability; encapsulate as a (logFloat) partition+  f (Energy e') = {- traceVal (show (e',e,p)) -} p where+    e = fromIntegral e' / 100+    p = if e' >= eMax then Partition 0 else Partition . exp $ -e / kt -- can NOT use mkPartition as these values are NOT NORMALIZED
Biobase/Vienna/Modification/Temperature.hs view
@@ -8,6 +8,7 @@  import Biobase.Vienna import Biobase.Turner.Tables+import Biobase.Constants   @@ -20,12 +21,14 @@ -- TODO this does not take into account that dangles are supposed to _always_ -- be beneficial. We should therefor transform the energies and then apply 'min -- 0' onto all dangle types.+--+-- TODO use EnergyTables (Int is just for im-/export) -adjustTemperature :: ViennaTables -> ViennaTables -> Temperature -> ViennaTables+adjustTemperature :: ViennaIntTables -> ViennaIntTables -> Temperature -> ViennaIntTables adjustTemperature trnrG trnrH cels = dZipWith f trnrG trnrH where   f vG vH =     let g = fromIntegral vG         h = fromIntegral vH-        k_0 = 273.15+        k_0 = kelvinC0         t_m = 37 + k_0     in  round $ h - (h-g) * ((cels+k_0)/t_m)
BiobaseVienna.cabal view
@@ -1,10 +1,10 @@ name:           BiobaseVienna-version:        0.0.2.1+version:        0.0.2.3 author:         Christian Hoener zu Siederdissen maintainer:     choener@tbi.univie.ac.at copyright:      Christian Hoener zu Siederdissen, 2010 category:       Bioinformatics-synopsis:       ViennaRNA parameter library+synopsis:       (deprecated) ViennaRNA parameter library license:        GPL-3 license-file:   LICENSE build-type:     Simple@@ -28,6 +28,7 @@     split >=0.1.2,     tuple >=0.2.0.1,     vector >=0.7 && <0.8,+    directory >=1,      PrimitiveArray >=0.0.2 && <0.0.3,     ParsecTools >=0.0.2 && <0.0.3,@@ -41,8 +42,10 @@     Biobase.Vienna.Import.Turner     Biobase.Vienna.Import.ViennaPar     Biobase.Vienna.Export.ViennaPar+    Biobase.Vienna.Export.ViennaC     Biobase.Vienna.Modification.NonStandard     Biobase.Vienna.Modification.Temperature+    Biobase.Vienna.Modification.Partition     Biobase.Vienna.Default    ghc-options:
templates/cheader view
@@ -2,9 +2,15 @@  /*     Automatically generated using the TurnerParser-    TurnerParser (c) 2008,2009+    TurnerParser (c) 2008,2009,2010       Christian Hoener zu Siederdissen, TBI Vienna       choener (at) tbi.univie.ac.at++    The library enabling this can be found at:+    http://hackage.haskell.org/package/BiobaseVienna+    the program can be found at:+    (sorry, not yet)+    install using cabal: cabal install (sorry, not yet) */  /*@@ -18,7 +24,7 @@      Enthalpies taken from:       A. Walter, D Turner, J Kim, M Lyttle, P M"uller, D Mathews, M Zuker-     "Coaxial stckaing of helices enhances binding of oligoribonucleotides.."+     "Coaxial stacking of helices enhances binding of oligoribonucleotides.."      PNAS, 91, pp 9218-9222, 1994       D.H. Turner, N. Sugimoto, and S.M. Freier.@@ -30,7 +36,7 @@      PNAS, 86, 7706-7710, October 1989.       L. He, R. Kierzek, J. SantaLucia, A.E. Walter, D.H. Turner-     "Nearest-Neughbor Parameters for GU Mismatches...."+     "Nearest-Neighbor Parameters for GU Mismatches...."      Biochemistry 1991, 30 11124-11132       A.E. Peritz, R. Kierzek, N, Sugimoto, D.H. Turner