packages feed

rank-product 0.1.0.0 → 0.1.0.1

raw patch · 5 files changed

+132/−132 lines, 5 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- RankProduct: prerankProduct :: [RankEntity] -> [RankProductEntity]
- RankProduct: rankList :: (Ord a) => [a] -> [Int]
- RankProduct: rankProduct :: [Entity] -> [RankProductEntity]
- RankProduct: rankProductPermutation :: Permutations -> [Entity] -> IO [(PValue, RankProductEntity)]
- Types: Entity :: [Double] -> Entity
- Types: PValue :: Double -> PValue
- Types: Permutations :: Int -> Permutations
- Types: RankEntity :: [Int] -> RankEntity
- Types: RankProductEntity :: Double -> RankProductEntity
- Types: [unEntity] :: Entity -> [Double]
- Types: [unPValue] :: PValue -> Double
- Types: [unRankEntity] :: RankEntity -> [Int]
- Types: [unRankProductEntity] :: RankProductEntity -> Double
- Types: instance GHC.Show.Show Types.Entity
- Types: instance GHC.Show.Show Types.PValue
- Types: instance GHC.Show.Show Types.RankProductEntity
- Types: newtype Entity
- Types: newtype PValue
- Types: newtype Permutations
- Types: newtype RankEntity
- Types: newtype RankProductEntity
+ Statistics.RankProduct: prerankProduct :: [RankEntity] -> [RankProductEntity]
+ Statistics.RankProduct: rankList :: (Ord a) => [a] -> [Int]
+ Statistics.RankProduct: rankProduct :: [Entity] -> [RankProductEntity]
+ Statistics.RankProduct: rankProductPermutation :: Permutations -> [Entity] -> IO [(PValue, RankProductEntity)]
+ Statistics.Types: Entity :: [Double] -> Entity
+ Statistics.Types: PValue :: Double -> PValue
+ Statistics.Types: Permutations :: Int -> Permutations
+ Statistics.Types: RankEntity :: [Int] -> RankEntity
+ Statistics.Types: RankProductEntity :: Double -> RankProductEntity
+ Statistics.Types: [unEntity] :: Entity -> [Double]
+ Statistics.Types: [unPValue] :: PValue -> Double
+ Statistics.Types: [unRankEntity] :: RankEntity -> [Int]
+ Statistics.Types: [unRankProductEntity] :: RankProductEntity -> Double
+ Statistics.Types: instance GHC.Show.Show Statistics.Types.Entity
+ Statistics.Types: instance GHC.Show.Show Statistics.Types.PValue
+ Statistics.Types: instance GHC.Show.Show Statistics.Types.RankProductEntity
+ Statistics.Types: newtype Entity
+ Statistics.Types: newtype PValue
+ Statistics.Types: newtype Permutations
+ Statistics.Types: newtype RankEntity
+ Statistics.Types: newtype RankProductEntity

Files

rank-product.cabal view
@@ -1,5 +1,5 @@ name:                rank-product-version:             0.1.0.0+version:             0.1.0.1 synopsis:            Find the rank product of a data set. description:         Find the rank product of a data set and get the p-value from a permutation test. homepage:            http://github.com/GregorySchwartz/rank-product#readme@@ -15,8 +15,8 @@  library   hs-source-dirs:      src-  exposed-modules:     Types-                     , RankProduct+  exposed-modules:     Statistics.Types+                     , Statistics.RankProduct   build-depends:       base >= 4.7 && < 5                      , random-fu   ghc-options:         -O2
− src/RankProduct.hs
@@ -1,104 +0,0 @@-{- RankProduct-Gregory W. Schwartz--Collects the functions pertaining to finding the rank product of a data set as-well as the associated p-value.--}--{-# LANGUAGE BangPatterns #-}--module RankProduct-    ( rankList-    , rankProduct-    , prerankProduct-    , rankProductPermutation-    ) where---- Standard-import Data.Function (on)-import Data.List-import Data.Random---- Cabal---- Local-import Types---- | Rank transform a list.-rankList :: (Ord a) => [a] -> [Int]-rankList = fmap fst-         . sortBy (compare `on` (fst . snd))-         . zip [1..]-         . sortBy (compare `on` snd)-         . zip [1..]---- | Get the rank product of a list of Entity.-rankProduct :: [Entity] -> [RankProductEntity]-rankProduct xs =-    fmap (RankProductEntity . (** (1 / genericLength xs)) . fromIntegral . product)-        . transpose-        . fmap rankList-        . transpose-        . fmap unEntity-        $ xs---- | Get the rank product of a pre-ranked data set [[ranked values for a gene in--- different data sets]].-prerankProduct :: [RankEntity] -> [RankProductEntity]-prerankProduct xs =-    fmap-        ( RankProductEntity-        . (** (1 / genericLength xs))-        . fromIntegral-        . product-        . unRankEntity-        )-        xs---- | Get a random permutation of the RankEntity's.-permuteEntities :: [RankEntity] -> IO [RankEntity]-permuteEntities = fmap (fmap RankEntity . transpose)-                . mapM (sample . shuffle)-                . transpose-                . fmap unRankEntity---- | Convert Bool to a number.-boolToNum :: (Num a) => Bool -> a-boolToNum False = 0-boolToNum True  = 1---- | Get the rank product of a list of Entity as well as the permutation--- p-value.-rankProductPermutation :: Permutations-                       -> [Entity]-                       -> IO [(PValue, RankProductEntity)]-rankProductPermutation (Permutations permutations) entities = do-    let ranked  = fmap RankEntity-                . transpose-                . fmap rankList-                . transpose-                . fmap unEntity-                $ entities-        obs     = prerankProduct ranked-        expTest (RankProductEntity o) = (<= o) . unRankProductEntity--    -- Lotsa space version.-    -- vals <- mapM (const (shuffleCosine xs ys)) . V.replicate nPerm $ 0-    -- let exps = V.filter (\x -> abs x >= abs obs) vals--    let successes :: [Int] -> Int -> IO [Int]-        successes !acc 0  = return acc-        successes !acc !n = do-            shuffledEntities <- permuteEntities ranked--            let res = prerankProduct shuffledEntities-                success = zipWith (\o -> boolToNum . expTest o) obs res--            successes (zipWith (+) acc success) (n - 1)--    exp <- successes (take (genericLength entities) [0,0..]) permutations--    let pVals =-            fmap (\e -> PValue $ (fromIntegral e) / (fromIntegral permutations)) exp--    return . zip pVals $ obs
+ src/Statistics/RankProduct.hs view
@@ -0,0 +1,104 @@+{- RankProduct+Gregory W. Schwartz++Collects the functions pertaining to finding the rank product of a data set as+well as the associated p-value.+-}++{-# LANGUAGE BangPatterns #-}++module Statistics.RankProduct+    ( rankList+    , rankProduct+    , prerankProduct+    , rankProductPermutation+    ) where++-- Standard+import Data.Function (on)+import Data.List+import Data.Random++-- Cabal++-- Local+import Statistics.Types++-- | Rank transform a list.+rankList :: (Ord a) => [a] -> [Int]+rankList = fmap fst+         . sortBy (compare `on` (fst . snd))+         . zip [1..]+         . sortBy (compare `on` snd)+         . zip [1..]++-- | Get the rank product of a list of Entity.+rankProduct :: [Entity] -> [RankProductEntity]+rankProduct xs =+    fmap (RankProductEntity . (** (1 / genericLength xs)) . fromIntegral . product)+        . transpose+        . fmap rankList+        . transpose+        . fmap unEntity+        $ xs++-- | Get the rank product of a pre-ranked data set [[ranked values for a gene in+-- different data sets]].+prerankProduct :: [RankEntity] -> [RankProductEntity]+prerankProduct xs =+    fmap+        ( RankProductEntity+        . (** (1 / genericLength xs))+        . fromIntegral+        . product+        . unRankEntity+        )+        xs++-- | Get a random permutation of the RankEntity's.+permuteEntities :: [RankEntity] -> IO [RankEntity]+permuteEntities = fmap (fmap RankEntity . transpose)+                . mapM (sample . shuffle)+                . transpose+                . fmap unRankEntity++-- | Convert Bool to a number.+boolToNum :: (Num a) => Bool -> a+boolToNum False = 0+boolToNum True  = 1++-- | Get the rank product of a list of Entity as well as the permutation+-- p-value.+rankProductPermutation :: Permutations+                       -> [Entity]+                       -> IO [(PValue, RankProductEntity)]+rankProductPermutation (Permutations permutations) entities = do+    let ranked  = fmap RankEntity+                . transpose+                . fmap rankList+                . transpose+                . fmap unEntity+                $ entities+        obs     = prerankProduct ranked+        expTest (RankProductEntity o) = (<= o) . unRankProductEntity++    -- Lotsa space version.+    -- vals <- mapM (const (shuffleCosine xs ys)) . V.replicate nPerm $ 0+    -- let exps = V.filter (\x -> abs x >= abs obs) vals++    let successes :: [Int] -> Int -> IO [Int]+        successes !acc 0  = return acc+        successes !acc !n = do+            shuffledEntities <- permuteEntities ranked++            let res = prerankProduct shuffledEntities+                success = zipWith (\o -> boolToNum . expTest o) obs res++            successes (zipWith (+) acc success) (n - 1)++    exp <- successes (take (genericLength entities) [0,0..]) permutations++    let pVals =+            fmap (\e -> PValue $ (fromIntegral e) / (fromIntegral permutations)) exp++    return . zip pVals $ obs
+ src/Statistics/Types.hs view
@@ -0,0 +1,25 @@+{- Types+Gregory W. Schwartz++Collects the types used in the program+-}++module Statistics.Types where++-- Standard++-- Cabal++-- Local+++-- Basic+newtype Permutations      = Permutations Int+newtype Entity            = Entity { unEntity :: [Double] } deriving (Show)+newtype RankEntity        = RankEntity { unRankEntity :: [Int] }+newtype RankProductEntity = RankProductEntity+    { unRankProductEntity :: Double+    } deriving ((Show))+newtype PValue            = PValue { unPValue :: Double } deriving (Show)++-- Advanced
− src/Types.hs
@@ -1,25 +0,0 @@-{- Types-Gregory W. Schwartz--Collects the types used in the program--}--module Types where---- Standard---- Cabal---- Local----- Basic-newtype Permutations      = Permutations Int-newtype Entity            = Entity { unEntity :: [Double] } deriving (Show)-newtype RankEntity        = RankEntity { unRankEntity :: [Int] }-newtype RankProductEntity = RankProductEntity-    { unRankProductEntity :: Double-    } deriving ((Show))-newtype PValue            = PValue { unPValue :: Double } deriving (Show)---- Advanced