packages feed

BiobaseTrainingData 0.1.0.0 → 0.1.1.0

raw patch · 4 files changed

+98/−14 lines, 4 filesdep +either-unwrapdep +vectorPVP ok

version bump matches the API change (PVP)

Dependencies added: either-unwrap, vector

API changes (from Hackage documentation)

+ Biobase.TrainingData.Filter: fErrorCheck :: TDmanip -> TDmanip
+ Biobase.TrainingData.Filter: fMinRelPairs :: Maybe Double -> TDmanip -> TDmanip
+ Biobase.TrainingData.Manip: type TDmanip = Either TrainingData TrainingData

Files

+ Biobase/TrainingData/Filter.hs view
@@ -0,0 +1,40 @@+{-# LANGUAGE RecordWildCards #-}++-- | Prospective 'TrainingData' elements need to be filtered as there are a+-- number of entries which do not provide good training.++module Biobase.TrainingData.Filter where++import Data.List+import qualified Data.Vector.Unboxed as VU++import Biobase.TrainingData+import Biobase.TrainingData.Manip++++-- | Filter out elements containing not enough base pairs (in relative terms)++fMinRelPairs :: Maybe Double -> TDmanip -> TDmanip+fMinRelPairs Nothing x    = x+fMinRelPairs _ l@(Left _) = l+fMinRelPairs (Just rel) r@(Right td@(TrainingData{..}))+  | rel > numps * 2 / lenpri = Left td+  | otherwise = r+  where+    lenpri = genericLength primary+    numps  = genericLength secondary++-- | Error-checking filter.++fErrorCheck :: TDmanip -> TDmanip+fErrorCheck l@(Left _) = l+fErrorCheck r@(Right td@(TrainingData{..}))+  | any (<0) ixs = Left td -- that one is really strange+  | any (>=l) ixs = Left td -- indices out of bounds+  | any ((=='&') . (v VU.!)) ixs = Left td -- index pointing to intramolecular symbol+  | otherwise = r+  where+    ixs = concatMap (\((i,j),_) -> [i,j]) secondary+    l = length primary+    v = VU.fromList primary
+ Biobase/TrainingData/Manip.hs view
@@ -0,0 +1,19 @@+{-# LANGUAGE RecordWildCards #-}++module Biobase.TrainingData.Manip where++import Biobase.Secondary.PseudoKnots++import Biobase.TrainingData++++-- | Left elements are filtered out, Right elements are kept.++type TDmanip = Either TrainingData TrainingData++-- | Remove pseudoknots from 'TrainingData'.++removePK rpk td@TrainingData{..}+  | not rpk   = td+  | otherwise = td{secondary = removeByCounting secondary}
BiobaseTrainingData.cabal view
@@ -1,5 +1,5 @@ name:           BiobaseTrainingData-version:        0.1.0.0+version:        0.1.1.0 author:         Christian Hoener zu Siederdissen maintainer:     choener@tbi.univie.ac.at homepage:       http://www.tbi.univie.ac.at/~choener/@@ -24,19 +24,25 @@                 .                 Note that several features are designed around /extended/ RNA                 secondary structures.+                .+                Now with some filtering and manipulation options.  library   build-depends:     base >3 && <5,     bytestring,+    either-unwrap,     iteratee,+    vector,     BiobaseDotP,     BiobaseFR3D,     BiobaseXNA >= 0.5.0.1    exposed-modules:     Biobase.TrainingData+    Biobase.TrainingData.Filter     Biobase.TrainingData.Import+    Biobase.TrainingData.Manip    ghc-options:     -O2
MkTrainingData.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE BangPatterns #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE DeriveDataTypeable #-}@@ -6,33 +7,44 @@  import System.Console.CmdArgs import Data.List as L+import Data.Either+import Data.Either.Unwrap+import Control.Monad (when)+import Data.Maybe (isJust, fromJust) -import Biobase.Secondary.PseudoKnots import qualified Biobase.FR3D as F import qualified Biobase.FR3D.Import as F import qualified Biobase.RNAstrand as R import qualified Biobase.RNAstrand.Import as R  import Biobase.TrainingData+import Biobase.TrainingData.Filter+import Biobase.TrainingData.Manip    data Options   -- | FR3D parses all files within a directory and all sub-directories.   = FR3D-    { removepk :: Bool-    , fromdir  :: FilePath+    { removepk  :: Bool+    , fromdir   :: FilePath+    , errorFile :: Maybe FilePath+    , relativePairs :: Maybe Double     }   -- | RNAstrand reads from one file   | RNAstrand-    { removepk :: Bool-    , fromfile :: FilePath+    { removepk  :: Bool+    , fromfile  :: FilePath+    , errorFile :: Maybe FilePath+    , relativePairs :: Maybe Double     }   deriving (Show,Data,Typeable)  fr3d = FR3D-  { removepk = False &= help "removes pseudoknots from the entry using a heuristic algorithm"-  , fromdir  = "./"  &= args+  { removepk  = False &= help "removes pseudoknots from the entry using a heuristic algorithm"+  , fromdir   = "./"  &= args+  , errorFile = def   &= help "put TrainingData which falls through the filter in this file (default: disabled)"+  , relativePairs = def &= help "Keep only TrainingData with that fraction of basepairs."   }  rnastrand = RNAstrand@@ -48,7 +60,19 @@  run FR3D{..} = do   xs <- F.fromDir fromdir-  mapM_ print $ map (removePK removepk . mkTrainingData . removeBIF . F.linearizeFR3D) xs+  let (ys :: [TDmanip]) = id+          . map (fErrorCheck)                 -- basic error-checking+          . map (fMinRelPairs relativePairs)  -- filtering out trainingdata with too few pairs+          . map (fmap (removePK removepk))    -- remove pseudoknots from trainingdata+          . map (fmap (mkTrainingData . removeBIF . F.linearizeFR3D)) -- basic conversions+          . map Right+          $ xs+  let (ls,rs) = partition isLeft ys+  when (isJust errorFile) $ do+    writeFile (fromJust errorFile) . unlines . map (show . fromLeft) $ ls+  mapM_ (print . fromRight) rs+  return ()+  -- mapM_ print $ map (removePK removepk . mkTrainingData . removeBIF . F.linearizeFR3D) xs  -- | RNAstrand importer @@ -65,8 +89,3 @@     | x == "bif" = False     | otherwise  = True --- | Remove pseudoknots--removePK rpk td@TrainingData{..}-  | not rpk   = td-  | otherwise = td{secondary = removeByCounting secondary}