diversity 0.8.0.2 → 0.8.1.0
raw patch · 3 files changed
+43/−14 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Math.Diversity.Diversity: diversityOfMapWithContribution :: (Ord a) => Double -> Map a Int -> (Double, Map a Double)
Files
- diversity.cabal +2/−2
- src/src-exec/Main.hs +13/−11
- src/src-lib/Math/Diversity/Diversity.hs +28/−1
diversity.cabal view
@@ -2,14 +2,14 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: diversity-version: 0.8.0.2+version: 0.8.1.0 synopsis: Quantify the diversity of a population description: Find the diversity of a collection of entities, mainly for use with fasta sequences. homepage: https://github.com/GregorySchwartz/diversity license: GPL-3 license-file: LICENSE author: Gregory W. Schwartz-maintainer: gregory.schwartz@drexel.edu+maintainer: gsch@mail.med.upenn.edu -- copyright: category: Bioinformatics build-type: Simple
src/src-exec/Main.hs view
@@ -27,7 +27,7 @@ data Options = Options { inputLabel :: String , inputOrder :: Double , inputWindow :: Int- , inputFasta :: String+ , inputFasta :: Maybe String , inputSampleField :: Int , inputCountField :: Int , inputSubsampling :: String@@ -59,21 +59,21 @@ <*> option auto ( long "input-order" <> short 'r'- <> metavar "[1]|INT"+ <> metavar "[1] | INT" <> value 1 <> help "The order of true diversity" ) <*> option auto ( long "input-window" <> short 'w'- <> metavar "[1]|INT"+ <> metavar "[1] | INT" <> value 1 <> help "The length of the sliding window for generating fragments" )- <*> strOption+ <*> optional ( strOption ( long "input-fasta" <> short 'i'- <> metavar "FILE"- <> value ""+ <> metavar "[Nothing] | FILE" <> help "The fasta file containing the germlines and clones" )+ ) <*> option auto ( long "input-sample-field" <> short 'S'@@ -166,7 +166,9 @@ ( long "std" <> short 't' <> help "Whether to output to stdout or to a file if no file is\- \ supplied" )+ \ supplied. Must still put some string in -O, -c, or -o\+ \ depending on which output is needed."+ ) <*> strOption ( long "output-rarefaction" <> short 'O'@@ -199,9 +201,9 @@ pipesPositionMap :: Options -> IO PositionMap pipesPositionMap opts = do- h <- if null . inputFasta $ opts- then return IO.stdin- else IO.openFile (inputFasta opts) IO.ReadMode+ h <- case inputFasta opts of+ Nothing -> return IO.stdin+ (Just x) -> IO.openFile x IO.ReadMode runEffect $ P.fold (Map.unionWith (Map.unionWith (+))) Map.empty id $ P.fromHandle h@@ -266,4 +268,4 @@ where opts = info (helper <*> options) ( fullDesc- <> progDesc "Quantify the diversity of a population" )+ <> progDesc "Quantify the diversity of a population." )
src/src-lib/Math/Diversity/Diversity.hs view
@@ -10,6 +10,7 @@ , richness , diversity , diversityOfMap+ , diversityOfMapWithContribution , chao1 , chao2 , chao1Var@@ -84,6 +85,33 @@ . Map.map ( \x -> p_i x * log (p_i x)) p_i x = fromIntegral x / fromIntegral (Map.foldl' (+) 0 sample) +-- | Returns the diversity of a map of the species and how many times it+-- appears, along with the contribution of each species.+diversityOfMapWithContribution+ :: (Ord a)+ => Double -> Map.Map a Int -> (Double, Map.Map a Double)+diversityOfMapWithContribution order sample+ | Map.null sample = (0, Map.empty)+ | order == 1 = (exp . h $ sample, contrib)+ | otherwise = ( ( Map.foldl' (+) 0+ . Map.map ((** order) . p_i)+ $ sample+ )+ ** pow+ , contrib+ )+ where+ contrib = Map.map+ ( (/ (fromIntegral $ Map.foldl' (+) 0 sample))+ . fromIntegral+ )+ sample+ pow = 1 / (1 - order)+ h = negate+ . Map.foldl' (+) 0+ . Map.map ( \x -> p_i x * log (p_i x))+ p_i x = fromIntegral x / fromIntegral (Map.foldl' (+) 0 sample)+ -- | Returns the richness of the observed data richness :: (Ord a, Ord b) => Map.Map (a, b) c -> Int richness = Map.size . Map.mapKeys snd@@ -323,4 +351,3 @@ (fromIntegral x) 1 (fromIntegral x)-