rank-product 0.2.1.1 → 0.2.2.0
raw patch · 4 files changed
+33/−11 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Statistics.Types: DefaultValue :: Double -> DefaultValue
+ Statistics.Types: newtype DefaultValue
- Statistics.Load: loadNamedEntities :: Vector (Map Text Text) -> [NamedEntity]
+ Statistics.Load: loadNamedEntities :: Maybe DefaultValue -> Vector (Map Text Text) -> [NamedEntity]
Files
- app/Main.hs +6/−2
- rank-product.cabal +1/−1
- src/Statistics/Load.hs +25/−8
- src/Statistics/Types.hs +1/−0
app/Main.hs view
@@ -31,13 +31,16 @@ <?> "([,] | CHAR) The delimiter of the CSV file. Format is name,replicate,value." , sortType :: Maybe Sort <?> "([Ascending] | Descending) Ascending ranks 1 as the lowest value while Descending ranks the highest value as 1."+ , defaultValue :: Maybe Double+ <?> "([Nothing] | DOUBLE) Default value of missing replicate rather than removing entity." } deriving (Generic) modifiers :: Modifiers modifiers = lispCaseModifiers { shortNameModifier = short } where- short x = firstLetter x+ short "defaultValue" = Just 'v'+ short x = firstLetter x instance ParseField Sort @@ -55,6 +58,7 @@ delim' = Delimiter . fromMaybe ',' . unHelpful . delimiter $ opts sortType' = fromMaybe Ascending . unHelpful . sortType $ opts+ defaultValue' = fmap DefaultValue . unHelpful . defaultValue $ opts decodeOpt = CSV.defaultDecodeOptions { CSV.decDelimiter = fromIntegral (ord . unDelimiter $ delim')@@ -64,7 +68,7 @@ fromIntegral (ord . unDelimiter $ delim') } - entities <- loadNamedEntities+ entities <- loadNamedEntities defaultValue' . either error snd . CSV.decodeByNameWith decodeOpt <$> B.getContents
rank-product.cabal view
@@ -1,5 +1,5 @@ name: rank-product-version: 0.2.1.1+version: 0.2.2.0 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
src/Statistics/Load.hs view
@@ -12,10 +12,11 @@ ) where -- Standard-import Data.List (sort)+import Data.List (sort, find) import qualified Data.Foldable as F import qualified Data.Map.Strict as Map import qualified Data.Sequence as Seq+import qualified Data.Set as Set import qualified Data.Text as T import qualified Data.Text.Read as T import qualified Data.Vector as V@@ -26,14 +27,18 @@ import Statistics.Types -- | Load entities from a list of rows.-loadNamedEntities :: V.Vector (Map.Map T.Text T.Text) -> [NamedEntity]-loadNamedEntities = fmap (uncurry NamedEntity)- . Map.toAscList- . Map.map (fmap snd . sort . F.toList)- . Map.fromListWith (Seq.><)- . fmap lookupInfo- . V.toList+loadNamedEntities ::+ Maybe DefaultValue -> V.Vector (Map.Map T.Text T.Text) -> [NamedEntity]+loadNamedEntities defVal rows =+ fmap (uncurry NamedEntity)+ . Map.toAscList+ . Map.map (fmap snd . supplyReplicates defVal allReplicates . F.toList)+ . Map.fromListWith (Seq.><)+ . fmap lookupInfo+ . V.toList+ $ rows where+ allReplicates = Set.fromList . fmap (lookupErr "replicate") . V.toList $ rows lookupErr x = Map.findWithDefault (error $ "Missing column: " <> show x) x lookupInfo m = ( Name $ lookupErr "name" m@@ -41,3 +46,15 @@ , either error fst . T.double $ lookupErr "value" m ) )++-- | Give a default value to missing replicates.+supplyReplicates :: Maybe DefaultValue+ -> Set.Set T.Text+ -> [(T.Text, Double)]+ -> [(T.Text, Double)]+supplyReplicates Nothing _ xs = sort xs+supplyReplicates (Just (DefaultValue defVal)) allReplicates xs =+ Map.toAscList . F.foldl' supply repMap . Set.toList $ allReplicates+ where+ supply m x = if Map.member x m then m else Map.insert x defVal m+ repMap = Map.fromList xs
src/Statistics/Types.hs view
@@ -20,6 +20,7 @@ newtype Delimiter = Delimiter { unDelimiter :: Char } deriving (Read, Show) newtype Name = Name { unName :: T.Text } deriving (Eq, Ord, Show) newtype Permutations = Permutations Int deriving (Show)+newtype DefaultValue = DefaultValue Double newtype Entity = Entity { unEntity :: [Double] } deriving (Show) newtype RankEntity = RankEntity { unRankEntity :: [Double] } deriving (Show) newtype RankProductEntity = RankProductEntity