BiobaseXNA 0.5.1.0 → 0.5.2.0
raw patch · 2 files changed
+77/−3 lines, 2 filesdep +PrimitiveArrayPVP ok
version bump matches the API change (PVP)
Dependencies added: PrimitiveArray
API changes (from Hackage documentation)
+ Biobase.Secondary.Constraint: bonusTable :: Double -> Double -> Constraint -> PrimArray (Int, Int) Double
Files
- Biobase/Secondary/Constraint.hs +70/−1
- BiobaseXNA.cabal +7/−2
Biobase/Secondary/Constraint.hs view
@@ -6,11 +6,15 @@ module Biobase.Secondary.Constraint where +import Data.Char (toLower) import Data.Primitive.Types import qualified Data.Vector.Generic as VG import qualified Data.Vector.Generic.Mutable as VGM import qualified Data.Vector.Unboxed as VU +import Data.PrimitiveArray+import Data.PrimitiveArray.Ix+ import Biobase.Secondary.Diagrams @@ -32,12 +36,77 @@ nobonusCC = VU.fromList ".x" {-# NOINLINE nobonusCC #-} +-- | Given a 'Constraint', create an NxN matrix with bonus energies. These+-- energies can be included in all pair-creating functions and will disallow or+-- strongly favor certain pairings, while others will receive neither bonus nor+-- malus.+--+-- In case, a pair (i,j) is annotated as both, bonus- and malus-receiving, it+-- will be set to receive a malus. This can happen, if something like "<" would+-- give a bonus, but "x" gives a malus (and other cases).+--+-- TODO and again, we should parametrize over "Energy", "Score", etc (that is,+-- Prim a) +bonusTable :: Double -> Double -> Constraint -> PrimArray (Int,Int) Double+bonusTable bonus malus (Constraint constraint) = arr where+ arr = fromAssocs (0,0) (n,n) 0 $ bonusBr ++ bonusAn ++ bonusBa ++ malusBr ++ malusAn ++ malusX+ n = VU.length constraint -1+ infixl 1 `xor`+ xor a b = a && not b || not a && b+ -- "()" bonus energies+ bonusBr = [ ((i,j),bonus)+ | (i,('(',j)) <- zip [0..] $ VU.toList constraint+ ]+ malusBr = [ ((i,j),malus)+ | i <- [0..n]+ , j <- [i..n]+ , let bi = constraint VU.! i+ , let bj = constraint VU.! j+ , fst bi == '(' && snd bi /= j || fst bj == ')' && snd bj /= i+ ]+ bonusAn = [ ((i,j),bonus)+ | i<-[0..n]+ , fst (constraint VU.! i) == '<'+ , j<-[i+1..n]+ ] +++ [ ((i,j),bonus)+ | j<-[0..n]+ , fst (constraint VU.! j) == '>'+ , i<-[0..j-1]+ ]+ malusAn = [ ((i,j),malus)+ | i<-[0..n]+ , j<-[i+1..n]+ , fst (constraint VU.! j) == '<'+ ] +++ [ ((i,j),malus)+ | i<-[0..n]+ , j<-[i+1..n]+ , fst (constraint VU.! i) == '>'+ ]+ bonusBa = [ ((i,j),bonus)+ | i<-[0..n]+ , j<-[i+1..n]+ , fst (constraint VU.! i) == '|' || fst (constraint VU.! j) == '|'+ ]+ malusX = [ ((i,j),malus)+ | i<-[0..n]+ , j<-[i+1..n]+ , fst (constraint VU.! i) == 'x' || fst (constraint VU.! j) == 'x'+ ] +{-+testC = putStrLn $ f as where+ f [] = ""+ f xs = show (take 9 xs) ++ "\n" ++ f (drop 9 xs)+ as = toList $ bonusTable (1) 2 (mkConstraint "(<<..x|>)")+-}+ -- * Instances instance MkConstraint String where- mkConstraint xs = mkConstraint . VU.fromList $ xs+ mkConstraint xs = mkConstraint . VU.fromList . map toLower $ xs instance MkConstraint (VU.Vector Char) where mkConstraint cs = Constraint $ VU.zip cs ks where
BiobaseXNA.cabal view
@@ -1,5 +1,5 @@ name: BiobaseXNA-version: 0.5.1.0+version: 0.5.2.0 author: Christian Hoener zu Siederdissen maintainer: choener@tbi.univie.ac.at homepage: http://www.tbi.univie.ac.at/~choener/@@ -17,6 +17,10 @@ efficient encodings for short sequences, as required by RNA folding tools. Extended RNA secondary structures can be represented as well.+ .+ Changes since 0.5.1.0+ .+ * bonusTable for constrained folding extra-source-files: @@ -28,7 +32,8 @@ text, tuple, vector >=0.7 && <0.8,- vector-read-instances+ vector-read-instances,+ PrimitiveArray exposed-modules: Biobase.Primary