module Math.Diversity.Print ( printDiversity
, printRarefaction
, printRarefactionCurve ) where
import Data.List
import qualified Data.Map as M
import Math.Diversity.Types
import Math.Diversity.Diversity
printDiversity :: Label -> Order -> Window -> PositionMap -> String
printDiversity label order window positionMap = header ++ body
where
header = "label,order,window,position,weight,diversity\n"
body = unlines
. map mapLine
. M.toAscList
$ positionMap
mapLine (p, xs) = intercalate "," . line p $ xs
line p xs = [ label
, show order
, show window
, show p
, show . length $ xs
, show . diversity order $ xs
]
printRarefaction :: Bool -> Label -> Window -> PositionMap -> String
printRarefaction fastBin label window positionMap = header ++ body
where
header = "label,window,position,weight,percent_above\n"
body = unlines
. map mapLine
. M.toAscList
$ positionMap
mapLine (p, xs) = intercalate "," . line p $ xs
line p xs = [ label
, show window
, show p
, show . length $ xs
, show . rarefactionViable . rarefactionCurve fastBin $ xs
]
printRarefactionCurve :: Bool -> Label -> Window -> PositionMap -> String
printRarefactionCurve fastBin label window positionMap = header ++ body
where
header = "label,window,position,weight,curve\n"
body = unlines
. map mapLine
. M.toAscList
$ positionMap
mapLine (p, xs) = intercalate "," . line p $ xs
line p xs = [ label
, show window
, show p
, show . length $ xs
, intercalate "/" . map show . rarefactionCurve fastBin $ xs
]