ViennaRNA-bindings 0.233.1.2 → 0.233.2.0
raw patch · 10 files changed
+132/−99 lines, 10 filesdep +bytestringPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: bytestring
API changes (from Hackage documentation)
- BioInf.ViennaRNA.Bindings: Duplex :: {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> !String -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> Duplex
+ BioInf.ViennaRNA.Bindings: Duplex :: {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> !ByteString -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> Duplex
- BioInf.ViennaRNA.Bindings: [structure] :: Duplex -> !String
+ BioInf.ViennaRNA.Bindings: [structure] :: Duplex -> !ByteString
- BioInf.ViennaRNA.Bindings: centroidTemp :: Double -> String -> IO (Double, String)
+ BioInf.ViennaRNA.Bindings: centroidTemp :: Double -> ByteString -> IO (Double, ByteString, Double)
- BioInf.ViennaRNA.Bindings: circPart :: String -> IO (Double, String, Array (Int, Int) Double)
+ BioInf.ViennaRNA.Bindings: circPart :: ByteString -> IO (Double, ByteString, Array (Int, Int) Double)
- BioInf.ViennaRNA.Bindings: circPartConstrained :: String -> String -> IO (Double, String, Array (Int, Int) Double)
+ BioInf.ViennaRNA.Bindings: circPartConstrained :: ByteString -> ByteString -> IO (Double, ByteString, Array (Int, Int) Double)
- BioInf.ViennaRNA.Bindings: circmfe :: String -> IO (Double, String)
+ BioInf.ViennaRNA.Bindings: circmfe :: ByteString -> IO (Double, ByteString)
- BioInf.ViennaRNA.Bindings: coeos :: String -> String -> Int -> IO Double
+ BioInf.ViennaRNA.Bindings: coeos :: ByteString -> ByteString -> Int -> IO Double
- BioInf.ViennaRNA.Bindings: comfe :: String -> Int -> IO (Double, String)
+ BioInf.ViennaRNA.Bindings: comfe :: ByteString -> Int -> IO (Double, ByteString)
- BioInf.ViennaRNA.Bindings: copart :: String -> Int -> IO (CofoldF, String, Array (Int, Int) Double)
+ BioInf.ViennaRNA.Bindings: copart :: ByteString -> Int -> IO (CofoldF, ByteString, Array (Int, Int) Double)
- BioInf.ViennaRNA.Bindings: copartConstrained :: String -> String -> Int -> IO (CofoldF, String, Array (Int, Int) Double)
+ BioInf.ViennaRNA.Bindings: copartConstrained :: ByteString -> ByteString -> Int -> IO (CofoldF, ByteString, Array (Int, Int) Double)
- BioInf.ViennaRNA.Bindings: duplexFold :: String -> String -> IO Duplex
+ BioInf.ViennaRNA.Bindings: duplexFold :: ByteString -> ByteString -> IO Duplex
- BioInf.ViennaRNA.Bindings: eos :: String -> String -> IO Double
+ BioInf.ViennaRNA.Bindings: eos :: ByteString -> ByteString -> IO Double
- BioInf.ViennaRNA.Bindings: eosCirc :: String -> String -> IO Double
+ BioInf.ViennaRNA.Bindings: eosCirc :: ByteString -> ByteString -> IO Double
- BioInf.ViennaRNA.Bindings: eosTemp :: Double -> String -> String -> IO Double
+ BioInf.ViennaRNA.Bindings: eosTemp :: Double -> ByteString -> ByteString -> IO Double
- BioInf.ViennaRNA.Bindings: mfe :: String -> IO (Double, String)
+ BioInf.ViennaRNA.Bindings: mfe :: ByteString -> IO (Double, ByteString)
- BioInf.ViennaRNA.Bindings: mfeTemp :: Double -> String -> IO (Double, String)
+ BioInf.ViennaRNA.Bindings: mfeTemp :: Double -> ByteString -> IO (Double, ByteString)
- BioInf.ViennaRNA.Bindings: part :: String -> IO (Double, String, Array (Int, Int) Double)
+ BioInf.ViennaRNA.Bindings: part :: ByteString -> IO (Double, ByteString, Array (Int, Int) Double)
- BioInf.ViennaRNA.Bindings: partConstrained :: String -> String -> IO (Double, String, Array (Int, Int) Double)
+ BioInf.ViennaRNA.Bindings: partConstrained :: ByteString -> ByteString -> IO (Double, ByteString, Array (Int, Int) Double)
- BioInf.ViennaRNA.Bindings.FFI.Centroid: ffiCentroidTemp :: Double -> String -> IO (Double, String)
+ BioInf.ViennaRNA.Bindings.FFI.Centroid: ffiCentroidTemp :: Double -> ByteString -> IO (Double, ByteString, Double)
- BioInf.ViennaRNA.Bindings.FFI.Centroid: fold_centroid_p :: CDouble -> CString -> CString -> IO CDouble
+ BioInf.ViennaRNA.Bindings.FFI.Centroid: fold_centroid_p :: CDouble -> CString -> CString -> Ptr CDouble -> IO CDouble
- BioInf.ViennaRNA.Bindings.FFI.CoFold: ffiCoEnergyOfStructure :: Int -> String -> String -> Int -> IO Double
+ BioInf.ViennaRNA.Bindings.FFI.CoFold: ffiCoEnergyOfStructure :: Int -> ByteString -> ByteString -> Int -> IO Double
- BioInf.ViennaRNA.Bindings.FFI.CoFold: ffiCoFold :: Int -> String -> IO (Double, String)
+ BioInf.ViennaRNA.Bindings.FFI.CoFold: ffiCoFold :: Int -> ByteString -> IO (Double, ByteString)
- BioInf.ViennaRNA.Bindings.FFI.CoFold: ffiCoPartitionConstrained :: Int -> String -> String -> IO (CofoldF, String, Array (Int, Int) Double)
+ BioInf.ViennaRNA.Bindings.FFI.CoFold: ffiCoPartitionConstrained :: Int -> ByteString -> ByteString -> IO (CofoldF, ByteString, Array (Int, Int) Double)
- BioInf.ViennaRNA.Bindings.FFI.CoFold: ffiCoPartitionFunction :: Int -> String -> IO (CofoldF, String, Array (Int, Int) Double)
+ BioInf.ViennaRNA.Bindings.FFI.CoFold: ffiCoPartitionFunction :: Int -> ByteString -> IO (CofoldF, ByteString, Array (Int, Int) Double)
- BioInf.ViennaRNA.Bindings.FFI.Duplex: Duplex :: {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> !String -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> Duplex
+ BioInf.ViennaRNA.Bindings.FFI.Duplex: Duplex :: {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> !ByteString -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Double -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> {-# UNPACK #-} !Int -> Duplex
- BioInf.ViennaRNA.Bindings.FFI.Duplex: [structure] :: Duplex -> !String
+ BioInf.ViennaRNA.Bindings.FFI.Duplex: [structure] :: Duplex -> !ByteString
- BioInf.ViennaRNA.Bindings.FFI.Duplex: ffiDuplexFold :: String -> String -> IO Duplex
+ BioInf.ViennaRNA.Bindings.FFI.Duplex: ffiDuplexFold :: ByteString -> ByteString -> IO Duplex
- BioInf.ViennaRNA.Bindings.FFI.Fold: ffiCircFold :: String -> IO (Double, String)
+ BioInf.ViennaRNA.Bindings.FFI.Fold: ffiCircFold :: ByteString -> IO (Double, ByteString)
- BioInf.ViennaRNA.Bindings.FFI.Fold: ffiEnergyOfCircStructure :: String -> String -> Int -> IO Double
+ BioInf.ViennaRNA.Bindings.FFI.Fold: ffiEnergyOfCircStructure :: ByteString -> ByteString -> Int -> IO Double
- BioInf.ViennaRNA.Bindings.FFI.Fold: ffiEnergyOfStructure :: String -> String -> Int -> IO Double
+ BioInf.ViennaRNA.Bindings.FFI.Fold: ffiEnergyOfStructure :: ByteString -> ByteString -> Int -> IO Double
- BioInf.ViennaRNA.Bindings.FFI.Fold: ffiEnergyOfStructureTemp :: Double -> String -> String -> Int -> IO Double
+ BioInf.ViennaRNA.Bindings.FFI.Fold: ffiEnergyOfStructureTemp :: Double -> ByteString -> ByteString -> Int -> IO Double
- BioInf.ViennaRNA.Bindings.FFI.Fold: ffiFold :: String -> IO (Double, String)
+ BioInf.ViennaRNA.Bindings.FFI.Fold: ffiFold :: ByteString -> IO (Double, ByteString)
- BioInf.ViennaRNA.Bindings.FFI.Fold: ffiFoldTemp :: Double -> String -> IO (Double, String)
+ BioInf.ViennaRNA.Bindings.FFI.Fold: ffiFoldTemp :: Double -> ByteString -> IO (Double, ByteString)
- BioInf.ViennaRNA.Bindings.FFI.PartFunc: ffi_pf_circ_fold :: String -> IO (Double, String, Array (Int, Int) Double)
+ BioInf.ViennaRNA.Bindings.FFI.PartFunc: ffi_pf_circ_fold :: ByteString -> IO (Double, ByteString, Array (Int, Int) Double)
- BioInf.ViennaRNA.Bindings.FFI.PartFunc: ffi_pf_circ_fold_constrained :: String -> String -> IO (Double, String, Array (Int, Int) Double)
+ BioInf.ViennaRNA.Bindings.FFI.PartFunc: ffi_pf_circ_fold_constrained :: ByteString -> ByteString -> IO (Double, ByteString, Array (Int, Int) Double)
- BioInf.ViennaRNA.Bindings.FFI.PartFunc: ffi_pf_fold :: String -> IO (Double, String, Array (Int, Int) Double)
+ BioInf.ViennaRNA.Bindings.FFI.PartFunc: ffi_pf_fold :: ByteString -> IO (Double, ByteString, Array (Int, Int) Double)
- BioInf.ViennaRNA.Bindings.FFI.PartFunc: ffi_pf_fold_constrained :: String -> String -> IO (Double, String, Array (Int, Int) Double)
+ BioInf.ViennaRNA.Bindings.FFI.PartFunc: ffi_pf_fold_constrained :: ByteString -> ByteString -> IO (Double, ByteString, Array (Int, Int) Double)
Files
- BioInf/ViennaRNA/Bindings.hs +22/−21
- BioInf/ViennaRNA/Bindings/FFI/Centroid.chs +14/−7
- BioInf/ViennaRNA/Bindings/FFI/CoFold.chs +19/−17
- BioInf/ViennaRNA/Bindings/FFI/Duplex.chs +6/−5
- BioInf/ViennaRNA/Bindings/FFI/Fold.chs +23/−22
- BioInf/ViennaRNA/Bindings/FFI/PartFunc.chs +22/−20
- C/ffiwrap_centroid.c +3/−3
- ViennaRNA-bindings.cabal +6/−2
- changelog.md +5/−0
- tests/properties.hs +12/−2
BioInf/ViennaRNA/Bindings.hs view
@@ -10,38 +10,39 @@ , Duplex (..) ) where +import Data.ByteString.Char8 import qualified Data.Array.IArray as A -import BioInf.ViennaRNA.Bindings.FFI.Centroid as FFI-import BioInf.ViennaRNA.Bindings.FFI.CoFold as FFI-import BioInf.ViennaRNA.Bindings.FFI.Duplex as FFI-import BioInf.ViennaRNA.Bindings.FFI.Fold as FFI-import BioInf.ViennaRNA.Bindings.FFI.PartFunc as FFI+import BioInf.ViennaRNA.Bindings.FFI.Centroid as FFI+import BioInf.ViennaRNA.Bindings.FFI.CoFold as FFI+import BioInf.ViennaRNA.Bindings.FFI.Duplex as FFI+import BioInf.ViennaRNA.Bindings.FFI.Fold as FFI+import BioInf.ViennaRNA.Bindings.FFI.PartFunc as FFI -- | Fold a sequence into an optimal secondary structure. Returns a pair of -- energy and structure. -mfe :: String -> IO (Double,String)+mfe :: ByteString -> IO (Double,ByteString) mfe = ffiFold -mfeTemp :: Double -> String -> IO (Double,String)+mfeTemp :: Double -> ByteString -> IO (Double,ByteString) mfeTemp = ffiFoldTemp -circmfe :: String -> IO (Double,String)+circmfe :: ByteString -> IO (Double,ByteString) circmfe = ffiCircFold -- | Given a sequence and a structure, returns the energy of the -- sequence/structure pair. -eos :: String -> String -> IO Double+eos :: ByteString -> ByteString -> IO Double eos i s = ffiEnergyOfStructure i s 0 -eosTemp :: Double -> String -> String -> IO Double+eosTemp :: Double -> ByteString -> ByteString -> IO Double eosTemp t i s = ffiEnergyOfStructureTemp t i s 0 -- | Energy of a circular structure -eosCirc :: String -> String -> IO Double+eosCirc :: ByteString -> ByteString -> IO Double eosCirc i s = ffiEnergyOfCircStructure i s 0 -- | Given a string, calculates the partition function for said string. Returns@@ -49,46 +50,46 @@ -- annotated with the strength of the potential pairing, and the whole base -- pair probability table. -part :: String -> IO (Double,String,A.Array (Int,Int) Double)+part :: ByteString -> IO (Double,ByteString,A.Array (Int,Int) Double) part = ffi_pf_fold -partConstrained :: String -> String -> IO (Double, String, A.Array (Int,Int) Double)+partConstrained :: ByteString -> ByteString -> IO (Double, ByteString, A.Array (Int,Int) Double) partConstrained = ffi_pf_fold_constrained -circPart :: String -> IO (Double,String,A.Array (Int,Int) Double)+circPart :: ByteString -> IO (Double,ByteString,A.Array (Int,Int) Double) circPart = ffi_pf_circ_fold -circPartConstrained :: String -> String -> IO (Double, String, A.Array (Int,Int) Double)+circPartConstrained :: ByteString -> ByteString -> IO (Double, ByteString, A.Array (Int,Int) Double) circPartConstrained = ffi_pf_circ_fold_constrained -- | Centroid structure -centroidTemp :: Double -> String -> IO (Double,String)+centroidTemp :: Double -> ByteString -> IO (Double,ByteString,Double) centroidTemp t i = ffiCentroidTemp t i -- * RNAcofold -- | Energy of struct for cofolded structures. -coeos :: String -> String -> Int -> IO Double+coeos :: ByteString -> ByteString -> Int -> IO Double coeos i s c = ffiCoEnergyOfStructure c i s 0 -- | mfe of co-folded structure -comfe :: String -> Int -> IO (Double,String)+comfe :: ByteString -> Int -> IO (Double,ByteString) 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 :: ByteString -> Int -> IO (CofoldF,ByteString,A.Array (Int,Int) Double) copart s c = ffiCoPartitionFunction c s -copartConstrained :: String -> String -> Int -> IO (CofoldF,String,A.Array (Int,Int) Double)+copartConstrained :: ByteString -> ByteString -> Int -> IO (CofoldF,ByteString,A.Array (Int,Int) Double) copartConstrained sq str c = ffiCoPartitionConstrained c sq str -- | Fold a duplex structure -duplexFold :: String -> String -> IO Duplex+duplexFold :: ByteString -> ByteString -> IO Duplex duplexFold = ffiDuplexFold
BioInf/ViennaRNA/Bindings/FFI/Centroid.chs view
@@ -1,10 +1,13 @@ module BioInf.ViennaRNA.Bindings.FFI.Centroid where +import Data.ByteString.Char8 as BS import Foreign.C.String import Foreign.C.Types import Foreign.Marshal.Alloc+import Foreign.Marshal.Utils import Foreign.Ptr+import Foreign.Storable import GHC.Float import Unsafe.Coerce @@ -16,15 +19,19 @@ -ffiCentroidTemp :: Double -> String -> IO (Double,String)+ffiCentroidTemp :: Double -> ByteString -> IO (Double,ByteString,Double) ffiCentroidTemp t inp =- withCAString inp $ \cinp ->- withCAString inp $ \struc -> do- e <- fold_centroid_p (realToFrac t) cinp struc- s <- peekCAString struc- return (cd2d e, s)+ if BS.null inp+ then return (0,BS.empty,0)+ else useAsCString inp $ \cinp ->+ useAsCString inp $ \struc ->+ with (0 :: CDouble) $ \dist -> do+ e <- if BS.null inp then return 0 else fold_centroid_p (realToFrac t) cinp struc dist+ s <- packCString struc+ d <- peek dist+ return (cd2d e, s, cd2d d) -foreign import ccall "ffiwrap_centroid_temp" fold_centroid_p :: CDouble -> CString -> CString -> IO CDouble+foreign import ccall "ffiwrap_centroid_temp" fold_centroid_p :: CDouble -> CString -> CString -> Ptr CDouble -> IO CDouble
BioInf/ViennaRNA/Bindings/FFI/CoFold.chs view
@@ -9,6 +9,7 @@ import Control.Applicative import Control.Monad+import Data.ByteString.Char8 (ByteString, useAsCString, packCString) import Foreign.C.String import Foreign.C.Types import Foreign.Marshal.Alloc@@ -17,6 +18,7 @@ import Foreign.Storable import GHC.Float import qualified Data.Array.IArray as A+import qualified Data.ByteString.Char8 as BS import Unsafe.Coerce import BioInf.ViennaRNA.Bindings.FFI.Utils@@ -50,36 +52,36 @@ -- | -ffiCoFold :: Int -> String -> IO (Double,String)-ffiCoFold cp inp = withCAString inp $ \cinp ->- withCAString inp $ \struc -> do+ffiCoFold :: Int -> ByteString -> IO (Double,ByteString)+ffiCoFold cp inp = useAsCString inp $ \cinp ->+ useAsCString inp $ \struc -> do setCutPoint cp e <- {#call cofold #} cinp struc- s <- peekCAString struc+ s <- packCString struc return (cf2d e, s) -- | -ffiCoEnergyOfStructure :: Int -> String -> String -> Int -> IO Double+ffiCoEnergyOfStructure :: Int -> ByteString -> ByteString -> Int -> IO Double ffiCoEnergyOfStructure cp inp struc verb =- withCAString inp $ \i ->- withCAString struc $ \s ->+ useAsCString inp $ \i ->+ useAsCString 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 :: Int -> ByteString -> IO (CofoldF,ByteString,A.Array (Int,Int) Double) ffiCoPartitionFunction cutpoint i =- withCAString i $ \ci ->- withCAString i $ \cs ->+ useAsCString i $ \ci ->+ useAsCString i $ \cs -> alloca $ \ptr -> do setCutPoint cutpoint- let n = length i+ let n = BS.length i let z = n * (n+1) `div` 2 +1 eF <- co_pf_fold_p ptr ci cs >> peek ptr- s <- peekCAString cs+ s <- packCString 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)@@ -87,16 +89,16 @@ -- | Constrained partition function -ffiCoPartitionConstrained :: Int -> String -> String -> IO (CofoldF,String,A.Array (Int,Int) Double)+ffiCoPartitionConstrained :: Int -> ByteString -> ByteString -> IO (CofoldF,ByteString,A.Array (Int,Int) Double) ffiCoPartitionConstrained cutpoint sq st =- withCAString sq $ \csq ->- withCAString st $ \cst ->+ useAsCString sq $ \csq ->+ useAsCString st $ \cst -> alloca $ \ptr -> do setCutPoint cutpoint- let n = length sq+ let n = BS.length sq let z = n * (n+1) `div` 2 +1 eF <- co_pf_fold_constrained_p ptr csq cst 1 >> peek ptr- s <- peekCAString cst+ s <- packCString cst 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)
BioInf/ViennaRNA/Bindings/FFI/Duplex.chs view
@@ -6,6 +6,7 @@ import Control.Applicative import Control.Monad+import Data.ByteString.Char8 import Foreign.C.String import Foreign.C.Types import Foreign.Marshal.Alloc@@ -29,7 +30,7 @@ { i :: {-# UNPACK #-} !Int , j :: {-# UNPACK #-} !Int , end :: {-# UNPACK #-} !Int- , structure :: !String+ , structure :: !ByteString , energy :: {-# UNPACK #-} !Double , energyBacktrack :: {-# UNPACK #-} !Double , openingBacktrackX :: {-# UNPACK #-} !Double@@ -52,7 +53,7 @@ <$> liftM fromIntegral ({# get duplexT->i #} p) <*> liftM fromIntegral ({# get duplexT->j #} p) <*> liftM fromIntegral ({# get duplexT->end #} p)- <*> (peekCAString =<< ({# get duplexT->structure #} p))+ <*> (packCString =<< ({# get duplexT->structure #} p)) <*> liftM realToFrac ({# get duplexT->energy #} p) <*> liftM realToFrac ({# get duplexT->energy_backtrack #} p) <*> liftM realToFrac ({# get duplexT->opening_backtrack_x #} p)@@ -66,10 +67,10 @@ <*> liftM fromIntegral ({# get duplexT->qb #} p) <*> liftM fromIntegral ({# get duplexT->qe #} p) -ffiDuplexFold :: String -> String -> IO Duplex+ffiDuplexFold :: ByteString -> ByteString -> IO Duplex ffiDuplexFold l r =- withCAString l $ \cl ->- withCAString r $ \cr ->+ useAsCString l $ \cl ->+ useAsCString r $ \cr -> alloca $ \ptr -> do d <- duplexfold_p ptr cl cr >> peek ptr return d
BioInf/ViennaRNA/Bindings/FFI/Fold.chs view
@@ -1,6 +1,7 @@ module BioInf.ViennaRNA.Bindings.FFI.Fold where +import Data.ByteString.Char8 as BS import Foreign.C.String import Foreign.C.Types import Foreign.Marshal.Alloc@@ -14,50 +15,50 @@ #include "ViennaRNA/fold.h" -ffiFold :: String -> IO (Double,String)-ffiFold inp = withCAString inp $ \cinp ->- withCAString inp $ \struc -> do- e <- {#call fold #} cinp struc- s <- peekCAString struc+ffiFold :: ByteString -> IO (Double,ByteString)+ffiFold inp = useAsCString inp $ \cinp ->+ useAsCString inp $ \struc -> do+ e <- if BS.null inp then return 0 else {#call fold #} cinp struc+ s <- packCString struc return (cf2d e, s) -ffiEnergyOfStructure :: String -> String -> Int -> IO Double+ffiEnergyOfStructure :: ByteString -> ByteString -> Int -> IO Double ffiEnergyOfStructure inp struc verb =- withCAString inp $ \i ->- withCAString struc $ \s ->+ useAsCString inp $ \i ->+ useAsCString struc $ \s -> setCutPoint (-1) >> {#call energy_of_structure #} i s (fromIntegral verb :: CInt) >>= (return . cf2d) -ffiEnergyOfCircStructure :: String -> String -> Int -> IO Double+ffiEnergyOfCircStructure :: ByteString -> ByteString -> Int -> IO Double ffiEnergyOfCircStructure inp struc verb =- withCAString inp $ \i ->- withCAString struc $ \s ->+ useAsCString inp $ \i ->+ useAsCString struc $ \s -> setCutPoint (-1) >> {#call energy_of_circ_structure #} i s (fromIntegral verb :: CInt) >>= (return . cf2d) -ffiCircFold :: String -> IO (Double,String)-ffiCircFold inp = withCAString inp $ \cinp ->- withCAString inp $ \struc -> do+ffiCircFold :: ByteString -> IO (Double,ByteString)+ffiCircFold inp = useAsCString inp $ \cinp ->+ useAsCString inp $ \struc -> do e <- {#call circfold #} cinp struc- s <- peekCAString struc+ s <- packCString struc return (cf2d e, s) -ffiFoldTemp :: Double -> String -> IO (Double,String)+ffiFoldTemp :: Double -> ByteString -> IO (Double,ByteString) ffiFoldTemp t inp =- withCAString inp $ \cinp ->- withCAString inp $ \struc -> do+ useAsCString inp $ \cinp ->+ useAsCString inp $ \struc -> do e <- fold_temp_p (realToFrac t) cinp struc- s <- peekCAString struc+ s <- packCString struc return (cf2d e, s) -ffiEnergyOfStructureTemp :: Double -> String -> String -> Int -> IO Double+ffiEnergyOfStructureTemp :: Double -> ByteString -> ByteString -> Int -> IO Double ffiEnergyOfStructureTemp t inp struc verb =- withCAString inp $ \i ->- withCAString struc $ \s ->+ useAsCString inp $ \i ->+ useAsCString struc $ \s -> setCutPoint (-1) >> eos_temp_p (realToFrac t) i s (fromIntegral verb :: CInt) >>= (return . cf2d)
BioInf/ViennaRNA/Bindings/FFI/PartFunc.chs view
@@ -6,6 +6,8 @@ , ffi_pf_circ_fold_constrained ) where +import Data.ByteString.Char8 (ByteString, packCString, useAsCString)+import qualified Data.ByteString.Char8 as BS import Foreign.C.String import Foreign.C.Types import Foreign.Marshal.Alloc@@ -21,53 +23,53 @@ #include "ViennaRNA/part_func.h" -ffi_pf_fold :: String -> IO (Double,String,A.Array (Int,Int) Double)+ffi_pf_fold :: ByteString -> IO (Double,ByteString,A.Array (Int,Int) Double) ffi_pf_fold i =- withCAString i $ \ci ->- withCAString i $ \cs -> do- let n = length i+ useAsCString i $ \ci ->+ useAsCString i $ \cs -> do+ let n = BS.length i let z = n * (n+1) `div` 2 +1 e <- {#call ffiwrap_pf_fold_constrained #} ci cs 0- s <- peekCAString cs+ s <- packCString cs bp <- {#call export_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 (cf2d e, s, ar) -ffi_pf_circ_fold :: String -> IO (Double,String,A.Array (Int,Int) Double)+ffi_pf_circ_fold :: ByteString -> IO (Double,ByteString,A.Array (Int,Int) Double) ffi_pf_circ_fold i =- withCAString i $ \ci -> do- withCAString i $ \cs -> do- let n = length i+ useAsCString i $ \ci -> do+ useAsCString i $ \cs -> do+ let n = BS.length i let z = n * (n+1) `div` 2 +1 e <- {#call pf_circ_fold #} ci cs- s <- peekCAString cs+ s <- packCString cs bp <- {#call export_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 (cf2d e, s, ar) -ffi_pf_fold_constrained :: String -> String -> IO (Double,String,A.Array (Int,Int) Double)+ffi_pf_fold_constrained :: ByteString -> ByteString -> IO (Double,ByteString,A.Array (Int,Int) Double) ffi_pf_fold_constrained i s =- withCAString i $ \ci ->- withCAString s $ \cs -> do- let n = length i+ useAsCString i $ \ci ->+ useAsCString s $ \cs -> do+ let n = BS.length i let z = n * (n+1) `div` 2 +1 e <- {#call ffiwrap_pf_fold_constrained #} ci cs 1- s <- peekCAString cs+ s <- packCString cs bp <- {#call export_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 (cf2d e, s, ar) -ffi_pf_circ_fold_constrained :: String -> String -> IO (Double,String,A.Array (Int,Int) Double)+ffi_pf_circ_fold_constrained :: ByteString -> ByteString -> IO (Double,ByteString,A.Array (Int,Int) Double) ffi_pf_circ_fold_constrained i s =- withCAString i $ \ci -> do- withCAString i $ \cs -> do- let n = length i+ useAsCString i $ \ci -> do+ useAsCString i $ \cs -> do+ let n = BS.length i let z = n * (n+1) `div` 2 +1 e <- {#call ffiwrap_pf_circ_fold_constrained #} ci cs 1- s <- peekCAString cs+ s <- packCString cs bp <- {#call export_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)
C/ffiwrap_centroid.c view
@@ -13,9 +13,9 @@ #include "ViennaRNA/alifold.h" #include "ViennaRNA/fold.h" -double ffiwrap_centroid_temp (double temp, const char *sequence, char *structure)+double ffiwrap_centroid_temp (double temp, const char *sequence, char *structure, double *dist) {- double dist, e;+ double e; char* cent; char* pf_struc; double cent_en;@@ -29,7 +29,7 @@ md.temperature = temp; vc = vrna_fold_compound(sequence, &md, 0); e = vrna_pf(vc, pf_struc);- cent = vrna_centroid(vc, &dist);+ cent = vrna_centroid(vc, dist); cent_en = vrna_eval_structure(vc, (const char*) cent); strcpy (structure, cent); free (cent);
ViennaRNA-bindings.cabal view
@@ -1,5 +1,5 @@ name: ViennaRNA-bindings-version: 0.233.1.2+version: 0.233.2.0 maintainer: choener@tbi.univie.ac.at homepage: https://github.com/choener/ViennaRNA-bindings bug-reports: https://github.com/choener/ViennaRNA-bindings/issues@@ -10,7 +10,7 @@ category: Bioinformatics, Bindings, FFI build-type: Simple cabal-version: >=1.10-tested-with: GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.1, GHC == 8.0.2+tested-with: GHC == 8.0.2, GHC == 8.2.1 synopsis: ViennaRNA v2 bindings description: Bindings to the ViennaRNA package, version 2.3.3. .@@ -58,11 +58,14 @@ BioInf.ViennaRNA.Bindings.FFI.Utils build-depends: base == 4.* , array+ , bytestring build-tools: c2hs extra-libraries: default-language: Haskell2010+ ghc-options:+ -O2 default-extensions: CPP , ForeignFunctionInterface , NondecreasingIndentation@@ -136,6 +139,7 @@ , TemplateHaskell build-depends: base , array+ , bytestring , QuickCheck , tasty >= 0.11 , tasty-hunit >= 0.9
changelog.md view
@@ -1,3 +1,8 @@+0.233.2.0+---------++- use ByteString.Char8 instead of String+ 0.233.1.2 - included C/$ALL.c C/config.h in distribution
tests/properties.hs view
@@ -1,6 +1,13 @@+{-# Language OverloadedStrings #-} +-- |+--+-- NOTE Remember that all calculations are done via @RNAfold -p --noLP@.+ module Main where +import Data.ByteString.Char8+ import Test.Tasty import Test.Tasty.HUnit import Test.Tasty.Silver as S@@ -102,15 +109,18 @@ case_centroidTemp_37_001 :: Assertion case_centroidTemp_37_001 = do- (e,s) <- V.centroidTemp 37 "cccaaaggg"+ (e,s,d) <- V.centroidTemp 37 "cccaaaggg" assertBool "energy" $ e =~ (-1.2) assertBool "structure" $ s == "(((...)))"+ assertBool "avg distance" $ d =~ 1.06 case_centroidTemp_37_003 :: Assertion case_centroidTemp_37_003 = do- (e,s) <- V.centroidTemp 37 "GGGCUAUUAGCUCAGUUGGUUAGAGCGCACCCCUGAUAAGGGUGAGGUCGCUGAUUCGAAUUCAGCAUAGCCCA"+ (e,s,d) <- V.centroidTemp 37 "GGGCUAUUAGCUCAGUUGGUUAGAGCGCACCCCUGAUAAGGGUGAGGUCGCUGAUUCGAAUUCAGCAUAGCCCA" assertBool "energy" $ e =~ (-28.10) assertBool "structure" $ s == "(((((((..((((.........)))).(((((.(....)))))).....(((((.......))))))))))))."+ -- using @--noLP@+ assertBool "avg distance" $ d =~ 11.86