packages feed

ViennaRNA-bindings 0.0.2.3 → 0.0.3.0

raw patch · 5 files changed

+142/−3 lines, 5 files

Files

BioInf/ViennaRNA/Bindings.hs view
@@ -1,11 +1,20 @@  -- | Bindings to important functions in the ViennaRNA library. -module BioInf.ViennaRNA.Bindings where+module BioInf.ViennaRNA.Bindings+  ( mfe+  , eos+  , part+  , coeos+  , comfe+  , copart+  , CofoldF (..)+  ) where  import qualified Data.Array.IArray as A  import BioInf.ViennaRNA.Bindings.FFI.Fold as FFI+import BioInf.ViennaRNA.Bindings.FFI.CoFold as FFI import BioInf.ViennaRNA.Bindings.FFI.PartFunc as FFI  -- | Fold a sequence into an optimal secondary structure. Returns a pair of@@ -27,4 +36,24 @@  part :: String -> IO (Double,String,A.Array (Int,Int) Double) part = ffiPartitionFunction++++-- * RNAcofold++-- | Energy of struct for cofolded structures.++coeos :: String -> String -> Int -> IO Double+coeos i s c = ffiCoEnergyOfStructure c i s 0++-- | mfe of co-folded structure++comfe :: String -> Int -> IO (Double,String)+comfe s c = ffiCoFold c s++-- | Cofolded partition function. Makes the set of different partfun values+-- from cofoldF available.++copart :: String -> Int -> IO (CofoldF,String,A.Array (Int,Int) Double)+copart s c = ffiCoPartitionFunction  c s 
+ BioInf/ViennaRNA/Bindings/FFI/CoFold.chs view
@@ -0,0 +1,97 @@+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE ForeignFunctionInterface #-}++module BioInf.ViennaRNA.Bindings.FFI.CoFold+  ( ffiCoFold+  , ffiCoEnergyOfStructure+  , ffiCoPartitionFunction+  , CofoldF (..)+  ) where++import Foreign.C.String+import Foreign.C.Types+import Foreign.Marshal.Alloc+import Foreign.Ptr+import Foreign.Storable+import GHC.Float+import Unsafe.Coerce+import qualified Data.Array.IArray as A+import Foreign.Marshal.Array+import Control.Applicative+import Control.Monad++import BioInf.ViennaRNA.Bindings.FFI.Utils++import Debug.Trace++++#include <ViennaRNA/fold.h>+#include <ViennaRNA/data_structures.h>+#include <ViennaRNA/cofold.h>+#include <ViennaRNA/part_func_co.h>++{#pointer *cofoldF as CofoldFPtr -> CofoldF #}++data CofoldF = CofoldF+  { f0ab :: Double+  , fab  :: Double+  , fcab :: Double+  , fa   :: Double+  , fb   :: Double+  }+  deriving (Show)++instance Storable CofoldF where+  sizeOf _ = {#sizeof cofoldF#}+  alignment _ = sizeOf (undefined :: CDouble)+  peek p = CofoldF <$> liftM unsafeCoerce ({# get cofoldF->F0AB #} p)+                   <*> liftM unsafeCoerce ({# get cofoldF->FAB  #} p)+                   <*> liftM unsafeCoerce ({# get cofoldF->FcAB #} p)+                   <*> liftM unsafeCoerce ({# get cofoldF->FA   #} p)+                   <*> liftM unsafeCoerce ({# get cofoldF->FB   #} p)++-- |++ffiCoFold :: Int -> String -> IO (Double,String)+ffiCoFold cp inp = withCAString inp $ \cinp ->+                   withCAString inp $ \struc -> do+  setCutPoint cp+  e <- {#call cofold #} cinp struc+  s <- peekCAString struc+  return (cf2d e, s)++-- |++ffiCoEnergyOfStructure :: Int -> String -> String -> Int -> IO Double+ffiCoEnergyOfStructure cp inp struc verb =+  withCAString inp   $ \i ->+  withCAString struc $ \s ->+    setCutPoint cp+    >>  {#call energy_of_structure #} i s (fromIntegral verb :: CInt)+    >>= (return . cf2d)++-- |++ffiCoPartitionFunction :: Int -> String -> IO (CofoldF,String,A.Array (Int,Int) Double)+ffiCoPartitionFunction cutpoint i =+  withCAString i $ \ci ->+  withCAString i $ \cs -> do+  setCutPoint cutpoint+  let n = length i+  let z = n * (n+1) `div` 2 +1+  eF <- co_pf_fold_p ci cs >>= peek -- {#call co_pf_fold #} ci cs+  s  <- peekCAString cs+  bp <- {#call export_co_bppm #}+  xs <- peekArray z (bp :: Ptr CDouble)+  let ar = A.accumArray (const id) 0 ((1,1),(n,n)) $ zip [ (ii,jj) | ii <- [n,n-1..1], jj <- [n,n-1..ii]] (drop 1 $ map unsafeCoerce xs)+  return (eF, s, ar)++foreign import ccall "co_pf_fold_P" co_pf_fold_p :: CString -> CString -> IO CofoldFPtr++#c+cofoldF * co_pf_fold_p (char * inp, char * str)+{ return & co_pf_fold (inp, str);+}+#endc+
BioInf/ViennaRNA/Bindings/FFI/Fold.chs view
@@ -1,4 +1,5 @@ {-# LANGUAGE ForeignFunctionInterface #-}+{-# LANGUAGE CPP #-}  module BioInf.ViennaRNA.Bindings.FFI.Fold   ( ffiFold@@ -16,6 +17,7 @@   + #include <ViennaRNA/fold.h>  ffiFold :: String -> IO (Double,String)@@ -29,5 +31,7 @@ ffiEnergyOfStructure inp struc verb =   withCAString inp   $ \i ->   withCAString struc $ \s ->-  {#call energy_of_structure #} i s (fromIntegral verb :: CInt) >>= (return . cf2d)+    setCutPoint (-1)+    >>  {#call energy_of_structure #} i s (fromIntegral verb :: CInt)+    >>= (return . cf2d) 
BioInf/ViennaRNA/Bindings/FFI/Utils.hs view
@@ -1,12 +1,20 @@+{-# LANGUAGE ForeignFunctionInterface #-}  module BioInf.ViennaRNA.Bindings.FFI.Utils where  import Foreign.C.Types import GHC.Float import Unsafe.Coerce+import Foreign.Ptr+import Foreign.Storable    cf2d :: CFloat -> Double cf2d = float2Double . unsafeCoerce++foreign import ccall "fold.h &cut_point" cut_point :: Ptr CInt++setCutPoint :: Int -> IO ()+setCutPoint = poke cut_point . unsafeCoerce 
ViennaRNA-bindings.cabal view
@@ -1,5 +1,5 @@ name:                ViennaRNA-bindings-version:             0.0.2.3+version:             0.0.3.0 synopsis:            ViennaRNA v2 bindings homepage:            http://www.tbi.univie.ac.at/~choener/ license:             OtherLicense@@ -35,6 +35,7 @@     -- public interfaces     BioInf.ViennaRNA.Bindings     -- the FFI+    BioInf.ViennaRNA.Bindings.FFI.CoFold     BioInf.ViennaRNA.Bindings.FFI.Fold     BioInf.ViennaRNA.Bindings.FFI.PartFunc     BioInf.ViennaRNA.Bindings.FFI.Utils