diversity 0.4.0.0 → 0.4.0.1
raw patch · 2 files changed
+15/−4 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
diversity.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: diversity-version: 0.4.0.0+version: 0.4.0.1 synopsis: Return the diversity at each position for all sequences in a fasta file description: Find the diversity of a collection of entities, mainly for use with fasta sequences. Produces a binary which works on fasta files to find the diversity of any order and rarefaction curves for a sliding window across all positions in the sequences. To analyze just a collection of entities, just use the whole sequences and list flag. homepage: https://github.com/GregorySchwartz/diversity
src/src-lib/Math/Diversity/Diversity.hs view
@@ -23,6 +23,16 @@ hamming :: String -> String -> Int hamming xs ys = length $ filter not $ zipWith (==) xs ys +-- | Fast product division+productDivision :: Double -> [Integer] -> [Integer] -> Double+productDivision acc [] [] = acc+productDivision acc [] (y:ys) = (acc / fromInteger y)+ * productDivision acc [] ys+productDivision acc (x:xs) [] = acc * fromInteger x * productDivision acc xs []+productDivision acc (x:xs) (y:ys)+ | x == y = productDivision acc xs ys+ | otherwise = (fromInteger x / fromInteger y) * productDivision acc xs ys+ -- | Returns the diversity of a list of things diversity :: (Ord b) => Double -> [b] -> Double diversity order sample@@ -39,9 +49,10 @@ -- | Binomial for small or large numbers (slow but works for big numbers, -- fast but works for small numbers) specialBinomial :: Bool -> Integer -> Integer -> Integer -> Double-specialBinomial False n_total g n = fromRational- $ product [(n_total - g - n + 1)..(n_total - g)]- % product [(n_total - n + 1)..n_total]+specialBinomial False n_total g n = productDivision 1 num den+ where+ num = [(n_total - g - n + 1)..(n_total - g)]+ den = [(n_total - n + 1)..n_total] specialBinomial True n_total g n = choose (fromIntegral n_total - fromIntegral g) (fromIntegral n)