{-# LANGUAGE DeriveGeneric #-}
module TLynx.Coalesce.Options
( CoalesceArguments (..),
coalesceArguments,
reportCoalesceArguments,
coalesceFooter,
)
where
import Data.List
import ELynx.Tools
import Options.Applicative
data CoalesceArguments = CoalesceArguments
{
argsNTrees :: Int,
argsNLeaves :: Int,
argsRho :: Maybe Double,
argsSumStat :: Bool,
argsSeed :: Seed
}
deriving (Eq, Show, Generic)
instance Reproducible CoalesceArguments where
inFiles _ = []
outSuffixes _ = [".tree"]
getSeed = Just . argsSeed
setSeed a s = a {argsSeed = Fixed s}
parser = coalesceArguments
cmdName = "coalesce"
cmdDsc =
[ "Simulate phylogenetic trees using the coalescent processes (see also the 'simulate' command for simulations using the birth and death process)."
]
cmdFtr = coalesceFooter
instance FromJSON CoalesceArguments
instance ToJSON CoalesceArguments
reportCoalesceArguments :: CoalesceArguments -> String
reportCoalesceArguments a =
intercalate
"\n"
[ "Number of simulated trees: " ++ show (argsNTrees a),
"Number of leaves per tree: " ++ show (argsNLeaves a),
"Sub-sampling: " ++ ssStr,
"Summary statistics only: " ++ show (argsSumStat a)
]
where
ssStr = case argsRho a of
Nothing -> "No"
Just r -> "Yes, with probability " <> show r
coalesceArguments :: Parser CoalesceArguments
coalesceArguments =
CoalesceArguments
<$> nTreeOpt
<*> nLeavesOpt
<*> rhoOpt
<*> sumStatOpt
<*> seedOpt
nTreeOpt :: Parser Int
nTreeOpt =
option auto $
long "nTrees"
<> short 't'
<> metavar "INT"
<> value 10
<> showDefault
<> help "Number of trees"
nLeavesOpt :: Parser Int
nLeavesOpt =
option auto $
long "nLeaves"
<> short 'n'
<> metavar "INT"
<> value 5
<> showDefault
<> help "Number of leaves per tree"
rhoOpt :: Parser (Maybe Double)
rhoOpt =
optional $
option auto $
long "sub-sample"
<> short 'r'
<> metavar "DOUBLE"
<> showDefault
<> help
"Perform random sub-sampling with sampling probability rho (see below)"
sumStatOpt :: Parser Bool
sumStatOpt =
switch $
long "summary-statistics" <> short 's' <> showDefault
<> help
"Only output number of children for each branch"
coalesceFooter :: [String]
coalesceFooter =
[ "Sub-sampling: simulate one big tree with n'=round(n/rho), n'>=n, leaves, and randomly sample sub-trees with n leaves. Hence, with rho=1.0, the same tree is reported over and over again.",
"Summary statistics: only print (NumberOfExtantChildren BranchLength) pairs for each branch of each tree. The trees are separated by a newline character."
]